@Override public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) { MethodSymbol symbol = ASTHelpers.getSymbol(tree); return describeIfObsolete( tree.getQualifierExpression(), ImmutableList.of(symbol.owner.asType()), state); }
private UStaticIdent staticMember(Symbol symbol) { return UStaticIdent.create( (ClassSymbol) symbol.getEnclosingElement(), symbol.getSimpleName(), template(symbol.asType())); }
private static Optional<Fix> linkedListFix(Tree tree, VisitorState state) { Type type = getTargetType(state); if (type == null) { return Optional.empty(); } Types types = state.getTypes(); for (String replacement : ImmutableList.of("java.util.ArrayList", "java.util.ArrayDeque")) { Symbol sym = state.getSymbolFromString(replacement); if (sym == null) { continue; } if (types.isAssignable(types.erasure(sym.asType()), types.erasure(type))) { SuggestedFix.Builder fix = SuggestedFix.builder(); while (tree instanceof ParameterizedTypeTree) { tree = ((ParameterizedTypeTree) tree).getType(); } fix.replace(tree, SuggestedFixes.qualifyType(state, fix, sym)); return Optional.of(fix.build()); } } return Optional.empty(); }
@Nullable private static String matchNaN(ExpressionTree tree) { Symbol sym = ASTHelpers.getSymbol(tree); if (sym != null && sym.owner != null && sym.owner.asType() != null && sym.getSimpleName().contentEquals("NaN")) { if (sym.owner.getQualifiedName().contentEquals("java.lang.Double")) { return "Double"; } else if (sym.owner.getQualifiedName().contentEquals("java.lang.Float")) { return "Float"; } } return null; } }
x -> EnumSet.of(TypeKind.INT, TypeKind.LONG) .contains(state.getTypes().unboxedTypeOrType(x.asType()).getKind())) .noneMatch(arg -> arg.isMemberOf(enclosing.enclClass(), state.getTypes()))) {
@Override public Choice<Unifier> visitIdentifier(final IdentifierTree ident, Unifier unifier) { Symbol sym = ASTHelpers.getSymbol(ident); if (sym != null && sym.owner.type != null) { JCExpression thisIdent = unifier.thisExpression(sym.owner.type); return getIdentifier() .unify(ident.getName(), unifier) .thenChoose(unifications(getExpression(), thisIdent)) .thenChoose(unifications(type(), sym.asType())); } return Choice.none(); }
@Override protected Choice<Unifier> defaultAction(Tree node, Unifier unifier) { Symbol symbol = ASTHelpers.getSymbol(node); if (symbol != null) { return classIdent() .unify(symbol.getEnclosingElement(), unifier) .thenChoose(unifications(getName(), symbol.getSimpleName())) .thenChoose(unifications(memberType(), symbol.asType())); } return Choice.none(); } }
@Override public Choice<Unifier> visitMemberSelect(MemberSelectTree fieldAccess, Unifier unifier) { if (ASTHelpers.getSymbol(fieldAccess) != null) { return getIdentifier() .unify(fieldAccess.getIdentifier(), unifier) .thenChoose(unifications(getExpression(), fieldAccess.getExpression())) .thenChoose(unifications(type(), ASTHelpers.getSymbol(fieldAccess).asType())); } return Choice.none(); }
Type canonicalType = types.erasure(importedType.asType()); if (canonicalType == null) { return null;
@Override public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) { MethodSymbol symbol = ASTHelpers.getSymbol(tree); return describeIfObsolete( tree.getQualifierExpression(), ImmutableList.of(symbol.owner.asType()), state); }
private UStaticIdent staticMember(Symbol symbol) { return UStaticIdent.create( (ClassSymbol) symbol.getEnclosingElement(), symbol.getSimpleName(), template(symbol.asType())); }
@Override public Symbol visitMemberSelect(MemberSelectTree node, Env<AttrContext> env) { Symbol site = visit(node.getExpression(), env); if (site.kind == ERR) return site; Name name = (Name)node.getIdentifier(); if (site.kind == PCK) { env.toplevel.packge = (PackageSymbol)site; return rs.findIdentInPackage(env, (TypeSymbol)site, name, TYP | PCK); } else { env.enclClass.sym = (ClassSymbol)site; return rs.findMemberType(env, site.asType(), name, (TypeSymbol)site); } }
/** * {@inheritDoc} */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); Scope scope = sym.members().dupUnshared(); List<Type> closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); return new FilteredMemberList(scope); } // where
/** * {@inheritDoc} */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); Scope scope = sym.members().dupUnshared(); List<Type> closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); return new FilteredMemberList(scope); } // where
/** * {@inheritDoc} */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); Scope scope = sym.members().dupUnshared(); List<Type> closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); return new FilteredMemberList(scope); } // where
/** * {@inheritDoc} */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); Scope scope = sym.members().dupUnshared(); List<Type> closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); return new FilteredMemberList(scope); } // where
@Override public Choice<Unifier> visitIdentifier(final IdentifierTree ident, Unifier unifier) { Symbol sym = ASTHelpers.getSymbol(ident); if (sym != null && sym.owner.type != null) { JCExpression thisIdent = unifier.thisExpression(sym.owner.type); return getIdentifier() .unify(ident.getName(), unifier) .thenChoose(unifications(getExpression(), thisIdent)) .thenChoose(unifications(type(), sym.asType())); } return Choice.none(); }
@Override protected Choice<Unifier> defaultAction(Tree node, Unifier unifier) { Symbol symbol = ASTHelpers.getSymbol(node); if (symbol != null) { return classIdent() .unify(symbol.getEnclosingElement(), unifier) .thenChoose(unifications(getName(), symbol.getSimpleName())) .thenChoose(unifications(memberType(), symbol.asType())); } return Choice.none(); } }
@Override public Choice<Unifier> visitMemberSelect(MemberSelectTree fieldAccess, Unifier unifier) { if (ASTHelpers.getSymbol(fieldAccess) != null) { return getIdentifier() .unify(fieldAccess.getIdentifier(), unifier) .thenChoose(unifications(getExpression(), fieldAccess.getExpression())) .thenChoose(unifications(type(), ASTHelpers.getSymbol(fieldAccess).asType())); } return Choice.none(); }