本文整理汇总了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;
}
示例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());
}
}
示例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;
}
示例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;
}