Search in sources :

Example 6 with AbstractAdditionalDependencyInfo

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

the class RefactorerFinds method findLikelyModulesWithChildren.

private HashSet<SourceModule> findLikelyModulesWithChildren(RefactoringRequest request, HierarchyNodeModel model, List<AbstractAdditionalDependencyInfo> infoForProject) {
    // get the modules that are most likely to have that declaration.
    HashSet<SourceModule> modulesToAnalyze = new HashSet<SourceModule>();
    for (AbstractAdditionalDependencyInfo additionalInfo : infoForProject) {
        IProgressMonitor monitor = request.getMonitor();
        if (monitor == null) {
            monitor = new NullProgressMonitor();
        }
        monitor.beginTask("Find likely modules with children", 100);
        monitor.setTaskName("Searching: " + model.name);
        try {
            List<ModulesKey> modules;
            try {
                request.pushMonitor(new SubProgressMonitor(monitor, 90));
                if (additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                    AdditionalProjectInterpreterInfo additionalProjectInterpreterInfo = (AdditionalProjectInterpreterInfo) additionalInfo;
                    modules = additionalProjectInterpreterInfo.getModulesWithToken(model.name, monitor);
                } else {
                    continue;
                }
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
            } finally {
                request.popMonitor().done();
            }
            try {
                request.pushMonitor(new SubProgressMonitor(monitor, 10));
                request.getMonitor().beginTask("Find likely modules with children", modules.size());
                for (ModulesKey declaringModuleName : modules) {
                    if (DEBUG) {
                        System.out.println("findLikelyModulesWithChildren: " + declaringModuleName);
                    }
                    IModule module = null;
                    IPythonNature pythonNature = null;
                    if (additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                        AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additionalInfo;
                        pythonNature = PythonNature.getPythonNature(projectInterpreterInfo.getProject());
                    }
                    if (pythonNature == null) {
                        pythonNature = request.nature;
                    }
                    BaseModuleRequest moduleRequest = new BaseModuleRequest(request.acceptTypeshed);
                    module = pythonNature.getAstManager().getModule(declaringModuleName.name, pythonNature, false, moduleRequest);
                    if (module == null && pythonNature != request.nature) {
                        module = request.nature.getAstManager().getModule(declaringModuleName.name, request.nature, false, moduleRequest);
                    }
                    if (module instanceof SourceModule) {
                        modulesToAnalyze.add((SourceModule) module);
                    }
                    request.getMonitor().worked(1);
                }
            } finally {
                request.popMonitor().done();
            }
        } finally {
            monitor.done();
        }
    }
    return modulesToAnalyze;
}
Also used : SourceModule(org.python.pydev.ast.codecompletion.revisited.modules.SourceModule) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IModule(org.python.pydev.core.IModule) BaseModuleRequest(org.python.pydev.core.BaseModuleRequest) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IPythonNature(org.python.pydev.core.IPythonNature) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) AdditionalProjectInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ModulesKey(org.python.pydev.core.ModulesKey) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) HashSet(java.util.HashSet)

Example 7 with AbstractAdditionalDependencyInfo

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

the class InterpreterInfoBuilder method syncInfoToPythonPath.

public BuilderResult syncInfoToPythonPath(IProgressMonitor monitor, IPythonNature nature) {
    ICodeCompletionASTManager astManager = nature.getAstManager();
    if (astManager == null) {
        return BuilderResult.MUST_SYNCH_LATER;
    }
    PythonPathHelper pythonPathHelper = (PythonPathHelper) astManager.getModulesManager().getPythonPathHelper();
    if (pythonPathHelper == null) {
        return BuilderResult.OK;
    }
    AbstractAdditionalDependencyInfo additionalInfo;
    try {
        additionalInfo = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
        IModulesManager modulesManager = astManager.getModulesManager();
        return this.syncInfoToPythonPath(monitor, pythonPathHelper, additionalInfo, modulesManager, null);
    } catch (MisconfigurationException e) {
        Log.log(e);
        return BuilderResult.OK;
    }
}
Also used : ICodeCompletionASTManager(org.python.pydev.core.ICodeCompletionASTManager) MisconfigurationException(org.python.pydev.core.MisconfigurationException) IModulesManager(org.python.pydev.core.IModulesManager) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) PythonPathHelper(org.python.pydev.ast.codecompletion.revisited.PythonPathHelper)

Example 8 with AbstractAdditionalDependencyInfo

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

the class InterpreterInfoBuilder method syncInfoToPythonPath.

@Override
public BuilderResult syncInfoToPythonPath(IProgressMonitor monitor, InterpreterInfo info) {
    ISystemModulesManager modulesManager = info.getModulesManager();
    IInterpreterManager manager = modulesManager.getInterpreterManager();
    AbstractAdditionalDependencyInfo additionalInfo;
    try {
        additionalInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(manager, info.getExecutableOrJar());
    } catch (MisconfigurationException e) {
        Log.log(e);
        return BuilderResult.OK;
    }
    return this.syncInfoToPythonPath(monitor, info, additionalInfo);
}
Also used : ISystemModulesManager(org.python.pydev.core.ISystemModulesManager) MisconfigurationException(org.python.pydev.core.MisconfigurationException) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) IInterpreterManager(org.python.pydev.core.IInterpreterManager)

Example 9 with AbstractAdditionalDependencyInfo

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

the class InterpreterInfoBuilderTest method testInterpreterInfoBuilder.

public void testInterpreterInfoBuilder() throws Exception {
    Collection<String> pythonpath = new ArrayList<String>();
    pythonpath.add(libDir.toString());
    final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
    IEclipsePreferences preferences = new InMemoryEclipsePreferences();
    final PythonInterpreterManager manager = new PythonInterpreterManager(preferences);
    InterpreterManagersAPI.setPythonInterpreterManager(manager);
    manager.setInfos(new IInterpreterInfo[] { info }, null, null);
    final AdditionalSystemInterpreterInfo additionalInfo = new AdditionalSystemInterpreterInfo(manager, info.getExecutableOrJar());
    AdditionalSystemInterpreterInfo.setAdditionalSystemInfo(manager, info.getExecutableOrJar(), additionalInfo);
    // Don't load it (otherwise it'll get the 'proper' info).
    // AdditionalSystemInterpreterInfo.loadAdditionalSystemInfo(manager, info.getExecutableOrJar());
    final ISystemModulesManager modulesManager = info.getModulesManager();
    assertEquals(0, modulesManager.getSize(false));
    assertEquals(0, additionalInfo.getAllTokens().size());
    InterpreterInfoBuilder builder = new InterpreterInfoBuilder();
    builder.syncInfoToPythonPath(null, info);
    int size = modulesManager.getSize(false);
    if (size != 3) {
        fail("Expected size = 3, found: " + size);
    }
    try {
        AbstractAdditionalDependencyInfo additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(manager, manager.getInterpreterInfos()[0].getExecutableOrJar(), true);
        if (additionalInfo != additionalSystemInfo) {
            throw new RuntimeException("Expecting it to be the same instance.");
        }
    } catch (MisconfigurationException e) {
        throw new RuntimeException(e);
    }
    Collection<IInfo> allTokens = additionalInfo.getAllTokens();
    size = allTokens.size();
    if (size != 3) {
        FastStringBuffer buf = new FastStringBuffer();
        for (IInfo i : allTokens) {
            buf.append(i.toString());
        }
        fail("Expected size = 3, found: " + size + "\nTokens: " + buf);
    }
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) MisconfigurationException(org.python.pydev.core.MisconfigurationException) PythonInterpreterManager(org.python.pydev.ast.interpreter_managers.PythonInterpreterManager) ArrayList(java.util.ArrayList) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) ISystemModulesManager(org.python.pydev.core.ISystemModulesManager) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) InMemoryEclipsePreferences(org.python.pydev.shared_core.preferences.InMemoryEclipsePreferences)

Example 10 with AbstractAdditionalDependencyInfo

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

the class AnalysisBuilderVisitor method visitingWillStart.

@Override
public void visitingWillStart(IProgressMonitor monitor, boolean isFullBuild, IPythonNature nature) {
    if (isFullBuild) {
        AbstractAdditionalDependencyInfo info;
        try {
            info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
        } catch (MisconfigurationException e) {
            Log.log(e);
            return;
        }
        info.clearAllInfo();
    }
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)

Aggregations

AbstractAdditionalDependencyInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)10 MisconfigurationException (org.python.pydev.core.MisconfigurationException)9 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 IPythonNature (org.python.pydev.core.IPythonNature)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 SourceModule (org.python.pydev.ast.codecompletion.revisited.modules.SourceModule)2 IInfo (org.python.pydev.core.IInfo)2 IInterpreterManager (org.python.pydev.core.IInterpreterManager)2 ISystemModulesManager (org.python.pydev.core.ISystemModulesManager)2 ModulesKey (org.python.pydev.core.ModulesKey)2 AbstractAdditionalTokensInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo)1 AdditionalProjectInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo)1 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)1 IReferenceSearches (com.python.pydev.analysis.additionalinfo.IReferenceSearches)1 File (java.io.File)1 Set (java.util.Set)1 IFile (org.eclipse.core.resources.IFile)1