Example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions warningTokenFromIrritant

List of usage examples for org.eclipse.jdt.internal.compiler.impl CompilerOptions warningTokenFromIrritant

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions warningTokenFromIrritant.

Prototype

public static String warningTokenFromIrritant(int irritant) 

Source Link

Document

For suppressable warnings

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/* w  w w.  j a va 2  s .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();
}