当前位置: 首页>>代码示例>>Java>>正文


Java ElementScanner7类代码示例

本文整理汇总了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);
}
 
开发者ID:cloudbees,项目名称:groovy-cps,代码行数:49,代码来源:Translator.java


注:本文中的javax.lang.model.util.ElementScanner7类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。