當前位置: 首頁>>代碼示例>>Java>>正文


Java TreeMaker類代碼示例

本文整理匯總了Java中com.sun.tools.javac.tree.TreeMaker的典型用法代碼示例。如果您正苦於以下問題:Java TreeMaker類的具體用法?Java TreeMaker怎麽用?Java TreeMaker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TreeMaker類屬於com.sun.tools.javac.tree包,在下文中一共展示了TreeMaker類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildReturnCheck

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
@NotNull
private static Optional<List<JCTree.JCStatement>> buildReturnCheck(@NotNull ReturnToInstrumentInfo info) {
    CompilationUnitProcessingContext context = info.getContext();
    ExpressionTree returnExpression = info.getReturnExpression().getExpression();
    if (!(returnExpression instanceof JCTree.JCExpression)) {
        context.getLogger().reportDetails(String.format(
                "find a 'return' expression of type %s but got %s",
                JCTree.JCExpression.class.getName(), returnExpression.getClass().getName()
        ));
        return Optional.empty();
    }
    JCTree.JCExpression returnJcExpression = (JCTree.JCExpression) returnExpression;

    TreeMaker factory = context.getAstFactory();
    Names symbolsTable = context.getSymbolsTable();
    ExceptionTextGenerator<ReturnToInstrumentInfo> generator =
            context.getExceptionTextGeneratorManager().getGenerator(METHOD_RETURN, context.getPluginSettings());
    String errorMessage = generator.generate(info);

    List<JCTree.JCStatement> result = List.of(
            factory.VarDef(
                    factory.Modifiers(0),
                    symbolsTable.fromString(info.getTmpVariableName()),
                    info.getReturnType(),
                    returnJcExpression
            )
    );
    String exceptionToThrow = info.getContext().getPluginSettings().getExceptionToThrow(METHOD_RETURN);
    result = result.append(InstrumentationUtil.buildVarCheck(factory,
                                                             symbolsTable,
                                                             info.getTmpVariableName(),
                                                             errorMessage,
                                                             exceptionToThrow));
    result = result.append(
            factory.Return(
                    factory.Ident(symbolsTable.fromString(info.getTmpVariableName()))));
    return Optional.of(result);
}
 
開發者ID:denis-zhdanov,項目名稱:traute,代碼行數:39,代碼來源:MethodReturnInstrumentator.java

示例2: CompilationUnitProcessingContext

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
public CompilationUnitProcessingContext(
        @NotNull TrautePluginSettings pluginSettings,
        @NotNull TreeMaker astFactory,
        @NotNull Names symbolsTable,
        @NotNull TrautePluginLogger logger,
        @NotNull StatsCollector statsCollector,
        @NotNull ExceptionTextGeneratorManager exceptionTextGeneratorManager,
        @NotNull PackageInfoManager packageInfoManager)
{
    this.pluginSettings = pluginSettings;
    this.statsCollector = statsCollector;
    this.astFactory = astFactory;
    this.symbolsTable = symbolsTable;
    this.logger = logger;
    this.exceptionTextGeneratorManager = exceptionTextGeneratorManager;
    this.packageInfoManager = packageInfoManager;
}
 
開發者ID:denis-zhdanov,項目名稱:traute,代碼行數:18,代碼來源:CompilationUnitProcessingContext.java

示例3: Enter

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
protected Enter(Context context) {
    context.put(enterKey, this);

    log = Log.instance(context);
    reader = ClassReader.instance(context);
    make = TreeMaker.instance(context);
    syms = Symtab.instance(context);
    chk = Check.instance(context);
    memberEnter = MemberEnter.instance(context);
    types = Types.instance(context);
    annotate = Annotate.instance(context);
    lint = Lint.instance(context);
    names = Names.instance(context);

    predefClassDef = make.ClassDef(
        make.Modifiers(PUBLIC),
        syms.predefClass.name, null, null, null, null);
    predefClassDef.sym = syms.predefClass;
    todo = Todo.instance(context);
    fileManager = context.get(JavaFileManager.class);

    Options options = Options.instance(context);
    pkginfoOpt = PkgInfo.get(options);
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:25,代碼來源:Enter.java

示例4: LambdaToMethod

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats");
    attr = Attr.instance(context);
    forceSerializable = options.isSet("forceSerializable");
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:LambdaToMethod.java

示例5: init

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
private void init(Context context) {
    modules = Modules.instance(context);
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);
    docTreeMaker = DocTreeMaker.instance(context);
    parser = ParserFactory.instance(context);
    syms = Symtab.instance(context);
    fileManager = context.get(JavaFileManager.class);
    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:JavacTrees.java

示例6: Analyzer

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
protected Analyzer(Context context) {
    context.put(analyzerKey, this);
    types = Types.instance(context);
    log = Log.instance(context);
    attr = Attr.instance(context);
    deferredAttr = DeferredAttr.instance(context);
    argumentAttr = ArgumentAttr.instance(context);
    make = TreeMaker.instance(context);
    names = Names.instance(context);
    Options options = Options.instance(context);
    String findOpt = options.get("find");
    //parse modes
    Source source = Source.instance(context);
    allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation();
    analyzerModes = AnalyzerMode.getAnalyzerModes(findOpt, source);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:Analyzer.java

示例7: Annotate

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
protected Annotate(Context context) {
    context.put(annotateKey, this);

    attr = Attr.instance(context);
    chk = Check.instance(context);
    cfolder = ConstFold.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);
    enter = Enter.instance(context);
    log = Log.instance(context);
    lint = Lint.instance(context);
    make = TreeMaker.instance(context);
    names = Names.instance(context);
    resolve = Resolve.instance(context);
    syms = Symtab.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    types = Types.instance(context);

    theUnfinishedDefaultValue =  new Attribute.Error(syms.errType);

    Source source = Source.instance(context);
    allowRepeatedAnnos = source.allowRepeatedAnnotations();
    sourceName = source.name;

    blockCount = 1;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:Annotate.java

示例8: LambdaToMethod

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    operators = Operators.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("debug.dumpLambdaToMethodStats");
    attr = Attr.instance(context);
    forceSerializable = options.isSet("forceSerializable");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:LambdaToMethod.java

示例9: run

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);

    test("abc",                     CLASS,      syms.stringType,    "abc");
    test(Boolean.FALSE,             BOOLEAN,    syms.booleanType,   Integer.valueOf(0));
    test(Boolean.TRUE,              BOOLEAN,    syms.booleanType,   Integer.valueOf(1));
    test(Byte.valueOf((byte) 1),    BYTE,       syms.byteType,      Byte.valueOf((byte) 1));
    test(Character.valueOf('a'),    CHAR,       syms.charType,      Integer.valueOf('a'));
    test(Double.valueOf(1d),        DOUBLE,     syms.doubleType,    Double.valueOf(1d));
    test(Float.valueOf(1f),         FLOAT,      syms.floatType,     Float.valueOf(1f));
    test(Integer.valueOf(1),        INT,        syms.intType,       Integer.valueOf(1));
    test(Long.valueOf(1),           LONG,       syms.longType,      Long.valueOf(1));
    test(Short.valueOf((short) 1),  SHORT,      syms.shortType,     Short.valueOf((short) 1));

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:MakeLiteralTest.java

示例10: translateTopLevelClass

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
@Override
public List<JCTree> translateTopLevelClass(Env<AttrContext> env, JCTree cdef, TreeMaker make) {
    List<JCTree> result = super.translateTopLevelClass(env, cdef, make);

    new TreeScanner() {
        @Override
        public void visitBinary(JCBinary tree) {
            hasNullCheck |= tree.operator.getSimpleName().contentEquals("!=") &&
                            "resource".equals(String.valueOf(TreeInfo.name(tree.lhs))) &&
                            TreeInfo.isNull(tree.rhs);
            super.visitBinary(tree);
        }
    }.scan(result);

    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:TwrAvoidNullCheck.java

示例11: translateTopLevelClass

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
@Override
public List<JCTree> translateTopLevelClass(Env<AttrContext> env, JCTree cdef, TreeMaker make) {
    List<JCTree> result = super.translateTopLevelClass(env, cdef, make);
    Map<Symbol, JCMethodDecl> declarations = new HashMap<>();
    Set<Symbol> toDump = new TreeSet<>(symbolComparator);

    new TreeScanner() {
        @Override
        public void visitMethodDef(JCMethodDecl tree) {
            if (tree.name.toString().startsWith("dump")) {
                toDump.add(tree.sym);
            }
            declarations.put(tree.sym, tree);
            super.visitMethodDef(tree);
        }
    }.scan(result);

    for (Symbol d : toDump) {
        dump(d, declarations, new HashSet<>());
    }

    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:BoxingAndSuper.java

示例12: setup

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
/**
 * Setup env by creating pseudo-random collection of names, packages and classes.
 */
void setup() {
    log ("setup");
    context = new Context();
    JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab
    make = TreeMaker.instance(context);
    names = Names.instance(context);       // Name.Table impls tied to an instance of Names
    symtab = Symtab.instance(context);
    types = Types.instance(context);
    int setupCount = rgen.nextInt(MAX_SETUP_COUNT);
    for (int i = 0; i < setupCount; i++) {
        switch (random(SetupKind.values())) {
            case NAMES:
                setupNames();
                break;
            case PACKAGE:
                setupPackage();
                break;
            case CLASS:
                setupClass();
                break;
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:StarImportTest.java

示例13: replaceExtCall

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
private void replaceExtCall( JCTree.JCMethodInvocation tree, Symbol.MethodSymbol method )
{
  JCExpression methodSelect = tree.getMethodSelect();
  if( methodSelect instanceof JCTree.JCFieldAccess )
  {
    JCTree.JCFieldAccess m = (JCTree.JCFieldAccess)methodSelect;
    boolean isStatic = m.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC );
    TreeMaker make = _tp.getTreeMaker();
    JavacElements javacElems = _tp.getElementUtil();
    JCExpression thisArg = m.selected;
    String extensionFqn = method.getEnclosingElement().asType().tsym.toString();
    m.selected = memberAccess( make, javacElems, extensionFqn );
    BasicJavacTask javacTask = ClassSymbols.instance( _sp.getTypeLoader().getModule() ).getJavacTask();
    Symbol.ClassSymbol extensionClassSym = ClassSymbols.instance( _sp.getTypeLoader().getModule() ).getClassSymbol( javacTask, extensionFqn ).getFirst();
    assignTypes( m.selected, extensionClassSym );
    m.sym = method;
    m.type = method.type;

    if( !isStatic )
    {
      ArrayList<JCExpression> newArgs = new ArrayList<>( tree.args );
      newArgs.add( 0, thisArg );
      tree.args = List.from( newArgs );
    }
  }
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:27,代碼來源:ExtensionTransformer.java

示例14: hijackJavacFileManager

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
private void hijackJavacFileManager()
{
  if( !(_fileManager instanceof ManifoldJavaFileManager) && _manFileManager == null )
  {
    _ctx = _javacTask.getContext();
    _fileManager = _ctx.get( JavaFileManager.class );
    _javaInputFiles = new HashSet<>();
    _gosuInputFiles = fetchGosuInputFiles();
    _treeMaker = TreeMaker.instance( _ctx );
    _javacElements = JavacElements.instance( _ctx );
    _typeProcessor = new TypeProcessor( _javacTask );
    _issueReporter = new IssueReporter( Log.instance( getContext() ) );
    _seenModules = new LinkedHashSet<>();

    injectManFileManager();
  }
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:18,代碼來源:JavacPlugin.java

示例15: Annotate

import com.sun.tools.javac.tree.TreeMaker; //導入依賴的package包/類
protected Annotate(Context context) {
    context.put(annotateKey, this);

    attr = Attr.instance(context);
    chk = Check.instance(context);
    cfolder = ConstFold.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);
    enter = Enter.instance(context);
    log = Log.instance(context);
    lint = Lint.instance(context);
    make = TreeMaker.instance(context);
    names = Names.instance(context);
    resolve = Resolve.instance(context);
    syms = Symtab.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    types = Types.instance(context);

    theUnfinishedDefaultValue =  new Attribute.Error(syms.errType);

    Source source = Source.instance(context);
    allowRepeatedAnnos = source.allowRepeatedAnnotations();
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:23,代碼來源:Annotate.java


注:本文中的com.sun.tools.javac.tree.TreeMaker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。