com.sun.tools.javac.code.Attribute.Compound Java Examples
The following examples show how to use
com.sun.tools.javac.code.Attribute.Compound.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UTemplater.java From Refaster with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public static ImmutableClassToInstanceMap<Annotation> annotationMap(Symbol symbol) { ImmutableClassToInstanceMap.Builder<Annotation> builder = ImmutableClassToInstanceMap.builder(); for (Compound compound : symbol.getAnnotationMirrors()) { Name qualifiedAnnotationType = ((TypeElement) compound.getAnnotationType().asElement()).getQualifiedName(); try { Class<? extends Annotation> annotationClazz = Class.forName(qualifiedAnnotationType.toString()).asSubclass(Annotation.class); builder.put((Class) annotationClazz, AnnotationProxyMaker.generateAnnotation(compound, annotationClazz)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Unrecognized annotation type", e); } } return builder.build(); }
Example #2
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, pos); }
Example #3
Source File: Check.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } }
Example #4
Source File: Check.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, pos); }
Example #5
Source File: Check.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, pos); }
Example #6
Source File: Check.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } }
Example #7
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@DefinedBy(Api.LANGUAGE_MODEL) public Map<MethodSymbol, Attribute> getElementValuesWithDefaults( AnnotationMirror a) { Attribute.Compound anno = cast(Attribute.Compound.class, a); DeclaredType annotype = a.getAnnotationType(); Map<MethodSymbol, Attribute> valmap = anno.getElementValues(); for (ExecutableElement ex : methodsIn(annotype.asElement().getEnclosedElements())) { MethodSymbol meth = (MethodSymbol) ex; Attribute defaultValue = meth.getDefaultValue(); if (defaultValue != null && !valmap.containsKey(meth)) { valmap.put(meth, defaultValue); } } return valmap; }
Example #8
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Returns all annotations of an element, whether * inherited or directly present. * * @param e the element being examined * @return all annotations of the element */ @Override @DefinedBy(Api.LANGUAGE_MODEL) public List<Attribute.Compound> getAllAnnotationMirrors(Element e) { Symbol sym = cast(Symbol.class, e); List<Attribute.Compound> annos = sym.getAnnotationMirrors(); while (sym.getKind() == ElementKind.CLASS) { Type sup = ((ClassSymbol) sym).getSuperclass(); if (!sup.hasTag(CLASS) || sup.isErroneous() || sup.tsym == syms.objectType.tsym) { break; } sym = sup.tsym; List<Attribute.Compound> oldAnnos = annos; List<Attribute.Compound> newAnnos = sym.getAnnotationMirrors(); for (Attribute.Compound anno : newAnnos) { if (isInherited(anno.type) && !containsAnnoOfType(oldAnnos, anno.type)) { annos = annos.prepend(anno); } } } return annos; }
Example #9
Source File: Check.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } }
Example #10
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, Errors.BadFunctionalIntfAnno1(ex.getDiagnostic())); } } }
Example #11
Source File: Annotate.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Fetches the actual Type that should be the containing annotation. */ private Type getContainingType(Attribute.Compound currentAnno, DiagnosticPosition pos, boolean reportError) { Type origAnnoType = currentAnno.type; TypeSymbol origAnnoDecl = origAnnoType.tsym; // Fetch the Repeatable annotation from the current // annotation's declaration, or null if it has none Attribute.Compound ca = origAnnoDecl.getAnnotationTypeMetadata().getRepeatable(); if (ca == null) { // has no Repeatable annotation if (reportError) log.error(pos, Errors.DuplicateAnnotationMissingContainer(origAnnoType)); return null; } return filterSame(extractContainingType(ca, pos, origAnnoDecl), origAnnoType); }
Example #12
Source File: Annotate.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private <T extends Attribute.Compound> T makeContainerAnnotation(List<T> toBeReplaced, AnnotationContext<T> ctx, Symbol sym, boolean isTypeParam) { // Process repeated annotations T validRepeated = processRepeatedAnnotations(toBeReplaced, ctx, sym, isTypeParam); if (validRepeated != null) { // Check that the container isn't manually // present along with repeated instances of // its contained annotation. ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym); if (manualContainer != null) { log.error(ctx.pos.get(manualContainer.first()), Errors.InvalidRepeatableAnnotationRepeatedAndContainerPresent(manualContainer.first().type.tsym)); } } // A null return will delete the Placeholder return validRepeated; }
Example #13
Source File: Check.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, pos); }
Example #14
Source File: Check.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, pos); }
Example #15
Source File: JavacElements.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@DefinedBy(Api.LANGUAGE_MODEL) public Map<MethodSymbol, Attribute> getElementValuesWithDefaults( AnnotationMirror a) { Attribute.Compound anno = cast(Attribute.Compound.class, a); DeclaredType annotype = a.getAnnotationType(); Map<MethodSymbol, Attribute> valmap = anno.getElementValues(); for (ExecutableElement ex : methodsIn(annotype.asElement().getEnclosedElements())) { MethodSymbol meth = (MethodSymbol) ex; Attribute defaultValue = meth.getDefaultValue(); if (defaultValue != null && !valmap.containsKey(meth)) { valmap.put(meth, defaultValue); } } return valmap; }
Example #16
Source File: JavacElements.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns all annotations of an element, whether * inherited or directly present. * * @param e the element being examined * @return all annotations of the element */ @Override @DefinedBy(Api.LANGUAGE_MODEL) public List<Attribute.Compound> getAllAnnotationMirrors(Element e) { Symbol sym = cast(Symbol.class, e); List<Attribute.Compound> annos = sym.getAnnotationMirrors(); while (sym.getKind() == ElementKind.CLASS) { Type sup = ((ClassSymbol) sym).getSuperclass(); if (!sup.hasTag(CLASS) || sup.isErroneous() || sup.tsym == syms.objectType.tsym) { break; } sym = sup.tsym; List<Attribute.Compound> oldAnnos = annos; List<Attribute.Compound> newAnnos = sym.getAnnotationMirrors(); for (Attribute.Compound anno : newAnnos) { if (isInherited(anno.type) && !containsAnnoOfType(oldAnnos, anno.type)) { annos = annos.prepend(anno); } } } return annos; }
Example #17
Source File: Check.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, pos); }
Example #18
Source File: Check.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } }
Example #19
Source File: Annotate.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Fetches the actual Type that should be the containing annotation. */ private Type getContainingType(Attribute.Compound currentAnno, DiagnosticPosition pos, boolean reportError) { Type origAnnoType = currentAnno.type; TypeSymbol origAnnoDecl = origAnnoType.tsym; // Fetch the Repeatable annotation from the current // annotation's declaration, or null if it has none Attribute.Compound ca = origAnnoDecl.getAnnotationTypeMetadata().getRepeatable(); if (ca == null) { // has no Repeatable annotation if (reportError) log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.repeatableType); return null; } return filterSame(extractContainingType(ca, pos, origAnnoDecl), origAnnoType); }
Example #20
Source File: Annotate.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private <T extends Attribute.Compound> T makeContainerAnnotation(List<T> toBeReplaced, AnnotationContext<T> ctx, Symbol sym, boolean isTypeParam) { // Process repeated annotations T validRepeated = processRepeatedAnnotations(toBeReplaced, ctx, sym, isTypeParam); if (validRepeated != null) { // Check that the container isn't manually // present along with repeated instances of // its contained annotation. ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym); if (manualContainer != null) { log.error(ctx.pos.get(manualContainer.first()), "invalid.repeatable.annotation.repeated.and.container.present", manualContainer.first().type.tsym); } } // A null return will delete the Placeholder return validRepeated; }
Example #21
Source File: Check.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, pos); }
Example #22
Source File: Check.java From hottub with GNU General Public License v2.0 | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } }
Example #23
Source File: Check.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, s, pos); }
Example #24
Source File: Check.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } }
Example #25
Source File: Check.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Validate the proposed container 'repeatable' on the * annotation type symbol 's'. Report errors at position * 'pos'. * * @param s The (annotation)type declaration annotated with a @Repeatable * @param repeatable the @Repeatable on 's' * @param pos where to report errors */ public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) { Assert.check(types.isSameType(repeatable.type, syms.repeatableType)); Type t = null; List<Pair<MethodSymbol,Attribute>> l = repeatable.values; if (!l.isEmpty()) { Assert.check(l.head.fst.name == names.value); t = ((Attribute.Class)l.head.snd).getValue(); } if (t == null) { // errors should already have been reported during Annotate return; } validateValue(t.tsym, s, pos); validateRetention(t.tsym, s, pos); validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); validateDefault(t.tsym, s, pos); }
Example #26
Source File: Check.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } }
Example #27
Source File: Check.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) { Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym); if (functionalType != null) { try { types.findDescriptorSymbol((TypeSymbol)cs); } catch (Types.FunctionDescriptorLookupError ex) { DiagnosticPosition pos = tree.pos(); for (JCAnnotation a : tree.getModifiers().annotations) { if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { pos = a.pos(); break; } } log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } }
Example #28
Source File: Check.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
Attribute.Array getAttributeTargetAttribute(Symbol s) { Attribute.Compound atTarget = s.attribute(syms.annotationTargetType.tsym); if (atTarget == null) return null; // ok, is applicable Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) return null; // error recovery return (Attribute.Array) atValue; }
Example #29
Source File: Check.java From hottub with GNU General Public License v2.0 | 5 votes |
/** Is the annotation applicable to types? */ protected boolean isTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { Attribute.Compound atTarget = a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); if (atTarget == null) { // An annotation without @Target is not a type annotation. return false; } Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) { return false; // error recovery } Attribute.Array arr = (Attribute.Array) atValue; for (Attribute app : arr.values) { if (!(app instanceof Attribute.Enum)) { return false; // recovery } Attribute.Enum e = (Attribute.Enum) app; if (e.value.name == names.TYPE_USE) return true; else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER) return true; } return false; }
Example #30
Source File: Check.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** Is the annotation applicable to types? */ protected boolean isTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { Attribute.Compound atTarget = a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); if (atTarget == null) { // An annotation without @Target is not a type annotation. return false; } Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) { return false; // error recovery } Attribute.Array arr = (Attribute.Array) atValue; for (Attribute app : arr.values) { if (!(app instanceof Attribute.Enum)) { return false; // recovery } Attribute.Enum e = (Attribute.Enum) app; if (e.value.name == names.TYPE_USE) return true; else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER) return true; } return false; }