use of com.sun.tools.javac.tree.JCTree.JCFieldAccess in project lombok by rzwitserloot.
the class HandleLog method processAnnotation.
public static void processAnnotation(LoggingFramework framework, AnnotationValues<?> annotation, JavacNode annotationNode, String loggerTopic) {
deleteAnnotationIfNeccessary(annotationNode, framework.getAnnotationClass());
JavacNode typeNode = annotationNode.up();
switch(typeNode.getKind()) {
case TYPE:
String logFieldName = annotationNode.getAst().readConfiguration(ConfigurationKeys.LOG_ANY_FIELD_NAME);
if (logFieldName == null)
logFieldName = "log";
boolean useStatic = !Boolean.FALSE.equals(annotationNode.getAst().readConfiguration(ConfigurationKeys.LOG_ANY_FIELD_IS_STATIC));
if ((((JCClassDecl) typeNode.get()).mods.flags & Flags.INTERFACE) != 0) {
annotationNode.addError("@Log is legal only on classes and enums.");
return;
}
if (fieldExists(logFieldName, typeNode) != MemberExistsResult.NOT_EXISTS) {
annotationNode.addWarning("Field '" + logFieldName + "' already exists.");
return;
}
JCFieldAccess loggingType = selfType(typeNode);
createField(framework, typeNode, loggingType, annotationNode.get(), logFieldName, useStatic, loggerTopic);
break;
default:
annotationNode.addError("@Log is legal only on types.");
break;
}
}
use of com.sun.tools.javac.tree.JCTree.JCFieldAccess in project lombok by rzwitserloot.
the class PrettyPrinter method visitApply.
@Override
public void visitApply(JCMethodInvocation tree) {
if (tree.typeargs.nonEmpty()) {
if (tree.meth instanceof JCFieldAccess) {
JCFieldAccess fa = (JCFieldAccess) tree.meth;
print(fa.selected);
print(".<");
print(tree.typeargs, ", ");
print(">");
print(fa.name);
} else {
print("<");
print(tree.typeargs, ", ");
print(">");
print(tree.meth);
}
} else {
print(tree.meth);
}
print("(");
print(tree.args, ", ");
print(")");
}
use of com.sun.tools.javac.tree.JCTree.JCFieldAccess in project error-prone by google.
the class ProtoFieldNullComparison 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 error-prone by google.
the class ProtoFieldNullComparison method isGetMethodInvocation.
private static boolean isGetMethodInvocation(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 error-prone by google.
the class ASTHelpers method getRootAssignable.
/**
* Find the root assignable expression of a chain of field accesses. If there is no root
* (i.e, a bare method call or a static method call), return null.
*
* <p>Examples:
* <pre>
* {@code
* a.trim().intern() ==> a
* a.b.trim().intern() ==> a.b
* this.intValue.foo() ==> this.intValue
* this.foo() ==> this
* intern() ==> null
* String.format() ==> null
* java.lang.String.format() ==> null
* }
* </pre>
*/
public static ExpressionTree getRootAssignable(MethodInvocationTree methodInvocationTree) {
if (!(methodInvocationTree instanceof JCMethodInvocation)) {
throw new IllegalArgumentException("Expected type to be JCMethodInvocation, but was " + methodInvocationTree.getClass());
}
// Check for bare method call, e.g. intern().
if (((JCMethodInvocation) methodInvocationTree).getMethodSelect() instanceof JCIdent) {
return null;
}
// Unwrap the field accesses until you get to an identifier.
ExpressionTree expr = methodInvocationTree;
while (expr instanceof JCMethodInvocation) {
expr = ((JCMethodInvocation) expr).getMethodSelect();
if (expr instanceof JCFieldAccess) {
expr = ((JCFieldAccess) expr).getExpression();
}
}
// We only want assignable identifiers.
Symbol sym = getSymbol(expr);
if (sym instanceof VarSymbol) {
return expr;
}
return null;
}
Aggregations