@Override public boolean matches(Tree tree, VisitorState visitorState) { if (!(tree instanceof NewClassTree)) { return false; } NewClassTree newClassTree = (NewClassTree) tree; if (newClassTree.getClassBody() == null) { return false; } return newClassTree.getClassBody().getMembers().stream() .filter(mem -> mem instanceof VariableTree) .anyMatch(mem -> !isFinal(mem)); }
@Override public Description matchNewClass(NewClassTree tree, VisitorState state) { ClassTree body = tree.getClassBody(); if (body == null) { return NO_MATCH;
@Override public Description matchNewClass(NewClassTree tree, VisitorState state) { if (!matchWithinClass) { return Description.NO_MATCH; } Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree); if (methodSymbol == null) { throw new RuntimeException("not expecting unresolved method here"); } List<? extends ExpressionTree> actualParams = tree.getArguments(); if (tree.getClassBody() != null && actualParams.size() > 0) { // passing parameters to constructor of anonymous class // this constructor just invokes the constructor of the superclass, and // in the AST does not have the parameter nullability annotations from the superclass. // so, treat as if the superclass constructor is being invoked directly // see https://github.com/uber/NullAway/issues/102 methodSymbol = getSymbolOfSuperConstructor(methodSymbol, state); } return handleInvocation(tree, state, methodSymbol, actualParams); }
Set<Modifier> replacementVisibility = Sets.intersection(proposedConstructor.getModifiers(), VISIBILITY_MODIFIERS); if (constructor.getClassBody() == null && !constructorVisibility.equals(replacementVisibility)) { continue;
@Override public UNewClass visitNewClass(NewClassTree tree, Void v) { return UNewClass.create( tree.getEnclosingExpression() == null ? null : template(tree.getEnclosingExpression()), templateTypeExpressions(tree.getTypeArguments()), template(tree.getIdentifier()), templateExpressions(tree.getArguments()), (tree.getClassBody() == null) ? null : visitClass(tree.getClassBody(), null)); }
@Override public Description matchClass(ClassTree tree, VisitorState state) { Tree parent = state.getPath().getParentPath().getLeaf(); if (parent instanceof NewClassTree && tree.equals(((NewClassTree) parent).getClassBody())) { // don't double-report anonymous implementations of obsolete interfaces return NO_MATCH; } ClassSymbol symbol = ASTHelpers.getSymbol(tree); if (symbol == null) { return NO_MATCH; } return describeIfObsolete(null, state.getTypes().directSupertypes(symbol.asType()), state); }
return Description.NO_MATCH; if (newClassTree.getClassBody() == null) { return Description.NO_MATCH; return Description.NO_MATCH; for (Tree def : newClassTree.getClassBody().getMembers()) { switch (def.getKind()) { case VARIABLE:
curr.getKind() == Kind.LAMBDA_EXPRESSION || (curr.getKind() == Kind.NEW_CLASS && ((NewClassTree) curr).getClassBody() != null) || (curr.getKind() == Kind.CLASS && parent.getKind() == Kind.BLOCK), (curr, unused) -> Objects.equals(var.owner, ASTHelpers.getSymbol(curr)))) {
@Override public Choice<State<JCNewClass>> visitNewClass(final NewClassTree node, State<?> state) { if (node.getEnclosingExpression() != null || (node.getTypeArguments() != null && !node.getTypeArguments().isEmpty()) || node.getClassBody() != null) { return Choice.none(); } return chooseSubtrees( state, s -> unifyExpression(node.getIdentifier(), s), s -> unifyExpressions(node.getArguments(), s), (ident, args) -> maker().NewClass(null, null, ident, args, null)); }
ExpressionTree argTree = tree.getArguments().get(0); if (argTree instanceof NewClassTree) { ClassTree annonClassBody = ((NewClassTree) argTree).getClassBody(); ExpressionTree argTree = tree.getArguments().get(0); if (argTree instanceof NewClassTree) { ClassTree annonClassBody = ((NewClassTree) argTree).getClassBody();
@Override @Nullable public Choice<Unifier> visitNewClass(NewClassTree newClass, @Nullable Unifier unifier) { return unifyNullable(unifier, getEnclosingExpression(), newClass.getEnclosingExpression()) .thenChoose(unifications(getTypeArguments(), newClass.getTypeArguments())) .thenChoose(unifications(getIdentifier(), newClass.getIdentifier())) .thenChoose(unifications(getClassBody(), newClass.getClassBody())) .thenChoose(unifications(getArguments(), newClass.getArguments())); }
describeIfObsolete( tree.getClassBody() == null ? tree.getIdentifier() : null, owner.name.isEmpty() ? state.getTypes().directSupertypes(owner.asType())
@Override public List<Tree> visitNewClass(NewClassTree node, ExpressionScanner.ExpressionsInfo p) { List<Tree> result = scan(node.getEnclosingExpression(), node.getIdentifier(), p); result = reduce(result, scan(node.getArguments(), p)); result = reduce(result, scan(node.getClassBody(), p)); if (result == null) { result = new ArrayList<Tree>(); } result.add(node); return result; }
public List<Tree> visitNewClass(NewClassTree node, ExpressionScanner.ExpressionsInfo p) { List<Tree> result = scan(node.getEnclosingExpression(), node.getIdentifier(), p); result = reduce(result, scan(node.getArguments(), p)); result = reduce(result, scan(node.getClassBody(), p)); if (result == null) { result = new ArrayList(); } result.add(node); return result; }
private NewClassTree modifyNewClassArgument(NewClassTree newClass, int index, ExpressionTree argument, Operation op) { NewClassTree copy = NewClass( newClass.getEnclosingExpression(), (List<ExpressionTree>) newClass.getTypeArguments(), newClass.getIdentifier(), c(newClass.getArguments(), index, argument, op), newClass.getClassBody() ); return copy; }
private NewClassTree modifyNewClassTypeArgument(NewClassTree newClass, int index, ExpressionTree typeArgument, Operation op) { NewClassTree copy = NewClass( newClass.getEnclosingExpression(), c((List<ExpressionTree>) newClass.getTypeArguments(), index, typeArgument, op), newClass.getIdentifier(), newClass.getArguments(), newClass.getClassBody() ); return copy; }
public R visitNewClass(NewClassTree node, P p) { R r = scan(node.getEnclosingExpression(), p); r = scanAndReduce(node.getIdentifier(), p, r); r = scanAndReduce(node.getTypeArguments(), p, r); r = scanAndReduce(node.getArguments(), p, r); r = scanAndReduce(node.getClassBody(), p, r); return r; }
public R visitNewClass(NewClassTree node, P p) { R r = scan(node.getEnclosingExpression(), p); r = scanAndReduce(node.getIdentifier(), p, r); r = scanAndReduce(node.getTypeArguments(), p, r); r = scanAndReduce(node.getArguments(), p, r); r = scanAndReduce(node.getClassBody(), p, r); return r; }
@Override @Nullable public Choice<Unifier> visitNewClass(NewClassTree newClass, @Nullable Unifier unifier) { return unifyNullable(unifier, getEnclosingExpression(), newClass.getEnclosingExpression()) .thenChoose(unifications(getTypeArguments(), newClass.getTypeArguments())) .thenChoose(unifications(getIdentifier(), newClass.getIdentifier())) .thenChoose(unifications(getClassBody(), newClass.getClassBody())) .thenChoose(unifications(getArguments(), newClass.getArguments())); }
@Override public Tree visitNewClass(NewClassTree tree, Void p) { NewClassTree n = make.NewClass((ExpressionTree)tree.getEnclosingExpression(), (List<? extends ExpressionTree>)tree.getTypeArguments(), tree.getIdentifier(), tree.getArguments(), tree.getClassBody()); model.setElement(n, model.getElement(tree)); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }