Example usage for org.eclipse.jdt.internal.compiler CompilationResult hasTasks

List of usage examples for org.eclipse.jdt.internal.compiler CompilationResult hasTasks

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler CompilationResult hasTasks.

Prototype

public boolean hasTasks() 

Source Link

Usage

From source file:de.plugins.eclipse.depclipse.testcommons.Util.java

License:Open Source License

/**
 * Returns the compilation errors / warnings for the given CompilationResult.
 *
 * @param compilationResult the compilation result
 * @param showCategory/*from w w w.  java2s . c  o m*/
 * @param showWarningToken
 * @return String the problem log
 */
public static String getProblemLog(CompilationResult compilationResult, boolean showCategory,
        boolean showWarningToken) {
    StringBuffer buffer = new StringBuffer(100);
    if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
        CategorizedProblem[] problems = compilationResult.getAllProblems();
        int count = problems.length;
        int problemCount = 0;
        char[] unitSource = compilationResult.compilationUnit.getContents();
        for (int i = 0; i < count; i++) {
            DefaultProblem problem = (DefaultProblem) problems[i];
            if (problem != null) {
                if (problemCount == 0)
                    buffer.append("----------\n");
                problemCount++;
                buffer.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
                buffer.append(" in " + new String(problem.getOriginatingFileName()).replace('/', '\\'));
                try {
                    buffer.append(problem.errorReportSource(unitSource));
                    buffer.append("\n");
                    if (showCategory) {
                        String category = problem.getInternalCategoryMessage();
                        if (category != null) {
                            buffer.append("[@cat:").append(category).append("] ");
                        }
                    }
                    if (showWarningToken) {
                        int irritant = ProblemReporter.getIrritant(problem.getID());
                        if (irritant != 0) {
                            String warningToken = CompilerOptions.warningTokenFromIrritant(irritant);
                            if (warningToken != null) {
                                buffer.append("[@sup:").append(warningToken).append("] ");
                            }
                        }
                    }
                    buffer.append(problem.getMessage());
                    buffer.append("\n");
                } catch (Exception e) {
                }
                buffer.append("----------\n");
            }
        }
    }
    return buffer.toString();
}

From source file:io.gige.compiler.internal.CompilerRequestorImpl.java

License:Apache License

@Override
public void acceptResult(CompilationResult result) {
    if (result.hasProblems()) {
        report(Kind.ERROR, result.getErrors());
    }//from w  w w.  j  a va  2s . com
    if (result.hasTasks()) {
        report(Kind.NOTE, result.getTasks());
    }
    try {
        for (ClassFile cf : result.getClassFiles()) {
            String className = new String(cf.fileName());
            JavaFileObject obj = this.manager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, className,
                    javax.tools.JavaFileObject.Kind.CLASS, null);
            try (OutputStream out = obj.openOutputStream()) {
                out.write(cf.getBytes());
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}