@Override public Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a) { String canonicalName = a.getCanonicalName(); if (canonicalName == null) { // null for anonymous and local classes or an array of those throw new IllegalArgumentException("Argument must represent an annotation type"); //$NON-NLS-1$ } TypeElement annoType = _processingEnv.getElementUtils().getTypeElement(canonicalName); return getElementsAnnotatedWith(annoType); }
RoundEnvImpl roundEnv = new RoundEnvImpl(units, referenceBindings, isLastRound, _processingEnv); if (_isFirstRound) { _isFirstRound = false; this, roundEnv, roundEnv.getRootAnnotations(), traceProcessorInfo, traceRounds); dispatcher.round();
/** * From the set of root elements and their enclosed elements, return the subset that are annotated * with {@code a}. If {@code a} is annotated with the {@link java.lang.annotation.Inherited} * annotation, include those elements that inherit the annotation from their superclasses. * Note that {@link java.lang.annotation.Inherited} only applies to classes (i.e. TypeElements). */ @Override public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) { if (a.getKind() != ElementKind.ANNOTATION_TYPE) { throw new IllegalArgumentException("Argument must represent an annotation type"); //$NON-NLS-1$ } Binding annoBinding = ((TypeElementImpl)a)._binding; if (0 != (annoBinding.getAnnotationTagBits() & TagBits.AnnotationInherited)) { Set<Element> annotatedElements = new HashSet<>(_annoToUnit.getValues(a)); // For all other root elements that are TypeElements, and for their recursively enclosed // types, add each element if it has a superclass are annotated with 'a' ReferenceBinding annoTypeBinding = (ReferenceBinding) annoBinding; for (TypeElement element : ElementFilter.typesIn(getRootElements())) { ReferenceBinding typeBinding = (ReferenceBinding)((TypeElementImpl)element)._binding; addAnnotatedElements(annoTypeBinding, typeBinding, annotatedElements); } return Collections.unmodifiableSet(annotatedElements); } return Collections.unmodifiableSet(_annoToUnit.getValues(a)); }
/** * For every type in types that is a class and that is annotated with anno, either directly or by inheritance, * add that type to result. Recursively descend on each types's child classes as well. * @param anno the compiler binding for an annotation type * @param type a type, not necessarily a class * @param result must be a modifiable Set; will accumulate annotated classes */ private void addAnnotatedElements(ReferenceBinding anno, ReferenceBinding type, Set<Element> result) { if (type.isClass()) { if (inheritsAnno(type, anno)) { result.add(_factory.newElement(type)); } } for (ReferenceBinding element : type.memberTypes()) { addAnnotatedElements(anno, element, result); } }
public RoundEnvImpl(CompilationUnitDeclaration[] units, ReferenceBinding[] binaryTypeBindings, boolean isLastRound, BaseProcessingEnvImpl env) { _processingEnv = env; _isLastRound = isLastRound; _units = units; _factory = _processingEnv.getFactory(); // Discover the annotations that will be passed to Processor.process() AnnotationDiscoveryVisitor visitor = new AnnotationDiscoveryVisitor(_processingEnv); if (_units != null) { for (CompilationUnitDeclaration unit : _units) { unit.traverse(visitor, unit.scope); } } _annoToUnit = visitor._annoToElement; if (binaryTypeBindings != null) collectAnnotations(binaryTypeBindings); _binaryTypes = binaryTypeBindings; }
@Override public Set<? extends Element> getRootElements() { return recordProcessedSources(() -> super.getRootElements()); }
@Override public void processAnnotations(CompilationUnitDeclaration[] units, ReferenceBinding[] referenceBindings, boolean isLastRound) { if (!isLastRound && suppressRegularRounds) { return; } if (isLastRound && suppressLastRound) { return; } RoundEnvImpl roundEnv = new _RoundEnvImpl(units, referenceBindings, isLastRound, _processingEnv); if (_isFirstRound) { _isFirstRound = false; } PrintWriter traceProcessorInfo = _printProcessorInfo ? _out : null; PrintWriter traceRounds = _printRounds ? _out : null; if (traceRounds != null) { traceRounds.println("Round " + ++_round + ':'); //$NON-NLS-1$ } RoundDispatcher dispatcher = new RoundDispatcher(this, roundEnv, roundEnv.getRootAnnotations(), traceProcessorInfo, traceRounds); dispatcher.round(); }
/** * For every type in types that is a class and that is annotated with anno, either directly or by inheritance, * add that type to result. Recursively descend on each types's child classes as well. * @param anno the compiler binding for an annotation type * @param type a type, not necessarily a class * @param result must be a modifiable Set; will accumulate annotated classes */ private void addAnnotatedElements(ReferenceBinding anno, ReferenceBinding type, Set<Element> result) { if (type.isClass()) { if (inheritsAnno(type, anno)) { result.add(_factory.newElement(type)); } } for (ReferenceBinding element : type.memberTypes()) { addAnnotatedElements(anno, element, result); } }
public RoundEnvImpl(CompilationUnitDeclaration[] units, ReferenceBinding[] binaryTypeBindings, boolean isLastRound, BaseProcessingEnvImpl env) { _processingEnv = env; _isLastRound = isLastRound; _units = units; _factory = _processingEnv.getFactory(); // Discover the annotations that will be passed to Processor.process() AnnotationDiscoveryVisitor visitor = new AnnotationDiscoveryVisitor(_processingEnv); if (_units != null) { for (CompilationUnitDeclaration unit : _units) { unit.traverse(visitor, unit.scope); } } _annoToUnit = visitor._annoToElement; if (binaryTypeBindings != null) collectAnnotations(binaryTypeBindings); _binaryTypes = binaryTypeBindings; }
@Override public Set<? extends Element> getRootElements() { return recordProcessedSources(() -> super.getRootElements()); }
@Override public void processAnnotations(CompilationUnitDeclaration[] units, ReferenceBinding[] referenceBindings, boolean isLastRound) { if (!isLastRound && suppressRegularRounds) { return; } if (isLastRound && suppressLastRound) { return; } RoundEnvImpl roundEnv = new _RoundEnvImpl(units, referenceBindings, isLastRound, _processingEnv); if (_isFirstRound) { _isFirstRound = false; } PrintWriter traceProcessorInfo = _printProcessorInfo ? _out : null; PrintWriter traceRounds = _printRounds ? _out : null; if (traceRounds != null) { traceRounds.println("Round " + ++_round + ':'); //$NON-NLS-1$ } RoundDispatcher dispatcher = new RoundDispatcher(this, roundEnv, roundEnv.getRootAnnotations(), traceProcessorInfo, traceRounds); dispatcher.round(); }
/** * From the set of root elements and their enclosed elements, return the subset that are annotated * with {@code a}. If {@code a} is annotated with the {@link java.lang.annotation.Inherited} * annotation, include those elements that inherit the annotation from their superclasses. * Note that {@link java.lang.annotation.Inherited} only applies to classes (i.e. TypeElements). */ @Override public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) { if (a.getKind() != ElementKind.ANNOTATION_TYPE) { throw new IllegalArgumentException("Argument must represent an annotation type"); //$NON-NLS-1$ } Binding annoBinding = ((TypeElementImpl)a)._binding; if (0 != (annoBinding.getAnnotationTagBits() & TagBits.AnnotationInherited)) { Set<Element> annotatedElements = new HashSet<>(_annoToUnit.getValues(a)); // For all other root elements that are TypeElements, and for their recursively enclosed // types, add each element if it has a superclass are annotated with 'a' ReferenceBinding annoTypeBinding = (ReferenceBinding) annoBinding; for (TypeElement element : ElementFilter.typesIn(getRootElements())) { ReferenceBinding typeBinding = (ReferenceBinding)((TypeElementImpl)element)._binding; addAnnotatedElements(annoTypeBinding, typeBinding, annotatedElements); } return Collections.unmodifiableSet(annotatedElements); } return Collections.unmodifiableSet(_annoToUnit.getValues(a)); }
RoundEnvImpl roundEnv = new RoundEnvImpl(units, referenceBindings, isLastRound, _processingEnv); if (_isFirstRound) { _isFirstRound = false; this, roundEnv, roundEnv.getRootAnnotations(), traceProcessorInfo, traceRounds); dispatcher.round();
/** * For every type in types that is a class and that is annotated with anno, either directly or by inheritance, * add that type to result. Recursively descend on each types's child classes as well. * @param anno the compiler binding for an annotation type * @param type a type, not necessarily a class * @param result must be a modifiable Set; will accumulate annotated classes */ private void addAnnotatedElements(ReferenceBinding anno, ReferenceBinding type, Set<Element> result) { if (type.isClass()) { if (inheritsAnno(type, anno)) { result.add(_factory.newElement(type)); } } for (ReferenceBinding element : type.memberTypes()) { addAnnotatedElements(anno, element, result); } }
public RoundEnvImpl(CompilationUnitDeclaration[] units, ReferenceBinding[] binaryTypeBindings, boolean isLastRound, BaseProcessingEnvImpl env) { _processingEnv = env; _isLastRound = isLastRound; _units = units; _factory = _processingEnv.getFactory(); // Discover the annotations that will be passed to Processor.process() AnnotationDiscoveryVisitor visitor = new AnnotationDiscoveryVisitor(_processingEnv); if (_units != null) { for (CompilationUnitDeclaration unit : _units) { unit.traverse(visitor, unit.scope); } } _annoToUnit = visitor._annoToElement; if (binaryTypeBindings != null) collectAnnotations(binaryTypeBindings); _binaryTypes = binaryTypeBindings; }
@Override public Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a) { String canonicalName = a.getCanonicalName(); if (canonicalName == null) { // null for anonymous and local classes or an array of those throw new IllegalArgumentException("Argument must represent an annotation type"); //$NON-NLS-1$ } TypeElement annoType = _processingEnv.getElementUtils().getTypeElement(canonicalName); return getElementsAnnotatedWith(annoType); }
/** * From the set of root elements and their enclosed elements, return the subset that are annotated * with {@code a}. If {@code a} is annotated with the {@link java.lang.annotation.Inherited} * annotation, include those elements that inherit the annotation from their superclasses. * Note that {@link java.lang.annotation.Inherited} only applies to classes (i.e. TypeElements). */ @Override public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) { if (a.getKind() != ElementKind.ANNOTATION_TYPE) { throw new IllegalArgumentException("Argument must represent an annotation type"); //$NON-NLS-1$ } Binding annoBinding = ((TypeElementImpl)a)._binding; if (0 != (annoBinding.getAnnotationTagBits() & TagBits.AnnotationInherited)) { Set<Element> annotatedElements = new HashSet<Element>(_annoToUnit.getValues(a)); // For all other root elements that are TypeElements, and for their recursively enclosed // types, add each element if it has a superclass are annotated with 'a' ReferenceBinding annoTypeBinding = (ReferenceBinding) annoBinding; for (TypeElement element : ElementFilter.typesIn(getRootElements())) { ReferenceBinding typeBinding = (ReferenceBinding)((TypeElementImpl)element)._binding; addAnnotatedElements(annoTypeBinding, typeBinding, annotatedElements); } return Collections.unmodifiableSet(annotatedElements); } return Collections.unmodifiableSet(_annoToUnit.getValues(a)); }
RoundEnvImpl roundEnv = new RoundEnvImpl(units, referenceBindings, isLastRound, _processingEnv); if (_isFirstRound) { _isFirstRound = false; this, roundEnv, roundEnv.getRootAnnotations(), traceProcessorInfo, traceRounds); dispatcher.round();
/** * For every type in types that is a class and that is annotated with anno, either directly or by inheritance, * add that type to result. Recursively descend on each types's child classes as well. * @param anno the compiler binding for an annotation type * @param types a set of types, not necessarily all classes * @param result must be a modifiable Set; will accumulate annotated classes */ private void addAnnotatedElements(ReferenceBinding anno, ReferenceBinding type, Set<Element> result) { if (type.isClass()) { if (inheritsAnno(type, anno)) { result.add(_factory.newElement(type)); } } for (ReferenceBinding element : type.memberTypes()) { addAnnotatedElements(anno, element, result); } }
public RoundEnvImpl(CompilationUnitDeclaration[] units, ReferenceBinding[] binaryTypeBindings, boolean isLastRound, BaseProcessingEnvImpl env) { _processingEnv = env; _isLastRound = isLastRound; _units = units; _factory = _processingEnv.getFactory(); // Discover the annotations that will be passed to Processor.process() AnnotationDiscoveryVisitor visitor = new AnnotationDiscoveryVisitor(_processingEnv); if (_units != null) { for (CompilationUnitDeclaration unit : _units) { unit.scope.suppressImportErrors = true; unit.traverse(visitor, unit.scope); unit.scope.suppressImportErrors = false; } } _annoToUnit = visitor._annoToElement; if (binaryTypeBindings != null) collectAnnotations(binaryTypeBindings); _binaryTypes = binaryTypeBindings; }