Search in sources :

Example 1 with CompilerProject

use of org.apache.flex.compiler.internal.projects.CompilerProject in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method checkFilePathForAllProblems.

private boolean checkFilePathForAllProblems(Path path, Boolean quick) {
    ICompilationUnit mainUnit = getCompilationUnit(path);
    if (mainUnit == null) {
        return false;
    }
    CompilerProject project = (CompilerProject) mainUnit.getProject();
    Collection<ICompilerProblem> fatalProblems = project.getFatalProblems();
    if (fatalProblems == null || fatalProblems.size() == 0) {
        fatalProblems = project.getProblems();
    }
    if (fatalProblems != null && fatalProblems.size() > 0) {
        URI uri = path.toUri();
        PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
        publish.setDiagnostics(new ArrayList<>());
        publish.setUri(uri.toString());
        codeProblemTracker.trackFileWithProblems(uri);
        for (ICompilerProblem problem : fatalProblems) {
            addCompilerProblem(problem, publish);
        }
        codeProblemTracker.cleanUpStaleProblems();
        if (languageClient != null) {
            languageClient.publishDiagnostics(publish);
        }
        return true;
    }
    IASNode ast = null;
    try {
        ast = mainUnit.getSyntaxTreeRequest().get().getAST();
    } catch (Exception e) {
        System.err.println("Exception during build: " + e);
        return false;
    }
    if (ast == null) {
        return false;
    }
    Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
    try {
        if (quick) {
            PublishDiagnosticsParams params = checkCompilationUnitForAllProblems(mainUnit);
            URI uri = Paths.get(mainUnit.getAbsoluteFilename()).toUri();
            files.put(uri, params);
        } else {
            boolean continueCheckingForErrors = true;
            while (continueCheckingForErrors) {
                try {
                    for (ICompilationUnit unit : compilationUnits) {
                        if (unit == null || unit instanceof SWCCompilationUnit) {
                            //compiled compilation units won't have problems
                            continue;
                        }
                        PublishDiagnosticsParams params = checkCompilationUnitForAllProblems(unit);
                        URI uri = Paths.get(unit.getAbsoluteFilename()).toUri();
                        files.put(uri, params);
                    }
                    continueCheckingForErrors = false;
                } catch (ConcurrentModificationException e) {
                //when we finished building one of the compilation
                //units, more were added to the collection, so we need
                //to start over because we can't iterate over a modified
                //collection.
                }
            }
            //only clean up stale errors on a full check
            codeProblemTracker.cleanUpStaleProblems();
        }
    } catch (Exception e) {
        System.err.println("Exception during build: " + e);
        e.printStackTrace();
        return false;
    }
    if (languageClient != null) {
        files.values().forEach(languageClient::publishDiagnostics);
    }
    return true;
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) ConcurrentModificationException(java.util.ConcurrentModificationException) HashMap(java.util.HashMap) CompilerProject(org.apache.flex.compiler.internal.projects.CompilerProject) URI(java.net.URI) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ICompilerProblem(org.apache.flex.compiler.problems.ICompilerProblem) SWCCompilationUnit(org.apache.flex.compiler.internal.units.SWCCompilationUnit) IASNode(org.apache.flex.compiler.tree.as.IASNode) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashMap (java.util.HashMap)1 CompilerProject (org.apache.flex.compiler.internal.projects.CompilerProject)1 SWCCompilationUnit (org.apache.flex.compiler.internal.units.SWCCompilationUnit)1 ICompilerProblem (org.apache.flex.compiler.problems.ICompilerProblem)1 IASNode (org.apache.flex.compiler.tree.as.IASNode)1 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)1 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)1