當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodTree.getParameters方法代碼示例

本文整理匯總了Java中com.sun.source.tree.MethodTree.getParameters方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodTree.getParameters方法的具體用法?Java MethodTree.getParameters怎麽用?Java MethodTree.getParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.source.tree.MethodTree的用法示例。


在下文中一共展示了MethodTree.getParameters方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createMethodSignature

import com.sun.source.tree.MethodTree; //導入方法依賴的package包/類
public static String createMethodSignature(MethodTree m, boolean skipName) {
    String sign = "";
    if (!skipName) {
        sign += m.getName();
    }
    sign += "(";
    if (m.getParameters() != null) {
        for (VariableTree p : m.getParameters()) {
            sign += getShortTypeName(p.getType()) + ",";
        }
        if (m.getParameters().size() > 0) {
            sign = sign.substring(0, sign.length() - 1);
        }
    }
    sign += ")";
    return sign;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:JavaSourceHelper.java

示例2: modifyDefaultConstructor

import com.sun.source.tree.MethodTree; //導入方法依賴的package包/類
public static ClassTree modifyDefaultConstructor(ClassTree classTree, ClassTree modifiedClassTree, WorkingCopy wc, MethodInfo modifiedConstructorInfo) {
    if (!"<init>".equals(modifiedConstructorInfo.getName())) {
        throw new IllegalArgumentException("modifiedConstructorInfo name must be <init>");
    }
    
    MethodTree modifiedConstructor = createMethod(wc, modifiedConstructorInfo);
    MethodTree constructor = null;
    for(Tree tree : modifiedClassTree.getMembers()) {
        if(Tree.Kind.METHOD == tree.getKind()) {
            MethodTree mtree = (MethodTree)tree;
            List<? extends VariableTree> mTreeParameters = mtree.getParameters();
            if(mtree.getName().toString().equals("<init>") &&
                    (mTreeParameters == null || mTreeParameters.isEmpty()) &&
                    !wc.getTreeUtilities().isSynthetic(wc.getTrees().getPath(wc.getCompilationUnit(), classTree))) {
                    constructor = mtree;
                    break;
            }
        }
    }
    if (constructor == null) {
        modifiedClassTree = wc.getTreeMaker().addClassMember(modifiedClassTree, modifiedConstructor);
    }
    else {
        wc.rewrite(constructor, modifiedConstructor);
    }
    return modifiedClassTree;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:JpaControllerUtil.java

示例3: ReplaceConstructorWithBuilderUI

import com.sun.source.tree.MethodTree; //導入方法依賴的package包/類
private ReplaceConstructorWithBuilderUI(TreePathHandle constructor, CompilationInfo info) {
    this.refactoring = new ReplaceConstructorWithBuilderRefactoring(constructor);
    ExecutableElement contructorElement = (ExecutableElement) constructor.resolveElement(info);
    this.name = contructorElement.getSimpleName().toString();
    MethodTree constTree = (MethodTree) constructor.resolve(info).getLeaf();
    paramaterNames = new ArrayList<String>();
    parameterTypes = new ArrayList<String>();
    parameterTypeVars = new ArrayList<Boolean>();
    boolean varargs = contructorElement.isVarArgs();
    List<? extends VariableElement> parameterElements = contructorElement.getParameters();
    List<? extends VariableTree> parameters = constTree.getParameters();
    for (int i = 0; i < parameters.size(); i++) {
        VariableTree var = parameters.get(i);
        paramaterNames.add(var.getName().toString());
        String type = contructorElement.getParameters().get(i).asType().toString();
        if(varargs && i+1 == parameters.size()) {
            if(var.getType().getKind() == Tree.Kind.ARRAY_TYPE) {
                ArrayTypeTree att = (ArrayTypeTree) var.getType();
                type = att.getType().toString();
                type += "..."; //NOI18N
            }
        }
        parameterTypes.add(type);
        parameterTypeVars.add(parameterElements.get(i).asType().getKind() == TypeKind.TYPEVAR);
    }
    TypeElement typeEl = (TypeElement) contructorElement.getEnclosingElement();
    if(typeEl.getNestingKind() != NestingKind.TOP_LEVEL) {
        PackageElement packageOf = info.getElements().getPackageOf(typeEl);
        builderFQN = packageOf.toString() + "." + typeEl.getSimpleName().toString();
    } else {
        builderFQN = typeEl.getQualifiedName().toString();
    }
    buildMethodName = "create" + typeEl.getSimpleName();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:ReplaceConstructorWithBuilderUI.java

示例4: isInHeader

import com.sun.source.tree.MethodTree; //導入方法依賴的package包/類
private static boolean isInHeader(CompilationInfo info, MethodTree tree, int offset) {
    CompilationUnitTree cut = info.getCompilationUnit();
    SourcePositions sp = info.getTrees().getSourcePositions();
    long lastKnownOffsetInHeader = sp.getStartPosition(cut, tree);
    
    List<? extends ExpressionTree> throwz;
    List<? extends VariableTree> params;
    List<? extends TypeParameterTree> typeparams;
    
    if ((throwz = tree.getThrows()) != null && !throwz.isEmpty()) {
        lastKnownOffsetInHeader = sp.getEndPosition(cut, throwz.get(throwz.size() - 1));
    } else if ((params = tree.getParameters()) != null && !params.isEmpty()) {
        lastKnownOffsetInHeader = sp.getEndPosition(cut, params.get(params.size() - 1));
    } else if ((typeparams = tree.getTypeParameters()) != null && !typeparams.isEmpty()) {
        lastKnownOffsetInHeader = sp.getEndPosition(cut, typeparams.get(typeparams.size() - 1));
    } else if (tree.getReturnType() != null) {
        lastKnownOffsetInHeader = sp.getEndPosition(cut, tree.getReturnType());
    } else if (tree.getModifiers() != null) {
        lastKnownOffsetInHeader = sp.getEndPosition(cut, tree.getModifiers());
    }
    
    TokenSequence<JavaTokenId> ts = info.getTreeUtilities().tokensFor(tree);
    
    ts.move((int) lastKnownOffsetInHeader);
    
    while (ts.moveNext()) {
        if (ts.token().id() == JavaTokenId.LBRACE || ts.token().id() == JavaTokenId.SEMICOLON) {
            return offset < ts.offset();
        }
    }
    
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:JavadocUtilities.java

示例5: visitMethod

import com.sun.source.tree.MethodTree; //導入方法依賴的package包/類
@Override
public MethodArgument[] visitMethod(MethodTree node, Object p) {
    long startMethod = positions.getStartPosition(tree, node);
    long endMethod = positions.getEndPosition(tree, node);
    if (methodInvocation || startMethod == Diagnostic.NOPOS || endMethod == Diagnostic.NOPOS ||
                            !(offset >= lineMap.getLineNumber(startMethod) &&
                             (offset <= lineMap.getLineNumber(endMethod)))) {
        return super.visitMethod(node, p);
    }
    List<? extends VariableTree> args = node.getParameters();
    List<? extends TypeParameterTree> argTypes = node.getTypeParameters();
    int n = args.size();
    arguments = new MethodArgument[n];
    for (int i = 0; i < n; i++) {
        VariableTree var = args.get(i);
        long startOffset = positions.getStartPosition(tree, var);
        long endOffset = positions.getEndPosition(tree, var);
        if (startOffset == Diagnostic.NOPOS || endOffset == Diagnostic.NOPOS) {
            return new MethodArgument[] {};
        }
        arguments[i] = new MethodArgument(var.getName().toString(),
                                          var.getType().toString(),
                                          positionDelegate.createPosition(
                                            (int) startOffset,
                                            (int) lineMap.getLineNumber(startOffset),
                                            (int) lineMap.getColumnNumber(startOffset)),
                                          positionDelegate.createPosition(
                                            (int) endOffset,
                                            (int) lineMap.getLineNumber(endOffset),
                                            (int) lineMap.getColumnNumber(endOffset)));
    }
    return arguments;
    //return composeArguments(args, argTypes);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:MethodArgumentsScanner.java


注:本文中的com.sun.source.tree.MethodTree.getParameters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。