Search in sources :

Example 1 with OfKind

use of com.google.errorprone.refaster.annotation.OfKind in project error-prone by google.

the class UTemplater method visitIdentifier.

@Override
public UExpression visitIdentifier(IdentifierTree tree, Void v) {
    Symbol sym = ASTHelpers.getSymbol(tree);
    if (sym instanceof ClassSymbol) {
        return UClassIdent.create((ClassSymbol) sym);
    } else if (sym != null && sym.isStatic()) {
        return staticMember(sym);
    } else if (freeVariables.containsKey(tree.getName().toString())) {
        VarSymbol symbol = freeVariables.get(tree.getName().toString());
        checkState(symbol == sym);
        UExpression ident = UFreeIdent.create(tree.getName());
        Matches matches = ASTHelpers.getAnnotation(symbol, Matches.class);
        if (matches != null) {
            ident = UMatches.create(getValue(matches), true, ident);
        }
        NotMatches notMatches = ASTHelpers.getAnnotation(symbol, NotMatches.class);
        if (notMatches != null) {
            ident = UMatches.create(getValue(notMatches), false, ident);
        }
        OfKind hasKind = ASTHelpers.getAnnotation(symbol, OfKind.class);
        if (hasKind != null) {
            EnumSet<Kind> allowed = EnumSet.copyOf(Arrays.asList(hasKind.value()));
            ident = UOfKind.create(ident, ImmutableSet.copyOf(allowed));
        }
        // @Repeated annotations need to be checked last.
        Repeated repeated = ASTHelpers.getAnnotation(symbol, Repeated.class);
        if (repeated != null) {
            ident = URepeated.create(tree.getName(), ident);
        }
        return ident;
    }
    if (sym == null) {
        return UTypeVarIdent.create(tree.getName());
    }
    switch(sym.getKind()) {
        case TYPE_PARAMETER:
            return UTypeVarIdent.create(tree.getName());
        default:
            return ULocalVarIdent.create(tree.getName());
    }
}
Also used : Matches(com.google.errorprone.refaster.annotation.Matches) NotMatches(com.google.errorprone.refaster.annotation.NotMatches) OfKind(com.google.errorprone.refaster.annotation.OfKind) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) Kind(com.sun.source.tree.Tree.Kind) OfKind(com.google.errorprone.refaster.annotation.OfKind) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) Repeated(com.google.errorprone.refaster.annotation.Repeated) NotMatches(com.google.errorprone.refaster.annotation.NotMatches)

Aggregations

Matches (com.google.errorprone.refaster.annotation.Matches)1 NotMatches (com.google.errorprone.refaster.annotation.NotMatches)1 OfKind (com.google.errorprone.refaster.annotation.OfKind)1 Repeated (com.google.errorprone.refaster.annotation.Repeated)1 Kind (com.sun.source.tree.Tree.Kind)1 Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)1 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)1