本文整理汇总了Java中javax.lang.model.util.ElementScanner6类的典型用法代码示例。如果您正苦于以下问题:Java ElementScanner6类的具体用法?Java ElementScanner6怎么用?Java ElementScanner6使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ElementScanner6类属于javax.lang.model.util包,在下文中一共展示了ElementScanner6类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isOverriddenInsideOutermostEnclosingClass
import javax.lang.model.util.ElementScanner6; //导入依赖的package包/类
private static boolean isOverriddenInsideOutermostEnclosingClass(final ExecutableElement ee, final ElementUtilities eu) {
final boolean[] ret = new boolean[] {false};
new ElementScanner6<Void, Void>() {
@Override
public Void visitType(TypeElement te, Void p) {
if (ret[0])
return null;
if (te != ee.getEnclosingElement() && eu.getImplementationOf(ee, te) != null && !isAnyEncloserPrivate(te))
ret[0] = true;
return super.visitType(te, p);
}
}.scan(eu.outermostTypeElement(ee));
return ret[0];
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:InstantRenamePerformer.java
示例2: getMainClasses
import javax.lang.model.util.ElementScanner6; //导入依赖的package包/类
/**
* Returns classes declared in the given source file which have the main method.
* @param fo source file
* @return the classes containing main method
* @throws IllegalArgumentException when file does not exist or is not a java source file.
*/
public static Collection<ElementHandle<TypeElement>> getMainClasses (final @NonNull FileObject fo) {
Parameters.notNull("fo", fo); //NOI18N
if (!fo.isValid()) {
throw new IllegalArgumentException ("FileObject : " + FileUtil.getFileDisplayName(fo) + " is not valid."); //NOI18N
}
if (fo.isVirtual()) {
throw new IllegalArgumentException ("FileObject : " + FileUtil.getFileDisplayName(fo) + " is virtual."); //NOI18N
}
final JavaSource js = JavaSource.forFileObject(fo);
if (js == null) {
throw new IllegalArgumentException ();
}
try {
final LinkedHashSet<ElementHandle<TypeElement>> result = new LinkedHashSet<> ();
js.runUserActionTask(new Task<CompilationController>() {
@Override
public void run(final CompilationController control) throws Exception {
if (control.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED).compareTo (JavaSource.Phase.ELEMENTS_RESOLVED)>=0) {
final List<TypeElement> types = new ArrayList<>();
final ElementScanner6<Void,Void> visitor = new ElementScanner6<Void, Void>() {
@Override
public Void visitType(TypeElement e, Void p) {
if (e.getEnclosingElement().getKind() == ElementKind.PACKAGE
|| e.getModifiers().contains(Modifier.STATIC)) {
types.add(e);
return super.visitType(e, p);
} else {
return null;
}
}
};
visitor.scan(control.getTopLevelElements(), null);
for (TypeElement type : types) {
for (ExecutableElement exec : ElementFilter.methodsIn(control.getElements().getAllMembers(type))) {
if (SourceUtils.isMainMethod(exec)) {
result.add (ElementHandle.create(type));
}
}
}
}
}
}, true);
return result;
} catch (IOException ioe) {
Exceptions.printStackTrace(ioe);
return Collections.<ElementHandle<TypeElement>>emptySet();
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:56,代码来源:SourceUtils.java
注:本文中的javax.lang.model.util.ElementScanner6类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论