Package com.sun.tools.javac.util

Examples of com.sun.tools.javac.util.Context


                             Iterable<String> options,
                             Iterable<String> classes,
                             Iterable<? extends JavaFileObject> compilationUnits)
    {
        try {
            Context context = new Context();
            ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

            final String kindMsg = "All compilation units must be of SOURCE kind";
            if (options != null)
                for (String option : options)
                    option.getClass(); // null check
            if (classes != null) {
                for (String cls : classes)
                    if (!SourceVersion.isName(cls)) // implicit null check
                        throw new IllegalArgumentException("Not a valid class name: " + cls);
            }
            if (compilationUnits != null) {
                compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
                for (JavaFileObject cu : compilationUnits) {
                    if (cu.getKind() != JavaFileObject.Kind.SOURCE)
                        throw new IllegalArgumentException(kindMsg);
                }
            }

            if (diagnosticListener != null)
                context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

            if (out == null)
                context.put(Log.outKey, new PrintWriter(System.err, true));
            else
                context.put(Log.outKey, new PrintWriter(out, true));

            if (fileManager == null)
                fileManager = getStandardFileManager(diagnosticListener, null, null);
            fileManager = ccw.wrap(fileManager);
            context.put(JavaFileManager.class, fileManager);
            processOptions(context, fileManager, options);
            Main compiler = new Main("javacTask", context.get(Log.outKey));
            return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
        } catch (ClientCodeException ex) {
            throw new RuntimeException(ex.getCause());
        }
    }
View Full Code Here


     */
    void run() throws Exception {
        Counter demoCounter = new Counter();
        Counter myAttrCounter = new Counter();

        Context context = new Context();
        // Use a custom file manager which creates classloaders for annotation
        // processors with a sensible delegation parent, so that all instances
        // of test classes come from the same class loader. This is important
        // because the test performs class checks on the instances of classes
        // found in the context for each round or processing.
        context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
            public JavaFileManager make(Context c) {
                return new JavacFileManager(c, true, null) {
                    @Override
                    protected ClassLoader getClassLoader(URL[] urls) {
                        return new URLClassLoader(urls, T7021650.class.getClassLoader());
View Full Code Here

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        round++;

        Context context = ((JavacProcessingEnvironment) processingEnv).getContext();

        // verify items in context as expected
        check("Demo", Demo.instance(context), Demo.class);
        check("Attr", Attr.instance(context), MyAttr.class);
View Full Code Here

        /** Get the context for the next round of processing.
         * Important values are propogated from round to round;
         * other values are implicitly reset.
         */
        private Context nextContext() {
            Context next = new Context(context);

            Options options = Options.instance(context);
            Assert.checkNonNull(options);
            next.put(Options.optionsKey, options);

            PrintWriter out = context.get(Log.outKey);
            Assert.checkNonNull(out);
            next.put(Log.outKey, out);
            Locale locale = context.get(Locale.class);
            if (locale != null)
                next.put(Locale.class, locale);
            Assert.checkNonNull(messages);
            next.put(JavacMessages.messagesKey, messages);

            final boolean shareNames = true;
            if (shareNames) {
                Names names = Names.instance(context);
                Assert.checkNonNull(names);
                next.put(Names.namesKey, names);
            }

            DiagnosticListener<?> dl = context.get(DiagnosticListener.class);
            if (dl != null)
                next.put(DiagnosticListener.class, dl);

            TaskListener tl = context.get(TaskListener.class);
            if (tl != null)
                next.put(TaskListener.class, tl);

            FSInfo fsInfo = context.get(FSInfo.class);
            if (fsInfo != null)
                next.put(FSInfo.class, fsInfo);

            JavaFileManager jfm = context.get(JavaFileManager.class);
            Assert.checkNonNull(jfm);
            next.put(JavaFileManager.class, jfm);
            if (jfm instanceof JavacFileManager) {
                ((JavacFileManager)jfm).setContext(next);
            }

            Names names = Names.instance(context);
            Assert.checkNonNull(names);
            next.put(Names.namesKey, names);

            Keywords keywords = Keywords.instance(context);
            Assert.checkNonNull(keywords);
            next.put(Keywords.keywordsKey, keywords);

            JavaCompiler oldCompiler = JavaCompiler.instance(context);
            JavaCompiler nextCompiler = JavaCompiler.instance(next);
            nextCompiler.initRound(oldCompiler);

            filer.newRound(next);
            messager.newRound(next);
            elementUtils.setContext(next);
            typeUtils.setContext(next);

            JavacTaskImpl task = context.get(JavacTaskImpl.class);
            if (task != null) {
                next.put(JavacTaskImpl.class, task);
                task.updateContext(next);
            }

            JavacTrees trees = context.get(JavacTrees.class);
            if (trees != null) {
                next.put(JavacTrees.class, trees);
                trees.updateContext(next);
            }

            context.clear();
            return next;
View Full Code Here

   
    @Override
    public void initialize() throws IOException {
        setSystemProperties();
        compiler = new Main("ceylon compile");
        Options options = Options.instance(new Context());
       
        if (modulesOrFiles.isEmpty() &&
                !javac.contains("-help") &&
                !javac.contains("-X") &&
                !javac.contains("-version")) {
View Full Code Here

            throw new IllegalStateException("Unexpected CeylonState " + ceylonState);
        }
    }

    private void addJavacArguments(List<String> arguments) {
        Options options = Options.instance(new Context());
        for (String argument : javac) {
            HELPER.lastError = null;
            String value = null;
            int index = argument.indexOf('=');
            if (index != -1) {
View Full Code Here

        ZipFileIndex zfi = zfic.getZipFileIndex(rt_jar, null, false, null, false);
        long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME);

        check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime);

        Context context = new Context();
        JavacFileManager fm = new JavacFileManager(context, false, null);
        ZipFileIndexArchive zfia = new ZipFileIndexArchive(fm, zfi);
        JavaFileObject jfo =
            zfia.getFileObject(TEST_ENTRY_NAME.dirname(),
                                   TEST_ENTRY_NAME.basename());
View Full Code Here

        Assert.assertTrue(exit == 0);
    }

    private void compileAndRun(File srcDir, File resDir, File outRepo, String[] modules, String[] dependencies, Set<String> removeAtRuntime) throws Exception {
        // Compile all the .ceylon files into a .car
        Context context = new Context();
        final ErrorCollector listener = new ErrorCollector();
        CeyloncFileManager.preRegister(context); // can't create it until Log
        // has been set up
        CeylonLog.preRegister(context);
        context.put(DiagnosticListener.class, listener);
       
        com.redhat.ceylon.compiler.java.launcher.Main compiler = new com.redhat.ceylon.compiler.java.launcher.Main("ceylonc");
        List<String> args = new ArrayList<>();
//            args.add("-verbose:code");
        args.add("-g");
View Full Code Here

        private TreeMaker m;

        ImportCleaner(JavaFileManager fm) {
            // ImportCleaner itself doesn't require a filemanager, but instantiating
            // a TreeMaker does, indirectly (via ClassReader, sigh)
            Context c = new Context();
            c.put(JavaFileManager.class, fm);
            m = TreeMaker.instance(c);
        }
View Full Code Here

        super(context, true, charset);
        setIgnoreSymbolFile(true);
    }

    static JavahFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log) {
        Context javac_context = new Context();

        if (dl != null)
            javac_context.put(DiagnosticListener.class, dl);
        javac_context.put(com.sun.tools.javac.util.Log.outKey, log);

        return new JavahFileManager(javac_context, null);
    }
View Full Code Here

TOP

Related Classes of com.sun.tools.javac.util.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.