Search in sources :

Example 26 with JCFieldAccess

use of com.sun.tools.javac.tree.JCTree.JCFieldAccess in project error-prone by google.

the class ProtoFieldPreconditionsCheckNotNull method isGetListMethodInvocation.

private static boolean isGetListMethodInvocation(ExpressionTree tree, VisitorState state) {
    if (tree.getKind() == Tree.Kind.METHOD_INVOCATION) {
        MethodInvocationTree method = (MethodInvocationTree) tree;
        if (!method.getArguments().isEmpty()) {
            return false;
        }
        if (!returnsListMatcher.matches(method, state)) {
            return false;
        }
        ExpressionTree expressionTree = method.getMethodSelect();
        if (expressionTree instanceof JCFieldAccess) {
            JCFieldAccess access = (JCFieldAccess) expressionTree;
            String methodName = access.sym.getQualifiedName().toString();
            return isFieldGetMethod(methodName);
        }
        return true;
    }
    return false;
}
Also used : JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) ExpressionTree(com.sun.source.tree.ExpressionTree)

Example 27 with JCFieldAccess

use of com.sun.tools.javac.tree.JCTree.JCFieldAccess in project lombok by rzwitserloot.

the class PrettyPrinter method printAnnotatedType0.

private void printAnnotatedType0(JCTree tree) {
    JCTree underlyingType = readObject(tree, "underlyingType", (JCTree) null);
    if (underlyingType instanceof JCFieldAccess) {
        print(((JCFieldAccess) underlyingType).selected);
        print(".");
        print(readObject(tree, "annotations", List.<JCExpression>nil()), " ");
        print(" ");
        print(((JCFieldAccess) underlyingType).name);
    } else {
        print(readObject(tree, "annotations", List.<JCExpression>nil()), " ");
        print(" ");
        print(underlyingType);
    }
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) JCTree(com.sun.tools.javac.tree.JCTree)

Example 28 with JCFieldAccess

use of com.sun.tools.javac.tree.JCTree.JCFieldAccess in project lombok by rzwitserloot.

the class JavacHandlerUtil method isConstructorCall.

public static boolean isConstructorCall(final JCStatement statement) {
    if (!(statement instanceof JCExpressionStatement))
        return false;
    JCExpression expr = ((JCExpressionStatement) statement).expr;
    if (!(expr instanceof JCMethodInvocation))
        return false;
    JCExpression invocation = ((JCMethodInvocation) expr).meth;
    String name;
    if (invocation instanceof JCFieldAccess) {
        name = ((JCFieldAccess) invocation).name.toString();
    } else if (invocation instanceof JCIdent) {
        name = ((JCIdent) invocation).name.toString();
    } else {
        name = "";
    }
    return "super".equals(name) || "this".equals(name);
}
Also used : JCMethodInvocation(com.sun.tools.javac.tree.JCTree.JCMethodInvocation) JCIdent(com.sun.tools.javac.tree.JCTree.JCIdent) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) JCExpressionStatement(com.sun.tools.javac.tree.JCTree.JCExpressionStatement)

Example 29 with JCFieldAccess

use of com.sun.tools.javac.tree.JCTree.JCFieldAccess in project lombok by rzwitserloot.

the class JavacHandlerUtil method cloneType0.

private static JCExpression cloneType0(JavacTreeMaker maker, JCTree in) {
    if (in == null)
        return null;
    if (in instanceof JCPrimitiveTypeTree)
        return (JCExpression) in;
    if (in instanceof JCIdent) {
        return maker.Ident(((JCIdent) in).name);
    }
    if (in instanceof JCFieldAccess) {
        JCFieldAccess fa = (JCFieldAccess) in;
        return maker.Select(cloneType0(maker, fa.selected), fa.name);
    }
    if (in instanceof JCArrayTypeTree) {
        JCArrayTypeTree att = (JCArrayTypeTree) in;
        return maker.TypeArray(cloneType0(maker, att.elemtype));
    }
    if (in instanceof JCTypeApply) {
        JCTypeApply ta = (JCTypeApply) in;
        ListBuffer<JCExpression> lb = new ListBuffer<JCExpression>();
        for (JCExpression typeArg : ta.arguments) {
            lb.append(cloneType0(maker, typeArg));
        }
        return maker.TypeApply(cloneType0(maker, ta.clazz), lb.toList());
    }
    if (in instanceof JCWildcard) {
        JCWildcard w = (JCWildcard) in;
        JCExpression newInner = cloneType0(maker, w.inner);
        TypeBoundKind newKind;
        switch(w.getKind()) {
            case SUPER_WILDCARD:
                newKind = maker.TypeBoundKind(BoundKind.SUPER);
                break;
            case EXTENDS_WILDCARD:
                newKind = maker.TypeBoundKind(BoundKind.EXTENDS);
                break;
            default:
            case UNBOUNDED_WILDCARD:
                newKind = maker.TypeBoundKind(BoundKind.UNBOUND);
                break;
        }
        return maker.Wildcard(newKind, newInner);
    }
    // This is somewhat unsafe, but it's better than outright throwing an exception here. Returning null will just cause an exception down the pipeline.
    return (JCExpression) in;
}
Also used : JCWildcard(com.sun.tools.javac.tree.JCTree.JCWildcard) JCPrimitiveTypeTree(com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCIdent(com.sun.tools.javac.tree.JCTree.JCIdent) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTypeApply(com.sun.tools.javac.tree.JCTree.JCTypeApply) JCArrayTypeTree(com.sun.tools.javac.tree.JCTree.JCArrayTypeTree) TypeBoundKind(com.sun.tools.javac.tree.JCTree.TypeBoundKind)

Example 30 with JCFieldAccess

use of com.sun.tools.javac.tree.JCTree.JCFieldAccess in project lombok by rzwitserloot.

the class JavacImportList method hasStarImport.

@Override
public boolean hasStarImport(String packageName) {
    if (pkgStr != null && pkgStr.equals(packageName))
        return true;
    if ("java.lang".equals(packageName))
        return true;
    if (pkgStr != null) {
        Collection<String> extra = LombokInternalAliasing.IMPLIED_EXTRA_STAR_IMPORTS.get(pkgStr);
        if (extra != null && extra.contains(packageName))
            return true;
    }
    for (JCTree def : defs) {
        if (!(def instanceof JCImport))
            continue;
        if (((JCImport) def).staticImport)
            continue;
        JCTree qual = ((JCImport) def).qualid;
        if (!(qual instanceof JCFieldAccess))
            continue;
        String simpleName = ((JCFieldAccess) qual).name.toString();
        if (!"*".equals(simpleName))
            continue;
        String starImport = ((JCFieldAccess) qual).selected.toString();
        if (packageName.equals(starImport))
            return true;
        Collection<String> extra = LombokInternalAliasing.IMPLIED_EXTRA_STAR_IMPORTS.get(starImport);
        if (extra != null && extra.contains(packageName))
            return true;
    }
    return false;
}
Also used : JCImport(com.sun.tools.javac.tree.JCTree.JCImport) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) JCTree(com.sun.tools.javac.tree.JCTree)

Aggregations

JCFieldAccess (com.sun.tools.javac.tree.JCTree.JCFieldAccess)35 JCTree (com.sun.tools.javac.tree.JCTree)13 ExpressionTree (com.sun.source.tree.ExpressionTree)12 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)11 JCIdent (com.sun.tools.javac.tree.JCTree.JCIdent)11 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)8 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)7 Type (com.sun.tools.javac.code.Type)6 ListBuffer (com.sun.tools.javac.util.ListBuffer)6 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)5 JCImport (com.sun.tools.javac.tree.JCTree.JCImport)5 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)5 Name (com.sun.tools.javac.util.Name)5 SuggestedFix (com.google.errorprone.fixes.SuggestedFix)4 Symbol (com.sun.tools.javac.code.Symbol)4 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)4 JCTypeApply (com.sun.tools.javac.tree.JCTree.JCTypeApply)4 JavacTreeMaker (lombok.javac.JavacTreeMaker)4 Fix (com.google.errorprone.fixes.Fix)3 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)3