com.sun.source.tree.ClassTree#getSimpleName ( )源码实例Demo

下面列出了com.sun.source.tree.ClassTree#getSimpleName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: RenameConstructor.java
@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;
}
 
源代码2 项目: netbeans   文件: ElementOverlay.java
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());
    }
}
 
源代码3 项目: netbeans   文件: GenerationUtils.java
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;
}
 
源代码4 项目: netbeans   文件: GenerationUtils.java
/**
 * 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;
}
 
源代码5 项目: netbeans   文件: GenerationUtils.java
/**
 * 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;
}