private static boolean hasAttribute(Symbol symbol, String name, VisitorState state) { Symbol annotation = state.getSymbolFromString(name); // If we can't look up the annotation in the current VisitorState, then presumably it couldn't // be present on a Symbol we're inspecting. return annotation != null && symbol.attribute(annotation) != null; }
private static boolean isInherited(VisitorState state, String annotationName) { Symbol annotationSym = state.getSymbolFromString(annotationName); if (annotationSym == null) { return false; } try { annotationSym.complete(); } catch (CompletionFailure e) { // @Inherited won't work if the annotation isn't on the classpath, but we can still check // if it's present directly } Symbol inheritedSym = state.getSymtab().inheritedType.tsym; return annotationSym.attribute(inheritedSym) != null; }
/** * Returns whether {@code anno} corresponds to a type annotation, or {@code null} if it could not * be determined. */ @Nullable public static AnnotationType getAnnotationType( AnnotationTree anno, @Nullable Symbol target, VisitorState state) { if (target == null) { return null; } Symbol annoSymbol = getSymbol(anno); if (annoSymbol == null) { return null; } Compound compound = target.attribute(annoSymbol); if (compound == null) { for (TypeCompound typeCompound : target.getRawTypeAttributes()) { if (typeCompound.type.tsym.equals(annoSymbol)) { compound = typeCompound; break; } } } if (compound == null) { return null; } return TypeAnnotations.instance(state.context).annotationTargetType(compound, target); }
/** * Reports a dep-ann error for a declaration if: (1) javadoc contains the deprecated javadoc tag * (2) the declaration is not annotated with {@link java.lang.Deprecated} */ @SuppressWarnings("javadoc") private Description checkDeprecatedAnnotation(Tree tree, VisitorState state) { Symbol symbol = ASTHelpers.getSymbol(tree); // (1) // javac sets the DEPRECATED bit in flags if the Javadoc contains @deprecated if ((symbol.flags() & DEPRECATED) == 0) { return Description.NO_MATCH; } // (2) if (symbol.attribute(state.getSymtab().deprecatedType.tsym) != null) { return Description.NO_MATCH; } return describeMatch(tree, SuggestedFix.prefixWith(tree, "@Deprecated\n")); } }
private void validateDocumented(Symbol container, Symbol contained, DiagnosticPosition pos) { if (contained.attribute(syms.documentedType.tsym) != null) { if (container.attribute(syms.documentedType.tsym) == null) { log.error(pos, "invalid.repeatable.annotation.not.documented", container, contained); } } }
private void validateInherited(Symbol container, Symbol contained, DiagnosticPosition pos) { if (contained.attribute(syms.inheritedType.tsym) != null) { if (container.attribute(syms.inheritedType.tsym) == null) { log.error(pos, "invalid.repeatable.annotation.not.inherited", container, contained); } } }
private void validateInherited(Symbol container, Symbol contained, DiagnosticPosition pos) { if (contained.attribute(syms.inheritedType.tsym) != null) { if (container.attribute(syms.inheritedType.tsym) == null) { log.error(pos, "invalid.repeatable.annotation.not.inherited", container, contained); } } }
private void validateDocumented(Symbol container, Symbol contained, DiagnosticPosition pos) { if (contained.attribute(syms.documentedType.tsym) != null) { if (container.attribute(syms.documentedType.tsym) == null) { log.error(pos, "invalid.repeatable.annotation.not.documented", container, contained); } } }
private static boolean hasAttribute(Symbol symbol, String name, VisitorState state) { Symbol annotation = state.getSymbolFromString(name); // If we can't look up the annotation in the current VisitorState, then presumably it couldn't // be present on a Symbol we're inspecting. return annotation != null && symbol.attribute(annotation) != null; }
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; }
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; }
public RetentionPolicy getRetention(Symbol sym) { RetentionPolicy vis = RetentionPolicy.CLASS; // the default Attribute.Compound c = sym.attribute(syms.retentionType.tsym); if (c != null) { Attribute value = c.member(names.value); if (value != null && value instanceof Attribute.Enum) { Name levelName = ((Attribute.Enum)value).value.name; if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; else ;// /* fail soft */ throw new AssertionError(levelName); } } return vis; } // </editor-fold>
public RetentionPolicy getRetention(Symbol sym) { RetentionPolicy vis = RetentionPolicy.CLASS; // the default Attribute.Compound c = sym.attribute(syms.retentionType.tsym); if (c != null) { Attribute value = c.member(names.value); if (value != null && value instanceof Attribute.Enum) { Name levelName = ((Attribute.Enum)value).value.name; if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; else ;// /* fail soft */ throw new AssertionError(levelName); } } return vis; } // </editor-fold>
private static boolean isInherited(VisitorState state, String annotationName) { Symbol annotationSym = state.getSymbolFromString(annotationName); if (annotationSym == null) { return false; } try { annotationSym.complete(); } catch (CompletionFailure e) { // @Inherited won't work if the annotation isn't on the classpath, but we can still check // if it's present directly } Symbol inheritedSym = state.getSymtab().inheritedType.tsym; return annotationSym.attribute(inheritedSym) != null; }
/** * Returns whether {@code anno} corresponds to a type annotation, or {@code null} if it could not * be determined. */ @Nullable public static AnnotationType getAnnotationType( AnnotationTree anno, @Nullable Symbol target, VisitorState state) { if (target == null) { return null; } Symbol annoSymbol = getSymbol(anno); if (annoSymbol == null) { return null; } Compound compound = target.attribute(annoSymbol); if (compound == null) { for (TypeCompound typeCompound : target.getRawTypeAttributes()) { if (typeCompound.type.tsym.equals(annoSymbol)) { compound = typeCompound; break; } } } if (compound == null) { return null; } return TypeAnnotations.instance(state.context).annotationTargetType(compound, target); }
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { if (allowAnnotations && lint.isEnabled(Lint.LintCategory.DEP_ANN) && (s.flags() & DEPRECATED) != 0 && !syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) == null) { log.warning(pos, "missing.deprecated.annotation"); } }
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { if (allowAnnotations && lint.isEnabled(Lint.LintCategory.DEP_ANN) && (s.flags() & DEPRECATED) != 0 && !syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) == null) { log.warning(pos, "missing.deprecated.annotation"); } }
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { if (allowAnnotations && lint.isEnabled(LintCategory.DEP_ANN) && (s.flags() & DEPRECATED) != 0 && !syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) == null) { log.warning(LintCategory.DEP_ANN, pos, "missing.deprecated.annotation"); } }
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { if (allowAnnotations && lint.isEnabled(LintCategory.DEP_ANN) && (s.flags() & DEPRECATED) != 0 && !syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) == null) { log.warning(LintCategory.DEP_ANN, pos, "missing.deprecated.annotation"); } }
/** * Reports a dep-ann error for a declaration if: (1) javadoc contains the deprecated javadoc tag * (2) the declaration is not annotated with {@link java.lang.Deprecated} */ @SuppressWarnings("javadoc") private Description checkDeprecatedAnnotation(Tree tree, VisitorState state) { Symbol symbol = ASTHelpers.getSymbol(tree); // (1) // javac sets the DEPRECATED bit in flags if the Javadoc contains @deprecated if ((symbol.flags() & DEPRECATED) == 0) { return Description.NO_MATCH; } // (2) if (symbol.attribute(state.getSymtab().deprecatedType.tsym) != null) { return Description.NO_MATCH; } return describeMatch(tree, SuggestedFix.prefixWith(tree, "@Deprecated\n")); } }