com.sun.source.tree.MethodInvocationTree Java Examples

The following examples show how to use com.sun.source.tree.MethodInvocationTree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: TencentKona-8   Author: Tencent   File: TestInvokeDynamic.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    super.visitMethodInvocation(node, p);
    JCMethodInvocation apply = (JCMethodInvocation)node;
    JCIdent ident = (JCIdent)apply.meth;
    Symbol oldSym = ident.sym;
    if (!oldSym.isConstructor()) {
        Object[] staticArgs = new Object[arity.arity];
        for (int i = 0; i < arity.arity ; i++) {
            staticArgs[i] = saks[i].getValue(syms, names, types);
        }
        ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
                oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
    }
    return null;
}
 
Example #2
Source Project: jdk8u60   Author: chenghanpeng   File: TestInvokeDynamic.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    super.visitMethodInvocation(node, p);
    JCMethodInvocation apply = (JCMethodInvocation)node;
    JCIdent ident = (JCIdent)apply.meth;
    Symbol oldSym = ident.sym;
    if (!oldSym.isConstructor()) {
        Object[] staticArgs = new Object[arity.arity];
        for (int i = 0; i < arity.arity ; i++) {
            staticArgs[i] = saks[i].getValue(syms, names, types);
        }
        ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
                oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
    }
    return null;
}
 
Example #3
Source Project: NullAway   Author: uber   File: RestrictiveAnnotationHandler.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onOverrideMayBeNullExpr(
    NullAway analysis, ExpressionTree expr, VisitorState state, boolean exprMayBeNull) {
  if (expr.getKind().equals(Tree.Kind.METHOD_INVOCATION)) {
    Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol((MethodInvocationTree) expr);
    if (NullabilityUtil.isUnannotated(methodSymbol, config)) {
      // with the generated-as-unannotated option enabled, we want to ignore
      // annotations in generated code
      if (config.treatGeneratedAsUnannotated() && NullabilityUtil.isGenerated(methodSymbol)) {
        return exprMayBeNull;
      } else {
        return Nullness.hasNullableAnnotation(methodSymbol, config) || exprMayBeNull;
      }
    } else {
      return exprMayBeNull;
    }
  }
  return exprMayBeNull;
}
 
Example #4
Source Project: openjdk-8-source   Author: keerath   File: TestInvokeDynamic.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    super.visitMethodInvocation(node, p);
    JCMethodInvocation apply = (JCMethodInvocation)node;
    JCIdent ident = (JCIdent)apply.meth;
    Symbol oldSym = ident.sym;
    if (!oldSym.isConstructor()) {
        Object[] staticArgs = new Object[arity.arity];
        for (int i = 0; i < arity.arity ; i++) {
            staticArgs[i] = saks[i].getValue(syms, names, types);
        }
        ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
                oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
    }
    return null;
}
 
Example #5
Source Project: netbeans   Author: apache   File: MethodArgumentsScanner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public MethodArgument[] visitMethodInvocation(MethodInvocationTree node, Object p) {
    if (!methodInvocation || offset != positions.getEndPosition(tree, node.getMethodSelect())) {
        return super.visitMethodInvocation(node, p);
        /*MethodArgument[] r = scan(node.getTypeArguments(), p);
        r = scanAndReduce(node.getMethodSelect(), p, r);
        r = scanAndReduce(node.getArguments(), p, r);
        return r;*/
    }
    List<? extends ExpressionTree> args = node.getArguments();
    List<? extends Tree> argTypes = node.getTypeArguments();
    /*int n = args.size();
    arguments = new MethodArgument[n];
    for (int i = 0; i < n; i++) {
        arguments[i] = new MethodArgument(args.get(i).toString(), argTypes.get(i).toString());
    }
    return arguments;*/
    arguments = composeArguments(args, argTypes);
    return arguments;
}
 
Example #6
Source Project: startup-os   Author: google   File: ProtobufCheck.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {

  // check whether it's a newBuilder() method of any protobuf-generated message class
  if (NEW_BUILDER.matches(tree, state)) {
    // find next method invocation in chain (on obj.method1().method2() it would return method2)
    ExpressionTree methodInvocation =
        ASTHelpers.findEnclosingNode(state.getPath(), MethodInvocationTree.class);
    // next invoked message is a build() method of any protobuf-generated message builder class
    if (BUILDER_BUILD.matches(methodInvocation, state)) {

      // select "newBuilder().build()" part of tree
      int start = state.getEndPosition(tree) - "newBuilder()".length();
      int end = state.getEndPosition(methodInvocation);

      // suggest to replace it with "getDefaultInstance()"
      return describeMatch(
          methodInvocation,
          SuggestedFix.builder().replace(start, end, "getDefaultInstance()").build());
    }
  }
  return NO_MATCH;
}
 
Example #7
Source Project: piranha   Author: uber   File: XPFlagCleaner.java    License: Apache License 2.0 6 votes vote down vote up
private API getXPAPI(ExpressionTree et) {
  et = ASTHelpers.stripParentheses(et);
  Kind k = et.getKind();
  if (k.equals(Tree.Kind.METHOD_INVOCATION)) {
    MethodInvocationTree mit = (MethodInvocationTree) et;
    if (!mit.getMethodSelect().getKind().equals(Kind.MEMBER_SELECT)) {
      return API.UNKNOWN;
    }
    MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
    String methodName = mst.getIdentifier().toString();
    if (!disabled && configMethodProperties.containsKey(methodName)) {
      return getXPAPI(mit, configMethodProperties.get(methodName));
    }
  }
  return API.UNKNOWN;
}
 
Example #8
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TestInvokeDynamic.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    super.visitMethodInvocation(node, p);
    JCMethodInvocation apply = (JCMethodInvocation)node;
    JCIdent ident = (JCIdent)apply.meth;
    Symbol oldSym = ident.sym;
    if (!oldSym.isConstructor()) {
        Object[] staticArgs = new Object[arity.arity];
        for (int i = 0; i < arity.arity ; i++) {
            staticArgs[i] = saks[i].getValue(syms, names, types);
        }
        ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
                oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
    }
    return null;
}
 
Example #9
Source Project: netbeans   Author: apache   File: TypeUtilitiesTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testTypeName() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject src  = root.createData("Test.java");
    TestUtilities.copyStringToFile(src, "package test; public class Test { { get().run(); } private <Z extends Exception&Runnable> Z get() { return null; } }");
    JavaSource js = JavaSource.create(ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])), ClassPathSupport.createClassPath(new URL[0]), ClassPathSupport.createClassPath(new URL[0])), src);
    
    js.runUserActionTask(new Task<CompilationController>() {
        public void run(CompilationController info) throws IOException  {
            info.toPhase(JavaSource.Phase.RESOLVED);
            TypeElement context = info.getTopLevelElements().get(0);
            assertEquals("java.util.List<java.lang.String>[]", info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]", context), TypeUtilities.TypeNameOptions.PRINT_FQN));
            assertEquals("List<String>[]", info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]", context)));
            assertEquals("java.util.List<java.lang.String>...", info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]", context), TypeUtilities.TypeNameOptions.PRINT_FQN, TypeUtilities.TypeNameOptions.PRINT_AS_VARARG));
            assertEquals("List<String>...", info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]", context), TypeUtilities.TypeNameOptions.PRINT_AS_VARARG));
            ClassTree clazz = (ClassTree) info.getCompilationUnit().getTypeDecls().get(0);
            BlockTree init = (BlockTree) clazz.getMembers().get(1);
            ExpressionStatementTree var = (ExpressionStatementTree) init.getStatements().get(0);
            ExpressionTree getInvocation = ((MemberSelectTree) ((MethodInvocationTree) var.getExpression()).getMethodSelect()).getExpression();
            TypeMirror intersectionType = info.getTrees().getTypeMirror(info.getTrees().getPath(info.getCompilationUnit(), getInvocation));
            assertEquals("Exception & Runnable", info.getTypeUtilities().getTypeName(intersectionType));
        }
    }, true);
    
}
 
Example #10
Source Project: javaide   Author: tranleduy2000   File: JavaInputAstVisitor.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void dotExpressionUpToArgs(ExpressionTree expression, Optional<BreakTag> tyargTag) {
    expression = getArrayBase(expression);
    switch (expression.getKind()) {
        case MEMBER_SELECT:
            MemberSelectTree fieldAccess = (MemberSelectTree) expression;
            visit(fieldAccess.getIdentifier());
            break;
        case METHOD_INVOCATION:
            MethodInvocationTree methodInvocation = (MethodInvocationTree) expression;
            if (!methodInvocation.getTypeArguments().isEmpty()) {
                builder.open(plusFour);
                addTypeArguments(methodInvocation.getTypeArguments(), ZERO);
                // TODO(jdd): Should indent the name -4.
                builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO, tyargTag);
                builder.close();
            }
            visit(getMethodName(methodInvocation));
            break;
        case IDENTIFIER:
            visit(((IdentifierTree) expression).getName());
            break;
        default:
            scan(expression, null);
            break;
    }
}
 
Example #11
Source Project: netbeans   Author: apache   File: TreeUtilitiesTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testForEachLoop() throws Exception {
    prepareTest("Test", "package test; public class Test { public Test(java.util.List<String> ll) { for (String s : ll.subList(0, ll.size())  ) { } } }");

    TreePath tp1 = info.getTreeUtilities().pathFor(122 - 30);
    assertEquals(Kind.IDENTIFIER, tp1.getLeaf().getKind());
    assertEquals("ll", ((IdentifierTree) tp1.getLeaf()).getName().toString());

    TreePath tp2 = info.getTreeUtilities().pathFor(127 - 30);
    assertEquals(Kind.MEMBER_SELECT, tp2.getLeaf().getKind());
    assertEquals("subList", ((MemberSelectTree) tp2.getLeaf()).getIdentifier().toString());

    TreePath tp3 = info.getTreeUtilities().pathFor(140 - 30);
    assertEquals(Kind.MEMBER_SELECT, tp3.getLeaf().getKind());
    assertEquals("size", ((MemberSelectTree) tp3.getLeaf()).getIdentifier().toString());

    TreePath tp4 = info.getTreeUtilities().pathFor(146 - 30);
    assertEquals(Kind.METHOD_INVOCATION, tp4.getLeaf().getKind());
    assertEquals("subList", ((MemberSelectTree) ((MethodInvocationTree) tp4.getLeaf()).getMethodSelect()).getIdentifier().toString());
}
 
Example #12
Source Project: netbeans   Author: apache   File: CreateElementUtilities.java    License: Apache License 2.0 6 votes vote down vote up
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
    boolean errorInRealArguments = false;
    
    for (Tree param : nat.getArguments()) {
        errorInRealArguments |= param == error;
    }
    
    if (errorInRealArguments) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
        
        if (ee.isEmpty()) { //cannot be resolved
            return null;
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return proposedTypes;
    }
    
    return null;
}
 
Example #13
Source Project: netbeans   Author: apache   File: ResourceStringFoldProvider.java    License: Apache License 2.0 6 votes vote down vote up
private String getBundleName(MethodInvocationTree n, int index, String bfn) {
    if (n.getArguments().size() <= index) {
        return null;
    }
    ExpressionTree t = n.getArguments().get(index);
    // recognize just string literals + .class references
    if (t.getKind() == Tree.Kind.STRING_LITERAL) {
        Object o = ((LiteralTree)t).getValue();
        return o == null ? null : o.toString();
    } else if (t.getKind() == Tree.Kind.MEMBER_SELECT) {
        MemberSelectTree mst = (MemberSelectTree)t;
        if (!mst.getIdentifier().contentEquals("class")) {
            return null;
        }
        return bundleFileFromClass(new TreePath(getCurrentPath(), mst.getExpression()), bfn);
    }
    return null;
}
 
Example #14
Source Project: netbeans   Author: apache   File: LoggerStringConcat.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void performRewrite(TransformationContext ctx) {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath invocation = ctx.getPath();
    TreePath message    = FixImpl.this.message.resolve(wc);
    MethodInvocationTree mit = (MethodInvocationTree) invocation.getLeaf();
    ExpressionTree level = null;

    if (logMethodName != null) {
        String logMethodNameUpper = logMethodName.toUpperCase();
        VariableElement c = findConstant(wc, logMethodNameUpper);

        level = wc.getTreeMaker().QualIdent(c);
    } else {
        level = mit.getArguments().get(0);
    }

    rewrite(wc, level, mit, message);
}
 
Example #15
Source Project: google-java-format   Author: google   File: JavaInputAstVisitor.java    License: Apache License 2.0 6 votes vote down vote up
private void dotExpressionUpToArgs(ExpressionTree expression, Optional<BreakTag> tyargTag) {
  expression = getArrayBase(expression);
  switch (expression.getKind()) {
    case MEMBER_SELECT:
      MemberSelectTree fieldAccess = (MemberSelectTree) expression;
      visit(fieldAccess.getIdentifier());
      break;
    case METHOD_INVOCATION:
      MethodInvocationTree methodInvocation = (MethodInvocationTree) expression;
      if (!methodInvocation.getTypeArguments().isEmpty()) {
        builder.open(plusFour);
        addTypeArguments(methodInvocation.getTypeArguments(), ZERO);
        // TODO(jdd): Should indent the name -4.
        builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO, tyargTag);
        builder.close();
      }
      visit(getMethodName(methodInvocation));
      break;
    case IDENTIFIER:
      visit(((IdentifierTree) expression).getName());
      break;
    default:
      scan(expression, null);
      break;
  }
}
 
Example #16
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TestInvokeDynamic.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    super.visitMethodInvocation(node, p);
    JCMethodInvocation apply = (JCMethodInvocation)node;
    JCIdent ident = (JCIdent)apply.meth;
    Symbol oldSym = ident.sym;
    if (!oldSym.isConstructor()) {
        Object[] staticArgs = new Object[arity.arity];
        for (int i = 0; i < arity.arity ; i++) {
            staticArgs[i] = saks[i].getValue(syms, names, types);
        }
        ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
                oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
    }
    return null;
}
 
Example #17
Source Project: netbeans   Author: apache   File: Tiny.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void performRewrite(JavaFix.TransformationContext ctx) throws Exception {
    Tree t = ctx.getPath().getLeaf();
    if (t.getKind() != Tree.Kind.METHOD_INVOCATION) {
        return;
    }
    MethodInvocationTree mi = (MethodInvocationTree)t;
    if (mi.getMethodSelect().getKind() != Tree.Kind.MEMBER_SELECT) {
        return;
    }
    MemberSelectTree selector = ((MemberSelectTree)mi.getMethodSelect());
    TreeMaker maker = ctx.getWorkingCopy().getTreeMaker();
    ExpressionTree ms = maker.MemberSelect(maker.QualIdent("java.util.Arrays"), deep ? "deepHashCode" : "hashCode"); // NOI18N
    Tree nue = maker.MethodInvocation(
                    Collections.<ExpressionTree>emptyList(), 
                    ms, 
                    Collections.singletonList(selector.getExpression())
    );
    ctx.getWorkingCopy().rewrite(t, nue);
}
 
Example #18
Source Project: netbeans   Author: apache   File: TooStrongCast.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether a method or constructor call would become ambiguous if the parameter type changes.
 * 
 * @param info compilation context
 * @param parentExec path to the constructor or method invocation
 * @param argIndex
 * @param casteeType
 * @return 
 */
private static boolean checkAmbiguous(CompilationInfo info, final TreePath parentExec, int argIndex, TypeMirror casteeType, TreePath realArgTree) {
    CharSequence altType = info.getTypeUtilities().getTypeName(casteeType, TypeUtilities.TypeNameOptions.PRINT_FQN);
    String prefix = null;
    if (casteeType != null && !(casteeType.getKind() == TypeKind.NULL || casteeType.getKind() == TypeKind.INTERSECTION)) {
        prefix = "(" + altType + ")"; // NOI18N
    }
    Tree leaf = parentExec.getLeaf();
    List<? extends Tree> arguments;
    if (leaf instanceof MethodInvocationTree) {
        MethodInvocationTree mi = (MethodInvocationTree)leaf;
        arguments = mi.getArguments();
    } else {
        arguments = ((NewClassTree)leaf).getArguments();
    }
    Tree argTree = arguments.get(argIndex);
    TreePath argPath = new TreePath(parentExec, argTree);
    return !Utilities.checkAlternativeInvocation(info, parentExec, argPath, realArgTree, prefix);
}
 
Example #19
Source Project: netbeans   Author: apache   File: UncaughtException.java    License: Apache License 2.0 6 votes vote down vote up
/**
    * Detects if we are parameter of this() or super() call
    * @return true if yes
    */ 
   private boolean isThisParameter(TreePath path) {
//anonymous class must not be on the path to top
while(!TreeUtilities.CLASS_TREE_KINDS.contains(path.getLeaf().getKind()) && path.getLeaf().getKind() != Kind.COMPILATION_UNIT) {
    if (path.getParentPath().getLeaf().getKind() == Kind.METHOD_INVOCATION) {
	MethodInvocationTree mi = (MethodInvocationTree) path.getParentPath().getLeaf();
	if(mi.getMethodSelect().getKind() == Kind.IDENTIFIER) {
	    String id = ((IdentifierTree) mi.getMethodSelect()).getName().toString();
	    if ("super".equals(id) || "this".equals(id))
		return true;
	}
    }
    path = path.getParentPath();
}
return false;
   }
 
Example #20
Source Project: besu   Author: hyperledger   File: DoNotCreateSecureRandomDirectly.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("TreeToString")
@Override
public Description matchMethodInvocation(
    final MethodInvocationTree tree, final VisitorState state) {
  if (tree.getMethodSelect().toString().equals("SecureRandom.getInstance")) {
    return describeMatch(tree);
  }

  return Description.NO_MATCH;
}
 
Example #21
Source Project: besu   Author: hyperledger   File: DoNotInvokeMessageDigestDirectly.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("TreeToString")
@Override
public Description matchMethodInvocation(
    final MethodInvocationTree tree, final VisitorState state) {
  if (tree.getMethodSelect().toString().equals("MessageDigest.getInstance")) {
    return describeMatch(tree);
  }
  return Description.NO_MATCH;
}
 
Example #22
Source Project: netbeans   Author: apache   File: GoToSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TreePath visitMethodInvocation(MethodInvocationTree tree, Void v) {
    if (tree.getMethodSelect().getKind() == Kind.IDENTIFIER && "super".equals(((IdentifierTree) tree.getMethodSelect()).getName().toString())) {
        return getCurrentPath();
    }
    
    return null;
}
 
Example #23
Source Project: compile-testing   Author: google   File: TreeDiffer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Void visitMethodInvocation(MethodInvocationTree expected, Tree actual) {
  Optional<MethodInvocationTree> other = checkTypeAndCast(expected, actual);
  if (!other.isPresent()) {
    addTypeMismatch(expected, actual);
    return null;
  }

  parallelScan(expected.getTypeArguments(), other.get().getTypeArguments());
  scan(expected.getMethodSelect(), other.get().getMethodSelect());
  parallelScan(expected.getArguments(), other.get().getArguments());
  return null;
}
 
Example #24
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: JavaInputAstVisitor.java    License: Apache License 2.0 5 votes vote down vote up
private boolean fillFirstArgument(
        ExpressionTree e,
        List<ExpressionTree> items,
        Indent indent) {
    // is there a trailing dereference?
    if (items.size() < 2) {
        return false;
    }
    // don't special-case calls nested inside expressions
    if (e.getKind() != METHOD_INVOCATION) {
        return false;
    }
    MethodInvocationTree methodInvocation = (MethodInvocationTree) e;
    Name name = getMethodName(methodInvocation);
    if (!(methodInvocation.getMethodSelect() instanceof IdentifierTree)
            || name.length() > 4
            || !methodInvocation.getTypeArguments().isEmpty()
            || methodInvocation.getArguments().size() != 1) {
        return false;
    }
    builder.open(ZERO);
    builder.open(indent);
    visit(name);
    token("(");
    ExpressionTree arg = getOnlyElement(methodInvocation.getArguments());
    scan(arg, null);
    builder.close();
    token(")");
    builder.close();
    return true;
}
 
Example #25
Source Project: FreeBuilder   Author: inferred   File: JavacMethodIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Void visitMethodInvocation(
    MethodInvocationTree node,
    BiConsumer<MethodInvocationTree, Name> biConsumer) {
  Name identifier = OWNED_IDENTIFIER.visit(node.getMethodSelect(), null);
  if (identifier != null) {
    biConsumer.accept(node, identifier);
  }
  return super.visitMethodInvocation(node, biConsumer);
}
 
Example #26
Source Project: teku   Author: PegaSysEng   File: DoNotInvokeMessageDigestDirectly.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Description matchMethodInvocation(
    final MethodInvocationTree tree, final VisitorState state) {
  if (GET_INSTANCE_MATCHER.matches(tree, state)) {
    return describeMatch(tree);
  }
  return Description.NO_MATCH;
}
 
Example #27
Source Project: piranha   Author: uber   File: XPFlagCleaner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * A utility method that simulated evaluation of isInTreatmentGroup and similar methods.
 *
 * @param methodInvocationTree The method call to isInTreatmentGroup
 * @return true if the second argument matches the treatmentGroup passed to this checker
 */
private boolean evalTreatmentGroupCheck(MethodInvocationTree methodInvocationTree) {
  Preconditions.checkArgument(
      methodInvocationTree.getArguments().size() == 2,
      "Treatment group checks (e.g. isInTreatmentGroup) must take two arguments");
  ExpressionTree arg = methodInvocationTree.getArguments().get(1);
  Symbol argSym = ASTHelpers.getSymbol(arg);
  return (argSym != null && argSym.toString().toLowerCase().equals(treatmentGroup));
}
 
Example #28
Source Project: netbeans   Author: apache   File: ComputeImports.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Map<String, Object> p) {
    scan(node.getTypeArguments(), new HashMap<String, Object>(), true);
    scan(node.getMethodSelect(), p);
    scan(node.getArguments(), new HashMap<String, Object>());
    return null;
}
 
Example #29
Source Project: google-java-format   Author: google   File: Trees.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns the simple name of a (possibly qualified) method invocation expression. */
static Name getMethodName(MethodInvocationTree methodInvocation) {
  ExpressionTree select = methodInvocation.getMethodSelect();
  return select instanceof MemberSelectTree
      ? ((MemberSelectTree) select).getIdentifier()
      : ((IdentifierTree) select).getName();
}
 
Example #30
Source Project: netbeans   Author: apache   File: AbstractTestGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private StatementTree generateEJBCleanUpCode(TreeMaker maker) {
    IdentifierTree container = maker.Identifier(CONTAINER_VAR_NAME);
    MethodInvocationTree invocation = maker.MethodInvocation(
        Collections.<ExpressionTree>emptyList(),
        maker.MemberSelect(container, "close"), // NOI18N
        Collections.<ExpressionTree>emptyList()
    );
    return maker.ExpressionStatement(invocation);
}