Search in sources :

Example 1 with IInvisibleCompilationUnit

use of org.apache.flex.compiler.units.IInvisibleCompilationUnit in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method getCompilationUnit.

private ICompilationUnit getCompilationUnit(Path path) {
    String absolutePath = path.toAbsolutePath().toString();
    currentUnit = null;
    currentProject = getProject();
    if (currentProject == null) {
        return null;
    }
    currentWorkspace = currentProject.getWorkspace();
    //we're going to start with the files passed into the compiler
    String[] files = currentProjectOptions.files;
    if (files != null) {
        for (int i = files.length - 1; i >= 0; i--) {
            String file = files[i];
            //a previous file may have created a compilation unit for the
            //current file, so use that, if available
            ICompilationUnit existingUnit = findCompilationUnit(file);
            if (existingUnit != null) {
                if (file.equals(absolutePath)) {
                    currentUnit = existingUnit;
                }
                continue;
            }
            IInvisibleCompilationUnit unit = currentProject.createInvisibleCompilationUnit(file, fileSpecGetter);
            if (unit == null) {
                System.err.println("Could not create compilation unit for file: " + file);
                continue;
            }
            invisibleUnits.add(unit);
            if (file.equals(absolutePath)) {
                currentUnit = unit;
            }
        }
    }
    compilationUnits = currentProject.getCompilationUnits();
    //if we didn't find the unit already, search the complete set of units
    if (currentUnit == null) {
        //might already be created
        for (ICompilationUnit unit : compilationUnits) {
            if (unit != null && unit.getAbsoluteFilename().equals(absolutePath)) {
                currentUnit = unit;
                break;
            }
        }
    }
    //if we still haven't found it, create it manually
    if (currentUnit == null) {
        //if all else fails, create the compilation unit manually
        IInvisibleCompilationUnit unit = currentProject.createInvisibleCompilationUnit(absolutePath, fileSpecGetter);
        if (unit == null) {
            System.err.println("Could not create compilation unit for file: " + absolutePath);
            return null;
        }
        invisibleUnits.add(unit);
        currentUnit = unit;
    }
    //for some reason, function nodes may not always be populated, but we
    //can force them to be populated
    IASNode ast = null;
    try {
        ast = currentUnit.getSyntaxTreeRequest().get().getAST();
    } catch (InterruptedException e) {
        System.err.println("Interrupted while getting AST");
    }
    if (ast instanceof IFileNode) {
        IFileNode fileNode = (IFileNode) ast;
        fileNode.populateFunctionNodes();
    }
    return currentUnit;
}
Also used : IInvisibleCompilationUnit(org.apache.flex.compiler.units.IInvisibleCompilationUnit) ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) IFileNode(org.apache.flex.compiler.tree.as.IFileNode) IASNode(org.apache.flex.compiler.tree.as.IASNode)

Aggregations

IASNode (org.apache.flex.compiler.tree.as.IASNode)1 IFileNode (org.apache.flex.compiler.tree.as.IFileNode)1 ICompilationUnit (org.apache.flex.compiler.units.ICompilationUnit)1 IInvisibleCompilationUnit (org.apache.flex.compiler.units.IInvisibleCompilationUnit)1