本文整理汇总了Java中com.sun.source.tree.ClassTree.getMembers方法的典型用法代码示例。如果您正苦于以下问题:Java ClassTree.getMembers方法的具体用法?Java ClassTree.getMembers怎么用?Java ClassTree.getMembers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.ClassTree
的用法示例。
在下文中一共展示了ClassTree.getMembers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitClass
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
public Void visitClass(ClassTree node, Boolean p) {
TypeElement te = (TypeElement)model.getElement(node);
if (te != null) {
List<Tree> members = new ArrayList<Tree>();
for(Tree m : node.getMembers())
members.add(m);
members.add(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "test", make.PrimitiveType(TypeKind.INT), null));
ClassTree decl = make.Class(node.getModifiers(), node.getSimpleName(), node.getTypeParameters(), node.getExtendsClause(), (List<ExpressionTree>)node.getImplementsClause(), members);
model.setElement(decl, te);
model.setType(decl, model.getType(node));
model.setPos(decl, model.getPos(node));
copy.rewrite(node, decl);
}
return null;
}
示例2: generateStubTestMethod
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
protected ClassTree generateStubTestMethod(ClassTree tstClass,
String testMethodName,
WorkingCopy workingCopy) {
List<? extends Tree> tstMembersOrig = tstClass.getMembers();
List<Tree> tstMembers = new ArrayList<Tree>(tstMembersOrig.size() + 4);
tstMembers.addAll(tstMembersOrig);
List<ExpressionTree> throwsList = Collections.emptyList();
MethodTree method = composeNewTestMethod(
STUB_TEST_NAME,
generateStubTestMethodBody(workingCopy),
throwsList,
workingCopy);
tstMembers.add(method);
ClassTree newClass = workingCopy.getTreeMaker().Class(
tstClass.getModifiers(),
tstClass.getSimpleName(),
tstClass.getTypeParameters(),
tstClass.getExtendsClause(),
(List<? extends ExpressionTree>) tstClass.getImplementsClause(),
tstMembers);
return newClass;
}
示例3: 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(";");
}
示例4: visitClass
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
@Override
public Void visitClass(ClassTree node, Void p) {
final SourcePositions sourcePositions = wc.getTrees().getSourcePositions();
final TreeMaker make = wc.getTreeMaker();
List<Tree> members = new LinkedList<Tree>();
ClassTree classTree = node;
for (Tree member : node.getMembers()) {
int s = (int) sourcePositions.getStartPosition(wc.getCompilationUnit(), member);
int e = (int) sourcePositions.getEndPosition(wc.getCompilationUnit(), member);
if (s >= start && e <= end) {
classTree = make.removeClassMember(classTree, member);
members.add(member);
}
}
classTree = GeneratorUtils.insertClassMembers(wc, classTree, members, start);
wc.rewrite(node, classTree);
return super.visitClass(classTree, p);
}
示例5: getIndexForField
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
protected int getIndexForField(ClassTree clazz){
int result = 0;
for (Tree each : clazz.getMembers()){
if (Tree.Kind.VARIABLE == each.getKind()){
result++;
}
}
return result;
}
示例6: modifyDefaultConstructor
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
public static ClassTree modifyDefaultConstructor(ClassTree classTree, ClassTree modifiedClassTree, WorkingCopy wc, MethodInfo modifiedConstructorInfo) {
if (!"<init>".equals(modifiedConstructorInfo.getName())) {
throw new IllegalArgumentException("modifiedConstructorInfo name must be <init>");
}
MethodTree modifiedConstructor = createMethod(wc, modifiedConstructorInfo);
MethodTree constructor = null;
for(Tree tree : modifiedClassTree.getMembers()) {
if(Tree.Kind.METHOD == tree.getKind()) {
MethodTree mtree = (MethodTree)tree;
List<? extends VariableTree> mTreeParameters = mtree.getParameters();
if(mtree.getName().toString().equals("<init>") &&
(mTreeParameters == null || mTreeParameters.isEmpty()) &&
!wc.getTreeUtilities().isSynthetic(wc.getTrees().getPath(wc.getCompilationUnit(), classTree))) {
constructor = mtree;
break;
}
}
}
if (constructor == null) {
modifiedClassTree = wc.getTreeMaker().addClassMember(modifiedClassTree, modifiedConstructor);
}
else {
wc.rewrite(constructor, modifiedConstructor);
}
return modifiedClassTree;
}
示例7: generateMissingInitMembers
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
/**
*/
@Override
protected ClassTree generateMissingInitMembers(ClassTree tstClass,
TreePath tstClassTreePath,
WorkingCopy workingCopy) {
if (!setup.isGenerateBefore() && !setup.isGenerateAfter()
&& !setup.isGenerateBeforeClass() && !setup.isGenerateAfterClass()) {
return tstClass;
}
ClassMap classMap = ClassMap.forClass(tstClass, tstClassTreePath,
workingCopy.getTrees());
if ((!setup.isGenerateBefore() || classMap.containsBefore())
&& (!setup.isGenerateAfter() || classMap.containsAfter())
&& (!setup.isGenerateBeforeClass() || classMap.containsBeforeClass())
&& (!setup.isGenerateAfterClass() || classMap.containsAfterClass())) {
return tstClass;
}
final TreeMaker maker = workingCopy.getTreeMaker();
List<? extends Tree> tstMembersOrig = tstClass.getMembers();
List<Tree> tstMembers = new ArrayList<Tree>(tstMembersOrig.size() + 4);
tstMembers.addAll(tstMembersOrig);
generateMissingInitMembers(tstMembers, classMap, workingCopy);
ClassTree newClass = maker.Class(
tstClass.getModifiers(),
tstClass.getSimpleName(),
tstClass.getTypeParameters(),
tstClass.getExtendsClause(),
(List<? extends ExpressionTree>) tstClass.getImplementsClause(),
tstMembers);
return newClass;
}
示例8: visitClass
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
@Override
public Void visitClass(ClassTree node, Void p) {
for (Tree t : node.getMembers()) {
visit(t, p);
}
return null;
}
示例9: validate
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
public void validate(CompilationInfo info) {
TypeElement test = info.getElements().getTypeElement("test.Test");
ClassTree ct = info.getTrees().getTree(test);
assertNotNull(ct);
int foundTestIdx = -1;
int idx = 0;
for (Tree t : ct.getMembers()) {
Name name = null;
switch(t.getKind()) {
case VARIABLE:
name = ((VariableTree)t).getName();
break;
case METHOD:
name = ((MethodTree)t).getName();
break;
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
name = ((ClassTree)t).getSimpleName();
break;
}
if (name != null) {
if (name.contentEquals("test")) {
assertEquals(-1, foundTestIdx);
foundTestIdx = idx;
} else if (name.contentEquals("<init>") && ((MethodTree)t).getParameters().size() > 0) {
assertEquals(-1, foundTestIdx);
foundTestIdx = idx;
}
}
idx++;
}
assertEquals(testIdx, foundTestIdx);
}
示例10: handleMapAnonClass
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
private void handleMapAnonClass(
MaplikeMethodRecord methodRecord,
MethodInvocationTree observableDotMap,
ClassTree annonClassBody,
VisitorState state) {
for (Tree t : annonClassBody.getMembers()) {
if (t instanceof MethodTree
&& ((MethodTree) t).getName().toString().equals(methodRecord.getInnerMethodName())) {
observableCallToInnerMethodOrLambda.put(observableDotMap, (MethodTree) t);
}
}
}
示例11: generateMissingSuiteClassMembers
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
/**
*/
private ClassTree generateMissingSuiteClassMembers(
ClassTree tstClass,
TreePath tstClassTreePath,
List<String> suiteMembers,
boolean isNewTestClass,
WorkingCopy workingCopy) {
final TreeMaker maker = workingCopy.getTreeMaker();
List<? extends Tree> tstMembersOrig = tstClass.getMembers();
List<Tree> tstMembers = new ArrayList<Tree>(tstMembersOrig.size() + 2);
tstMembers.addAll(tstMembersOrig);
boolean membersChanged = false;
ClassMap classMap = ClassMap.forClass(tstClass,
tstClassTreePath,
workingCopy.getTrees());
membersChanged |= generateMissingInitMembers(tstMembers,
classMap,
workingCopy);
return finishSuiteClass(tstClass,
tstClassTreePath,
tstMembers,
suiteMembers,
membersChanged,
classMap,
workingCopy);
}
示例12: detectMethodsForClass
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
private List<int[]> detectMethodsForClass(CompilationInfo info, Document document, TreePath clazz, List<TypeElement> superTypes, TypeElement thisType) {
List<int[]> highlights = new ArrayList<int[]>();
ClassTree clazzTree = (ClassTree) clazz.getLeaf();
TypeElement jlObject = info.getElements().getTypeElement("java.lang.Object");
OUTER: for (Tree member: clazzTree.getMembers()) {
if (isCancelled()) {
return null;
}
if (member.getKind() == Kind.METHOD) {
TreePath path = new TreePath(clazz, member);
Element el = info.getTrees().getElement(path);
if (el.getKind() == ElementKind.METHOD) {
for (TypeElement superType : superTypes) {
for (ExecutableElement ee : ElementFilter.methodsIn(info.getElements().getAllMembers(superType))) {
if (info.getElements().overrides((ExecutableElement) el, ee, thisType) && (superType.getKind().isClass() || !ee.getEnclosingElement().equals(jlObject))) {
Token t = Utilities.getToken(info, document, path);
if (t != null) {
highlights.add(new int[] {t.offset(null), t.offset(null) + t.length()});
}
continue OUTER;
}
}
}
}
}
}
return highlights;
}
示例13: tooManyConstructors
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
@Hint(
displayName = "#DN_ClassConstructorCount",
description = "#DESC_ClassConstructorCount",
category = "metrics",
options = { Hint.Options.HEAVY, Hint.Options.QUERY },
enabled = false
)
@UseOptions({OPTION_CLASS_CONSTRUCTORS_LIMIT})
@TriggerTreeKind(Tree.Kind.CLASS)
public static ErrorDescription tooManyConstructors(HintContext ctx) {
ClassTree clazz = (ClassTree)ctx.getPath().getLeaf();
int methodCount = 0;
for (Tree member : clazz.getMembers()) {
if (member.getKind() != Tree.Kind.METHOD) {
continue;
}
MethodTree method = (MethodTree)member;
if (method.getReturnType() != null) {
// a constructor ?
continue;
}
methodCount++;
}
int limit = ctx.getPreferences().getInt(OPTION_CLASS_CONSTRUCTORS_LIMIT, DEFAULT_CLASS_CONSTRUCTORS_LIMIT);
if (methodCount <= limit) {
return null;
}
return ErrorDescriptionFactory.forName(ctx,
ctx.getPath(),
TEXT_ClassManyConstructors(clazz.getSimpleName().toString(), methodCount));
}
示例14: handleFilterAnonClass
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
private void handleFilterAnonClass(
StreamTypeRecord streamType,
MethodInvocationTree observableDotFilter,
ClassTree annonClassBody,
VisitorState state) {
for (Tree t : annonClassBody.getMembers()) {
if (t instanceof MethodTree && ((MethodTree) t).getName().toString().equals("test")) {
filterMethodOrLambdaSet.add(t);
observableCallToInnerMethodOrLambda.put(observableDotFilter, (MethodTree) t);
handleChainFromFilter(streamType, observableDotFilter, t, state);
}
}
}
示例15: insertClassMembers
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
/**
* Inserts members to a class. Using the rules specified in the {@link CodeStyle}
* it finds the proper place for each of the members and calls {@link TreeMaker.insertClassMember}
*
* @param clazz the class to insert the members to
* @param members the members to insert
* @param offset the caret location to use for {@code CodeStyle.InsertionPoint.CARET_LOCATION}
* @return the modified class
* @since 2.9
*/
public ClassTree insertClassMembers(ClassTree clazz, List<? extends Tree> members, int offset) {
if (members.isEmpty()) {
return clazz;
}
CodeStyle codeStyle = DiffContext.getCodeStyle(copy);
if (offset < 0 || codeStyle.getClassMemberInsertionPoint() != CodeStyle.InsertionPoint.CARET_LOCATION) {
return GeneratorUtilities.get(copy).insertClassMembers(clazz, members);
}
int index = 0;
SourcePositions sp = copy.getTrees().getSourcePositions();
Document doc = null;
try {
doc = copy.getDocument();
if (doc == null) {
doc = copy.getSnapshot().getSource().getDocument(true);
}
} catch (IOException ioe) {}
Tree lastMember = null;
Tree nextMember = null;
for (Tree tree : clazz.getMembers()) {
if (offset <= sp.getStartPosition(copy.getCompilationUnit(), tree)) {
DocumentGuards guards = LineDocumentUtils.as(doc, DocumentGuards.class);
if (doc == null || guards == null) {
nextMember = tree;
break;
}
int pos = (int)(lastMember != null ? sp.getEndPosition(copy.getCompilationUnit(), lastMember) : sp.getStartPosition(copy.getCompilationUnit(), clazz));
pos = guards.adjustPosition(pos, true);
if (pos <= sp.getStartPosition(copy.getCompilationUnit(), tree)) {
nextMember = tree;
break;
}
}
index++;
lastMember = tree;
}
if (lastMember != null) {
// do not move the comments tied to last member in guarded block:
moveCommentsAfterOffset(copy, lastMember, members.get(0), offset, doc);
}
if (nextMember != null) {
moveCommentsBeforeOffset(copy, nextMember, members.get(members.size() - 1), offset, doc);
}
TreeMaker tm = copy.getTreeMaker();
ClassTree newClazz = clazz;
for (int i = members.size() - 1; i >= 0; i--) {
newClazz = tm.insertClassMember(newClazz, index, members.get(i));
}
return newClazz;
}