use of com.sun.tools.javac.code.Symbol.MethodSymbol 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.MethodSymbol in project error-prone by google.
the class TypeParameterUnusedInFormals method matchMethod.
@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
if (methodSymbol == null) {
return Description.NO_MATCH;
}
// Only match methods where the return type is just a type parameter.
// e.g. the following is OK: <T> List<T> newArrayList();
TypeVar retType;
switch(methodSymbol.getReturnType().getKind()) {
case TYPEVAR:
retType = (TypeVar) methodSymbol.getReturnType();
break;
default:
return Description.NO_MATCH;
}
if (!methodSymbol.equals(retType.tsym.owner)) {
return Description.NO_MATCH;
}
// e.g.: <T extends Enum<T>> T unsafeEnumDeserializer();
if (retType.bound != null && TypeParameterFinder.visit(retType.bound).contains(retType.tsym)) {
return Description.NO_MATCH;
}
// e.g.: <T> T noop(T t);
for (VarSymbol formalParam : methodSymbol.getParameters()) {
if (TypeParameterFinder.visit(formalParam.type).contains(retType.tsym)) {
return Description.NO_MATCH;
}
}
return describeMatch(tree);
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class UnnecessaryTypeArgument method check.
private Description check(Tree tree, List<? extends Tree> arguments, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(tree);
if (!(sym instanceof MethodSymbol)) {
return Description.NO_MATCH;
}
MethodSymbol methodSymbol = (MethodSymbol) sym;
int expected = methodSymbol.getTypeParameters().size();
int actual = arguments.size();
if (actual <= expected) {
return Description.NO_MATCH;
}
for (MethodSymbol superMethod : ASTHelpers.findSuperMethods(methodSymbol, state.getTypes())) {
if (!superMethod.getTypeParameters().isEmpty()) {
// two types.
return Description.NO_MATCH;
}
}
return describeMatch(tree, buildFix(tree, arguments, state));
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class TryFailThrowable method getMessageSnippet.
private static String getMessageSnippet(StatementTree failStatement, VisitorState state, HasOtherParameters hasOtherParameters) {
ExpressionTree expression = ((ExpressionStatementTree) failStatement).getExpression();
MethodSymbol sym = (MethodSymbol) getSymbol(expression);
String tail = hasOtherParameters == HasOtherParameters.TRUE ? ", " : "";
// The above casts were checked earlier by failOrAssert.
return hasInitialStringParameter(sym, state) ? state.getSourceForNode(((MethodInvocationTree) expression).getArguments().get(0)) + tail : "";
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class MustBeClosedChecker method matchMethodInvocation.
/**
* Check that invocations of methods annotated with {@link MustBeClosed} are called within the
* resource variable initializer of a try-with-resources statement.
*/
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
MethodSymbol msym = getSymbol(tree);
if (msym == null) {
return Description.NO_MATCH;
}
String methodName = msym.getSimpleName().toString();
return matchNewClassOrMethodInvocation(methodName, tree, state);
}
Aggregations