static ClassAndMethod make(MethodSymbol methodSymbol, @Nullable Types types) { // TODO(b/71812955): consider just wrapping methodSymbol instead of copying everything out. ImmutableList<String> annotations = MoreAnnotations.getDeclarationAndTypeAttributes(methodSymbol) .map(Object::toString) .collect(toImmutableList()); ClassSymbol clazzSymbol = (ClassSymbol) methodSymbol.owner; return new ClassAndMethod( clazzSymbol.getQualifiedName().toString(), methodSymbol.getSimpleName().toString(), annotations, methodSymbol.isStatic(), methodSymbol.getReturnType().isPrimitive(), methodSymbol.getReturnType().getTag() == BOOLEAN, hasGenericResult(methodSymbol), knownNonNullMethod(methodSymbol, clazzSymbol, types)); }
if (msym.getParameters().stream() .noneMatch(p -> maybeFunctionalInterface(p.type, types, state))) { continue; if (msym.isConstructor() && !msym.owner.equals(origin)) { continue; if (msym.getParameters().stream() .noneMatch(p -> maybeFunctionalInterface(p.type, types, state))) { continue; ImmutableList<MethodSymbol> overrides = clash.stream() .filter(m -> msym2.overrides(m, origin, types, /*checkResult=*/ false)) .collect(toImmutableList()); worklist.addAll(overrides);
MethodSymbol sym = ASTHelpers.getSymbol(tree); if (sym == null || !sym.isStatic() || !Flags.asFlagSet(sym.flags()).contains(Flag.NATIVE)) { return NO_MATCH; if (enclosing == null || enclosing.isStatic() || enclosing.isConstructor()) { return NO_MATCH; EnumSet.of(TypeKind.INT, TypeKind.LONG) .contains(state.getTypes().unboxedTypeOrType(x.asType()).getKind())) .noneMatch(arg -> arg.isMemberOf(enclosing.enclClass(), state.getTypes()))) { arg -> arg.getSimpleName().contentEquals("this") && arg.isMemberOf(enclosing.enclClass(), state.getTypes()))) { Symbol finalizeSym = getFinalizer(state, enclosing.enclClass()); if (finalizeSym == null || finalizeSym.equals(enclosing)) {
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) { Symbol javadocSymbol = getElement(path); if (javadocSymbol == null) return null; ElementKind kind = javadocSymbol.getKind(); List<? extends Symbol> params = List.nil(); if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) { MethodSymbol ee = (MethodSymbol) javadocSymbol; params = ptag.isTypeParameter() ? ee.getTypeParameters() : ee.getParameters(); } else if (kind.isClass() || kind.isInterface()) { ClassSymbol te = (ClassSymbol) javadocSymbol; params = te.getTypeParameters(); } for (Symbol param : params) { if (param.getSimpleName() == ptag.getName().getName()) { return param; } } return null; }
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) { Symbol javadocSymbol = getElement(path); if (javadocSymbol == null) return null; ElementKind kind = javadocSymbol.getKind(); List<? extends Symbol> params = List.nil(); if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) { MethodSymbol ee = (MethodSymbol) javadocSymbol; params = ptag.isTypeParameter() ? ee.getTypeParameters() : ee.getParameters(); } else if (kind.isClass() || kind.isInterface()) { ClassSymbol te = (ClassSymbol) javadocSymbol; params = te.getTypeParameters(); } for (Symbol param : params) { if (param.getSimpleName() == ptag.getName().getName()) { return param; } } return null; }
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()) { // Exempt methods that override generic methods to preserve the substitutability of the // two types. return Description.NO_MATCH; } } return describeMatch(tree, buildFix(tree, arguments, state)); }
/** * Returns true if this element represents a method which * implements a method in an interface the parent class implements. */ public boolean implementsMethod(ExecutableElement element) { MethodSymbol m = (MethodSymbol)element; TypeSymbol owner = (TypeSymbol) m.owner; for (Type type : jctypes.interfaces(m.owner.type)) { for (Symbol sym : type.tsym.members().getSymbolsByName(m.name)) { if (m.overrides(sym, owner, jctypes, true)) return true; } } return false; }
/** * Returns {@code true} for {@link MethodSymbol}s of generic methods where one of the method's * type parameters <b>is</b> the result type, {@code false} otherwise. */ private static boolean hasGenericResult(MethodSymbol methodSymbol) { Type resultType = methodSymbol.getReturnType(); for (TypeVariableSymbol var : methodSymbol.getTypeParameters()) { if (resultType.tsym.equals(var)) { return true; } } return false; }
void checkOverride(JCTree tree, Type site, ClassSymbol origin, MethodSymbol m) { TypeSymbol c = site.tsym; Scope.Entry e = c.members().lookup(m.name); while (e.scope != null) { if (m.overrides(e.sym, origin, types, false)) { if ((e.sym.flags() & ABSTRACT) == 0) { checkOverride(tree, m, (MethodSymbol)e.sym, origin); } } e = e.next(); } }
/** Clone this symbol with new owner. */ public MethodSymbol clone(Symbol newOwner) { MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) { @Override public Symbol baseSymbol() { return MethodSymbol.this; } }; m.code = code; return m; }
/** * Create new synthetic method with given flags, name, type, owner */ private MethodSymbol makePrivateSyntheticMethod(long flags, Name name, Type type, Symbol owner) { return new MethodSymbol(flags | SYNTHETIC | PRIVATE, name, type, owner); }
void checkOverride(JCTree tree, Type site, ClassSymbol origin, MethodSymbol m) { TypeSymbol c = site.tsym; Scope.Entry e = c.members().lookup(m.name); while (e.scope != null) { if (m.overrides(e.sym, origin, types, false)) { if ((e.sym.flags() & ABSTRACT) == 0) { checkOverride(tree, m, (MethodSymbol)e.sym, origin); } } e = e.next(); } }
/** Clone this symbol with new owner. */ public MethodSymbol clone(Symbol newOwner) { MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner); m.code = code; return m; }
/** Clone this symbol with new owner. */ public MethodSymbol clone(Symbol newOwner) { MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner); m.code = code; return m; }
public void visitBlock(JCBlock tree) { MethodSymbol oldMethodSym = currentMethodSym; if (currentMethodSym == null) { // Block is a static or instance initializer. currentMethodSym = new MethodSymbol(tree.flags | BLOCK, names.empty, null, currentClass); } super.visitBlock(tree); currentMethodSym = oldMethodSym; }
@Override public void visitMethodDef(JCMethodDecl that) { initTypeIfNeeded(that); if (that.sym == null) { that.sym = new MethodSymbol(0, that.name, that.type, syms.noSymbol); } super.visitMethodDef(that); }
public void visitBlock(JCBlock tree) { MethodSymbol oldMethodSym = currentMethodSym; if (currentMethodSym == null) { // Block is a static or instance initializer. currentMethodSym = new MethodSymbol(tree.flags | BLOCK, names.empty, null, currentClass); } super.visitBlock(tree); currentMethodSym = oldMethodSym; }
public void visitBlock(JCBlock tree) { MethodSymbol oldMethodSym = currentMethodSym; if (currentMethodSym == null) { // Block is a static or instance initializer. currentMethodSym = new MethodSymbol(tree.flags | BLOCK, names.empty, null, currentClass); } super.visitBlock(tree); currentMethodSym = oldMethodSym; }
@Override public void visitNewClass(JCNewClass that) { if (that.constructor == null) { that.constructor = new MethodSymbol(0, names.init, syms.unknownType, syms.noSymbol); } if (that.constructorType == null) { that.constructorType = syms.unknownType; } super.visitNewClass(that); }
@Override protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { Scope sc = new Scope(syms.arrayClass); MethodSymbol arrayConstr = new MethodSymbol(PUBLIC, name, null, site.tsym); arrayConstr.type = new MethodType(List.<Type>of(syms.intType), site, List.<Type>nil(), syms.methodClass); sc.enter(arrayConstr); return findMethodInScope(env, site, name, argtypes, typeargtypes, sc, methodNotFound, phase.isBoxingRequired(), phase.isVarargsRequired(), false, false); }