Example usage for org.eclipse.jdt.internal.compiler.problem DefaultProblem getInternalCategoryMessage

List of usage examples for org.eclipse.jdt.internal.compiler.problem DefaultProblem getInternalCategoryMessage

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.problem DefaultProblem getInternalCategoryMessage.

Prototype

public String getInternalCategoryMessage() 

Source Link

Document

Answers a readable name for the category which this problem belongs to, or null if none could be found.

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 ww.  jav a  2  s. c om
 * @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();
}