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;
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations