Search in sources :

Example 1 with JavacOutputParser

use of com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser in project intellij-community by JetBrains.

the class OutputParser method processJavacMessages.

private static void processJavacMessages(final List<String> javacMessages, final AntBuildMessageView messageView, final Project project) {
    if (javacMessages == null) {
        return;
    }
    final com.intellij.compiler.OutputParser outputParser = new JavacOutputParser(project);
    com.intellij.compiler.OutputParser.Callback callback = new com.intellij.compiler.OutputParser.Callback() {

        private int myIndex = -1;

        @Nullable
        public String getCurrentLine() {
            if (myIndex >= javacMessages.size()) {
                return null;
            }
            return javacMessages.get(myIndex);
        }

        public String getNextLine() {
            final int size = javacMessages.size();
            final int next = Math.min(myIndex + 1, javacMessages.size());
            myIndex = next;
            if (next >= size) {
                return null;
            }
            return javacMessages.get(next);
        }

        @Override
        public void pushBack(String line) {
            myIndex--;
        }

        public void message(final CompilerMessageCategory category, final String message, final String url, final int lineNum, final int columnNum) {
            StringTokenizer tokenizer = new StringTokenizer(message, "\n", false);
            final String[] strings = new String[tokenizer.countTokens()];
            //noinspection ForLoopThatDoesntUseLoopVariable
            for (int idx = 0; tokenizer.hasMoreTokens(); idx++) {
                strings[idx] = tokenizer.nextToken();
            }
            ApplicationManager.getApplication().runReadAction(() -> {
                VirtualFile file = url == null ? null : VirtualFileManager.getInstance().findFileByUrl(url);
                messageView.outputJavacMessage(convertCategory(category), strings, file, url, lineNum, columnNum);
                if (file != null && category == CompilerMessageCategory.ERROR) {
                    final WolfTheProblemSolver wolf = WolfTheProblemSolver.getInstance(project);
                    final Problem problem = wolf.convertToProblem(file, lineNum, columnNum, strings);
                    wolf.weHaveGotNonIgnorableProblems(file, Collections.singletonList(problem));
                }
            });
        }

        public void setProgressText(String text) {
        }

        public void fileProcessed(String path) {
        }

        public void fileGenerated(String path) {
        }
    };
    try {
        while (true) {
            if (!outputParser.processMessageLine(callback)) {
                break;
            }
        }
    } catch (Exception e) {
    //ignore
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) VirtualFile(com.intellij.openapi.vfs.VirtualFile) WolfTheProblemSolver(com.intellij.problems.WolfTheProblemSolver) JavacOutputParser(com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser) StringTokenizer(com.intellij.util.text.StringTokenizer) Problem(com.intellij.problems.Problem) JavacOutputParser(com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser)

Aggregations

JavacOutputParser (com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser)1 CompilerMessageCategory (com.intellij.openapi.compiler.CompilerMessageCategory)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Problem (com.intellij.problems.Problem)1 WolfTheProblemSolver (com.intellij.problems.WolfTheProblemSolver)1 StringTokenizer (com.intellij.util.text.StringTokenizer)1