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


Java ClassTree.getSimpleName方法代碼示例

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


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

示例1: run

import com.sun.source.tree.ClassTree; //導入方法依賴的package包/類
@Override
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    if (treePath.getLeaf().getKind() == Kind.METHOD) {
        MethodTree mt = (MethodTree) treePath.getLeaf();
        TreePath parentPath = treePath.getParentPath();
        ClassTree ct = (ClassTree) parentPath.getLeaf();
        Trees trees = compilationInfo.getTrees();
        Types types = compilationInfo.getTypes();
        TreeUtilities tu = compilationInfo.getTreeUtilities();
        TypeMirror type = types.erasure(trees.getTypeMirror(treePath));
        if (!Utilities.isValidType(type)) {
            return null;
        }
        for (Tree member : ct.getMembers()) {
            TreePath memberPath = new TreePath(parentPath, member);
            if (member.getKind() == Kind.METHOD && "<init>".contentEquals(((MethodTree)member).getName()) //NOI18N
                    && !tu.isSynthetic(memberPath) && types.isSameType(types.erasure(trees.getTypeMirror(memberPath)), type)) {
                return null;
            }
        }
        RenameConstructorFix fix = new RenameConstructorFix(compilationInfo.getSnapshot().getSource(), TreePathHandle.create(treePath, compilationInfo), offset, mt.getName(), ct.getSimpleName());
        return Collections.<Fix>singletonList(fix);
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:RenameConstructor.java

示例2: enterClass

import com.sun.source.tree.ClassTree; //導入方法依賴的package包/類
public void enterClass(ClassTree ct) {
    if (ct.getSimpleName() == null || ct.getSimpleName().length() == 0 || anonymousCounter > 0) {
        anonymousCounter++;
    } else {
        if (fqn.length() > 0) fqn.append('.');
        fqn.append(ct.getSimpleName());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:ElementOverlay.java

示例3: ensureNoArgConstructor

import com.sun.source.tree.ClassTree; //導入方法依賴的package包/類
public ClassTree ensureNoArgConstructor(ClassTree classTree) {
    TypeElement typeElement = SourceUtils.classTree2TypeElement(copy, classTree);
    if (typeElement == null) {
        throw new IllegalArgumentException("No TypeElement for ClassTree " + classTree.getSimpleName());
    }
    ExecutableElement constructor = SourceUtils.getNoArgConstructor(copy, typeElement);
    MethodTree constructorTree = constructor != null ? copy.getTrees().getTree(constructor) : null;
    MethodTree newConstructorTree = null;
    TreeMaker make = getTreeMaker();
    if (constructor != null) {
        if (!constructor.getModifiers().contains(Modifier.PUBLIC)) {
            ModifiersTree oldModifiersTree = constructorTree.getModifiers();
            Set newModifiers = EnumSet.of(Modifier.PUBLIC);
       //     for (Modifier modifier : oldModifiersTree.getFlags()) {
         //       if (!Modifier.PROTECTED.equals(modifier) && !Modifier.PRIVATE.equals(modifier)) {
           //         newModifiers.add(modifier);
             //   }
            //}
            newConstructorTree = make.Constructor(
                make.Modifiers(newModifiers),
                constructorTree.getTypeParameters(),
                constructorTree.getParameters(),
                constructorTree.getThrows(),
                constructorTree.getBody());
        }
    } else {
        newConstructorTree = make.Constructor(
                createModifiers(Modifier.PUBLIC),
                Collections.<TypeParameterTree>emptyList(),
                Collections.<VariableTree>emptyList(),
                Collections.<ExpressionTree>emptyList(),
                "{ }"); // NOI18N
    }
    ClassTree newClassTree = classTree;
    if (newConstructorTree != null) {
        if (constructorTree != null) {
            newClassTree = make.removeClassMember(newClassTree, constructorTree);
        }
        newClassTree = make.addClassMember(newClassTree, newConstructorTree);
    }
    return newClassTree;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:43,代碼來源:GenerationUtils.java

示例4: ensureNoArgConstructor

import com.sun.source.tree.ClassTree; //導入方法依賴的package包/類
/**
 * Ensures the given class has a public no-arg constructor.
 *
 * @param  classTree the class to ensure the constructor for; cannot be null.
 * @return a modified class if a no-arg constructor was added, the original
 *         class otherwise; never null.
 */
public ClassTree ensureNoArgConstructor(ClassTree classTree) {
    TypeElement typeElement = SourceUtils.classTree2TypeElement(copy, classTree);
    if (typeElement == null) {
        throw new IllegalArgumentException("No TypeElement for ClassTree " + classTree.getSimpleName());
    }
    ExecutableElement constructor = SourceUtils.getNoArgConstructor(copy, typeElement);
    MethodTree constructorTree = constructor != null ? copy.getTrees().getTree(constructor) : null;
    MethodTree newConstructorTree = null;
    TreeMaker make = getTreeMaker();
    if (constructor != null) {
        if (!constructor.getModifiers().contains(Modifier.PUBLIC)) {
            ModifiersTree oldModifiersTree = constructorTree.getModifiers();
            Set<Modifier> newModifiers = EnumSet.of(Modifier.PUBLIC);
            for (Modifier modifier : oldModifiersTree.getFlags()) {
                if (!Modifier.PROTECTED.equals(modifier) && !Modifier.PRIVATE.equals(modifier)) {
                    newModifiers.add(modifier);
                }
            }
            newConstructorTree = make.Constructor(
                make.Modifiers(newModifiers),
                constructorTree.getTypeParameters(),
                constructorTree.getParameters(),
                constructorTree.getThrows(),
                constructorTree.getBody());
        }
    } else {
        newConstructorTree = make.Constructor(
                createModifiers(Modifier.PUBLIC),
                Collections.<TypeParameterTree>emptyList(),
                Collections.<VariableTree>emptyList(),
                Collections.<ExpressionTree>emptyList(),
                "{ }"); // NOI18N
    }
    ClassTree newClassTree = classTree;
    if (newConstructorTree != null) {
        if (constructorTree != null) {
            newClassTree = make.removeClassMember(newClassTree, constructorTree);
        }
        newClassTree = make.addClassMember(newClassTree, newConstructorTree);
    }
    return newClassTree;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:50,代碼來源:GenerationUtils.java


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