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


Java TypeParameterTree类代码示例

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


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

示例1: createMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
private static MethodTree createMethod(WorkingCopy wc, MethodInfo mInfo) {
    TreeMaker make = wc.getTreeMaker();
    TypeInfo[] pTypes = mInfo.getParameterTypes();
    String[] pNames = mInfo.getParameterNames();
    List<VariableTree> params = new ArrayList<VariableTree>();
    for (int i = 0 ; pTypes != null && i < pTypes.length; i++) {
        VariableTree vtree = createVariable(wc, pNames[i], pTypes[i]);
        params.add(vtree);
    }
    
    TypeInfo[] excepTypes = mInfo.getExceptionTypes();
    List<ExpressionTree> throwsList = new ArrayList<ExpressionTree>();
    for (int i = 0 ; excepTypes != null && i < excepTypes.length; i++) {
        throwsList.add((ExpressionTree)createType(wc, excepTypes[i]));
    }
    
    String body = mInfo.getMethodBodyText();
    if(body == null) {
        body = "";
    }
    
    MethodTree mtree = make.Method(createModifiers(wc, mInfo.getModifiers(), mInfo.getAnnotations()),
            mInfo.getName(),
            createType(wc, mInfo.getReturnType()),
            Collections.<TypeParameterTree>emptyList(),
            params,
            throwsList,
            "{" + body + "}",
            null
            );
    
    //         if(mInfo.getCommentText() != null) {
    //             Comment comment = Comment.create(Comment.Style.JAVADOC, -2,
    //                     -2, -2, mInfo.getCommentText());
    //             make.addComment(mtree, comment, true);
    //         }
    
    return mtree;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:JpaControllerUtil.java

示例2: createHashCodeMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
public MethodTree createHashCodeMethod(List<VariableTree> fields) {
    StringBuilder body = new StringBuilder(20 + fields.size() * 30);
    body.append("{"); // NOI18N
    body.append("int hash = 0;"); // NOI18N
    for (VariableTree field : fields) {
        body.append(createHashCodeLineForField(field));
    }
    body.append("return hash;"); // NOI18N
    body.append("}"); // NOI18N
    TreeMaker make = copy.getTreeMaker();
    // XXX Javadoc
    return make.Method(make.Modifiers(EnumSet.of(Modifier.PUBLIC),
            Collections.singletonList(genUtils.createAnnotation("java.lang.Override"))), "hashCode",
            make.PrimitiveType(TypeKind.INT), Collections.<TypeParameterTree>emptyList(),
            Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body.toString(), null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:EntityMethodGenerator.java

示例3: createEqualsMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
public  MethodTree createEqualsMethod(String simpleClassName, List<VariableTree> fields) {
    StringBuilder body = new StringBuilder(50 + fields.size() * 30);
    body.append("{"); // NOI18N
    body.append("// TODO: Warning - this method won't work in the case the id fields are not set\n"); // NOI18N
    body.append("if (!(object instanceof "); // NOI18N
    body.append(simpleClassName + ")) {return false;}"); // NOI18N
    body.append(simpleClassName + " other = (" + simpleClassName + ")object;"); // NOI18N
    for (VariableTree field : fields) {
        body.append(createEqualsLineForField(field));
    }
    body.append("return true;"); // NOI18N
    body.append("}"); // NOI18N
    TreeMaker make = copy.getTreeMaker();
    // XXX Javadoc
    return make.Method(make.Modifiers(EnumSet.of(Modifier.PUBLIC),
            Collections.singletonList(genUtils.createAnnotation("java.lang.Override"))), "equals",
            make.PrimitiveType(TypeKind.BOOLEAN), Collections.<TypeParameterTree>emptyList(),
            Collections.singletonList(genUtils.createVariable(scope, "object", "java.lang.Object")),
            Collections.<ExpressionTree>emptyList(), body.toString(), null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:EntityMethodGenerator.java

示例4: createToStringMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
public MethodTree createToStringMethod(String fqn, List<VariableTree> fields) {
    StringBuilder body = new StringBuilder(30 + fields.size() * 30);
    body.append("{"); // NOI18N
    body.append("return \"" + fqn + "[ "); // NOI18N
    for (Iterator<VariableTree> i = fields.iterator(); i.hasNext();) {
        String fieldName = i.next().getName().toString();
        body.append(fieldName + "=\" + " + fieldName + " + \""); //NOI18N
        body.append(i.hasNext() ? ", " : " ]\";"); //NOI18N
    }
    body.append("}"); // NOI18N
    TreeMaker make = copy.getTreeMaker();
    // XXX Javadoc
    return make.Method(make.Modifiers(EnumSet.of(Modifier.PUBLIC),
            Collections.singletonList(genUtils.createAnnotation("java.lang.Override"))), "toString",
            genUtils.createType("java.lang.String", scope), Collections.<TypeParameterTree>emptyList(),
            Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body.toString(), null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:EntityMethodGenerator.java

示例5: makeTypeParamsCopy

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
/**
 * Makes a list of trees representing the given type parameter elements.
 */
private static List<TypeParameterTree> makeTypeParamsCopy(
                            List<? extends TypeParameterElement> typeParams,
                            TreeMaker maker) {
    if (typeParams.isEmpty()) {
        return Collections.emptyList();
    }

    int size = typeParams.size();
    if (size == 1) {
        return Collections.singletonList(makeCopy(typeParams.get(0), maker));
    }

    List<TypeParameterTree> result = new ArrayList(size);
    for (TypeParameterElement typeParam : typeParams) {
        result.add(makeCopy(typeParam, maker));
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:AbstractTestGenerator.java

示例6: createMainMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
/**
 * Creates a public static {@code main(String[])} method
 * with the body taken from settings.
 *
 * @param  maker  {@code TreeMaker} to use for creating the method
 * @return  created {@code main(...)} method,
 *          or {@code null} if the method body would be empty
 */
private MethodTree createMainMethod(TreeMaker maker) {
    String initialMainMethodBody = getInitialMainMethodBody();
    if (initialMainMethodBody.length() == 0) {
        return null;
    }

    ModifiersTree modifiers = maker.Modifiers(
            createModifierSet(Modifier.PUBLIC, Modifier.STATIC));
    VariableTree param = maker.Variable(
                    maker.Modifiers(Collections.<Modifier>emptySet()),
                    "argList",                                      //NOI18N
                    maker.Identifier("String[]"),                   //NOI18N
                    null);            //initializer - not used in params
    MethodTree mainMethod = maker.Method(
          modifiers,                            //public static
          "main",                               //method name "main"//NOI18N
          maker.PrimitiveType(TypeKind.VOID),   //return type "void"
          Collections.<TypeParameterTree>emptyList(),     //type params
          Collections.<VariableTree>singletonList(param), //method param
          Collections.<ExpressionTree>emptyList(),        //throws-list
          '{' + initialMainMethodBody + '}',    //body text
          null);                                //only for annotations

    return mainMethod;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:AbstractTestGenerator.java

示例7: composeNewTestClass

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
/**
 */
@Override
protected ClassTree composeNewTestClass(WorkingCopy workingCopy,
                                        String name,
                                        List<? extends Tree> members) {
    final TreeMaker maker = workingCopy.getTreeMaker();
    ModifiersTree modifiers = maker.Modifiers(
                                  Collections.<Modifier>singleton(PUBLIC));
    return maker.Class(
                modifiers,                                 //modifiers
                name,                                      //name
                Collections.<TypeParameterTree>emptyList(),//type params
                null,                                      //extends
                Collections.<ExpressionTree>emptyList(),   //implements
                members);                                  //members
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:TestGenerator.java

示例8: composeNewTestMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
/**
 */
@Override
protected MethodTree composeNewTestMethod(String testMethodName,
                                          BlockTree testMethodBody,
                                          List<ExpressionTree> throwsList,
                                          WorkingCopy workingCopy) {
    TreeMaker maker = workingCopy.getTreeMaker();
    return maker.Method(
            createModifiersTree(ANN_TEST,
                                createModifierSet(PUBLIC),
                                workingCopy),
            testMethodName,
            maker.PrimitiveType(TypeKind.VOID),
            Collections.<TypeParameterTree>emptyList(),
            Collections.<VariableTree>emptyList(),
            throwsList,
            testMethodBody,
            null);          //default value - used by annotations
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:TestGenerator.java

示例9: typeParametersRest

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
/**
 * Does not omit the leading '<', which should be associated with the type name.
 */
private void typeParametersRest(
        List<? extends TypeParameterTree> typeParameters, Indent plusIndent) {
    builder.open(plusIndent);
    builder.breakOp();
    builder.open(ZERO);
    boolean first = true;
    for (TypeParameterTree typeParameter : typeParameters) {
        if (!first) {
            token(",");
            builder.breakOp(" ");
        }
        scan(typeParameter, null);
        first = false;
    }
    token(">");
    builder.close();
    builder.close();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:JavaInputAstVisitor.java

示例10: composeNewTestClass

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
/**
 */
protected ClassTree composeNewTestClass(WorkingCopy workingCopy,
                                        String name,
                                        List<? extends Tree> members) {
    final TreeMaker maker = workingCopy.getTreeMaker();
    ModifiersTree modifiers = maker.Modifiers(
                                  Collections.<Modifier>singleton(PUBLIC));
    Tree extendsClause = getClassIdentifierTree(TEST_CASE, workingCopy);
    return maker.Class(
                modifiers,                                 //modifiers
                name,                                      //name
                Collections.<TypeParameterTree>emptyList(),//type params
                extendsClause,                             //extends
                Collections.<ExpressionTree>emptyList(),   //implements
                members);                                  //members
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JUnit3TestGenerator.java

示例11: composeNewTestMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
/**
 */
protected MethodTree composeNewTestMethod(String testMethodName,
                                          BlockTree testMethodBody,
                                          List<ExpressionTree> throwsList,
                                          WorkingCopy workingCopy) {
    TreeMaker maker = workingCopy.getTreeMaker();
    return maker.Method(
            maker.Modifiers(createModifierSet(PUBLIC)),
            testMethodName,
            maker.PrimitiveType(TypeKind.VOID),
            Collections.<TypeParameterTree>emptyList(),
            Collections.<VariableTree>emptyList(),
            throwsList,
            testMethodBody,
            null);          //default value - used by annotations
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JUnit3TestGenerator.java

示例12: createMainMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
/**
 * Creates a public static {@literal main(String[])} method
 * with the body taken from settings.
 *
 * @param  maker  {@literal TreeMaker} to use for creating the method
 * @return  created {@literal main(...)} method,
 *          or {@literal null} if the method body would be empty
 */
private MethodTree createMainMethod(TreeMaker maker) {
    String initialMainMethodBody = getInitialMainMethodBody();
    if (initialMainMethodBody.length() == 0) {
        return null;
    }

    ModifiersTree modifiers = maker.Modifiers(
            createModifierSet(Modifier.PUBLIC, Modifier.STATIC));
    VariableTree param = maker.Variable(
                    maker.Modifiers(Collections.<Modifier>emptySet()),
                    "argList",                                      //NOI18N
                    maker.Identifier("String[]"),                   //NOI18N
                    null);            //initializer - not used in params
    MethodTree mainMethod = maker.Method(
          modifiers,                            //public static
          "main",                               //method name "main"//NOI18N
          maker.PrimitiveType(TypeKind.VOID),   //return type "void"
          Collections.<TypeParameterTree>emptyList(),     //type params
          Collections.<VariableTree>singletonList(param), //method param
          Collections.<ExpressionTree>emptyList(),        //throws-list
          '{' + initialMainMethodBody + '}',    //body text
          null);                                //only for annotations

    return mainMethod;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:AbstractTestGenerator.java

示例13: visitMethod

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
@Override
public Number visitMethod(MethodTree node, Void p) {
    String name = node.getName().toString();
    String newName = name;

    if (name.startsWith("$")) {
        if (parameterNames.containsKey(name)) {
            newName = parameterNames.get(name);
        }
    }

    List<? extends TypeParameterTree> typeParams = resolveMultiParameters(node.getTypeParameters());
    List<? extends VariableTree> params = resolveMultiParameters(node.getParameters());
    List<? extends ExpressionTree> thrown = resolveMultiParameters(node.getThrows());
    
    MethodTree nue = make.Method(node.getModifiers(), newName, node.getReturnType(), typeParams, params, thrown, node.getBody(), (ExpressionTree) node.getDefaultValue());
    
    rewrite(node, nue);
    
    return super.visitMethod(nue, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JavaFixUtilities.java

示例14: visitClass

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
@Override
public Number visitClass(ClassTree node, Void p) {
    String name = node.getSimpleName().toString();
    String newName = name;

    if (name.startsWith("$")) {
        if (parameterNames.containsKey(name)) {
            newName = parameterNames.get(name);
        }
    }

    List<? extends TypeParameterTree> typeParams = resolveMultiParameters(node.getTypeParameters());
    List<? extends Tree> implementsClauses = resolveMultiParameters(node.getImplementsClause());
    List<? extends Tree> members = resolveMultiParameters(Utilities.filterHidden(getCurrentPath(), node.getMembers()));
    Tree extend = resolveOptionalValue(node.getExtendsClause());
    ClassTree nue = make.Class(node.getModifiers(), newName, typeParams, extend, implementsClauses, members);
    
    rewrite(node, nue);
    
    return super.visitClass(nue, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JavaFixUtilities.java

示例15: visitTypeParameter

import com.sun.source.tree.TypeParameterTree; //导入依赖的package包/类
@Override
public Void visitTypeParameter(TypeParameterTree node, Void p) {
    Element el = info.getTrees().getElement(getCurrentPath());
    if (toFind.equals(el)) {
        try {
            int[] span = treeUtils.findNameSpan(node);
            if(span != null) {
                MutablePositionRegion region = createRegion(doc, span[0], span[1]);
                usages.add(region);
            }
        } catch (BadLocationException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return super.visitTypeParameter(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:FindLocalUsagesQuery.java


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