Thread: [Pydev-cvs] org.python.pydev/src/org/python/pydev/plugin/nature PythonNatureStore.java, 1.22, 1.23
Brought to you by:
fabioz
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/nature In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4313/src/org/python/pydev/plugin/nature Modified Files: PythonNatureStore.java PythonNature.java SystemPythonNature.java PythonPathNature.java AbstractPythonNature.java Log Message: Synching to latest changes: Pydev <ul> <li><strong>Editor</strong>: Cursor settings no longer overridden</li> <li><strong>Code-completion</strong>: If __all__ is defined with runtime elements (and not only in a single assign statement), it's ignored for code-completion purposes</li> <li><strong>Debugger</strong>: Pythonpath the same in debug and regular modes (sys.path[0] is the same directory as the file run)</li> <li><strong>Debugger</strong>: Persist choices done in the debugger when files from the debugger are not found</li> <li><strong>Interpreter config</strong>: "email" automatically added to the "forced builtins"</li> <li><strong>Parser</strong>: Correctly recognizing absolute import with 3 or more levels</li> <li><strong>Syntax check</strong>: Option to do only on active editor</li> </ul> Also: tabs changed for spaces Index: SystemPythonNature.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/nature/SystemPythonNature.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** SystemPythonNature.java 2 May 2008 23:24:14 -0000 1.12 --- SystemPythonNature.java 28 Sep 2008 12:45:40 -0000 1.13 *************** *** 19,110 **** public class SystemPythonNature extends AbstractPythonNature implements IPythonNature{ ! private IInterpreterManager manager; ! private SystemASTManager systemASTManager; ! public SystemPythonNature(IInterpreterManager manager){ ! this.manager = manager; ! } ! public String getVersion() throws CoreException { ! if(this.manager.isPython()){ ! return IPythonNature.PYTHON_VERSION_LATEST; ! }else if(this.manager.isJython()){ ! return IPythonNature.JYTHON_VERSION_LATEST; ! }else{ ! throw new RuntimeException("Not python nor jython?"); ! } ! } ! public String getDefaultVersion() { ! try { return getVersion(); } catch (CoreException e) { throw new RuntimeException(e); } ! } ! public void setVersion(String version) throws CoreException { ! throw new RuntimeException("Not Implemented: the system nature is read-only."); ! } ! public boolean isJython() throws CoreException { ! return manager.isJython(); ! } ! public boolean isPython() throws CoreException { ! return manager.isPython(); ! } ! public int getRelatedId() throws CoreException { ! return PythonNature.getRelatedId(this); ! } ! public File getCompletionsCacheDir() { ! throw new RuntimeException("Not Implemented"); ! } ! public void saveAstManager() { ! throw new RuntimeException("Not Implemented: system nature is only transient."); ! } ! public IPythonPathNature getPythonPathNature() { ! throw new RuntimeException("Not Implemented"); ! } ! public String resolveModule(String file) { ! InterpreterInfo info = (InterpreterInfo) this.manager.getDefaultInterpreterInfo(new NullProgressMonitor()); if(info == null){ return null; } ! return info.getModulesManager().resolveModule(file); ! } ! public ICodeCompletionASTManager getAstManager() { ! if(systemASTManager == null){ ! systemASTManager = new SystemASTManager(this.manager, this); ! } ! return systemASTManager; ! } ! public void configure() throws CoreException { ! } ! public void deconfigure() throws CoreException { ! } ! public IProject getProject() { ! return null; ! } ! public void setProject(IProject project) { ! } ! public void rebuildPath() { ! throw new RuntimeException("Not Implemented"); ! } ! public void rebuildPath(String defaultSelectedInterpreter, IProgressMonitor monitor) { ! throw new RuntimeException("Not Implemented"); ! } public IInterpreterManager getRelatedInterpreterManager() { --- 19,110 ---- public class SystemPythonNature extends AbstractPythonNature implements IPythonNature{ ! private IInterpreterManager manager; ! private SystemASTManager systemASTManager; ! public SystemPythonNature(IInterpreterManager manager){ ! this.manager = manager; ! } ! public String getVersion() throws CoreException { ! if(this.manager.isPython()){ ! return IPythonNature.PYTHON_VERSION_LATEST; ! }else if(this.manager.isJython()){ ! return IPythonNature.JYTHON_VERSION_LATEST; ! }else{ ! throw new RuntimeException("Not python nor jython?"); ! } ! } ! public String getDefaultVersion() { ! try { return getVersion(); } catch (CoreException e) { throw new RuntimeException(e); } ! } ! public void setVersion(String version) throws CoreException { ! throw new RuntimeException("Not Implemented: the system nature is read-only."); ! } ! public boolean isJython() throws CoreException { ! return manager.isJython(); ! } ! public boolean isPython() throws CoreException { ! return manager.isPython(); ! } ! public int getRelatedId() throws CoreException { ! return PythonNature.getRelatedId(this); ! } ! public File getCompletionsCacheDir() { ! throw new RuntimeException("Not Implemented"); ! } ! public void saveAstManager() { ! throw new RuntimeException("Not Implemented: system nature is only transient."); ! } ! public IPythonPathNature getPythonPathNature() { ! throw new RuntimeException("Not Implemented"); ! } ! public String resolveModule(String file) { ! InterpreterInfo info = (InterpreterInfo) this.manager.getDefaultInterpreterInfo(new NullProgressMonitor()); if(info == null){ return null; } ! return info.getModulesManager().resolveModule(file); ! } ! public ICodeCompletionASTManager getAstManager() { ! if(systemASTManager == null){ ! systemASTManager = new SystemASTManager(this.manager, this); ! } ! return systemASTManager; ! } ! public void configure() throws CoreException { ! } ! public void deconfigure() throws CoreException { ! } ! public IProject getProject() { ! return null; ! } ! public void setProject(IProject project) { ! } ! public void rebuildPath() { ! throw new RuntimeException("Not Implemented"); ! } ! public void rebuildPath(String defaultSelectedInterpreter, IProgressMonitor monitor) { ! throw new RuntimeException("Not Implemented"); ! } public IInterpreterManager getRelatedInterpreterManager() { *************** *** 116,140 **** private IToken[] builtinCompletions; ! public IToken[] getBuiltinCompletions() { ! return builtinCompletions; ! } ! public void setBuiltinCompletions(IToken[] toks) { ! this.builtinCompletions = toks; ! } ! ! ! //builtin mod ! private IModule builtinMod; ! public IModule getBuiltinMod() { ! return builtinMod; ! } ! public void setBuiltinMod(IModule mod) { ! this.builtinMod = mod; ! } ! public int getGrammarVersion() { IInterpreterInfo info = manager.getDefaultInterpreterInfo(new NullProgressMonitor()); --- 116,140 ---- private IToken[] builtinCompletions; ! public IToken[] getBuiltinCompletions() { ! return builtinCompletions; ! } ! public void setBuiltinCompletions(IToken[] toks) { ! this.builtinCompletions = toks; ! } ! ! ! //builtin mod ! private IModule builtinMod; ! public IModule getBuiltinMod() { ! return builtinMod; ! } ! public void setBuiltinMod(IModule mod) { ! this.builtinMod = mod; ! } ! public int getGrammarVersion() { IInterpreterInfo info = manager.getDefaultInterpreterInfo(new NullProgressMonitor()); Index: PythonNature.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/nature/PythonNature.java,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** PythonNature.java 31 Jul 2008 01:47:36 -0000 1.67 --- PythonNature.java 28 Sep 2008 12:45:39 -0000 1.68 *************** *** 88,101 **** JobProgressComunicator jobProgressComunicator = new JobProgressComunicator(monitorArg, "Rebuilding modules", IProgressMonitor.UNKNOWN, this); try { ! ICodeCompletionASTManager tempAstManager = astManager; if (tempAstManager == null) { ! tempAstManager = new ASTManager(); } synchronized(tempAstManager){ ! astManager = tempAstManager; ! tempAstManager.setProject(getProject(), PythonNature.this, false); //it is a new manager, so, remove all deltas //begins task automatically ! tempAstManager.changePythonPath(paths, project, jobProgressComunicator, defaultSelectedInterpreter); saveAstManager(); --- 88,101 ---- JobProgressComunicator jobProgressComunicator = new JobProgressComunicator(monitorArg, "Rebuilding modules", IProgressMonitor.UNKNOWN, this); try { ! ICodeCompletionASTManager tempAstManager = astManager; if (tempAstManager == null) { ! tempAstManager = new ASTManager(); } synchronized(tempAstManager){ ! astManager = tempAstManager; ! tempAstManager.setProject(getProject(), PythonNature.this, false); //it is a new manager, so, remove all deltas //begins task automatically ! tempAstManager.changePythonPath(paths, project, jobProgressComunicator, defaultSelectedInterpreter); saveAstManager(); *************** *** 105,109 **** observer.notifyProjectPythonpathRestored(PythonNature.this, jobProgressComunicator, defaultSelectedInterpreter); } catch (Exception e) { ! //let's keep it safe PydevPlugin.log(e); } --- 105,109 ---- observer.notifyProjectPythonpathRestored(PythonNature.this, jobProgressComunicator, defaultSelectedInterpreter); } catch (Exception e) { ! //let's keep it safe PydevPlugin.log(e); } *************** *** 214,250 **** */ public void setProject(final IProject project) { ! getStore().setProject(project); ! this.project = project; this.pythonPathNature.setProject(project, this); if(project != null && !initializationStarted && !initializationFinished){ ! synchronized (jobs) { ! Job job = jobs.get(project); ! if(job != null){ ! job.cancel(); ! } ! job = new Job("PyDev: Restoring projects python nature") { ! ! protected IStatus run(IProgressMonitor monitor) { ! try { ! if(monitor.isCanceled()){ ! return Status.OK_STATUS; ! } ! init(null, null, monitor); ! synchronized (jobs) { ! if(jobs.get(project) == this){ ! jobs.remove(project); ! } ! } ! } catch (Throwable t) { ! PydevPlugin.log(t); ! } ! return Status.OK_STATUS; ! } ! ! }; ! jobs.put(project, job); ! job.schedule(250L); //wait to see if we've more than 1 request. ! } } --- 214,250 ---- */ public void setProject(final IProject project) { ! getStore().setProject(project); ! this.project = project; this.pythonPathNature.setProject(project, this); if(project != null && !initializationStarted && !initializationFinished){ ! synchronized (jobs) { ! Job job = jobs.get(project); ! if(job != null){ ! job.cancel(); ! } ! job = new Job("PyDev: Restoring projects python nature") { ! ! protected IStatus run(IProgressMonitor monitor) { ! try { ! if(monitor.isCanceled()){ ! return Status.OK_STATUS; ! } ! init(null, null, monitor); ! synchronized (jobs) { ! if(jobs.get(project) == this){ ! jobs.remove(project); ! } ! } ! } catch (Throwable t) { ! PydevPlugin.log(t); ! } ! return Status.OK_STATUS; ! } ! ! }; ! jobs.put(project, job); ! job.schedule(250L); //wait to see if we've more than 1 request. ! } } *************** *** 253,265 **** public static synchronized IPythonNature addNature(IEditorInput element) { if(element instanceof FileEditorInput){ ! IFile file = (IFile)((FileEditorInput)element).getAdapter(IFile.class); ! if (file != null){ ! try { ! return PythonNature.addNature(file.getProject(), null, null, null); ! } catch (CoreException e) { ! PydevPlugin.log(e); ! } ! } ! } return null; } --- 253,265 ---- public static synchronized IPythonNature addNature(IEditorInput element) { if(element instanceof FileEditorInput){ ! IFile file = (IFile)((FileEditorInput)element).getAdapter(IFile.class); ! if (file != null){ ! try { ! return PythonNature.addNature(file.getProject(), null, null, null); ! } catch (CoreException e) { ! PydevPlugin.log(e); ! } ! } ! } return null; } *************** *** 392,451 **** @SuppressWarnings("unchecked") private void init(String version, String projectPythonpath, IProgressMonitor monitor) { ! if(version != null || projectPythonpath != null){ ! this.getStore().startInit(); ! try { ! if(projectPythonpath != null){ ! this.getPythonPathNature().setProjectSourcePath(projectPythonpath); ! } ! if(version != null){ ! this.setVersion(version); ! } ! } catch (CoreException e) { ! PydevPlugin.log(e); ! }finally{ ! this.getStore().endInit(); ! } ! }else{ ! //Change: 1.3.10: it could be reloaded more than once... (when it shouldn't) ! if(astManager != null){ ! return; //already initialized... ! } ! } ! ! if(initializationStarted || monitor.isCanceled()){ ! return; ! } ! ! initializationStarted = true; //Change: 1.3.10: no longer in a Job... should already be called in a job if that's needed. try { ! astManager = (ICodeCompletionASTManager) ASTManager.loadFromFile(getAstOutputFile()); ! if (astManager != null) { ! synchronized (astManager) { ! astManager.setProject(getProject(), this, true); // this is the project related to it, restore the deltas (we may have some crash) ! //just a little validation so that we restore the needed info if we did not get the modules ! if (astManager.getModulesManager().getOnlyDirectModules().length < 5) { ! astManager = null; ! } ! if (astManager != null) { ! List<IInterpreterObserver> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_INTERPRETER_OBSERVER); ! for (IInterpreterObserver observer : participants) { ! try { ! observer.notifyNatureRecreated(this, monitor); ! } catch (Exception e) { ! //let's not fail because of other plugins ! PydevPlugin.log(e); ! } ! } ! } ! } ! } ! } catch (Exception e) { ! PydevPlugin.log(e); ! astManager = null; ! } //errors can happen when restoring it --- 392,451 ---- @SuppressWarnings("unchecked") private void init(String version, String projectPythonpath, IProgressMonitor monitor) { ! if(version != null || projectPythonpath != null){ ! this.getStore().startInit(); ! try { ! if(projectPythonpath != null){ ! this.getPythonPathNature().setProjectSourcePath(projectPythonpath); ! } ! if(version != null){ ! this.setVersion(version); ! } ! } catch (CoreException e) { ! PydevPlugin.log(e); ! }finally{ ! this.getStore().endInit(); ! } ! }else{ ! //Change: 1.3.10: it could be reloaded more than once... (when it shouldn't) ! if(astManager != null){ ! return; //already initialized... ! } ! } ! ! if(initializationStarted || monitor.isCanceled()){ ! return; ! } ! ! initializationStarted = true; //Change: 1.3.10: no longer in a Job... should already be called in a job if that's needed. try { ! astManager = (ICodeCompletionASTManager) ASTManager.loadFromFile(getAstOutputFile()); ! if (astManager != null) { ! synchronized (astManager) { ! astManager.setProject(getProject(), this, true); // this is the project related to it, restore the deltas (we may have some crash) ! //just a little validation so that we restore the needed info if we did not get the modules ! if (astManager.getModulesManager().getOnlyDirectModules().length < 5) { ! astManager = null; ! } ! if (astManager != null) { ! List<IInterpreterObserver> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_INTERPRETER_OBSERVER); ! for (IInterpreterObserver observer : participants) { ! try { ! observer.notifyNatureRecreated(this, monitor); ! } catch (Exception e) { ! //let's not fail because of other plugins ! PydevPlugin.log(e); ! } ! } ! } ! } ! } ! } catch (Exception e) { ! PydevPlugin.log(e); ! astManager = null; ! } //errors can happen when restoring it *************** *** 461,465 **** ! /** * Returns the directory that should store completions. * --- 461,465 ---- ! /** * Returns the directory that should store completions. * *************** *** 492,508 **** */ public void rebuildPath() { ! this.rebuildPath(null, new NullProgressMonitor()); } ! public void rebuildPath(String defaultSelectedInterpreter, IProgressMonitor monitor) { ! try { ! clearCaches(); ! String paths = this.pythonPathNature.getOnlyProjectPythonPathStr(); ! this.rebuildPath(defaultSelectedInterpreter, paths); ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! } --- 492,508 ---- */ public void rebuildPath() { ! this.rebuildPath(null, new NullProgressMonitor()); } ! public void rebuildPath(String defaultSelectedInterpreter, IProgressMonitor monitor) { ! try { ! clearCaches(); ! String paths = this.pythonPathNature.getOnlyProjectPythonPathStr(); ! this.rebuildPath(defaultSelectedInterpreter, paths); ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! } *************** *** 524,541 **** public ICodeCompletionASTManager getAstManager() { if(astManager == null){ ! //this is needed because it may not be restarted already... ! //also, this will only happen when initializing eclipse with some editors already open ! ! for(int i=0; i<10 && astManager == null && !initializationFinished; i++){ //we will wait 10 seconds for it ! try { ! Thread.sleep(1000); ! } catch (InterruptedException e) { //ignore ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } ! //next time we won't wait as long. ! initializationFinished = true; } --- 524,541 ---- public ICodeCompletionASTManager getAstManager() { if(astManager == null){ ! //this is needed because it may not be restarted already... ! //also, this will only happen when initializing eclipse with some editors already open ! ! for(int i=0; i<10 && astManager == null && !initializationFinished; i++){ //we will wait 10 seconds for it ! try { ! Thread.sleep(1000); ! } catch (InterruptedException e) { //ignore ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } ! //next time we won't wait as long. ! initializationFinished = true; } *************** *** 563,583 **** */ public static List<IPythonNature> getAllPythonNatures() { ! List<IPythonNature> natures = new ArrayList<IPythonNature>(); ! IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); ! IProject[] projects = root.getProjects(); ! for (IProject project : projects) { ! PythonNature nature = getPythonNature(project); ! if(nature != null){ ! natures.add(nature); ! } ! } ! return natures; } public static PythonNature getPythonNature(IResource resource) { ! if(resource == null){ ! return null; ! } ! return getPythonNature(resource.getProject()); } --- 563,583 ---- */ public static List<IPythonNature> getAllPythonNatures() { ! List<IPythonNature> natures = new ArrayList<IPythonNature>(); ! IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); ! IProject[] projects = root.getProjects(); ! for (IProject project : projects) { ! PythonNature nature = getPythonNature(project); ! if(nature != null){ ! natures.add(nature); ! } ! } ! return natures; } public static PythonNature getPythonNature(IResource resource) { ! if(resource == null){ ! return null; ! } ! return getPythonNature(resource.getProject()); } *************** *** 615,626 **** public String getVersion() throws CoreException { if(project != null){ ! if (versionPropertyCache == null) { ! String storeVersion = getStore().getPropertyFromXml(getPythonProjectVersionQualifiedName()); ! if(storeVersion == null){ //there is no such property set (let's set it to the default) ! setVersion(getDefaultVersion()); //will set the versionPropertyCache too ! }else{ ! versionPropertyCache = storeVersion; } ! } } return versionPropertyCache; --- 615,626 ---- public String getVersion() throws CoreException { if(project != null){ ! if (versionPropertyCache == null) { ! String storeVersion = getStore().getPropertyFromXml(getPythonProjectVersionQualifiedName()); ! if(storeVersion == null){ //there is no such property set (let's set it to the default) ! setVersion(getDefaultVersion()); //will set the versionPropertyCache too ! }else{ ! versionPropertyCache = storeVersion; } ! } } return versionPropertyCache; *************** *** 632,638 **** */ public void setVersion(String version) throws CoreException{ ! clearCaches(); if(project != null){ ! this.versionPropertyCache = version; getStore().setPropertyToXml(getPythonProjectVersionQualifiedName(), version, true); } --- 632,638 ---- */ public void setVersion(String version) throws CoreException{ ! clearCaches(); if(project != null){ ! this.versionPropertyCache = version; getStore().setPropertyToXml(getPythonProjectVersionQualifiedName(), version, true); } *************** *** 656,671 **** public void saveAstManager() { ! if(astManager == null){ ! REF.writeToFile(null, getAstOutputFile()); ! ! }else{ ! synchronized(astManager){ ! REF.writeToFile(astManager, getAstOutputFile()); ! } ! } } public int getRelatedId() throws CoreException { ! return getRelatedId(this); } --- 656,671 ---- public void saveAstManager() { ! if(astManager == null){ ! REF.writeToFile(null, getAstOutputFile()); ! ! }else{ ! synchronized(astManager){ ! REF.writeToFile(astManager, getAstOutputFile()); ! } ! } } public int getRelatedId() throws CoreException { ! return getRelatedId(this); } *************** *** 723,741 **** Boolean isJython = null; //cache ! public void setBuiltinCompletions(IToken[] comps) { ! this.getRelatedInterpreterManager().setBuiltinCompletions(comps); ! } ! public IToken[] getBuiltinCompletions() { ! return this.getRelatedInterpreterManager().getBuiltinCompletions(); ! } ! public IModule getBuiltinMod() { ! return this.getRelatedInterpreterManager().getBuiltinMod(); ! } ! public void setBuiltinMod(IModule mod) { ! this.getRelatedInterpreterManager().setBuiltinMod(mod); ! } public static List<IPythonNature> getPythonNaturesRelatedTo(int relatedTo) { --- 723,741 ---- Boolean isJython = null; //cache ! public void setBuiltinCompletions(IToken[] comps) { ! this.getRelatedInterpreterManager().setBuiltinCompletions(comps); ! } ! public IToken[] getBuiltinCompletions() { ! return this.getRelatedInterpreterManager().getBuiltinCompletions(); ! } ! public IModule getBuiltinMod() { ! return this.getRelatedInterpreterManager().getBuiltinMod(); ! } ! public void setBuiltinMod(IModule mod) { ! this.getRelatedInterpreterManager().setBuiltinMod(mod); ! } public static List<IPythonNature> getPythonNaturesRelatedTo(int relatedTo) { *************** *** 775,779 **** protected IPythonNatureStore getStore(){ ! return pythonNatureStore; } --- 775,779 ---- protected IPythonNatureStore getStore(){ ! return pythonNatureStore; } Index: AbstractPythonNature.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/nature/AbstractPythonNature.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbstractPythonNature.java 7 Jul 2007 18:03:07 -0000 1.2 --- AbstractPythonNature.java 28 Sep 2008 12:45:40 -0000 1.3 *************** *** 19,39 **** */ public boolean isResourceInPythonpath(IResource resource) { ! return resolveModule(resource) != null; } public boolean isResourceInPythonpath(String absPath) { ! return resolveModule(absPath) != null; } ! /** * @param resource the resource we want to get the name from * @return the name of the module in the environment */ public String resolveModule(IResource resource) { ! return resolveModule(PydevPlugin.getIResourceOSString(resource)); } public String resolveModule(File file) { ! return resolveModule(REF.getFileAbsolutePath(file)); } --- 19,39 ---- */ public boolean isResourceInPythonpath(IResource resource) { ! return resolveModule(resource) != null; } public boolean isResourceInPythonpath(String absPath) { ! return resolveModule(absPath) != null; } ! /** * @param resource the resource we want to get the name from * @return the name of the module in the environment */ public String resolveModule(IResource resource) { ! return resolveModule(PydevPlugin.getIResourceOSString(resource)); } public String resolveModule(File file) { ! return resolveModule(REF.getFileAbsolutePath(file)); } *************** *** 48,71 **** */ public synchronized boolean startRequests() { ! ICodeCompletionASTManager astManager = this.getAstManager(); ! if(astManager == null){ ! return false; ! } ! IModulesManager modulesManager = astManager.getModulesManager(); ! if(modulesManager == nu... [truncated message content] |