Search in sources :

Example 1 with CompilableJSUnit

use of net.vtst.ow.closure.compiler.compile.CompilableJSUnit in project ow by vtst.

the class ClosureContentAssistIncovationContext method computeCompilerRun.

private void computeCompilerRun() {
    IFile file = OwJsClosurePlugin.getDefault().getEditorRegistry().getFile(getDocument());
    if (file != null) {
        CompilableJSUnit unit = ResourceProperties.getJSUnitOrNullIfCoreException(file);
        if (unit != null) {
            run = unit.getLastAvailableCompilerRun();
            if (run != null) {
                run.fastCompile();
                node = run.getNode(unit, getPrefixOffset());
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CompilableJSUnit(net.vtst.ow.closure.compiler.compile.CompilableJSUnit)

Example 2 with CompilableJSUnit

use of net.vtst.ow.closure.compiler.compile.CompilableJSUnit in project ow by vtst.

the class ClosureTextHover method getHoverHTML.

/* (non-Javadoc)
   * @see net.vtst.ow.eclipse.js.closure.editor.hover.AbstractTextHover#getHoverHTML(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
   */
@Override
protected String getHoverHTML(ITextViewer viewer, IRegion region) {
    CompilableJSUnit unit = getJSUnit();
    if (unit == null)
        return null;
    CompilerRun run = getCompilerRun(unit);
    if (run == null)
        return null;
    Node node = run.getNode(unit, region.getOffset());
    if (node == null)
        return null;
    JSElementInfo info = getElementInfo(run, node);
    if (info == null)
        return null;
    return info.getHTMLStringForHover();
}
Also used : Node(com.google.javascript.rhino.Node) JSElementInfo(net.vtst.ow.eclipse.js.closure.editor.JSElementInfo) CompilerRun(net.vtst.ow.closure.compiler.compile.CompilerRun) CompilableJSUnit(net.vtst.ow.closure.compiler.compile.CompilableJSUnit)

Example 3 with CompilableJSUnit

use of net.vtst.ow.closure.compiler.compile.CompilableJSUnit in project ow by vtst.

the class ClosureBuilder method compileJavaScriptFile.

/**
   * Compile a JavaScript file.
   */
private void compileJavaScriptFile(IFile file, CompilerOptions options, boolean fileIsOpen, boolean stripIncludedFiles, boolean doNotKeepCompilationResultsOfClosedFilesInMemory, boolean force) throws CoreException {
    OwJsDev.log("Compiling %s", file.getFullPath().toOSString());
    CompilableJSUnit unit = ResourceProperties.getJSUnit(file);
    if (unit == null)
        return;
    ErrorManager errorManager = new ErrorManagerForFileBuild(unit, file);
    boolean keepCompilationResultsInMemory = !doNotKeepCompilationResultsOfClosedFilesInMemory || fileIsOpen;
    boolean force2 = force || editorRegistry.isNewlyOpenedFile(file);
    CompilerRun run = unit.fullCompile(options, errorManager, keepCompilationResultsInMemory, stripIncludedFiles, force2);
    run.setErrorManager(new NullErrorManager());
}
Also used : ErrorManager(com.google.javascript.jscomp.ErrorManager) NullErrorManager(net.vtst.ow.closure.compiler.util.NullErrorManager) CompilerRun(net.vtst.ow.closure.compiler.compile.CompilerRun) CompilableJSUnit(net.vtst.ow.closure.compiler.compile.CompilableJSUnit) NullErrorManager(net.vtst.ow.closure.compiler.util.NullErrorManager)

Example 4 with CompilableJSUnit

use of net.vtst.ow.closure.compiler.compile.CompilableJSUnit in project ow by vtst.

the class ClosureBuilder method fullBuild.

// **************************************************************************
// Full build
/**
   * Perform a full build of a project.
   * @param monitor  The project monitor.  This methods reports two units of work.
   * @param project  The project to build.
   * @throws CoreException, OperationCanceledException
   */
private void fullBuild(IProgressMonitor monitor, IProject project) throws CoreException {
    monitor.subTask(messages.format("build_prepare"));
    boolean forgetIfCanceled = true;
    Compiler compiler = CompilerUtils.makeCompiler(new ErrorManagerForProjectBuild(project));
    compiler.initOptions(CompilerUtils.makeOptionsForParsingAndErrorReporting());
    try {
        File pathOfClosureBase = ClosureCompiler.getPathOfClosureBase(project);
        if (pathOfClosureBase == null) {
            monitor.worked(1);
            return;
        }
        // Create or get the project
        JSProject jsProject = ResourceProperties.getOrCreateJSProject(project);
        boolean jsProjectUpdated = updateJSProjectIfNeeded(monitor, compiler, project, jsProject);
        // Set the compilation units
        Set<IFile> files = ClosureCompiler.getJavaScriptFilesOfProject(project);
        ResourceProperties.setJavaScriptFiles(project, files);
        List<CompilableJSUnit> units = new ArrayList<CompilableJSUnit>(files.size());
        for (IFile file : files) {
            Utils.checkCancel(monitor);
            CompilableJSUnit unit = ResourceProperties.getJSUnit(file);
            if (unit == null) {
                unit = new CompilableJSUnit(jsProject, file.getLocation().toFile(), pathOfClosureBase, new CompilationUnitProviderFromEclipseIFile(file));
                ResourceProperties.setJSUnit(file, unit);
            } else {
                if (jsProjectUpdated)
                    unit.clear();
            }
            units.add(unit);
        }
        try {
            jsProject.setUnits(compiler, units);
            monitor.worked(1);
            forgetIfCanceled = false;
            compileJavaScriptFiles(monitor, project, files, false);
        } catch (CircularDependencyException e) {
            CompilerUtils.reportError(compiler, JSError.make(CIRCULAR_DEPENDENCY_ERROR, e.getMessage()));
            forgetLastBuiltState();
        }
    } catch (OperationCanceledException e) {
        if (forgetIfCanceled)
            forgetLastBuiltState();
        throw e;
    } finally {
        compiler.getErrorManager().generateReport();
    }
}
Also used : ClosureCompiler(net.vtst.ow.eclipse.js.closure.compiler.ClosureCompiler) Compiler(com.google.javascript.jscomp.Compiler) AbstractJSProject(net.vtst.ow.closure.compiler.deps.AbstractJSProject) JSProject(net.vtst.ow.closure.compiler.deps.JSProject) IFile(org.eclipse.core.resources.IFile) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) CompilableJSUnit(net.vtst.ow.closure.compiler.compile.CompilableJSUnit) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CircularDependencyException(com.google.javascript.jscomp.deps.SortedDependencies.CircularDependencyException)

Aggregations

CompilableJSUnit (net.vtst.ow.closure.compiler.compile.CompilableJSUnit)4 CompilerRun (net.vtst.ow.closure.compiler.compile.CompilerRun)2 IFile (org.eclipse.core.resources.IFile)2 Compiler (com.google.javascript.jscomp.Compiler)1 ErrorManager (com.google.javascript.jscomp.ErrorManager)1 CircularDependencyException (com.google.javascript.jscomp.deps.SortedDependencies.CircularDependencyException)1 Node (com.google.javascript.rhino.Node)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 AbstractJSProject (net.vtst.ow.closure.compiler.deps.AbstractJSProject)1 JSProject (net.vtst.ow.closure.compiler.deps.JSProject)1 NullErrorManager (net.vtst.ow.closure.compiler.util.NullErrorManager)1 ClosureCompiler (net.vtst.ow.eclipse.js.closure.compiler.ClosureCompiler)1 JSElementInfo (net.vtst.ow.eclipse.js.closure.editor.JSElementInfo)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1