Search in sources :

Example 1 with AnalysisBuilderVisitor

use of com.python.pydev.analysis.additionalinfo.builders.AnalysisBuilderVisitor in project Pydev by fabioz.

the class ForceCodeAnalysisOnTree method forceCodeAnalysisOnFiles.

public static void forceCodeAnalysisOnFiles(PythonNature nature, IProgressMonitor monitor, List<IFile> filesToVisit, Set<IFile> filesVisited, List<IExternalCodeAnalysisVisitor> externalVisitors) {
    if (nature == null) {
        return;
    }
    AnalysisBuilderVisitor visitor = new AnalysisBuilderVisitor();
    visitor.visitingWillStart(new NullProgressMonitor(), false, null);
    FastStringBuffer buf = new FastStringBuffer();
    for (IFile f : filesToVisit) {
        if (monitor.isCanceled()) {
            break;
        }
        if (filesVisited.contains(f)) {
            continue;
        }
        filesVisited.add(f);
        monitor.setTaskName(buf.clear().append("Scheduling: ").append(f.getName()).toString());
        IDocument doc = FileUtilsFileBuffer.getDocFromResource(f);
        visitor.memo = new VisitorMemo();
        visitor.memo.put(PyDevBuilderVisitor.IS_FULL_BUILD, false);
        long documentTime = System.currentTimeMillis();
        visitor.memo.put(PyDevBuilderVisitor.DOCUMENT_TIME, documentTime);
        String moduleName;
        try {
            moduleName = nature.resolveModule(f);
        } catch (MisconfigurationException e) {
            Log.log(e);
            continue;
        }
        if (moduleName == null) {
            continue;
        }
        AnalysisBuilderVisitor.setModuleNameInCache(visitor.memo, f, moduleName);
        if (!PythonPathHelper.isValidSourceFile(f)) {
            AnalysisRunner.deleteMarkers(f, true);
            continue;
        }
        IModule module = nature.getAstManager().getModule(moduleName, nature, true, new BaseModuleRequest(false));
        if (module == null) {
            Log.log(IStatus.WARNING, "Unable to get module: " + moduleName + " for resource: " + f, null);
            continue;
        }
        visitor.doVisitChangedResource(nature, f, doc, null, module, new NullProgressMonitor(), true, AnalysisBuilderRunnable.ANALYSIS_CAUSE_PARSER, documentTime, false, externalVisitors);
    }
    visitor.visitingEnded(new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IModule(org.python.pydev.core.IModule) IFile(org.eclipse.core.resources.IFile) FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) MisconfigurationException(org.python.pydev.core.MisconfigurationException) BaseModuleRequest(org.python.pydev.core.BaseModuleRequest) VisitorMemo(org.python.pydev.ast.builder.VisitorMemo) AnalysisBuilderVisitor(com.python.pydev.analysis.additionalinfo.builders.AnalysisBuilderVisitor) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with AnalysisBuilderVisitor

use of com.python.pydev.analysis.additionalinfo.builders.AnalysisBuilderVisitor in project Pydev by fabioz.

the class AnalysisParserObserver method analyze.

private static void analyze(ChangedParserInfoForObservers info, SimpleNode root, IFile fileAdapter, boolean force, IPythonNature nature, boolean forceAnalyzeInThisThread) {
    if (!nature.startRequests()) {
        return;
    }
    IModule module;
    try {
        // we visit external because we must index them
        String moduleName = nature.resolveModuleOnlyInProjectSources(fileAdapter, true);
        if (moduleName == null) {
            AnalysisRunner.deleteMarkers(fileAdapter);
            // we only analyze resources that are in the pythonpath
            return;
        }
        IPath location = fileAdapter.getLocation();
        if (location == null) {
            return;
        }
        String file = location.toOSString();
        module = AbstractModule.createModule(root, new File(file), moduleName, nature);
    } catch (Exception e) {
        // Not much we can do about it.
        Log.log(e);
        return;
    } finally {
        nature.endRequests();
    }
    // visit it
    AnalysisBuilderVisitor visitor = new AnalysisBuilderVisitor();
    visitor.memo = new VisitorMemo();
    visitor.memo.put(PyDevBuilderVisitor.IS_FULL_BUILD, false);
    visitor.memo.put(PyDevBuilderVisitor.DOCUMENT_TIME, info.documentMillisTime);
    visitor.visitingWillStart(new NullProgressMonitor(), false, null);
    try {
        visitor.doVisitChangedResource(nature, fileAdapter, info.doc, null, module, new NullProgressMonitor(), force, AnalysisBuilderRunnable.ANALYSIS_CAUSE_PARSER, info.documentMillisTime, forceAnalyzeInThisThread);
    } finally {
        visitor.visitingEnded(new NullProgressMonitor());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IModule(org.python.pydev.core.IModule) IPath(org.eclipse.core.runtime.IPath) VisitorMemo(org.python.pydev.ast.builder.VisitorMemo) IFile(org.eclipse.core.resources.IFile) File(java.io.File) AnalysisBuilderVisitor(com.python.pydev.analysis.additionalinfo.builders.AnalysisBuilderVisitor)

Aggregations

AnalysisBuilderVisitor (com.python.pydev.analysis.additionalinfo.builders.AnalysisBuilderVisitor)2 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 VisitorMemo (org.python.pydev.ast.builder.VisitorMemo)2 IModule (org.python.pydev.core.IModule)2 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1 IDocument (org.eclipse.jface.text.IDocument)1 BaseModuleRequest (org.python.pydev.core.BaseModuleRequest)1 MisconfigurationException (org.python.pydev.core.MisconfigurationException)1 FastStringBuffer (org.python.pydev.shared_core.string.FastStringBuffer)1