Search in sources :

Example 1 with AbstractAdditionalDependencyInfo

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

the class AnalysisBuilderRunnableForRemove method removeInfoForModule.

/**
 * @param moduleName this is the module name
 * @param nature this is the nature
 */
public static void removeInfoForModule(String moduleName, IPythonNature nature, boolean isFullBuild) {
    if (moduleName != null && nature != null) {
        AbstractAdditionalDependencyInfo info;
        try {
            info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
        } catch (MisconfigurationException e) {
            Log.log(e);
            return;
        }
        boolean generateDelta;
        if (isFullBuild) {
            generateDelta = false;
        } else {
            generateDelta = true;
        }
        info.removeInfoFromModule(moduleName, generateDelta);
    } else {
        if (DebugSettings.DEBUG_ANALYSIS_REQUESTS) {
            org.python.pydev.shared_core.log.ToLogFile.toLogFile("Unable to remove info. name: " + moduleName + " or nature:" + nature + " is null.", AnalysisBuilderRunnableForRemove.class);
        }
    }
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)

Example 2 with AbstractAdditionalDependencyInfo

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

the class PyGlobalsBrowser method getFromManagerAndRelatedNatures.

/**
 * Gets it using all the natures that match a given interpreter manager.
 * @throws MisconfigurationException
 */
private static void getFromManagerAndRelatedNatures(String selectedText, IInterpreterManager useManager) {
    AbstractAdditionalTokensInfo additionalSystemInfo;
    try {
        additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(useManager, useManager.getDefaultInterpreterInfo(true).getExecutableOrJar());
    } catch (MisconfigurationException e) {
        MessageDialog.openError(EditorUtils.getShell(), "Error", "Additional info is not available (default interpreter not configured).");
        handle(e);
        return;
    }
    List<AbstractAdditionalTokensInfo> additionalInfo = new ArrayList<AbstractAdditionalTokensInfo>();
    additionalInfo.add(additionalSystemInfo);
    List<IPythonNature> natures = PythonNature.getPythonNaturesRelatedTo(useManager.getInterpreterType());
    for (IPythonNature nature : natures) {
        AbstractAdditionalDependencyInfo info;
        try {
            info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
            if (info != null) {
                additionalInfo.add(info);
            }
        } catch (MisconfigurationException e) {
            // just go on to the next nature if one is not properly configured.
            handle(e);
        }
    }
    doSelect(natures, additionalInfo, selectedText);
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) ArrayList(java.util.ArrayList) IPythonNature(org.python.pydev.core.IPythonNature) AbstractAdditionalTokensInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)

Example 3 with AbstractAdditionalDependencyInfo

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

the class RefactorerFinds method findChildren.

private void findChildren(RefactoringRequest request, HierarchyNodeModel initialModel, HashMap<HierarchyNodeModel, HierarchyNodeModel> allFound) {
    try {
        request.getMonitor().beginTask("Find children", 100);
        // and now the children...
        List<AbstractAdditionalDependencyInfo> infoForProject;
        try {
            infoForProject = AdditionalProjectInterpreterInfo.getAdditionalInfoForProjectAndReferencing(request.nature);
        } catch (MisconfigurationException e) {
            Log.log(e);
            return;
        }
        HashSet<HierarchyNodeModel> foundOnRound = new HashSet<HierarchyNodeModel>();
        foundOnRound.add(initialModel);
        int totalWork = 1000;
        while (foundOnRound.size() > 0) {
            HashSet<HierarchyNodeModel> nextRound = new HashSet<HierarchyNodeModel>(foundOnRound);
            foundOnRound.clear();
            for (HierarchyNodeModel toFindOnRound : nextRound) {
                HashSet<SourceModule> modulesToAnalyze;
                int work = totalWork / 250;
                if (work <= 0) {
                    work = 1;
                    totalWork = 0;
                }
                totalWork -= work;
                try {
                    request.pushMonitor(new SubProgressMonitor(request.getMonitor(), work));
                    modulesToAnalyze = findLikelyModulesWithChildren(request, toFindOnRound, infoForProject);
                } finally {
                    request.popMonitor().done();
                }
                request.communicateWork("Likely modules with matches:" + modulesToAnalyze.size());
                findChildrenOnModules(request, allFound, foundOnRound, toFindOnRound, modulesToAnalyze);
            }
        }
    } finally {
        request.getMonitor().done();
    }
}
Also used : SourceModule(org.python.pydev.ast.codecompletion.revisited.modules.SourceModule) MisconfigurationException(org.python.pydev.core.MisconfigurationException) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) HierarchyNodeModel(org.python.pydev.ast.refactoring.HierarchyNodeModel) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) HashSet(java.util.HashSet)

Example 4 with AbstractAdditionalDependencyInfo

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

the class PySearchIndexQuery method run.

@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
    SearchIndexResult searchResult = (SearchIndexResult) getSearchResult();
    // Remove all so that we don't get duplicates on a search refresh.
    searchResult.removeAll();
    StringMatcherWithIndexSemantics stringMatcher = createStringMatcher();
    Set<String> moduleNamesFilter = scopeAndData.getModuleNamesFilter();
    OrderedMap<String, Set<String>> fieldNameToValues = new OrderedMap<>();
    if (moduleNamesFilter != null && !moduleNamesFilter.isEmpty()) {
        fieldNameToValues.put(IReferenceSearches.FIELD_MODULE_NAME, moduleNamesFilter);
    }
    Set<String> split = makeTextFieldPatternsToSearchFromText();
    fieldNameToValues.put(IReferenceSearches.FIELD_CONTENTS, split);
    final List<IPythonNature> pythonNatures = PyScopeAndData.getPythonNatures(scopeAndData);
    monitor.beginTask("Search indexes", pythonNatures.size());
    try {
        for (IPythonNature nature : pythonNatures) {
            AbstractAdditionalDependencyInfo info;
            try {
                info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
            } catch (MisconfigurationException e) {
                Log.log(e);
                continue;
            }
            IReferenceSearches referenceSearches = info.getReferenceSearches();
            List<ModulesKey> search = referenceSearches.search(nature.getProject(), fieldNameToValues, new SubProgressMonitor(monitor, 1));
            IFile workspaceFile;
            for (ModulesKey modulesKey : search) {
                File file = modulesKey.file;
                if (file == null || !file.exists()) {
                    Log.logInfo(StringUtils.format("Ignoring: %s. File no longer exists.", file));
                }
                workspaceFile = FindWorkspaceFiles.getWorkspaceFile(file, nature.getProject());
                if (workspaceFile == null) {
                    Log.logInfo(StringUtils.format("Ignoring: %s. Unable to resolve to a file in the Eclipse workspace.", file));
                    continue;
                }
                IDocument doc = FileUtilsFileBuffer.getDocFromResource(workspaceFile);
                String text = doc.get();
                createMatches(doc, text, stringMatcher, workspaceFile, searchResult, modulesKey);
            }
        }
    } finally {
        monitor.done();
    }
    return Status.OK_STATUS;
}
Also used : StringMatcherWithIndexSemantics(org.python.pydev.shared_ui.search.StringMatcherWithIndexSemantics) Set(java.util.Set) IFile(org.eclipse.core.resources.IFile) MisconfigurationException(org.python.pydev.core.MisconfigurationException) IPythonNature(org.python.pydev.core.IPythonNature) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IReferenceSearches(com.python.pydev.analysis.additionalinfo.IReferenceSearches) SearchIndexResult(org.python.pydev.shared_ui.search.SearchIndexResult) ModulesKey(org.python.pydev.core.ModulesKey) OrderedMap(org.python.pydev.shared_core.structure.OrderedMap) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with AbstractAdditionalDependencyInfo

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

the class AnalysisTestsBase method restoreSystemPythonPath.

// ---------------------------------------------------------------------- additional info
@Override
protected boolean restoreSystemPythonPath(boolean force, String path) {
    boolean restored = super.restoreSystemPythonPath(force, path);
    if (restored) {
        IProgressMonitor monitor = new NullProgressMonitor();
        // try to load it from previous session
        IInterpreterManager interpreterManager = getInterpreterManager();
        try {
            String defaultInterpreter = interpreterManager.getDefaultInterpreterInfo(false).getExecutableOrJar();
            boolean recreate = forceAdditionalInfoRecreation;
            if (!recreate) {
                // one last check: if TestCase is not found, recreate it!
                AbstractAdditionalDependencyInfo additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(interpreterManager, defaultInterpreter);
                Collection<IInfo> tokensStartingWith = additionalSystemInfo.getTokensStartingWith("TestCase", AbstractAdditionalTokensInfo.TOP_LEVEL);
                recreate = true;
                for (IInfo info : tokensStartingWith) {
                    if (info.getName().equals("TestCase")) {
                        if (info.getDeclaringModuleName().equals("unittest")) {
                            recreate = false;
                            break;
                        }
                    }
                }
            }
            if (recreate) {
                // Commented out some noise on the build
                // System.out.println("Recreating: " + this.getClass() + " - "
                // + interpreterManager.getInterpreterInfo(defaultInterpreter, null));
                observer.notifyDefaultPythonpathRestored(interpreterManager, defaultInterpreter, monitor);
            }
        } catch (MisconfigurationException e) {
            throw new RuntimeException(e);
        }
    }
    return restored;
}
Also used : IInfo(org.python.pydev.core.IInfo) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MisconfigurationException(org.python.pydev.core.MisconfigurationException) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) IInterpreterManager(org.python.pydev.core.IInterpreterManager)

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