Search in sources :

Example 1 with ProjectModulesManager

use of org.python.pydev.ast.codecompletion.revisited.ProjectModulesManager in project Pydev by fabioz.

the class ClassHierarchySearchTest method tearDown.

@Override
public void tearDown() throws Exception {
    CompiledModule.COMPILED_MODULES_ENABLED = false;
    SourceModule.TESTING = false;
    ProjectModulesManager projectModulesManager = ((ProjectModulesManager) nature.getAstManager().getModulesManager());
    projectModulesManager.doRemoveSingleModule(new ModulesKey("foo", null));
    projectModulesManager.doRemoveSingleModule(new ModulesKey("foo0", null));
    projectModulesManager.doRemoveSingleModule(new ModulesKey("fooIn1", null));
    projectModulesManager.doRemoveSingleModule(new ModulesKey("fooIn10", null));
    projectModulesManager = ((ProjectModulesManager) nature2.getAstManager().getModulesManager());
    projectModulesManager.doRemoveSingleModule(new ModulesKey("fooIn2", null));
    projectModulesManager.doRemoveSingleModule(new ModulesKey("fooIn20", null));
    FileUtils.deleteDirectoryTree(baseDir);
    FileUtils.deleteDirectoryTree(baseDir2);
    super.tearDown();
}
Also used : ModulesKey(org.python.pydev.core.ModulesKey) ProjectModulesManager(org.python.pydev.ast.codecompletion.revisited.ProjectModulesManager)

Example 2 with ProjectModulesManager

use of org.python.pydev.ast.codecompletion.revisited.ProjectModulesManager in project Pydev by fabioz.

the class DjangoProjectProperties method createContents.

@Override
protected Control createContents(Composite parent) {
    project = getElement().getAdapter(IProject.class);
    Composite topComp = new Composite(parent, SWT.NONE);
    GridLayout innerLayout = new GridLayout();
    innerLayout.numColumns = 2;
    innerLayout.marginHeight = 0;
    innerLayout.marginWidth = 0;
    topComp.setLayout(innerLayout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    topComp.setLayoutData(gd);
    if (project != null) {
        try {
            IPythonPathNature pathNature = PythonNature.getPythonPathNature(project);
            final PythonNature nature = PythonNature.getPythonNature(project);
            Map<String, String> variableSubstitution = pathNature.getVariableSubstitution(false);
            Label label = new Label(topComp, SWT.None);
            label.setText("Django manage.py");
            Text text = new Text(topComp, SWT.BORDER);
            textDjangoManage = text;
            textDjangoManage.setToolTipText("This is the name of the project-relative location of manage.py (i.e.: src/myapp/manage.py)");
            label = new Label(topComp, SWT.None);
            labelErrorManage = new Label(topComp, SWT.None);
            labelErrorManage.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            ModifyListener manageValidator = new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                    try {
                        String path = textDjangoManage.getText().trim();
                        if (path.trim().length() == 0) {
                            labelErrorSettings.setText("Please specify the manage.py relative name (i.e.: src/myapp/manage.py)");
                            return;
                        }
                        IFile file = project.getFile(new Path(path));
                        if (!file.exists()) {
                            labelErrorManage.setText(StringUtils.format("File: %s could not be found.", path));
                        } else {
                            labelErrorManage.setText("");
                        }
                    } catch (Exception e1) {
                        Log.log(e1);
                    }
                }
            };
            text.addModifyListener(manageValidator);
            text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            String string = variableSubstitution.get(DjangoConstants.DJANGO_MANAGE_VARIABLE);
            if (string != null) {
                text.setText(string);
            } else {
                text.setText("");
            }
            // Settings
            label = new Label(topComp, SWT.None);
            label.setText("Django settings module");
            text = new Text(topComp, SWT.BORDER);
            textDjangoSettings = text;
            textDjangoSettings.setToolTipText("This is the name of the django settings module (i.e.: myapp.settings)");
            label = new Label(topComp, SWT.None);
            labelErrorSettings = new Label(topComp, SWT.None);
            labelErrorSettings.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            ModifyListener settingsValidator = new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                    try {
                        String moduleName = textDjangoSettings.getText().trim();
                        if (moduleName.trim().length() == 0) {
                            labelErrorSettings.setText("Please specify the name of the module (i.e.: myapp.settings)");
                            return;
                        }
                        ICodeCompletionASTManager astManager = nature.getAstManager();
                        ProjectModulesManager modulesManager = (ProjectModulesManager) astManager.getModulesManager();
                        IModule moduleInDirectManager = modulesManager.getModuleInDirectManager(moduleName, nature, true, new BaseModuleRequest(false));
                        if (moduleInDirectManager == null) {
                            labelErrorSettings.setText(StringUtils.format("Module: %s could not be found.", moduleName));
                        } else {
                            labelErrorSettings.setText("");
                        }
                    } catch (Exception e1) {
                        Log.log(e1);
                    }
                }
            };
            text.addModifyListener(settingsValidator);
            text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            string = variableSubstitution.get(DjangoConstants.DJANGO_SETTINGS_MODULE);
            if (string != null) {
                text.setText(string);
            } else {
                text.setText("");
            }
        } catch (Exception e) {
            Log.log(e);
        }
    } else {
        Label label = new Label(topComp, SWT.None);
        label.setText("Internal error: project not set!");
    }
    return topComp;
}
Also used : Path(org.eclipse.core.runtime.Path) IModule(org.python.pydev.core.IModule) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) PythonNature(org.python.pydev.plugin.nature.PythonNature) ModifyListener(org.eclipse.swt.events.ModifyListener) BaseModuleRequest(org.python.pydev.core.BaseModuleRequest) IPythonPathNature(org.python.pydev.core.IPythonPathNature) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) ProjectModulesManager(org.python.pydev.ast.codecompletion.revisited.ProjectModulesManager) IProject(org.eclipse.core.resources.IProject) ICodeCompletionASTManager(org.python.pydev.core.ICodeCompletionASTManager) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData)

Example 3 with ProjectModulesManager

use of org.python.pydev.ast.codecompletion.revisited.ProjectModulesManager in project Pydev by fabioz.

the class PyDevBuilderVisitor method isResourceInPythonpathProjectSources.

public boolean isResourceInPythonpathProjectSources(IResource resource, IPythonNature nature, boolean addExternal) throws CoreException, MisconfigurationException {
    Boolean isInProjectPythonpath = (Boolean) memo.get(MODULE_IN_PROJECT_PYTHONPATH + addExternal);
    if (isInProjectPythonpath == null) {
        // This was simply: String moduleName = nature.resolveModuleOnlyInProjectSources(resource, addExternal);
        // Inlined with the code below because nature.getPythonPathNature().getOnlyProjectPythonPathStr was one of
        // the slowest things when doing a full build.
        List<String> onlyProjectPythonPathLst = memo.getOnlyProjectPythonPathStr(nature, addExternal);
        String resourceOSString = SharedCorePlugin.getIResourceOSString(resource);
        String moduleName = null;
        if (resourceOSString != null) {
            ICodeCompletionASTManager astManager = nature.getAstManager();
            if (astManager != null) {
                IModulesManager modulesManager = astManager.getModulesManager();
                if (modulesManager instanceof ProjectModulesManager) {
                    PythonPathHelper pythonPathHelper = ((ProjectModulesManager) modulesManager).getPythonPathHelper();
                    moduleName = pythonPathHelper.resolveModule(resourceOSString, false, onlyProjectPythonPathLst, nature.getProject());
                }
            }
        }
        isInProjectPythonpath = (moduleName != null);
        if (isInProjectPythonpath) {
            setModuleNameInCache(memo, resource, moduleName);
        }
    }
    return isInProjectPythonpath;
}
Also used : ICodeCompletionASTManager(org.python.pydev.core.ICodeCompletionASTManager) IModulesManager(org.python.pydev.core.IModulesManager) ProjectModulesManager(org.python.pydev.ast.codecompletion.revisited.ProjectModulesManager) PythonPathHelper(org.python.pydev.ast.codecompletion.revisited.PythonPathHelper)

Aggregations

ProjectModulesManager (org.python.pydev.ast.codecompletion.revisited.ProjectModulesManager)3 ICodeCompletionASTManager (org.python.pydev.core.ICodeCompletionASTManager)2 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 Path (org.eclipse.core.runtime.Path)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 PythonPathHelper (org.python.pydev.ast.codecompletion.revisited.PythonPathHelper)1 BaseModuleRequest (org.python.pydev.core.BaseModuleRequest)1 IModule (org.python.pydev.core.IModule)1 IModulesManager (org.python.pydev.core.IModulesManager)1 IPythonPathNature (org.python.pydev.core.IPythonPathNature)1 ModulesKey (org.python.pydev.core.ModulesKey)1 PythonNature (org.python.pydev.plugin.nature.PythonNature)1