本文整理汇总了Java中com.sun.source.util.Trees.getScope方法的典型用法代码示例。如果您正苦于以下问题:Java Trees.getScope方法的具体用法?Java Trees.getScope怎么用?Java Trees.getScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.util.Trees
的用法示例。
在下文中一共展示了Trees.getScope方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitClass
import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public Tree visitClass(ClassTree tree, final Element p) {
final TreePath currentPath = getCurrentPath();
renameDeclIfMatch(getCurrentPath(), tree, p);
Element el = workingCopy.getTrees().getElement(currentPath);
if (el != null && el.getEnclosedElements().contains(p)) {
Trees trees = workingCopy.getTrees();
Scope scope = trees.getScope(trees.getPath(p));
shadowed = workingCopy.getElementUtilities().getLocalMembersAndVars(scope, new ElementUtilities.ElementAcceptor() {
@Override
public boolean accept(Element element, TypeMirror type) {
return !element.equals(p) && element.getKind().equals(p.getKind()) && element.getSimpleName().contentEquals(newName);
}
});
}
Tree value = super.visitClass(tree, p);
shadowed = null;
return value;
}
示例2: createDefaultMethodBody
import com.sun.source.util.Trees; //导入方法依赖的package包/类
private static BlockTree createDefaultMethodBody(WorkingCopy wc, TreePath targetTree, TypeMirror returnType, String name) {
TreeUtilities tu = wc.getTreeUtilities();
TypeElement targetClazz = (TypeElement)wc.getTrees().getElement(targetTree);
StatementTree st = tu.parseStatement("{class ${abstract " + (returnType != null ? returnType.toString() : "void") + " " + ("<init>".equals(name) ? targetClazz.getSimpleName() : name) + "();}}", new SourcePositions[1]); //NOI18N
Trees trees = wc.getTrees();
List<? extends Tree> members = ((ClassTree) targetTree.getLeaf()).getMembers();
Scope scope = members.isEmpty() ? trees.getScope(targetTree) : trees.getScope(new TreePath(targetTree, members.get(0)));
tu.attributeTree(st, scope);
Tree first = null;
for(Tree t : ((ClassTree)((BlockTree)st).getStatements().get(0)).getMembers()) {
if (t.getKind() == Tree.Kind.METHOD && !"<init>".contentEquals(((MethodTree)t).getName())) { //NOI19N
first = t;
break;
}
}
ExecutableElement ee = (ExecutableElement) wc.getTrees().getElement(new TreePath(targetTree, first));
return GeneratorUtilities.get(wc).createAbstractMethodImplementation(targetClazz, ee).getBody();
}
示例3: addInnerClasses
import com.sun.source.util.Trees; //导入方法依赖的package包/类
private void addInnerClasses(TypeElement te, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
CompilationInfo controller = jdctx.javac;
Element srcEl = jdctx.handle.resolve(controller);
Elements elements = controller.getElements();
Types types = controller.getTypes();
Trees trees = controller.getTrees();
TreeUtilities tu = controller.getTreeUtilities();
TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
for (Element e : controller.getElementUtilities().getMembers(te.asType(), null)) {
if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
String name = e.getSimpleName().toString();
if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e)) && trees.isAccessible(scope, (TypeElement)e) && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)) {
items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
}
}
}
}
示例4: addPackageContent
import com.sun.source.util.Trees; //导入方法依赖的package包/类
private void addPackageContent(PackageElement pe, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
CompilationInfo controller = jdctx.javac;
Element srcEl = jdctx.handle.resolve(controller);
Elements elements = controller.getElements();
Types types = controller.getTypes();
Trees trees = controller.getTrees();
TreeUtilities tu = controller.getTreeUtilities();
ElementUtilities eu = controller.getElementUtilities();
TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
for(Element e : pe.getEnclosedElements()) {
if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
String name = e.getSimpleName().toString();
if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
&& trees.isAccessible(scope, (TypeElement)e)
&& isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)
&& !Utilities.isExcluded(eu.getElementName(e, true))) {
items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
}
}
}
}
示例5: typeToImport
import com.sun.source.util.Trees; //导入方法依赖的package包/类
private static TypeMirror typeToImport(CompilationInfo info, TreePath tp, TypeMirror origin) {
if (tp.getLeaf().getKind() == Tree.Kind.MEMBER_SELECT) {
MemberSelectTree mst = (MemberSelectTree) tp.getLeaf();
if (mst.getExpression().getKind() == Tree.Kind.IDENTIFIER) {
ClassIndex index = info.getClasspathInfo().getClassIndex();
Types types = info.getTypes();
Trees trees = info.getTrees();
Scope scope = trees.getScope(tp);
for (ElementHandle<TypeElement> teHandle : index.getDeclaredTypes(((IdentifierTree)mst.getExpression()).getName().toString(), ClassIndex.NameKind.SIMPLE_NAME, EnumSet.allOf(ClassIndex.SearchScope.class))) {
TypeElement te = teHandle.resolve(info);
if (te != null && trees.isAccessible(scope, te)) {
TypeMirror toImport = te.asType();
if (types.isSubtype(toImport, origin)) {
return toImport;
}
}
}
}
}
return origin;
}
示例6: visitIdentifier
import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
System.err.println("visitIdentifier: " + t);
trees.getScope(getCurrentPath());
return null;
}