use of com.sun.tools.javac.code.Symbol in project lombok by rzwitserloot.
the class HandleExtensionMethod method getExtension.
public Extension getExtension(final JavacNode typeNode, final ClassType extensionMethodProviderType) {
List<MethodSymbol> extensionMethods = new ArrayList<MethodSymbol>();
TypeSymbol tsym = extensionMethodProviderType.asElement();
if (tsym != null)
for (Symbol member : tsym.getEnclosedElements()) {
if (member.getKind() != ElementKind.METHOD)
continue;
MethodSymbol method = (MethodSymbol) member;
if ((method.flags() & (STATIC | PUBLIC)) == 0)
continue;
if (method.params().isEmpty())
continue;
extensionMethods.add(method);
}
return new Extension(extensionMethods, tsym);
}
use of com.sun.tools.javac.code.Symbol in project bazel by bazelbuild.
the class StrictJavaDepsPlugin method isAnnotationProcessorExempt.
/**
* Returns true if the compilation unit contains a single top-level class generated by an exempt
* annotation processor (according to its {@link @Generated} annotation).
*
* <p>Annotation processors are expected to never generate more than one top level class, as
* required by the style guide.
*/
public ProcessorDependencyMode isAnnotationProcessorExempt(JCTree.JCCompilationUnit unit) {
if (unit.getTypeDecls().size() != 1) {
return ProcessorDependencyMode.DEFAULT;
}
Symbol sym = TreeInfo.symbolFor(getOnlyElement(unit.getTypeDecls()));
if (sym == null) {
return ProcessorDependencyMode.DEFAULT;
}
Generated generated = sym.getAnnotation(Generated.class);
if (generated == null) {
return ProcessorDependencyMode.DEFAULT;
}
for (String value : generated.value()) {
// Relax strict deps for dagger-generated code (b/17979436).
if (value.startsWith(DAGGER_PROCESSOR_PREFIX)) {
return ProcessorDependencyMode.EXEMPT_NORECORD;
}
if (dependencyModule.getExemptGenerators().contains(value)) {
return ProcessorDependencyMode.EXEMPT_RECORD;
}
}
return ProcessorDependencyMode.DEFAULT;
}
use of com.sun.tools.javac.code.Symbol in project error-prone by google.
the class FilesLinesLeak method inTWR.
private boolean inTWR(VisitorState state) {
TreePath path = state.getPath().getParentPath();
while (path.getLeaf().getKind() == Tree.Kind.CONDITIONAL_EXPRESSION) {
path = path.getParentPath();
}
Symbol sym = ASTHelpers.getSymbol(path.getLeaf());
return sym != null && sym.getKind() == ElementKind.RESOURCE_VARIABLE;
}
use of com.sun.tools.javac.code.Symbol in project error-prone by google.
the class CompileTimeConstantChecker method handleMatch.
/**
* If the non-constant variable is annotated with @CompileTimeConstant, it must have been
* non-final. Suggest making it final in the error message.
*/
private Description handleMatch(ExpressionTree actualParam, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(actualParam);
if (!(sym instanceof VarSymbol)) {
return describeMatch(actualParam);
}
VarSymbol var = (VarSymbol) sym;
if (!hasCompileTimeConstantAnnotation(state, var)) {
return describeMatch(actualParam);
}
return buildDescription(actualParam).setMessage(this.message() + String.format(DID_YOU_MEAN_FINAL_FMT_MESSAGE, var.getSimpleName())).build();
}
use of com.sun.tools.javac.code.Symbol in project error-prone by google.
the class DefaultCharset method variableTypeFix.
private void variableTypeFix(SuggestedFix.Builder fix, VisitorState state, Class<?> original, Class<?> replacement) {
Tree parent = state.getPath().getParentPath().getLeaf();
Symbol sym;
switch(parent.getKind()) {
case VARIABLE:
sym = ASTHelpers.getSymbol((VariableTree) parent);
break;
case ASSIGNMENT:
sym = ASTHelpers.getSymbol(((AssignmentTree) parent).getVariable());
break;
default:
return;
}
if (!ASTHelpers.isSameType(sym.type, state.getTypeFromString(original.getCanonicalName()), state)) {
return;
}
state.getPath().getCompilationUnit().accept(new TreeScanner<Void, Void>() {
@Override
public Void visitVariable(VariableTree node, Void aVoid) {
if (sym.equals(ASTHelpers.getSymbol(node))) {
fix.replace(node.getType(), replacement.getSimpleName()).addImport(replacement.getCanonicalName());
}
return null;
}
}, null);
}
Aggregations