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


Java Context类代码示例

本文整理汇总了Java中com.sun.tools.javac.util.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于com.sun.tools.javac.util包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDirectAccess1

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
@Test
public void testDirectAccess1() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
        if (t.call()) {
            System.err.println("task succeeded");
        } else {
            throw new Exception("task failed");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:JavadocTaskImplTest.java

示例2: VeryPretty

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
private VeryPretty(Context context, CodeStyle cs, Map<Tree, ?> tree2Tag, Map<Tree, DocCommentTree> tree2Doc, Map<?, int[]> tag2Span, String origText) {
names = Names.instance(context);
enclClass = null;
       commentHandler = CommentHandlerService.instance(context);
       operators = Operators.instance(context);
widthEstimator = new WidthEstimator(context);
       danglingElseChecker = new DanglingElseChecker();
       prec = TreeInfo.notExpression;
       this.cs = cs;
       out = new CharBuffer(cs.getRightMargin(), cs.getTabSize(), cs.expandTabToSpaces());
       out.addTrimObserver(this);
       this.indentSize = cs.getIndentSize();
       this.tree2Tag = tree2Tag;
       this.tree2Doc = tree2Doc == null ? Collections.EMPTY_MAP : tree2Doc;
       this.tag2Span = (Map<Object, int[]>) tag2Span;//XXX
       this.origText = origText;
       this.comments = CommentHandlerService.instance(context);
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:VeryPretty.java

示例3: Analyzer

import com.sun.tools.javac.util.Context; //导入依赖的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

示例4: analyze

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
public static void analyze(Iterable<? extends Element> elems, Context ctx) {
    assert elems != null;
    PostFlowAnalysis postFlowAnalysis = new PostFlowAnalysis(ctx);
    for (Element e : elems) {
        if (e instanceof TypeSymbol) {
            Env<AttrContext> env = postFlowAnalysis.enter.getClassEnv((TypeSymbol)e);
            if (env != null) {
                JavaFileObject prev = postFlowAnalysis.log.useSource(env.enclClass.sym.sourcefile != null
                        ? env.enclClass.sym.sourcefile : env.toplevel.sourcefile);
                try {
                    postFlowAnalysis.scan(env.toplevel);
                } finally {
                    postFlowAnalysis.log.useSource(prev);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:PostFlowAnalysis.java

示例5: translate

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
@NonNull Tree translate(final @NonNull Tree original, final @NonNull Map<? extends Tree, ? extends Tree> original2Translated, ImportAnalysis2 ia, Map<Tree, Object> tree2Tag) {
    ImmutableTreeTranslator itt = new ImmutableTreeTranslator(info instanceof WorkingCopy ? (WorkingCopy)info : null) {
        private @NonNull Map<Tree, Tree> map = new HashMap<Tree, Tree>(original2Translated);
        @Override
        public Tree translate(Tree tree) {
            Tree translated = map.remove(tree);

            if (translated != null) {
                return translate(translated);
            } else {
                return super.translate(tree);
            }
        }
    };

    Context c = info.impl.getJavacTask().getContext();

    itt.attach(c, ia, tree2Tag);

    return itt.translate(original);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TreeUtilities.java

示例6: run

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource()));
    Iterable<? extends CompilationUnitTree> elements = ct.parse();
    ct.analyze();
    Assert.check(elements.iterator().hasNext());
    JCTree topLevel = (JCTree)elements.iterator().next();
    new TreeScanner() {
        @Override
        public void visitReference(JCMemberReference tree) {
            Assert.check(tree.getOverloadKind() != null);
        }
    }.scan(topLevel);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:FieldOverloadKindNotAssignedTest.java

示例7: make0

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
/**
 *  Construct a new javadoc tool.
 */
public static JavadocTool make0(Context context) {
    Messager messager = null;
    try {
        // force the use of Javadoc's class reader
        JavadocClassReader.preRegister(context);

        // force the use of Javadoc's own enter phase
        JavadocEnter.preRegister(context);

        // force the use of Javadoc's own member enter phase
        JavadocMemberEnter.preRegister(context);

        // force the use of Javadoc's own todo phase
        JavadocTodo.preRegister(context);

        // force the use of Messager as a Log
        messager = Messager.instance0(context);

        return new JavadocTool(context);
    } catch (CompletionFailure ex) {
        messager.error(Position.NOPOS, ex.getMessage());
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:JavadocTool.java

示例8: run

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
public void run(JavaCompiler comp) {
    JavaSource source = new JavaSource();
    JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, null, dc,
            Arrays.asList("-g"), null, Arrays.asList(source));
    Context context = ct.getContext();
    Symtab syms = Symtab.instance(context);
    Names names = Names.instance(context);
    Types types = Types.instance(context);
    ct.addTaskListener(new Indifier(syms, names, types));
    try {
        ct.generate();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new AssertionError(
                String.format("Error thrown when compiling following code\n%s",
                        source.source));
    }
    if (dc.diagFound) {
        throw new AssertionError(
                String.format("Diags found when compiling following code\n%s\n\n%s",
                        source.source, dc.printDiags()));
    }
    verifyBytecode();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:TestBootstrapMethodsCount.java

示例9: run

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
void run(String trySpec, boolean expected) throws IOException {
    String template = "public class Test implements AutoCloseable {\n" +
                      "    void t(int i) {\n" +
                      "        TRY\n" +
                      "    }\n" +
                      "    public void close() { }\n" +
                      "}\n";
    String code = template.replace("TRY", trySpec);
    Context ctx = new Context();
    DumpLower.preRegister(ctx);
    Iterable<ToolBox.JavaSource> files = Arrays.asList(new ToolBox.JavaSource(code));
    JavacTask task = JavacTool.create().getTask(null, null, null, null, null, files, ctx);
    task.call();
    boolean actual = ((DumpLower) DumpLower.instance(ctx)).closeSeen;

    if (expected != actual) {
        throw new IllegalStateException("expected: " + expected + "; actual: " + actual + "; code:\n" + code);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TwrShareCloseCode.java

示例10: getStandardFileManager

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER)
public JavacFileManager getStandardFileManager(
    DiagnosticListener<? super JavaFileObject> diagnosticListener,
    Locale locale,
    Charset charset) {
    Context context = new Context();
    context.put(Locale.class, locale);
    if (diagnosticListener != null)
        context.put(DiagnosticListener.class, diagnosticListener);
    PrintWriter pw = (charset == null)
            ? new PrintWriter(System.err, true)
            : new PrintWriter(new OutputStreamWriter(System.err, charset), true);
    context.put(Log.errKey, pw);
    CacheFSInfo.preRegister(context);
    return new JavacFileManager(context, true, charset);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:JavacTool.java

示例11: init

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.trees = Trees.instance(processingEnv);
    this.messager = processingEnv.getMessager();
    this.filer = processingEnv.getFiler();
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    daoGenHelper = new DaoGenHelper(trees,context);
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:10,代码来源:DaoGenProcessor.java

示例12: preRegister

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
/**
 * Register a Context.Factory to create a JavacFileManager.
 */
public static void preRegister(Context context) {
    context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
        public JavaFileManager make(Context c) {
            return new JavacFileManager(c, true, null);
        }
    });

}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:12,代码来源:JavacFileManager.java

示例13: JavacFileManager

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
/**
 * Create a JavacFileManager using a given context, optionally registering
 * it as the JavaFileManager for that context.
 */
public JavacFileManager(Context context, boolean register, Charset charset) {
    super(charset);
    if (register)
        context.put(JavaFileManager.class, this);
    setContext(context);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:JavacFileManager.java

示例14: preRegister

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
public static void preRegister(final Context context, final ClasspathInfo cpInfo) {
    context.put(docEnvKey, new Context.Factory<DocEnv>() {
        public DocEnv make(Context c) {
            return new JavadocEnv(c, cpInfo);
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:JavadocEnv.java

示例15: compile

import com.sun.tools.javac.util.Context; //导入依赖的package包/类
/**
 * Programmatic interface for main function.
 *
 * @param args The command line parameters.
 */
public int compile(String[] args) {
    Context context = new Context();
    JavacFileManager.preRegister(context); // can't create it until Log has been set up
    int result = compile(args, context);
    if (fileManager instanceof JavacFileManager) {
        // A fresh context was created above, so jfm must be a JavacFileManager
        ((JavacFileManager) fileManager).close();
    }
    return result;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:Main.java


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