public int match(Annotation node, MatchingNodeSet nodeSet) { if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; MemberValuePair[] pairs = node.memberValuePairs(); if (pairs == null || pairs.length == 0) return IMPOSSIBLE_MATCH; int length = pairs.length; MemberValuePair pair = null; for (int i=0; i<length; i++) { pair = node.memberValuePairs()[i]; if (matchesName(this.pattern.selector, pair.name)) { ASTNode possibleNode = (node instanceof SingleMemberAnnotation) ? (ASTNode) node : pair; return nodeSet.addMatch(possibleNode, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } } return IMPOSSIBLE_MATCH; } //public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
public int match(Annotation node, MatchingNodeSet nodeSet) { if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; MemberValuePair[] pairs = node.memberValuePairs(); if (pairs == null || pairs.length == 0) return IMPOSSIBLE_MATCH; int length = pairs.length; MemberValuePair pair = null; for (int i=0; i<length; i++) { pair = node.memberValuePairs()[i]; if (matchesName(this.pattern.selector, pair.name)) { ASTNode possibleNode = (node instanceof SingleMemberAnnotation) ? (ASTNode) node : pair; return nodeSet.addMatch(possibleNode, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } } return IMPOSSIBLE_MATCH; } //public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
public int match(Annotation node, MatchingNodeSet nodeSet) { if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; MemberValuePair[] pairs = node.memberValuePairs(); if (pairs == null || pairs.length == 0) return IMPOSSIBLE_MATCH; int length = pairs.length; MemberValuePair pair = null; for (int i=0; i<length; i++) { pair = node.memberValuePairs()[i]; if (matchesName(this.pattern.selector, pair.name)) { ASTNode possibleNode = (node instanceof SingleMemberAnnotation) ? (ASTNode) node : pair; return nodeSet.addMatch(possibleNode, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } } return IMPOSSIBLE_MATCH; } //public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
public int match(Annotation node, MatchingNodeSet nodeSet) { if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; MemberValuePair[] pairs = node.memberValuePairs(); if (pairs == null || pairs.length == 0) return IMPOSSIBLE_MATCH; int length = pairs.length; MemberValuePair pair = null; for (int i=0; i<length; i++) { pair = node.memberValuePairs()[i]; if (matchesName(this.pattern.selector, pair.name)) { ASTNode possibleNode = (node instanceof SingleMemberAnnotation) ? (ASTNode) node : pair; return nodeSet.addMatch(possibleNode, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } } return IMPOSSIBLE_MATCH; } //public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
@Override public int match(Annotation node, MatchingNodeSet nodeSet) { if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; MemberValuePair[] pairs = node.memberValuePairs(); if (pairs == null || pairs.length == 0) return IMPOSSIBLE_MATCH; int length = pairs.length; MemberValuePair pair = null; for (int i=0; i<length; i++) { pair = node.memberValuePairs()[i]; if (matchesName(this.pattern.selector, pair.name)) { ASTNode possibleNode = (node instanceof SingleMemberAnnotation) ? (ASTNode) node : pair; return nodeSet.addMatch(possibleNode, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } } return IMPOSSIBLE_MATCH; } //public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
public int match(Annotation node, MatchingNodeSet nodeSet) { if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; MemberValuePair[] pairs = node.memberValuePairs(); if (pairs == null || pairs.length == 0) return IMPOSSIBLE_MATCH; int length = pairs.length; MemberValuePair pair = null; for (int i=0; i<length; i++) { pair = node.memberValuePairs()[i]; if (matchesName(this.pattern.selector, pair.name)) { ASTNode possibleNode = (node instanceof SingleMemberAnnotation) ? (ASTNode) node : pair; return nodeSet.addMatch(possibleNode, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } } return IMPOSSIBLE_MATCH; } //public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
boolean isValueProvidedUsingAnnotation(FieldDeclaration fieldDecl) { // a member field annotated with @Inject is considered to be initialized by the injector if (fieldDecl.annotations != null) { int length = fieldDecl.annotations.length; for (int i = 0; i < length; i++) { Annotation annotation = fieldDecl.annotations[i]; if (annotation.resolvedType.id == TypeIds.T_JavaxInjectInject) { return true; // no concept of "optional" } else if (annotation.resolvedType.id == TypeIds.T_ComGoogleInjectInject) { MemberValuePair[] memberValuePairs = annotation.memberValuePairs(); if (memberValuePairs == Annotation.NoValuePairs) return true; for (int j = 0; j < memberValuePairs.length; j++) { // if "optional=false" is specified, don't rely on initialization by the injector: if (CharOperation.equals(memberValuePairs[j].name, TypeConstants.OPTIONAL)) return memberValuePairs[j].value instanceof FalseLiteral; } } } } return false; }
boolean isValueProvidedUsingAnnotation(FieldDeclaration fieldDecl) { // a member field annotated with @Inject is considered to be initialized by the injector if (fieldDecl.annotations != null) { int length = fieldDecl.annotations.length; for (int i = 0; i < length; i++) { Annotation annotation = fieldDecl.annotations[i]; if (annotation.resolvedType.id == TypeIds.T_JavaxInjectInject) { return true; // no concept of "optional" } else if (annotation.resolvedType.id == TypeIds.T_ComGoogleInjectInject) { MemberValuePair[] memberValuePairs = annotation.memberValuePairs(); if (memberValuePairs == Annotation.NoValuePairs) return true; for (int j = 0; j < memberValuePairs.length; j++) { // if "optional=false" is specified, don't rely on initialization by the injector: if (CharOperation.equals(memberValuePairs[j].name, TypeConstants.OPTIONAL)) return memberValuePairs[j].value instanceof FalseLiteral; } } } } return false; }
boolean isValueProvidedUsingAnnotation(FieldDeclaration fieldDecl) { // a member field annotated with @Inject is considered to be initialized by the injector if (fieldDecl.annotations != null) { int length = fieldDecl.annotations.length; for (int i = 0; i < length; i++) { Annotation annotation = fieldDecl.annotations[i]; if (annotation.resolvedType.id == TypeIds.T_JavaxInjectInject) { return true; // no concept of "optional" } else if (annotation.resolvedType.id == TypeIds.T_ComGoogleInjectInject) { MemberValuePair[] memberValuePairs = annotation.memberValuePairs(); if (memberValuePairs == Annotation.NoValuePairs) return true; for (int j = 0; j < memberValuePairs.length; j++) { // if "optional=false" is specified, don't rely on initialization by the injector: if (CharOperation.equals(memberValuePairs[j].name, TypeConstants.OPTIONAL)) return memberValuePairs[j].value instanceof FalseLiteral; } } } } return false; }
public void checkRepeatableMetaAnnotation(BlockScope scope) { // `this' is the @Repeatable meta annotation, its recipient is the *repeatable* annotation type - we are at the declaration site, not the repeating use site. ReferenceBinding repeatableAnnotationType = (ReferenceBinding) this.recipient; // know it to be an annotation type. On target miss we don't get here MemberValuePair[] valuePairs = this.memberValuePairs(); if (valuePairs == null || valuePairs.length != 1) return; Object value = valuePairs[0].compilerElementPair.value; if (!(value instanceof ReferenceBinding)) return; // Has deeper problems, will bark elsewhere. ReferenceBinding containerAnnotationType = (ReferenceBinding) value; if (!containerAnnotationType.isAnnotationType()) return; // Has deeper problems, will bark elsewhere. repeatableAnnotationType.setContainerAnnotationType(containerAnnotationType); // For now. May be reset later to PRB in case of problems. checkContainerAnnotationType(valuePairs[0], scope, containerAnnotationType, repeatableAnnotationType, false); // false => not use site, i.e declaration site error reporting requested. }
public void checkRepeatableMetaAnnotation(BlockScope scope) { // `this' is the @Repeatable meta annotation, its recipient is the *repeatable* annotation type - we are at the declaration site, not the repeating use site. ReferenceBinding repeatableAnnotationType = (ReferenceBinding) this.recipient; // know it to be an annotation type. On target miss we don't get here MemberValuePair[] valuePairs = this.memberValuePairs(); if (valuePairs == null || valuePairs.length != 1) return; Object value = valuePairs[0].compilerElementPair.value; if (!(value instanceof ReferenceBinding)) return; // Has deeper problems, will bark elsewhere. ReferenceBinding containerAnnotationType = (ReferenceBinding) value; if (!containerAnnotationType.isAnnotationType()) return; // Has deeper problems, will bark elsewhere. repeatableAnnotationType.setContainerAnnotationType(containerAnnotationType); // For now. May be reset later to PRB in case of problems. checkContainerAnnotationType(valuePairs[0], scope, containerAnnotationType, repeatableAnnotationType, false); // false => not use site, i.e declaration site error reporting requested. }
public void checkRepeatableMetaAnnotation(BlockScope scope) { // `this' is the @Repeatable meta annotation, its recipient is the *repeatable* annotation type - we are at the declaration site, not the repeating use site. ReferenceBinding repeatableAnnotationType = (ReferenceBinding) this.recipient; // know it to be an annotation type. On target miss we don't get here MemberValuePair[] valuePairs = this.memberValuePairs(); if (valuePairs == null || valuePairs.length != 1) return; Object value = valuePairs[0].compilerElementPair.value; if (!(value instanceof ReferenceBinding)) return; // Has deeper problems, will bark elsewhere. ReferenceBinding containerAnnotationType = (ReferenceBinding) value; if (!containerAnnotationType.isAnnotationType()) return; // Has deeper problems, will bark elsewhere. repeatableAnnotationType.setContainerAnnotationType(containerAnnotationType); // For now. May be reset later to PRB in case of problems. checkContainerAnnotationType(valuePairs[0], scope, containerAnnotationType, repeatableAnnotationType, false); // false => not use site, i.e declaration site error reporting requested. }
public void checkRepeatableMetaAnnotation(BlockScope scope) { // `this' is the @Repeatable meta annotation, its recipient is the *repeatable* annotation type - we are at the declaration site, not the repeating use site. ReferenceBinding repeatableAnnotationType = (ReferenceBinding) this.recipient; // know it to be an annotation type. On target miss we don't get here MemberValuePair[] valuePairs = this.memberValuePairs(); if (valuePairs == null || valuePairs.length != 1) return; Object value = valuePairs[0].compilerElementPair.value; if (!(value instanceof ReferenceBinding)) return; // Has deeper problems, will bark elsewhere. ReferenceBinding containerAnnotationType = (ReferenceBinding) value; if (!containerAnnotationType.isAnnotationType()) return; // Has deeper problems, will bark elsewhere. repeatableAnnotationType.setContainerAnnotationType(containerAnnotationType); // For now. May be reset later to PRB in case of problems. checkContainerAnnotationType(valuePairs[0], scope, containerAnnotationType, repeatableAnnotationType, false); // false => not use site, i.e declaration site error reporting requested. }
public void checkRepeatableMetaAnnotation(BlockScope scope) { // `this' is the @Repeatable meta annotation, its recipient is the *repeatable* annotation type - we are at the declaration site, not the repeating use site. ReferenceBinding repeatableAnnotationType = (ReferenceBinding) this.recipient; // know it to be an annotation type. On target miss we don't get here MemberValuePair[] valuePairs = this.memberValuePairs(); if (valuePairs == null || valuePairs.length != 1) return; Object value = valuePairs[0].compilerElementPair.value; if (!(value instanceof ReferenceBinding)) return; // Has deeper problems, will bark elsewhere. ReferenceBinding containerAnnotationType = (ReferenceBinding) value; if (!containerAnnotationType.isAnnotationType()) return; // Has deeper problems, will bark elsewhere. repeatableAnnotationType.setContainerAnnotationType(containerAnnotationType); // For now. May be reset later to PRB in case of problems. checkContainerAnnotationType(valuePairs[0], scope, containerAnnotationType, repeatableAnnotationType, false); // false => not use site, i.e declaration site error reporting requested. }
public void checkRepeatableMetaAnnotation(BlockScope scope) { // `this' is the @Repeatable meta annotation, its recipient is the *repeatable* annotation type - we are at the declaration site, not the repeating use site. ReferenceBinding repeatableAnnotationType = (ReferenceBinding) this.recipient; // know it to be an annotation type. On target miss we don't get here MemberValuePair[] valuePairs = this.memberValuePairs(); if (valuePairs == null || valuePairs.length != 1) return; Object value = valuePairs[0].compilerElementPair.value; if (!(value instanceof ReferenceBinding)) return; // Has deeper problems, will bark elsewhere. ReferenceBinding containerAnnotationType = (ReferenceBinding) value; if (!containerAnnotationType.isAnnotationType()) return; // Has deeper problems, will bark elsewhere. repeatableAnnotationType.setContainerAnnotationType(containerAnnotationType); // For now. May be reset later to PRB in case of problems. checkContainerAnnotationType(valuePairs[0], scope, containerAnnotationType, repeatableAnnotationType, false); // false => not use site, i.e declaration site error reporting requested. }
public void checkRepeatableMetaAnnotation(BlockScope scope) { // `this' is the @Repeatable meta annotation, its recipient is the *repeatable* annotation type - we are at the declaration site, not the repeating use site. ReferenceBinding repeatableAnnotationType = (ReferenceBinding) this.recipient; // know it to be an annotation type. On target miss we don't get here MemberValuePair[] valuePairs = this.memberValuePairs(); if (valuePairs == null || valuePairs.length != 1) return; Object value = valuePairs[0].compilerElementPair.value; if (!(value instanceof ReferenceBinding)) return; // Has deeper problems, will bark elsewhere. ReferenceBinding containerAnnotationType = (ReferenceBinding) value; if (!containerAnnotationType.isAnnotationType()) return; // Has deeper problems, will bark elsewhere. repeatableAnnotationType.setContainerAnnotationType(containerAnnotationType); // For now. May be reset later to PRB in case of problems. checkContainerAnnotationType(valuePairs[0], scope, containerAnnotationType, repeatableAnnotationType, false); // false => not use site, i.e declaration site error reporting requested. }
public void checkRepeatableMetaAnnotation(BlockScope scope) { // `this' is the @Repeatable meta annotation, its recipient is the *repeatable* annotation type - we are at the declaration site, not the repeating use site. ReferenceBinding repeatableAnnotationType = (ReferenceBinding) this.recipient; // know it to be an annotation type. On target miss we don't get here MemberValuePair[] valuePairs = this.memberValuePairs(); if (valuePairs == null || valuePairs.length != 1) return; Object value = valuePairs[0].compilerElementPair.value; if (!(value instanceof ReferenceBinding)) return; // Has deeper problems, will bark elsewhere. ReferenceBinding containerAnnotationType = (ReferenceBinding) value; if (!containerAnnotationType.isAnnotationType()) return; // Has deeper problems, will bark elsewhere. repeatableAnnotationType.setContainerAnnotationType(containerAnnotationType); // For now. May be reset later to PRB in case of problems. checkContainerAnnotationType(valuePairs[0], scope, containerAnnotationType, repeatableAnnotationType, false); // false => not use site, i.e declaration site error reporting requested. }
public AnnotationData createData(@NonNull String name, @NonNull Annotation annotation) { MemberValuePair[] pairs = annotation.memberValuePairs(); if (pairs == null || pairs.length == 0) { return new AnnotationData(name); } return new AnnotationData(name, pairs); }
public AnnotationData createData(@NonNull String name, @NonNull Annotation annotation) { MemberValuePair[] pairs = annotation.memberValuePairs(); if (pairs == null || pairs.length == 0) { return new AnnotationData(name); } return new AnnotationData(name, pairs); }
private static Annotation findAnnotation(Annotation elementAnnotation, AnnotationBinding annotationBinding) { if (annotationBinding == elementAnnotation.getCompilerAnnotation()) { return elementAnnotation; } MemberValuePair[] memberValuePairs = elementAnnotation.memberValuePairs(); for (MemberValuePair mvp : memberValuePairs) { Expression v = mvp.value; if (v instanceof Annotation) { Annotation a = findAnnotation((Annotation) v, annotationBinding); if (a != null) { return a; } } else if (v instanceof ArrayInitializer) { Expression[] expressions = ((ArrayInitializer) v).expressions; for (Expression e : expressions) { if (e instanceof Annotation) { Annotation a = findAnnotation((Annotation) e, annotationBinding); if (a != null) { return a; } } } } } return null; }