当前位置: 首页>>代码示例>>Java>>正文


Java MethodInvocationTree.getArguments方法代码示例

本文整理汇总了Java中com.sun.source.tree.MethodInvocationTree.getArguments方法的典型用法代码示例。如果您正苦于以下问题:Java MethodInvocationTree.getArguments方法的具体用法?Java MethodInvocationTree.getArguments怎么用?Java MethodInvocationTree.getArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.source.tree.MethodInvocationTree的用法示例。


在下文中一共展示了MethodInvocationTree.getArguments方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CreateElementUtilities.java

示例2: visitMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
@Override
public Boolean visitMethodInvocation(MethodInvocationTree node, Void p) {
    Boolean expr = scan(node.getMethodSelect(), p);
    if (expr == Boolean.TRUE) {
        // check invoked methods
        incompatibleMethodCalled = true;
        return expr;
    } else {
        for (ExpressionTree et : node.getArguments()) {
            Boolean used = scan(et, p);
            if (used == Boolean.TRUE) {
                passedToMethod = true;
            }
        }
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ReplaceBufferByString.java

示例3: checkAmbiguous

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:TooStrongCast.java

示例4: visitMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:MethodArgumentsScanner.java

示例5: getLambdaIndexFromInvokingTree

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
private int getLambdaIndexFromInvokingTree(Tree invokingTree) {
    List<? extends ExpressionTree> invokingArgs;
    if (invokingTree.getKind() == Tree.Kind.METHOD_INVOCATION) {
        MethodInvocationTree invokingMethTree = ((MethodInvocationTree) invokingTree);
        invokingArgs = invokingMethTree.getArguments();
    } else if (invokingTree.getKind() == Tree.Kind.NEW_CLASS) {
        NewClassTree invokingConstrTree = (NewClassTree) invokingTree;
        invokingArgs = invokingConstrTree.getArguments();
    } else {
        return -1;
    }

    return getIndexOfLambdaInArgs(newClassTree, invokingArgs);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ConvertToLambdaPreconditionChecker.java

示例6: visitMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
@Override
public State visitMethodInvocation(MethodInvocationTree node, Void p) {
    Element target = ci.getTrees().getElement(getCurrentPath());
    if (target == null) {
        return State.NO;
    }
    State r = null;
    if (target == checkMethod && breakContinueJumps.isEmpty()) {
        if (node.getMethodSelect().getKind() != Tree.Kind.IDENTIFIER) {
            this.thisTree = null;

            returnIfRecurse(r = scan(node.getMethodSelect(), p));
            if (this.thisTree != null) {
                r = State.MUST;
            }
        } else {
            r = State.MUST;
        }
    } else {
        r = scan(node.getMethodSelect(), p);
    }
    if (r == null) {
        for (Tree arg : node.getArguments()) {
            if (returnIfRecurse(r = scan(arg, p))) {
                break;
            }
        }
    }
    this.thisTree = null;
    if (r == null || r == State.NO) {
        return State.NO;
    }
    recursionPoints.add(getCurrentPath());
    return knownResult = State.MUST;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:InfiniteRecursion.java

示例7: computeMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
    int realArgumentError = -1;
    int i = 0;
    for (Tree param : nat.getArguments()) {
        if (param == error) {
            realArgumentError = i;
            break;
        }
        i++;
    }
    
    if (realArgumentError != (-1)) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
        
        if (ee.isEmpty()) { //cannot be resolved
            TypeMirror executable = info.getTrees().getTypeMirror(new TreePath(parent, nat.getMethodSelect()));
            
            if (executable == null || executable.getKind() != TypeKind.EXECUTABLE) return null;
            
            ExecutableType et = (ExecutableType) executable;
            
            if (realArgumentError >= et.getParameterTypes().size()) {
                return null;
            }
            
            proposedTypes.add(et.getParameterTypes().get(realArgumentError));
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return proposedTypes;
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:CreateElementUtilities.java

示例8: matchMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  final Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
  if (methodSymbol == null) {
    throw new RuntimeException("not expecting unresolved method here");
  }
  handler.onMatchMethodInvocation(this, tree, state, methodSymbol);
  // assuming this list does not include the receiver
  List<? extends ExpressionTree> actualParams = tree.getArguments();
  return handleInvocation(state, methodSymbol, actualParams);
}
 
开发者ID:uber,项目名称:NullAway,代码行数:15,代码来源:NullAway.java

示例9: performRewrite

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
@Override protected void performRewrite(JavaFix.TransformationContext ctx) throws Exception {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath treePath = ctx.getPath();
            TreeMaker make = wc.getTreeMaker();
            if (treePath.getLeaf().getKind() == Kind.METHOD_INVOCATION) {
                MethodInvocationTree mit = (MethodInvocationTree) treePath.getLeaf();
                CompilationUnitTree cut = wc.getCompilationUnit();
                boolean imported = false;
                String importBundleStar = cut.getPackageName() + ".Bundle.*";
                for (ImportTree it : cut.getImports()) {
                    if (it.isStatic() && it.getQualifiedIdentifier().toString().equals(importBundleStar)) {
                        imported = true;
                        break;
                    }
                }
                if (!imported) {
                    wc.rewrite(cut, make.addCompUnitImport(cut, make.Import(make.Identifier(importBundleStar), true)));
                }
                List<? extends ExpressionTree> args = mit.getArguments();
                List<? extends ExpressionTree> params;
                if (args.size() == 3 && args.get(2).getKind() == Kind.NEW_ARRAY) {
                    params = ((NewArrayTree) args.get(2)).getInitializers();
                } else {
                    params = args.subList(2, args.size());
                }
                wc.rewrite(mit, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.Identifier(toIdentifier(key)), params));
            } // else annotation value, nothing to change
            if (!isAlreadyRegistered) {
                EditableProperties ep = new EditableProperties(true);
                InputStream is = ctx.getResourceContent(bundleProperties);
                try {
                    ep.load(is);
                } finally {
                    is.close();
                }
                List<ExpressionTree> lines = new ArrayList<ExpressionTree>();
                for (String comment : ep.getComment(key)) {
                    lines.add(make.Literal(comment));
                }
                lines.add(make.Literal(key + '=' + ep.remove(key)));
                TypeElement nbBundleMessages = wc.getElements().getTypeElement("org.openide.util.NbBundle.Messages");
                if (nbBundleMessages == null) {
                    throw new IllegalArgumentException("cannot resolve org.openide.util.NbBundle.Messages");
                }
                GeneratorUtilities gu = GeneratorUtilities.get(wc);
                Tree enclosing = findEnclosingElement(wc, treePath);
                Tree modifiers;
                Tree nueModifiers;
                ExpressionTree[] linesA = lines.toArray(new ExpressionTree[lines.size()]);
                switch (enclosing.getKind()) {
                case METHOD:
                    modifiers = wc.resolveRewriteTarget(((MethodTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                case VARIABLE:
                    modifiers = wc.resolveRewriteTarget(((VariableTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                case COMPILATION_UNIT:
                    modifiers = wc.resolveRewriteTarget(enclosing);
                    nueModifiers = gu.appendToAnnotationValue((CompilationUnitTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                default:
                    modifiers = wc.resolveRewriteTarget(((ClassTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                }
                wc.rewrite(modifiers, nueModifiers);
            // XXX remove NbBundle import if now unused
            OutputStream os = ctx.getResourceOutput(bundleProperties);
            try {
                ep.store(os);
            } finally {
                os.close();
            }
        }
    // XXX after JavaFix rewrite, Savable.save (on DataObject.find(src)) no longer works (JG13 again)
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:78,代码来源:UseNbBundleMessages.java

示例10: visitMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
@Override
        public Void visitMethodInvocation(MethodInvocationTree tree, EnumSet<UseTypes> d) {
            Tree possibleIdent = tree.getMethodSelect();
            boolean handled = false;
            
            if (possibleIdent.getKind() == Kind.IDENTIFIER) {
                //handle "this" and "super" constructors:
                String ident = ((IdentifierTree) possibleIdent).getName().toString();
                
                if ("super".equals(ident) || "this".equals(ident)) { //NOI18N
                    Element resolved = info.getTrees().getElement(getCurrentPath());
                    
                    addUse(resolved, EnumSet.of(UseTypes.EXECUTE), null, null);
                    handled = true;
                }
            }
            
            if (!handled) {
                handlePossibleIdentifier(new TreePath(getCurrentPath(), possibleIdent), EnumSet.of(UseTypes.EXECUTE));
            }
            
            List<? extends Tree> ta = tree.getTypeArguments();
            long afterTypeArguments = ta.isEmpty() ? -1 : info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), ta.get(ta.size() - 1));
            
            switch (tree.getMethodSelect().getKind()) {
                case IDENTIFIER:
                case MEMBER_SELECT:
                    memberSelectBypass = afterTypeArguments;
                    scan(tree.getMethodSelect(), EnumSet.of(UseTypes.READ));
                    memberSelectBypass = -1;
                    break;
                default:
                    //todo: log
                    scan(tree.getMethodSelect(), EnumSet.of(UseTypes.READ));
            }

            handleMethodTypeArguments(getCurrentPath(), ta);
            
            scan(tree.getTypeArguments(), null);
            
//            if (tree.getMethodSelect().getKind() == Kind.MEMBER_SELECT && tree2Token.get(tree.getMethodSelect()) == null) {
////                if (ts.moveNext()) ???
//                    firstIdentifier(((MemberSelectTree) tree.getMethodSelect()).getIdentifier().toString());
//            }

            if (tree.getArguments() != null) {
                for (Tree expr : tree.getArguments()) {
                    if (expr instanceof IdentifierTree) {
                        handlePossibleIdentifier(new TreePath(getCurrentPath(), expr), EnumSet.of(UseTypes.READ));
                    }
                }
            }
            
            scan(tree.getArguments(), EnumSet.of(UseTypes.READ));
            
//            super.visitMethodInvocation(tree, null);
            return null;
        }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:SemanticHighlighterBase.java

示例11: checkMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
private static boolean checkMethodInvocation(HintContext ctx, TreePath invPath, TreePath valPath) {
    Trees trees = ctx.getInfo().getTrees();
    Tree invLeaf = invPath.getLeaf();
    List<? extends ExpressionTree> arguments;
    TypeMirror m;
    
    switch (invLeaf.getKind()) {
        case METHOD_INVOCATION: {
            MethodInvocationTree mit = (MethodInvocationTree)invLeaf;
            arguments = mit.getArguments();
            m = trees.getTypeMirror(new TreePath(invPath, mit.getMethodSelect()));
            break;
        }
        case NEW_CLASS: {
            NewClassTree nct = (NewClassTree)invLeaf;
            arguments = nct.getArguments();
            Element e = trees.getElement(invPath);
            TypeMirror cl = trees.getTypeMirror(invPath);
            if (!Utilities.isValidType(cl) || cl.getKind().isPrimitive()) {
                return false;
            }
            m = ctx.getInfo().getTypes().asMemberOf((DeclaredType)cl, e);
            break;
        }
        default:
            return false;
    }
    
    if (!Utilities.isValidType(m) || m.getKind() != TypeKind.EXECUTABLE) {
        return false;
    }
    ExecutableType execType = (ExecutableType)m;
    int idx = arguments.indexOf(ctx.getPath().getLeaf());
    if (idx < 0 || idx >= execType.getParameterTypes().size()) {
        return false;
    }
    TypeMirror paramType = execType.getParameterTypes().get(idx);
    TypeMirror curType = trees.getTypeMirror(ctx.getPath());
    TypeMirror valType = trees.getTypeMirror(valPath);
    
    if (!paramType.getKind().isPrimitive() && valType.getKind().isPrimitive()) {
        valType = ctx.getInfo().getTypes().boxedClass((PrimitiveType)valType).asType();
        // ensure that the passed INSTANCE type will not change when the boxing is removed
        if (!ctx.getInfo().getTypes().isSameType(curType, valType)) {
            return false;
        }
    }
            
    return Utilities.checkAlternativeInvocation(ctx.getInfo(), invPath, ctx.getPath(), valPath, null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:51,代码来源:UnnecessaryBoxing.java

示例12: okToReadBeforeInitialized

import com.sun.source.tree.MethodInvocationTree; //导入方法依赖的package包/类
/**
 * @param path tree path to read operation
 * @return true if it is permissible to perform this read before the field has been initialized,
 *     false otherwise
 */
private boolean okToReadBeforeInitialized(TreePath path) {
  TreePath parentPath = path.getParentPath();
  Tree leaf = path.getLeaf();
  Tree parent = parentPath.getLeaf();
  if (parent instanceof AssignmentTree) {
    // ok if it's actually a write
    AssignmentTree assignment = (AssignmentTree) parent;
    return assignment.getVariable().equals(leaf);
  } else if (parent instanceof BinaryTree) {
    // ok if we're comparing to null
    BinaryTree binaryTree = (BinaryTree) parent;
    Tree.Kind kind = binaryTree.getKind();
    if (kind.equals(Tree.Kind.EQUAL_TO) || kind.equals(Tree.Kind.NOT_EQUAL_TO)) {
      ExpressionTree left = binaryTree.getLeftOperand();
      ExpressionTree right = binaryTree.getRightOperand();
      return (left.equals(leaf) && right.getKind().equals(Tree.Kind.NULL_LITERAL))
          || (right.equals(leaf) && left.getKind().equals(Tree.Kind.NULL_LITERAL));
    }
  } else if (parent instanceof MethodInvocationTree) {
    // ok if it's invoking castToNonNull and the read is the argument
    MethodInvocationTree methodInvoke = (MethodInvocationTree) parent;
    Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(methodInvoke);
    String qualifiedName =
        ASTHelpers.enclosingClass(methodSymbol) + "." + methodSymbol.getSimpleName().toString();
    if (qualifiedName.equals(config.getCastToNonNullMethod())) {
      List<? extends ExpressionTree> arguments = methodInvoke.getArguments();
      return arguments.size() == 1 && leaf.equals(arguments.get(0));
    }
  }
  return false;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:37,代码来源:NullAway.java


注:本文中的com.sun.source.tree.MethodInvocationTree.getArguments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。