本文整理汇总了Java中javax.lang.model.util.ElementScanner7类的典型用法代码示例。如果您正苦于以下问题:Java ElementScanner7类的具体用法?Java ElementScanner7怎么用?Java ElementScanner7使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ElementScanner7类属于javax.lang.model.util包,在下文中一共展示了ElementScanner7类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: translate
import javax.lang.model.util.ElementScanner7; //导入依赖的package包/类
/**
* Transforms a single class.
*/
public void translate(String fqcn, String outfqcn, String sourceJarName) throws JClassAlreadyExistsException {
final JDefinedClass $output = codeModel._class(outfqcn);
$output.annotate(Generated.class).param("value", Translator.class.getName()).param("date", new Date().toString()).param("comments", "based on " + sourceJarName);
$output.annotate(SuppressWarnings.class).param("value", "rawtypes");
$output.constructor(JMod.PRIVATE);
CompilationUnitTree dgmCut = getDefaultGroovyMethodCompilationUnitTree(parsed, fqcn);
overloadsResolved.clear();
ClassSymbol dgm = (ClassSymbol) elements.getTypeElement(fqcn);
dgm.accept(new ElementScanner7<Void,Void>() {
@Override
public Void visitExecutable(ExecutableElement e, Void __) {
if (translatable.contains(fqcn + "." + e)) {
overloadsResolved.put(mangledName(e), e);
}
// System.err.println("Not translating " + e.getAnnotationMirrors() + " " + e.getModifiers() + " " + fqcn + "." + e);
// TODO else if it is public and has a Closure argument, translate to a form that just throws UnsupportedOperationException when called in CPS mode
return null;
}
},null);
// TODO verify that we actually found everything listed in translatables
overloadsResolved.forEach((overloadResolved, e) -> {
try {
translateMethod(dgmCut, e, $output, fqcn, overloadResolved);
} catch (Exception x) {
throw new RuntimeException("Unable to transform " + fqcn + "." + e, x);
}
});
/*
private static MethodLocation loc(String methodName) {
return new MethodLocation(CpsDefaultGroovyMethods.class,methodName);
}
*/
JClass $MethodLocation = codeModel.ref("com.cloudbees.groovy.cps.MethodLocation");
$output.method(JMod.PRIVATE|JMod.STATIC, $MethodLocation, "loc").tap( m -> {
JVar $methodName = m.param(String.class, "methodName");
m.body()._return(JExpr._new($MethodLocation).arg($output.dotclass()).arg($methodName));
});
// Record the fqcn we've already translated for possible use later.
otherTranslated.put(fqcn, $output);
}