Package com.asakusafw.utils.java.jsr199.testing

Examples of com.asakusafw.utils.java.jsr199.testing.MockProcessor


     * コンパイルを指定の注釈プロセッサを利用して実行し、コンパイル結果のローダーを返す。
     * @param processor 利用する注釈プロセッサ
     * @return コンパイル結果
     */
    protected ClassLoader start(Processor processor) {
        SafeProcessor safe = new SafeProcessor(processor);
        compiler.addProcessor(safe);
        ClassLoader loader = start();
        safe.rethrow();
        return loader;
    }
View Full Code Here


    /**
     * コンパイルを実行し、エラーが発生することを確認する。
     * @param procs 利用する演算子プロセッサの一覧
     */
    protected void error(final OperatorProcessor... procs) {
        SafeProcessor proc = new SafeProcessor(new OperatorCompiler() {
            @Override
            protected Iterable<OperatorProcessor> findOperatorProcessors(OperatorCompilingEnvironment env) {
                return Arrays.asList(procs);
            }
        });
        compiler.addProcessor(proc);
        List<Diagnostic<? extends JavaFileObject>> diagnostics = doCompile();
        proc.rethrow();
        assertThat(diagnostics.isEmpty(), is(false));
    }
View Full Code Here

        assert compiler != null;
        assert jar != null;

        DiagnosticCollector<JavaFileObject> diagnostics =
            new DiagnosticCollector<JavaFileObject>();
        VolatileClassOutputManager fileManager = new VolatileClassOutputManager(
                compiler.getStandardFileManager(
                        diagnostics,
                        Locale.getDefault(),
                        CHARSET));
        try {
            List<String> arguments = Lists.create();
            Collections.addAll(arguments, "-source", "1.6");
            Collections.addAll(arguments, "-target", "1.6");
            Collections.addAll(arguments, "-encoding", CHARSET.name());

            StringWriter errors = new StringWriter();
            PrintWriter pw = new PrintWriter(errors);

            CompilationTask task = compiler.getTask(
                    pw,
                    fileManager,
                    diagnostics,
                    arguments,
                    Collections.<String>emptyList(),
                    emitter.getEmitted());

            Boolean successed = task.call();
            pw.close();
            for (Diagnostic<?> diagnostic : diagnostics.getDiagnostics()) {
                switch (diagnostic.getKind()) {
                case ERROR:
                case MANDATORY_WARNING:
                    getEnvironment().error(diagnostic.getMessage(null));
                    break;
                case WARNING:
                    LOG.warn(diagnostic.getMessage(null));
                    break;
                default:
                    LOG.info(diagnostic.getMessage(null));
                    break;
                }
            }
            if(Boolean.TRUE.equals(successed) == false) {
                throw new IOException(MessageFormat.format(
                        "{0}のコンパイルに失敗しました: {1}",
                        getEnvironment().getTargetId(),
                        errors.toString()));
            }

            for (VolatileResourceFile file : fileManager.getResources()) {
                addEntry(jar, file);
            }
            for (VolatileClassFile file : fileManager.getCompiled()) {
                addEntry(jar, file);
            }
            for (Map.Entry<String, byte[]> entry : contents.entrySet()) {
                addEntry(jar, entry.getKey(), entry.getValue());
            }
        } finally {
            fileManager.close();
        }
    }
View Full Code Here

     * @throws Exception if occur
     */
    @Before
    public void setUp() throws Exception {
        f = Models.getModelFactory();
        compiler = new VolatileCompiler();
        target = new Jsr269(f);
    }
View Full Code Here

     */
    @Before
    public void setUp() throws Exception {
        f = Models.getModelFactory();
        files = new ArrayList<VolatileJavaFile>();
        compiler = new VolatileCompiler();
    }
View Full Code Here

        for (JavaFileObject java : sources) {
            javaCompiler.addSource(java);
        }
        if (sources.isEmpty()) {
            javaCompiler.addSource(new VolatileJavaFile("A", "public class A {}"));
        }
        List<Diagnostic<? extends JavaFileObject>> diagnostics = javaCompiler.doCompile();
        if (dump) {
            for (Diagnostic<? extends JavaFileObject> d : diagnostics) {
                System.out.println("====");
View Full Code Here

    private void start(Callback callback, JavaFileObject... sources) {
        for (JavaFileObject java : sources) {
            compiler.addSource(java);
        }
        if (sources.length == 0) {
            compiler.addSource(new VolatileJavaFile("A", "public class A {}"));
        }
        compiler.addProcessor(new DelegateProcessor(callback));
        List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler.doCompile();
        for (Diagnostic<?> d : diagnostics) {
            if (d.getKind() == Diagnostic.Kind.ERROR) {
View Full Code Here

                in.close();
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
        sources.add(new VolatileJavaFile(
                name.replace('.', '/'),
                buf.toString()));
    }
View Full Code Here

        compiler.addArguments("-Xlint:unchecked");
        for (JavaFileObject java : sources) {
            compiler.addSource(java);
        }
        if (sources.isEmpty()) {
            compiler.addSource(new VolatileJavaFile("A", "public class A {}"));
        }
        List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler.doCompile();
        for (JavaFileObject java : compiler.getSources()) {
            try {
                System.out.println("====" + java.getName());
View Full Code Here

            buf.append(packageDeclOrNull.getName().toNameString().replace('.', '/'));
            buf.append("/");
        }
        assert subPath.endsWith(".java");
        buf.append(subPath.substring(0, subPath.length() - 5));
        VolatileJavaFile file = new VolatileJavaFile(buf.toString());
        register(file);
        return new PrintWriter(file.openWriter());
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.utils.java.jsr199.testing.MockProcessor

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.