public AnnotationDiscoveryVisitor(BaseProcessingEnvImpl env) { _env = env; _factory = env.getFactory(); _annoToElement = new ManyToMany<>(); }
/** * Remove the key and its associated key/value entries. * Calling removeKey(k) is equivalent to calling remove(k,v) * for every v in getValues(k). * @return true if the key existed in the map prior to removal */ public synchronized boolean removeKey(T1 key) { // Remove all back-references to key. Set<T2> values = _forward.get(key); if (null == values) { // key does not exist in map. assert checkIntegrity(); return false; } for (T2 value : values) { Set<T1> keys = _reverse.get(value); if (null != keys) { keys.remove(key); if (keys.isEmpty()) { _reverse.remove(value); } } } // Now remove the forward references from key. _forward.remove(key); _dirty = true; assert checkIntegrity(); return true; }
/** * Return the set of annotation types that were discovered on the root elements. * This does not include inherited annotations, only those directly on the root * elements. * @return a set of annotation types, possibly empty. */ public Set<TypeElement> getRootAnnotations() { return Collections.unmodifiableSet(_annoToUnit.getKeySet()); }
private void resolveAnnotations( BlockScope scope, Annotation[] annotations, Binding currentBinding) { ASTNode.resolveAnnotations(scope, annotations, currentBinding); for (Annotation annotation : annotations) { AnnotationBinding binding = annotation.getCompilerAnnotation(); if (binding != null) { // binding should be resolved, but in case it's not, ignore it TypeElement anno = (TypeElement)_factory.newElement(binding.getAnnotationType()); Element element = _factory.newElement(currentBinding); _annoToElement.put(anno, element); } } } }
/** * 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)); }
private void resolveAnnotations( BlockScope scope, Annotation[] annotations, Binding currentBinding) { ASTNode.resolveAnnotations(scope, annotations, currentBinding); for (Annotation annotation : annotations) { AnnotationBinding binding = annotation.getCompilerAnnotation(); if (binding != null) { // binding should be resolved, but in case it's not, ignore it TypeElement anno = (TypeElement)_factory.newElement(binding.getAnnotationType()); Element element = _factory.newElement(currentBinding); _annoToElement.put(anno, element); } } } }
/** * 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)); }
/** * Remove the value and its associated key/value entries. * Calling removeValue(v) is equivalent to calling remove(k,v) * for every k in getKeys(v). * @return true if the value existed in the map prior to removal. */ public synchronized boolean removeValue(T2 value) { // Remove any forward references to value Set<T1> keys = _reverse.get(value); if (null == keys) { // value does not exist in map. assert checkIntegrity(); return false; } for (T1 key : keys) { Set<T2> values = _forward.get(key); if (null != values) { values.remove(value); if (values.isEmpty()) { _forward.remove(key); } } } // Now remove the reverse references from value. _reverse.remove(value); _dirty = true; assert checkIntegrity(); return true; }
private void resolveAnnotations( BlockScope scope, Annotation[] annotations, Binding currentBinding) { ASTNode.resolveAnnotations(scope, annotations, currentBinding); for (Annotation annotation : annotations) { AnnotationBinding binding = annotation.getCompilerAnnotation(); if (binding != null) { // binding should be resolved, but in case it's not, ignore it TypeElement anno = (TypeElement)_factory.newElement(binding.getAnnotationType()); Element element = _factory.newElement(currentBinding); _annoToElement.put(anno, element); } } } }
public AnnotationDiscoveryVisitor(BaseProcessingEnvImpl env) { _env = env; _factory = env.getFactory(); _annoToElement = new ManyToMany<>(); }
/** * Return the set of annotation types that were discovered on the root elements. * This does not include inherited annotations, only those directly on the root * elements. * @return a set of annotation types, possibly empty. */ public Set<TypeElement> getRootAnnotations() { return Collections.unmodifiableSet(_annoToUnit.getKeySet()); }
/** * 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)); }
/** * Remove a particular key-value association. This is the inverse * of put(key, value). If the key does not exist, or the value * does not exist, or the association does not exist, this call * has no effect. * @return true if the key/value pair existed in the map prior to removal */ public synchronized boolean remove(T1 key, T2 value) { Set<T2> values = _forward.get(key); if (values == null) { assert checkIntegrity(); return false; } boolean removed = values.remove(value); if (values.isEmpty()) { _forward.remove(key); } if (removed) { _dirty = true; // it existed, so we need to remove from reverse map as well Set<T1> keys = _reverse.get(value); keys.remove(key); if (keys.isEmpty()) { _reverse.remove(value); } } assert checkIntegrity(); return removed; }
private void resolveAnnotations(BlockScope scope, Annotation[] annotations, Binding currentBinding) { int length = annotations == null ? 0 : annotations.length; if (length == 0) return; boolean old = scope.insideTypeAnnotation; scope.insideTypeAnnotation = true; currentBinding.getAnnotationTagBits(); scope.insideTypeAnnotation = old; ElementImpl element = (ElementImpl) _factory.newElement(currentBinding); AnnotationBinding [] annotationBindings = element.getPackedAnnotationBindings(); // discovery is never in terms of repeating annotation. for (AnnotationBinding binding : annotationBindings) { ReferenceBinding annotationType = binding.getAnnotationType(); if (binding != null && Annotation.isAnnotationTargetAllowed(scope, annotationType, currentBinding) ) { // binding should be resolved, but in case it's not, ignore it: it could have been wrapped into a container. TypeElement anno = (TypeElement)_factory.newElement(annotationType); _annoToElement.put(anno, element); } } } }
public AnnotationDiscoveryVisitor(BaseProcessingEnvImpl env) { _env = env; _factory = env.getFactory(); _annoToElement = new ManyToMany<>(); }
/** * Return the set of annotation types that were discovered on the root elements. * This does not include inherited annotations, only those directly on the root * elements. * @return a set of annotation types, possibly empty. */ public Set<TypeElement> getRootAnnotations() { return Collections.unmodifiableSet(_annoToUnit.getKeySet()); }
/** * 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)); }
/** * Remove the key and its associated key/value entries. * Calling removeKey(k) is equivalent to calling remove(k,v) * for every v in getValues(k). * @return true if the key existed in the map prior to removal */ public synchronized boolean removeKey(T1 key) { // Remove all back-references to key. Set<T2> values = _forward.get(key); if (null == values) { // key does not exist in map. assert checkIntegrity(); return false; } for (T2 value : values) { Set<T1> keys = _reverse.get(value); if (null != keys) { keys.remove(key); if (keys.isEmpty()) { _reverse.remove(value); } } } // Now remove the forward references from key. _forward.remove(key); _dirty = true; assert checkIntegrity(); return true; }
private void resolveAnnotations(BlockScope scope, Annotation[] annotations, Binding currentBinding) { int length = annotations == null ? 0 : annotations.length; if (length == 0) return; boolean old = scope.insideTypeAnnotation; scope.insideTypeAnnotation = true; currentBinding.getAnnotationTagBits(); scope.insideTypeAnnotation = old; ElementImpl element = (ElementImpl) _factory.newElement(currentBinding); AnnotationBinding [] annotationBindings = element.getPackedAnnotationBindings(); // discovery is never in terms of repeating annotation. for (AnnotationBinding binding : annotationBindings) { ReferenceBinding annotationType = binding.getAnnotationType(); if (binding != null && Annotation.isAnnotationTargetAllowed(scope, annotationType, currentBinding) ) { // binding should be resolved, but in case it's not, ignore it: it could have been wrapped into a container. TypeElement anno = (TypeElement)_factory.newElement(annotationType); _annoToElement.put(anno, element); } } } }
public AnnotationDiscoveryVisitor(BaseProcessingEnvImpl env) { _env = env; _factory = env.getFactory(); _annoToElement = new ManyToMany<TypeElement, Element>(); }