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


Java ClassTree類代碼示例

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


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

示例1: getClassTree

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
public static ClassTree getClassTree(
        TreeMaker make,
        WorkingCopy workingCopy,
        String name,
        String superClass,
        List<ExpressionTree> implementsList,
        Set<Modifier> modifiers) {        
        
    Tree extendsTree = make.QualIdent(workingCopy.getElements().getTypeElement(superClass));        
    Map<String,String> params = new HashMap<String, String>();
    params.put("param1", "String");
    MethodTree mt = Common.createMethod(make, "method", params);
    VariableTree vt = Common.createField(make, "variable", EnumSet.of(Modifier.PROTECTED), "double");
    List<Tree> members = new ArrayList<Tree>();
    members.add(mt);
    members.add(vt);
    members.add(make.Block(Collections.EMPTY_LIST, false));
    ClassTree innerClass = make.Class(
            make.Modifiers(modifiers),
            name,
            Collections.EMPTY_LIST,
            extendsTree,
            implementsList,
            members);        
    return innerClass;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:Common.java

示例2: testGetterNamingConvention0

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
public void testGetterNamingConvention0() throws Exception {//#165241
    performTest("package test;\npublic class Test {\nprivate int eMai;\npublic Test(){\n}\n }\n", new GetterSetterTask(34, false), new Validator() {

        public void validate(CompilationInfo info) {
            ClassTree ct = (ClassTree) info.getCompilationUnit().getTypeDecls().get(0);

            for (Tree member : ct.getMembers()) {
                if (member.getKind() == Kind.METHOD) {
                    String name = ((MethodTree) member).getName().toString();
                    if (!name.equals("<init>")) {
                        assertEquals(name, "seteMai");
                    }
                }
            }
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:GeneratorUtilitiesTest.java

示例3: instantiateStrategy

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
private EntityManagerGenerationStrategy instantiateStrategy(Class<? extends EntityManagerGenerationStrategy> strategy, WorkingCopy workingCopy,
        TreeMaker make, ClassTree clazz, GenerationOptions options){
    
    EntityManagerGenerationStrategy result = null;
    
    try{
        result = strategy.newInstance();
        result.setClassTree(clazz);
        result.setWorkingCopy(workingCopy);
        result.setGenerationOptions(options);
        result.setTreeMaker(make);
        result.setPersistenceUnit(getPersistenceUnit());
    } catch (IllegalAccessException iae){
        throw new RuntimeException(iae); //TODO
    } catch (InstantiationException ie){
        throw new RuntimeException(ie); //TODO
    }
    
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:EntityManagerGenerator.java

示例4: run

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
public void run(WorkingCopy workingCopy) throws Exception {
    
    workingCopy.toPhase(Phase.RESOLVED);
    CompilationUnitTree cut = workingCopy.getCompilationUnit();
    TreeMaker make = workingCopy.getTreeMaker();
    
    for (Tree typeDeclaration : cut.getTypeDecls()){
        if (TreeUtilities.CLASS_TREE_KINDS.contains(typeDeclaration.getKind())){
            ClassTree clazz = (ClassTree) typeDeclaration;
            EntityManagerGenerationStrategySupport strategy =
                    (EntityManagerGenerationStrategySupport) getStrategy(workingCopy, make, clazz, new GenerationOptions());
            doAsserts(strategy);
        } else {
            fail("No class found"); // should not happen
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:EntityManagerGenerationStrategySupportTest.java

示例5: findTopClasses

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
/**
 * 
 * @return  list of top classes, or an empty list of none were found
 */
static List<ClassTree> findTopClasses(
                                    CompilationUnitTree compilationUnit,
                                    TreeUtilities treeUtils) {
    List<? extends Tree> typeDecls = compilationUnit.getTypeDecls();
    if ((typeDecls == null) || typeDecls.isEmpty()) {
        return Collections.<ClassTree>emptyList();
    }

    List<ClassTree> result = new ArrayList<ClassTree>(typeDecls.size());
    
    for (Tree typeDecl : typeDecls) {
        if (TreeUtilities.CLASS_TREE_KINDS.contains(typeDecl.getKind())) {
            ClassTree clsTree = (ClassTree) typeDecl;
            if (isTestable(clsTree, treeUtils)) {
                result.add(clsTree);
            }
        }
    }

    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:TopClassFinder.java

示例6: findMainClass

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
/**
 * Finds a main class.
 *
 * @param  compInfo  defines scope in which the class is to be found
 * @param  className  name of the class to be found
 * @return  the found class; or <code>null</code> if the class was not
 *          found (e.g. because of a broken source file)
 */
public static ClassTree findMainClass(final CompilationInfo compInfo) {
    final String className = compInfo.getFileObject().getName();
    
    CompilationUnitTree compUnitTree = compInfo.getCompilationUnit();
    String shortClassName = getSimpleName(className);
    for (Tree typeDecl : compUnitTree.getTypeDecls()) {
        if (TreeUtilities.CLASS_TREE_KINDS.contains(typeDecl.getKind())) {
            ClassTree clazz = (ClassTree) typeDecl;
            if (clazz.getSimpleName().toString().equals(shortClassName)) {
                return clazz;
            }
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:TestUtil.java

示例7: visitClass

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
@Override
public synchronized Void visitClass(ClassTree t, Void v) {
    Element el = info.getTrees().getElement(getCurrentPath());
    if (el == null) {
        return null;
    }
    TypeElement te = (TypeElement) el;
    List<VariableElement> fields = ElementFilter.fieldsIn(te.getEnclosedElements());
    enumConsts = new LinkedList<String>();
    for (VariableElement field : fields) {
        if (field.getKind() == ElementKind.ENUM_CONSTANT) {
            String name = field.getSimpleName().toString();
            enumConsts.add(name);
        }
    }
    return null;
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:18,代碼來源:EnumStructureFactory.java

示例8: composeNewTestClass

import com.sun.source.tree.ClassTree; //導入依賴的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

示例9: testVariableInitWrapped

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
public void testVariableInitWrapped() throws Exception {
    String code = "package hierbas.del.litoral;\n\n" +
        "import java.util.concurrent.atomic.AtomicBoolean;\n\n" +
        "public class Test {\n" +
        "    public void t() {\n" +
        "        new AtomicBoolean();\n" + 
        "    }\n" +
        "}\n";
    runWrappingTest(code, new Task<WorkingCopy>() {
        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree method = (MethodTree) clazz.getMembers().get(1);
            ExpressionStatementTree init = (ExpressionStatementTree) method.getBody().getStatements().get(0);
            VariableTree nue = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "ab", make.Type("java.util.concurrent.atomic.AtomicBoolean"), init.getExpression());
            workingCopy.rewrite(init, nue);
        }
    }, FmtOptions.wrapAssignOps, WrapStyle.WRAP_IF_LONG.name());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:WrappingTest.java

示例10: composeNewTestClass

import com.sun.source.tree.ClassTree; //導入依賴的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: performArithmeticTest

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
private void performArithmeticTest(String orig, String nue) throws Exception {
    String code = replace("0");

    prepareTest("Test.java", code);
    ClassTree clazz = (ClassTree) info.getCompilationUnit().getTypeDecls().get(0);
    VariableTree variable = (VariableTree) clazz.getMembers().get(1);
    ExpressionTree init = variable.getInitializer();
    TreePath tp = new TreePath(new TreePath(new TreePath(new TreePath(info.getCompilationUnit()), clazz), variable), init);
    Fix fix = JavaFixUtilities.rewriteFix(info, "A", tp, orig, Collections.<String, TreePath>emptyMap(), Collections.<String, Collection<? extends TreePath>>emptyMap(), Collections.<String, String>emptyMap(), Collections.<String, TypeMirror>emptyMap(), Collections.<String, String>emptyMap());
    fix.implement();

    String golden = replace(nue);
    String out = doc.getText(0, doc.getLength());

    assertEquals(golden, out);

    LifecycleManager.getDefault().saveAll();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:JavaFixUtilitiesTest.java

示例12: visitAnnotationType

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
public void visitAnnotationType(ClassTree node) {
    sync(node);
    builder.open(ZERO);
    visitAndBreakModifiers(node.getModifiers(), Direction.VERTICAL, Optional.<BreakTag>absent());
    builder.open(ZERO);
    token("@");
    token("interface");
    builder.breakOp(" ");
    visit(node.getSimpleName());
    builder.close();
    builder.close();
    if (node.getMembers() == null) {
        builder.open(plusFour);
        token(";");
        builder.close();
    } else {
        addBodyDeclarations(node.getMembers(), BracesOrNot.YES, FirstDeclarationsOrNot.YES);
    }
    builder.guessToken(";");
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:21,代碼來源:JavaInputAstVisitor.java

示例13: implement

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
public ChangeInfo implement(){
    CancellableTask<WorkingCopy> task = new CancellableTask<WorkingCopy>(){
        public void cancel() {}
        
        public void run(WorkingCopy workingCopy) throws Exception {
            workingCopy.toPhase(JavaSource.Phase.RESOLVED);
            TypeElement clazz = classHandle.resolve(workingCopy);
            
            if (clazz != null){    
                ClassTree clazzTree = workingCopy.getTrees().getTree(clazz);
                GenerationUtils genUtils = GenerationUtils.newInstance(workingCopy);
                ClassTree modifiedClazz = genUtils.addImplementsClause(clazzTree, "java.io.Serializable"); // NOI18N
                workingCopy.rewrite(clazzTree, modifiedClazz);
            }
        }
    };
    
    JavaSource javaSource = JavaSource.forFileObject(fileObject);
    
    try{
        javaSource.runModificationTask(task).commit();
    } catch (IOException e){
        JPAProblemFinder.LOG.log(Level.SEVERE, e.getMessage(), e);
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ImplementSerializable.java

示例14: createSetter

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
/**
 * Creates a setter method for a field.
 *
 * @param clazz the class to create the setter within
 * @param field field to create setter for
 * @return the setter method
 * @since 0.20
 */
public MethodTree createSetter(ClassTree clazz, VariableTree field) {
    assert clazz != null && field != null;
    TreeMaker make = copy.getTreeMaker();
    Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);
    boolean isStatic = field.getModifiers().getFlags().contains(Modifier.STATIC);
    if (isStatic)
        mods.add(Modifier.STATIC);
    CharSequence name = field.getName();
    assert name.length() > 0;
    CodeStyle cs = DiffContext.getCodeStyle(copy);
    String propName = removeFieldPrefixSuffix(field, cs);
    String setterName = CodeStyleUtils.computeSetterName(field.getName(), isStatic, cs);
    String paramName = addParamPrefixSuffix(propName, cs);
    List<VariableTree> params = Collections.singletonList(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), paramName, field.getType(), null));
    BlockTree body = make.Block(Collections.singletonList(make.ExpressionStatement(make.Assignment(make.MemberSelect(isStatic? make.Identifier(clazz.getSimpleName()) : make.Identifier("this"), name), make.Identifier(paramName)))), false); //NOI18N
    return make.Method(make.Modifiers(mods), setterName, make.Type(copy.getTypes().getNoType(TypeKind.VOID)), Collections.<TypeParameterTree>emptyList(), params, Collections.<ExpressionTree>emptyList(), body, null);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:GeneratorUtilities.java

示例15: testEnsureNoArgConstructorMakesConstructorPublic

import com.sun.source.tree.ClassTree; //導入依賴的package包/類
public void testEnsureNoArgConstructorMakesConstructorPublic() throws Exception {
    TestUtilities.copyStringToFileObject(testFO,
            "package foo;" +
            "public class TestClass {" +
            "    private TestClass() {" +
            "    }" +
            "}");
    runModificationTask(testFO, new Task<WorkingCopy>() {
        public void run(WorkingCopy copy) throws Exception {
            GenerationUtils genUtils = GenerationUtils.newInstance(copy);
            ClassTree classTree = (ClassTree)copy.getCompilationUnit().getTypeDecls().get(0);
            ClassTree newClassTree = genUtils.ensureNoArgConstructor(classTree);
            copy.rewrite(classTree, newClassTree);
        }
    }).commit();
    runUserActionTask(testFO, new Task<CompilationController>() {
        public void run(CompilationController controller) throws Exception {
            TypeElement typeElement = SourceUtils.getPublicTopLevelElement(controller);
            assertTrue(SourceUtils.getNoArgConstructor(controller, typeElement).getModifiers().contains(Modifier.PUBLIC));
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:GenerationUtilsTest.java


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