[Pydev-cvs] org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited Comp
Brought to you by:
fabioz
Update of /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4313/src_completions/org/python/pydev/editor/codecompletion/revisited Modified Files: CompletionState.java SystemModulesManager.java CompletionStateWrapper.java PyCodeCompletionVisitor.java SystemASTManager.java AbstractToken.java AbstractASTManager.java AssignAnalysis.java ProjectModulesManager.java ASTManager.java ModulesManagerCache.java CompletionStateFactory.java PythonPathHelper.java SourceModuleProposal.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: SystemModulesManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/SystemModulesManager.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** SystemModulesManager.java 14 Jun 2008 22:14:55 -0000 1.10 --- SystemModulesManager.java 28 Sep 2008 12:45:45 -0000 1.11 *************** *** 62,66 **** */ public String[] getBuiltins(String defaultSelectedInterpreter) { ! return getBuiltins(); } --- 62,66 ---- */ public String[] getBuiltins(String defaultSelectedInterpreter) { ! return getBuiltins(); } *************** *** 73,104 **** ! public void setPythonNature(IPythonNature nature) { ! this.nature = nature; ! } ! public IPythonNature getNature() { ! return this.nature; ! } ! public ISystemModulesManager getSystemModulesManager() { ! return this; //itself ! } ! public IModule getModule(String name, IPythonNature nature, boolean checkSystemManager, boolean dontSearchInit) { ! return getModule(name, nature, dontSearchInit); ! } ! public String resolveModule(String full, boolean checkSystemManager) { ! return super.resolveModule(full); ! } ! public List<String> getCompletePythonPath(String interpreter) { ! return super.getPythonPath(); } ! public List<String> getCompletePythonPath(String interpreter, IPythonNature nature2) { if(interpreter == null){ ! return super.getPythonPath(); }else{ IInterpreterManager manager = nature2.getRelatedInterpreterManager(); --- 73,104 ---- ! public void setPythonNature(IPythonNature nature) { ! this.nature = nature; ! } ! public IPythonNature getNature() { ! return this.nature; ! } ! public ISystemModulesManager getSystemModulesManager() { ! return this; //itself ! } ! public IModule getModule(String name, IPythonNature nature, boolean checkSystemManager, boolean dontSearchInit) { ! return getModule(name, nature, dontSearchInit); ! } ! public String resolveModule(String full, boolean checkSystemManager) { ! return super.resolveModule(full); ! } ! public List<String> getCompletePythonPath(String interpreter) { ! return super.getPythonPath(); } ! public List<String> getCompletePythonPath(String interpreter, IPythonNature nature2) { if(interpreter == null){ ! return super.getPythonPath(); }else{ IInterpreterManager manager = nature2.getRelatedInterpreterManager(); *************** *** 106,119 **** return info.getPythonPath(); } ! } ! public IModule getRelativeModule(String name, IPythonNature nature) { ! return super.getModule(name, nature, true); ! } ! /** ! * Called after the pythonpath is changed. ! */ protected void onChangePythonpath(String defaultSelectedInterpreter, SortedMap<ModulesKey, ModulesKey> keys) { //create the builtin modules --- 106,119 ---- return info.getPythonPath(); } ! } ! public IModule getRelativeModule(String name, IPythonNature nature) { ! return super.getModule(name, nature, true); ! } ! /** ! * Called after the pythonpath is changed. ! */ protected void onChangePythonpath(String defaultSelectedInterpreter, SortedMap<ModulesKey, ModulesKey> keys) { //create the builtin modules Index: SystemASTManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/SystemASTManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SystemASTManager.java 31 Jul 2008 01:47:36 -0000 1.3 --- SystemASTManager.java 28 Sep 2008 12:45:45 -0000 1.4 *************** *** 13,41 **** @SuppressWarnings("serial") public class SystemASTManager extends AbstractASTManager{ ! ! private IInterpreterManager manager; ! public SystemASTManager(IInterpreterManager manager, IPythonNature nature) { ! this.manager = manager; ! InterpreterInfo info = (InterpreterInfo) this.manager.getDefaultInterpreterInfo(new NullProgressMonitor()); this.modulesManager = info.getModulesManager(); ! setNature(nature); ! } ! public void setProject(IProject project, IPythonNature nature, boolean restoreDeltas) { ! throw new RuntimeException("Not implemented"); ! } ! public void rebuildModule(File file, IDocument doc, IProject project, IProgressMonitor monitor, IPythonNature nature) { ! throw new RuntimeException("Not implemented"); ! } ! public void removeModule(File file, IProject project, IProgressMonitor monitor) { ! throw new RuntimeException("Not implemented"); ! } ! public void changePythonPath(String pythonpath, IProject project, IProgressMonitor monitor, String defaultSelectedInterpreter) { ! throw new RuntimeException("Not implemented"); ! } } --- 13,41 ---- @SuppressWarnings("serial") public class SystemASTManager extends AbstractASTManager{ ! ! private IInterpreterManager manager; ! public SystemASTManager(IInterpreterManager manager, IPythonNature nature) { ! this.manager = manager; ! InterpreterInfo info = (InterpreterInfo) this.manager.getDefaultInterpreterInfo(new NullProgressMonitor()); this.modulesManager = info.getModulesManager(); ! setNature(nature); ! } ! public void setProject(IProject project, IPythonNature nature, boolean restoreDeltas) { ! throw new RuntimeException("Not implemented"); ! } ! public void rebuildModule(File file, IDocument doc, IProject project, IProgressMonitor monitor, IPythonNature nature) { ! throw new RuntimeException("Not implemented"); ! } ! public void removeModule(File file, IProject project, IProgressMonitor monitor) { ! throw new RuntimeException("Not implemented"); ! } ! public void changePythonPath(String pythonpath, IProject project, IProgressMonitor monitor, String defaultSelectedInterpreter) { ! throw new RuntimeException("Not implemented"); ! } } Index: PyCodeCompletionVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/PyCodeCompletionVisitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyCodeCompletionVisitor.java 25 Mar 2007 16:09:03 -0000 1.1 --- PyCodeCompletionVisitor.java 28 Sep 2008 12:45:45 -0000 1.2 *************** *** 24,34 **** public class PyCodeCompletionVisitor extends PyDevBuilderVisitor { ! public static final int PRIORITY_CODE_COMPLETION = PRIORITY_DEFAULT; ! ! @Override ! protected int getPriority() { ! return PRIORITY_CODE_COMPLETION; ! } ! /** * @see org.python.pydev.builder.PyDevBuilderVisitor#shouldVisitInitDependency() --- 24,34 ---- public class PyCodeCompletionVisitor extends PyDevBuilderVisitor { ! public static final int PRIORITY_CODE_COMPLETION = PRIORITY_DEFAULT; ! ! @Override ! protected int getPriority() { ! return PRIORITY_CODE_COMPLETION; ! } ! /** * @see org.python.pydev.builder.PyDevBuilderVisitor#shouldVisitInitDependency() Index: CompletionState.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/CompletionState.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CompletionState.java 4 May 2008 16:48:46 -0000 1.8 --- CompletionState.java 28 Sep 2008 12:45:45 -0000 1.9 *************** *** 72,85 **** static class Memo<E>{ ! private int max; ! public Memo(){ ! this.max = MAX_NUMBER_OF_OCURRENCES; ! } ! ! public Memo(int max){ ! this.max = max; ! } ! /** * if more than this number of ocurrences is found, we are in a recursion --- 72,85 ---- static class Memo<E>{ ! private int max; ! public Memo(){ ! this.max = MAX_NUMBER_OF_OCURRENCES; ! } ! ! public Memo(int max){ ! this.max = max; ! } ! /** * if more than this number of ocurrences is found, we are in a recursion *************** *** 200,209 **** } ! public void checkFindDefinitionMemory(IModule mod, String tok) throws CompletionRecursionException { ! if(this.findDefinitionMemory.isInRecursion(mod, tok)){ ! throw new CompletionRecursionException("Possible recursion found -- probably programming error -- (module: "+mod.getName()+", value: "+tok+") - stopping analysis."); ! } ! } ! /** * @param module --- 200,209 ---- } ! public void checkFindDefinitionMemory(IModule mod, String tok) throws CompletionRecursionException { ! if(this.findDefinitionMemory.isInRecursion(mod, tok)){ ! throw new CompletionRecursionException("Possible recursion found -- probably programming error -- (module: "+mod.getName()+", value: "+tok+") - stopping analysis."); ! } ! } ! /** * @param module *************** *** 254,261 **** * @param base */ ! public void checkFindModuleCompletionsMemory(IModule mod, String tok) throws CompletionRecursionException{ ! if(this.findModuleCompletionsMemory.isInRecursion(mod, tok)){ ! throw new CompletionRecursionException("Possible recursion found -- probably programming error -- (module: "+mod.getName()+", token: "+tok+") - stopping analysis."); ! } } --- 254,261 ---- * @param base */ ! public void checkFindModuleCompletionsMemory(IModule mod, String tok) throws CompletionRecursionException{ ! if(this.findModuleCompletionsMemory.isInRecursion(mod, tok)){ ! throw new CompletionRecursionException("Possible recursion found -- probably programming error -- (module: "+mod.getName()+", token: "+tok+") - stopping analysis."); ! } } *************** *** 310,318 **** } ! public void raiseNFindTokensOnImportedModsCalled(IModule mod, String tok) throws CompletionRecursionException { ! if(this.importedModsCalled.isInRecursion(mod, tok)){ ! throw new CompletionRecursionException("Possible recursion found (mod: "+mod.getName()+", tok: "+ tok +" ) - stopping analysis."); ! } ! } public boolean getIsInCalltip() { --- 310,318 ---- } ! public void raiseNFindTokensOnImportedModsCalled(IModule mod, String tok) throws CompletionRecursionException { ! if(this.importedModsCalled.isInRecursion(mod, tok)){ ! throw new CompletionRecursionException("Possible recursion found (mod: "+mod.getName()+", tok: "+ tok +" ) - stopping analysis."); ! } ! } public boolean getIsInCalltip() { Index: AssignAnalysis.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/AssignAnalysis.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AssignAnalysis.java 2 Mar 2008 20:00:46 -0000 1.6 --- AssignAnalysis.java 28 Sep 2008 12:45:45 -0000 1.7 *************** *** 90,96 **** String act = NodeUtils.getFullRepresentationString(return1.value); if(act == null){ ! return; //may happen if the return we're seeing is a return without anything } ! copy.setActivationToken (act); copy.setLine(return1.value.beginLine-1); copy.setCol(return1.value.beginColumn-1); --- 90,96 ---- String act = NodeUtils.getFullRepresentationString(return1.value); if(act == null){ ! return; //may happen if the return we're seeing is a return without anything } ! copy.setActivationToken (act); copy.setLine(return1.value.beginLine-1); copy.setCol(return1.value.beginColumn-1); Index: CompletionStateFactory.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/CompletionStateFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CompletionStateFactory.java 25 Feb 2008 11:21:34 -0000 1.4 --- CompletionStateFactory.java 28 Sep 2008 12:45:45 -0000 1.5 *************** *** 7,33 **** public class CompletionStateFactory { ! /** ! * @return a default completion state for globals (empty act. token) ! */ ! public static ICompletionState getEmptyCompletionState(IPythonNature nature, ICompletionCache completionCache) { ! return new CompletionState(-1, -1, "", nature, "", completionCache); ! } ! /** ! * @return a default completion state for globals (act token defined) ! */ ! public static ICompletionState getEmptyCompletionState(String token, IPythonNature nature, ICompletionCache completionCache) { ! return new CompletionState(-1, -1, token, nature, "", completionCache); ! } ! /** ! * @param line: start at 0 ! * @param col: start at 0 ! * @return a default completion state for globals (act token defined) ! */ ! public static ICompletionState getEmptyCompletionState(String token, IPythonNature nature, int line, int col, ! ICompletionCache completionCache) { ! return new CompletionState(line, col, token, nature, "", completionCache); ! } } --- 7,33 ---- public class CompletionStateFactory { ! /** ! * @return a default completion state for globals (empty act. token) ! */ ! public static ICompletionState getEmptyCompletionState(IPythonNature nature, ICompletionCache completionCache) { ! return new CompletionState(-1, -1, "", nature, "", completionCache); ! } ! /** ! * @return a default completion state for globals (act token defined) ! */ ! public static ICompletionState getEmptyCompletionState(String token, IPythonNature nature, ICompletionCache completionCache) { ! return new CompletionState(-1, -1, token, nature, "", completionCache); ! } ! /** ! * @param line: start at 0 ! * @param col: start at 0 ! * @return a default completion state for globals (act token defined) ! */ ! public static ICompletionState getEmptyCompletionState(String token, IPythonNature nature, int line, int col, ! ICompletionCache completionCache) { ! return new CompletionState(line, col, token, nature, "", completionCache); ! } } Index: CompletionStateWrapper.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/CompletionStateWrapper.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CompletionStateWrapper.java 14 Jun 2008 22:14:55 -0000 1.8 --- CompletionStateWrapper.java 28 Sep 2008 12:45:45 -0000 1.9 *************** *** 169,176 **** public String toString() { FastStringBuffer buf = new FastStringBuffer(); ! buf.append("CompletionStateWrapper[ "); ! buf.append(this.activationToken); ! buf.append(" ]"); ! return buf.toString(); } --- 169,176 ---- public String toString() { FastStringBuffer buf = new FastStringBuffer(); ! buf.append("CompletionStateWrapper[ "); ! buf.append(this.activationToken); ! buf.append(" ]"); ! return buf.toString(); } Index: AbstractASTManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/AbstractASTManager.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** AbstractASTManager.java 31 Jul 2008 23:48:18 -0000 1.18 --- AbstractASTManager.java 28 Sep 2008 12:45:45 -0000 1.19 *************** *** 38,42 **** --- 38,44 ---- import org.python.pydev.editor.codecompletion.PyCodeCompletion; import org.python.pydev.editor.codecompletion.revisited.modules.AbstractModule; + import org.python.pydev.editor.codecompletion.revisited.modules.SourceModule; import org.python.pydev.editor.codecompletion.revisited.modules.SourceToken; + import org.python.pydev.editor.codecompletion.revisited.visitors.GlobalModelVisitor; import org.python.pydev.parser.PyParser; import org.python.pydev.parser.jython.SimpleNode; *************** *** 47,63 **** [...974 lines suppressed...] ! //it with __init__ if it was the parent module ! if (mod.getName().length() <= parentModule.length()){ ! return new Tuple<IModule, String>(null, null); ! } } return new Tuple<IModule, String>((AbstractModule)mod, tok); --- 1289,1301 ---- if(dontSearchInit && currentModuleName != null && mod != null){ ! String parentModule = FullRepIterable.getParentModule(currentModuleName); ! //if we are looking for some relative import token, it can only match if the name found is not less than the parent ! //of the current module because of the way in that relative imports are meant to be written. ! ! //if it equal, it should not match either, as it was found as the parent module... this can not happen because it must find ! //it with __init__ if it was the parent module ! if (mod.getName().length() <= parentModule.length()){ ! return new Tuple<IModule, String>(null, null); ! } } return new Tuple<IModule, String>((AbstractModule)mod, tok); Index: PythonPathHelper.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelper.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PythonPathHelper.java 13 Aug 2008 21:12:15 -0000 1.12 --- PythonPathHelper.java 28 Sep 2008 12:45:45 -0000 1.13 *************** *** 43,52 **** * This is a list of Files containg the pythonpath. */ ! private volatile List<String> pythonpath = new ArrayList<String>(); /** * Returns the default path given from the string. * @param str - * @param acceptPoint says if we can have dots in the str that has the path to be analyzed * @return a trimmed string with all the '\' converted to '/' */ --- 43,51 ---- * This is a list of Files containg the pythonpath. */ ! private final List<String> pythonpath = new ArrayList<String>(); /** * Returns the default path given from the string. * @param str * @return a trimmed string with all the '\' converted to '/' */ *************** *** 54,58 **** //this check is no longer done... could result in other problems // if(acceptPoint == false && str.indexOf(".") == 0){ //cannot start with a dot ! // throw new RuntimeException("The pythonpath can only have absolute paths (cannot start with '.', therefore, the path: '"+str+"' is not valid."); // } return StringUtils.replaceAllSlashes(str.trim()); --- 53,57 ---- //this check is no longer done... could result in other problems // if(acceptPoint == false && str.indexOf(".") == 0){ //cannot start with a dot ! // throw new RuntimeException("The pythonpath can only have absolute paths (cannot start with '.', therefore, the path: '"+str+"' is not valid."); // } return StringUtils.replaceAllSlashes(str.trim()); *************** *** 240,358 **** if (requireFileToExist && !moduleFile.exists()) { return null; ! } boolean isFile = moduleFile.isFile(); ! synchronized (pythonpath) { ! //go through our pythonpath and check the beggining ! for (Iterator<String> iter = pythonpath.iterator(); iter.hasNext();) { ! String element = getDefaultPathStr(iter.next()); ! if (fullPath.startsWith(element)) { ! int len = element.length(); ! String s = fullPath.substring(len); ! String sWithoutExtension = fullPathWithoutExtension.substring(len); ! if (s.startsWith("/")) { ! s = s.substring(1); ! } ! if (sWithoutExtension.startsWith("/")) { ! sWithoutExtension = sWithoutExtension.substring(1); ! } ! if (!isValidModule(sWithoutExtension)) { continue; } ! s = s.replaceAll("/", "."); ! if (s.indexOf(".") != -1) { ! File root = new File(element); ! if (root.exists() == false) { ! continue; ! } ! ! //this means that more than 1 module is specified, so, in order to get it, ! //we have to go and see if all the folders to that module have __init__.py in it... ! String[] modulesParts = StringUtils.dotSplit(s); ! if (modulesParts.length > 1 && isFile) { ! String[] t = new String[modulesParts.length - 1]; ! for (int i = 0; i < modulesParts.length - 1; i++) { ! t[i] = modulesParts[i]; ! } ! t[t.length - 1] = t[t.length - 1] + "." + modulesParts[modulesParts.length - 1]; ! modulesParts = t; } ! //here, in modulesParts, we have something like ! //["compiler", "ast.py"] - if file ! //["pywin","debugger"] - if folder ! // ! //root starts with the pythonpath folder that starts with the same ! //chars as the full path passed in. ! boolean isValid = true; ! for (int i = 0; i < modulesParts.length && root != null; i++) { ! root = new File(REF.getFileAbsolutePath(root) + "/" + modulesParts[i]); ! //check if file is in root... ! if (isValidFileMod(modulesParts[i])) { ! if (root.exists() && root.isFile()) { ! break; ! } ! } else { ! //this part is a folder part... check if it is a valid module (has init). ! if (isFileOrFolderWithInit(root) == false) { ! isValid = false; ! break; ! } ! //go on and check the next part. } } ! if (isValid) { ! if (isFile) { s = stripExtension(s); - } else if (moduleFile.exists() == false) { - //ok, it does not exist, so isFile will not work, let's just check if it is - //a valid module (ends with .py or .pyw) and if it is, strip the extension - if (isValidFileMod(s)) { - s = stripExtension(s); - } } - return s; - } - } else { - //simple part, we don't have to go into subfolders to check validity... - if (!isFile && moduleFile.isDirectory() && isFileOrFolderWithInit(moduleFile) == false) { - return null; } return s; } } - } ! //ok, it was not found in any existing way, so, if we don't require the file to exist, let's just do some simpler search and get the ! //first match (if any)... this is useful if the file we are looking for has just been deleted ! if (!requireFileToExist) { ! //we have to remove the last part (.py, .pyc, .pyw) ! for (String element : pythonpath) { ! element = getDefaultPathStr(element); ! if (fullPathWithoutExtension.startsWith(element)) { ! String s = fullPathWithoutExtension.substring(element.length()); ! if (s.startsWith("/")) { ! s = s.substring(1); ! } ! if (!isValidModule(s)) { ! continue; ! } ! s = s.replaceAll("/", "."); ! return s; } } } - return null; - } } --- 239,355 ---- if (requireFileToExist && !moduleFile.exists()) { return null; ! } boolean isFile = moduleFile.isFile(); ! List<String> pythonPathCopy = getPythonpath(); ! //go through our pythonpath and check the beggining ! for(String pathEntry : pythonPathCopy) { ! String element = getDefaultPathStr(pathEntry); ! if (fullPath.startsWith(element)) { ! int len = element.length(); ! String s = fullPath.substring(len); ! String sWithoutExtension = fullPathWithoutExtension.substring(len); ! if (s.startsWith("/")) { ! s = s.substring(1); ! } ! if (sWithoutExtension.startsWith("/")) { ! sWithoutExtension = sWithoutExtension.substring(1); ! } ! if (!isValidModule(sWithoutExtension)) { ! continue; ! } ! ! s = s.replaceAll("/", "."); ! if (s.indexOf(".") != -1) { ! File root = new File(element); ! if (root.exists() == false) { continue; } ! //this means that more than 1 module is specified, so, in order to get it, ! //we have to go and see if all the folders to that module have __init__.py in it... ! String[] modulesParts = StringUtils.dotSplit(s); ! if (modulesParts.length > 1 && isFile) { ! String[] t = new String[modulesParts.length - 1]; ! for (int i = 0; i < modulesParts.length - 1; i++) { ! t[i] = modulesParts[i]; } + t[t.length - 1] = t[t.length - 1] + "." + modulesParts[modulesParts.length - 1]; + modulesParts = t; + } ! //here, in modulesParts, we have something like ! //["compiler", "ast.py"] - if file ! //["pywin","debugger"] - if folder ! // ! //root starts with the pythonpath folder that starts with the same ! //chars as the full path passed in. ! boolean isValid = true; ! for (int i = 0; i < modulesParts.length && root != null; i++) { ! root = new File(REF.getFileAbsolutePath(root) + "/" + modulesParts[i]); ! //check if file is in root... ! if (isValidFileMod(modulesParts[i])) { ! if (root.exists() && root.isFile()) { ! break; ! } ! } else { ! //this part is a folder part... check if it is a valid module (has init). ! if (isFileOrFolderWithInit(root) == false) { ! isValid = false; ! break; } + //go on and check the next part. } ! } ! if (isValid) { ! if (isFile) { ! s = stripExtension(s); ! } else if (moduleFile.exists() == false) { ! //ok, it does not exist, so isFile will not work, let's just check if it is ! //a valid module (ends with .py or .pyw) and if it is, strip the extension ! if (isValidFileMod(s)) { s = stripExtension(s); } } return s; } + } else { + //simple part, we don't have to go into subfolders to check validity... + if (!isFile && moduleFile.isDirectory() && isFileOrFolderWithInit(moduleFile) == false) { + return null; + } + return s; } } ! ! } ! //ok, it was not found in any existing way, so, if we don't require the file to exist, let's just do some simpler search and get the ! //first match (if any)... this is useful if the file we are looking for has just been deleted ! if (!requireFileToExist) { ! //we have to remove the last part (.py, .pyc, .pyw) ! for (String element : pythonPathCopy) { ! element = getDefaultPathStr(element); ! if (fullPathWithoutExtension.startsWith(element)) { ! String s = fullPathWithoutExtension.substring(element.length()); ! if (s.startsWith("/")) { ! s = s.substring(1); } + if (!isValidModule(s)) { + continue; + } + s = s.replaceAll("/", "."); + return s; } } } + return null; } *************** *** 438,450 **** } public List<String> getPythonpath() { ! synchronized (pythonpath) { ! return new ArrayList<String>(pythonpath); ! } } /** ! * This method should traverse the pythonpath passed and return a structure with the info that could be collected ! * about the files that are related to python modules. */ public ModulesFoundStructure getModulesFoundStructure(IProgressMonitor monitor) { --- 435,453 ---- } + /** + * @return a list with the pythonpath, such that each element of the list is a part of + * the pythonpath + * @note returns a copy and not a reference to the internal list. + */ public List<String> getPythonpath() { ! synchronized (pythonpath) { ! return new ArrayList<String>(pythonpath); ! } } /** ! * This method should traverse the pythonpath passed and return a structure ! * with the info that could be collected about the files that are related to ! * python modules. */ public ModulesFoundStructure getModulesFoundStructure(IProgressMonitor monitor) { Index: ASTManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/ASTManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ASTManager.java 13 Aug 2008 21:12:15 -0000 1.4 --- ASTManager.java 28 Sep 2008 12:45:45 -0000 1.5 *************** *** 39,46 **** public class ASTManager extends AbstractASTManager implements ICodeCompletionASTManager, Serializable{ ! ! /** ! * changed to 10L on release 1.0 ! */ protected static final long serialVersionUID = 10L; --- 39,46 ---- public class ASTManager extends AbstractASTManager implements ICodeCompletionASTManager, Serializable{ ! ! /** ! * changed to 10L on release 1.0 ! */ protected static final long serialVersionUID = 10L; *************** *** 70,80 **** * @return modules manager wrapped cast to the interface we expect. Creates it if needed. */ ! private synchronized IProjectModulesManager getProjectModulesManager() { ! if(modulesManager == null){ ! modulesManager = new ProjectModulesManager(); ! } ! return (IProjectModulesManager) modulesManager; ! } ! //----------------------- AUXILIARIES --- 70,80 ---- * @return modules manager wrapped cast to the interface we expect. Creates it if needed. */ ! private synchronized IProjectModulesManager getProjectModulesManager() { ! if(modulesManager == null){ ! modulesManager = new ProjectModulesManager(); ! } ! return (IProjectModulesManager) modulesManager; ! } ! //----------------------- AUXILIARIES *************** *** 121,125 **** return o; } catch (Exception e) { ! //ok, no need to log it. return null; } --- 121,125 ---- return o; } catch (Exception e) { ! //ok, no need to log it. return null; } Index: ModulesManagerCache.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/ModulesManagerCache.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ModulesManagerCache.java 27 Oct 2007 12:22:05 -0000 1.3 --- ModulesManagerCache.java 28 Sep 2008 12:45:45 -0000 1.4 *************** *** 19,44 **** * The access to the cache is synchronized */ ! LRUCache<Tuple<ModulesKey, ModulesManager>, AbstractModule> internalCache; ! ModulesManagerCache() { internalCache = new LRUCache<Tuple<ModulesKey, ModulesManager>, AbstractModule>(MAX_NUMBER_OF_MODULES); ! } ! /** ! * Overriden so that if we do not find the key, we have the chance to create it. ! */ ! public AbstractModule getObj(ModulesKey key, ModulesManager modulesManager) { synchronized (modulesManager.modulesKeys) { ! Tuple<ModulesKey, ModulesManager> keyTuple = new Tuple<ModulesKey, ModulesManager>(key, modulesManager); AbstractModule obj = internalCache.getObj(keyTuple); ! if(obj == null && modulesManager.modulesKeys.containsKey(key)){ ! key = modulesManager.modulesKeys.get(key); //get the 'real' key ! obj = AbstractModule.createEmptyModule(key); internalCache.add(keyTuple, obj); ! } ! return obj; } ! } public void remove(ModulesKey key, ModulesManager modulesManager) { --- 19,44 ---- * The access to the cache is synchronized */ ! LRUCache<Tuple<ModulesKey, ModulesManager>, AbstractModule> internalCache; ! ModulesManagerCache() { internalCache = new LRUCache<Tuple<ModulesKey, ModulesManager>, AbstractModule>(MAX_NUMBER_OF_MODULES); ! } ! /** ! * Overriden so that if we do not find the key, we have the chance to create it. ! */ ! public AbstractModule getObj(ModulesKey key, ModulesManager modulesManager) { synchronized (modulesManager.modulesKeys) { ! Tuple<ModulesKey, ModulesManager> keyTuple = new Tuple<ModulesKey, ModulesManager>(key, modulesManager); AbstractModule obj = internalCache.getObj(keyTuple); ! if(obj == null && modulesManager.modulesKeys.containsKey(key)){ ! key = modulesManager.modulesKeys.get(key); //get the 'real' key ! obj = AbstractModule.createEmptyModule(key); internalCache.add(keyTuple, obj); ! } ! return obj; } ! } public void remove(ModulesKey key, ModulesManager modulesManager) { Index: SourceModuleProposal.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/SourceModuleProposal.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SourceModuleProposal.java 21 Aug 2008 20:56:29 -0000 1.3 --- SourceModuleProposal.java 28 Sep 2008 12:45:45 -0000 1.4 *************** *** 64,82 **** // // //if not preset, let's find it. ! // if(module.getFile() == null){ //its same ! // doc = dummy; ! // ! // }else{//another ! // IPath path = new Path(REF.getFileAbsolutePath(module.getFile())); ! // IEditorPart part = PyOpenEditor.doOpenEditor(path); ! // ! // if(part instanceof PyEdit){ ! // edit = (PyEdit) part; ! // doc = edit.getDocumentProvider().getDocument(edit.getEditorInput()); ! // }else{ ! // String contents = REF.getFileContents(module.getFile()); ! // doc = new Document(contents); ! // } ! // } // } // --- 64,82 ---- // // //if not preset, let's find it. ! // if(module.getFile() == null){ //its same ! // doc = dummy; ! // ! // }else{//another ! // IPath path = new Path(REF.getFileAbsolutePath(module.getFile())); ! // IEditorPart part = PyOpenEditor.doOpenEditor(path); ! // ! // if(part instanceof PyEdit){ ! // edit = (PyEdit) part; ! // doc = edit.getDocumentProvider().getDocument(edit.getEditorInput()); ! // }else{ ! // String contents = REF.getFileContents(module.getFile()); ! // doc = new Document(contents); ! // } ! // } // } // *************** *** 109,113 **** // // //return original... ! // return fReplacementOffset; // } // --- 109,113 ---- // // //return original... ! // return fReplacementOffset; // } // Index: AbstractToken.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/AbstractToken.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AbstractToken.java 14 Jun 2008 22:14:55 -0000 1.5 --- AbstractToken.java 28 Sep 2008 12:45:45 -0000 1.6 *************** *** 215,225 **** */ public String getAsRelativeImport(String baseModule) { ! String completePath = getOriginalRep(true); ! ! return makeRelative(baseModule, completePath); } public String getAsAbsoluteImport() { ! return getAsRelativeImport("."); } --- 215,225 ---- */ public String getAsRelativeImport(String baseModule) { ! String completePath = getOriginalRep(true); ! ! return makeRelative(baseModule, completePath); } public String getAsAbsoluteImport() { ! return getAsRelativeImport("."); } *************** *** 234,257 **** public static String makeRelative(String baseModule, String completePath) { if(baseModule == null){ ! return completePath; ! } ! ! if(completePath.startsWith(baseModule)){ ! String relative = completePath.substring(baseModule.length()); ! baseModule = FullRepIterable.headAndTail(baseModule)[0]; ! ! if(baseModule.length() == 0){ ! if(relative.length() > 0 && relative.charAt(0) == '.'){ ! return relative.substring(1); ! } ! } ! if(relative.length() > 0 && relative.charAt(0) == '.'){ ! return baseModule+relative; ! }else{ ! return baseModule+'.'+relative; ! } ! } ! return completePath; } --- 234,257 ---- public static String makeRelative(String baseModule, String completePath) { if(baseModule == null){ ! return completePath; ! } ! ! if(completePath.startsWith(baseModule)){ ! String relative = completePath.substring(baseModule.length()); ! baseModule = FullRepIterable.headAndTail(baseModule)[0]; ! ! if(baseModule.length() == 0){ ! if(relative.length() > 0 && relative.charAt(0) == '.'){ ! return relative.substring(1); ! } ! } ! if(relative.length() > 0 && relative.charAt(0) == '.'){ ! return baseModule+relative; ! }else{ ! return baseModule+'.'+relative; ! } ! } ! return completePath; } *************** *** 272,281 **** */ public String getOriginalWithoutRep(){ ! int i = originalRep.length() - rep.length() -1; ! if(i > 0){ ! return originalRep.substring(0, i); ! }else{ ! return ""; ! } } --- 272,281 ---- */ public String getOriginalWithoutRep(){ ! int i = originalRep.length() - rep.length() -1; ! if(i > 0){ ! return originalRep.substring(0, i); ! }else{ ! return ""; ! } } *************** *** 293,297 **** public boolean isImportFrom() { ! return false; } --- 293,297 ---- public boolean isImportFrom() { ! return false; } *************** *** 308,312 **** */ public int[] getLineColEnd() { ! return new int[]{UNDEFINED, UNDEFINED}; } --- 308,312 ---- */ public int[] getLineColEnd() { ! return new int[]{UNDEFINED, UNDEFINED}; } Index: ProjectModulesManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/ProjectModulesManager.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ProjectModulesManager.java 13 Aug 2008 21:12:15 -0000 1.18 --- ProjectModulesManager.java 28 Sep 2008 12:45:45 -0000 1.19 *************** *** 20,24 **** import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; - import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; --- 20,23 ---- *************** *** 180,184 **** public ISystemModulesManager getSystemModulesManager(){ ! return getSystemModulesManager(null); } --- 179,183 ---- public ISystemModulesManager getSystemModulesManager(){ ! return getSystemModulesManager(null); } *************** *** 188,207 **** */ public ISystemModulesManager getSystemModulesManager(String defaultSelectedInterpreter){ ! if(nature == null){ ! PydevPlugin.log("Nature still not set"); ! return null; //still not set (initialization) ! } IInterpreterManager iMan = PydevPlugin.getInterpreterManager(nature); if(defaultSelectedInterpreter == null){ ! try { ! defaultSelectedInterpreter = iMan.getDefaultInterpreter(); ! } catch (NotConfiguredInterpreterException e) { ! return null; //not configured ! } } InterpreterInfo info = (InterpreterInfo) iMan.getInterpreterInfo(defaultSelectedInterpreter, new NullProgressMonitor()); if(info == null){ ! PydevPlugin.log("Info still not set"); ! return null; //may happen during initialization } return info.getModulesManager(); --- 187,206 ---- */ public ISystemModulesManager getSystemModulesManager(String defaultSelectedInterpreter){ ! if(nature == null){ ! PydevPlugin.log("Nature still not set"); ! return null; //still not set (initialization) ! } IInterpreterManager iMan = PydevPlugin.getInterpreterManager(nature); if(defaultSelectedInterpreter == null){ ! try { ! defaultSelectedInterpreter = iMan.getDefaultInterpreter(); ! } catch (NotConfiguredInterpreterException e) { ! return null; //not configured ! } } InterpreterInfo info = (InterpreterInfo) iMan.getInterpreterInfo(defaultSelectedInterpreter, new NullProgressMonitor()); if(info == null){ ! PydevPlugin.log("Info still not set"); ! return null; //may happen during initialization } return info.getModulesManager(); *************** *** 229,238 **** @Override public SortedMap<ModulesKey, ModulesKey> getAllModulesStartingWith(String strStartingWith) { ! SortedMap<ModulesKey, ModulesKey> ret = new TreeMap<ModulesKey, ModulesKey>(); ! IModulesManager[] managersInvolved = this.getManagersInvolved(true); ! for (int i = 0; i < managersInvolved.length; i++) { ! ret.putAll(managersInvolved[i].getAllDirectModulesStartingWith(strStartingWith)); ! } ! return ret; } --- 228,237 ---- @Override public SortedMap<ModulesKey, ModulesKey> getAllModulesStartingWith(String strStartingWith) { ! SortedMap<ModulesKey, ModulesKey> ret = new TreeMap<ModulesKey, ModulesKey>(); ! IModulesManager[] managersInvolved = this.getManagersInvolved(true); ! for (int i = 0; i < managersInvolved.length; i++) { ! ret.putAll(managersInvolved[i].getAllDirectModulesStartingWith(strStartingWith)); ! } ! return ret; } *************** *** 249,253 **** */ public IModule getRelativeModule(String name, IPythonNature nature) { ! return super.getModule(false, name, nature, true); //cannot be a compiled module } --- 248,252 ---- */ public IModule getRelativeModule(String name, IPythonNature nature) { ! return super.getModule(false, name, nature, true); //cannot be a compiled module } *************** *** 320,326 **** protected String getResolveModuleErr(IResource member) { ! return "Unable to find the path "+member+" in the project were it\n" + "is added as a source folder for pydev (project: "+project.getName()+")"; ! } /** --- 319,325 ---- protected String getResolveModuleErr(IResource member) { ! return "Unable to find the path "+member+" in the project were it\n" + "is added as a source folder for pydev (project: "+project.getName()+")"; ! } /** *************** *** 381,385 **** public String[] getBuiltins() { ! return getBuiltins(null); } --- 380,384 ---- public String[] getBuiltins() { ! return getBuiltins(null); } *************** *** 406,427 **** */ private synchronized IModulesManager[] getManagers(boolean checkSystemManager, boolean referenced) { ! if(this.completionCache != null){ ! IModulesManager[] ret = this.completionCache.getManagers(referenced); ! if(ret != null){ ! return ret; ! } ! } ArrayList<IModulesManager> list = new ArrayList<IModulesManager>(); ISystemModulesManager systemModulesManager = getSystemModulesManager(null); if(systemModulesManager == null){ ! //may happen in initialization ! // PydevPlugin.log("System modules manager still not available (still initializing or not set)."); ! return new IModulesManager[]{}; } //get the projects 1st if(project != null){ ! HashSet<IProject> projs = new HashSet<IProject>(); ! getProjectsRecursively(project, referenced, projs); addModuleManagers(list, projs); } --- 405,426 ---- */ private synchronized IModulesManager[] getManagers(boolean checkSystemManager, boolean referenced) { ! if(this.completionCache != null){ ! IModulesManager[] ret = this.completionCache.getManagers(referenced); ! if(ret != null){ ! return ret; ! } ! } ArrayList<IModulesManager> list = new ArrayList<IModulesManager>(); ISystemModulesManager systemModulesManager = getSystemModulesManager(null); if(systemModulesManager == null){ ! //may happen in initialization ! // PydevPlugin.log("System modules manager still not available (still initializing or not set)."); ! return new IModulesManager[]{}; } //get the projects 1st if(project != null){ ! HashSet<IProject> projs = new HashSet<IProject>(); ! getProjectsRecursively(project, referenced, projs); addModuleManagers(list, projs); } *************** *** 437,441 **** IModulesManager[] ret = (IModulesManager[]) list.toArray(new IModulesManager[list.size()]); if(this.completionCache != null){ ! this.completionCache.setManagers(ret, referenced); } return ret; --- 436,440 ---- IModulesManager[] ret = (IModulesManager[]) list.toArray(new IModulesManager[list.size()]); if(this.completionCache != null){ ! this.completionCache.setManagers(ret, referenced); } return ret; *************** *** 448,479 **** * @param memo (out) this is the place where all the projects will e available. */ ! public static void getProjectsRecursively(IProject project, boolean referenced, HashSet<IProject> memo) { ! IProject[] projects = null; ! try { ! if(referenced){ ! projects = project.getReferencedProjects(); ! }else{ ! projects = project.getReferencingProjects(); ! } ! } catch (CoreException e) { ! //ignore (it's closed) ! } ! ! ! HashSet<IProject> newFound = new HashSet<IProject>(); ! ! if(projects != null){ ! for (IProject p : projects) { ! if(!memo.contains(p)){ ! memo.add(p); ! newFound.add(p); ! } ! } ! } ! ! for (IProject p : newFound) { ! getProjectsRecursively(p, referenced, memo); ! } ! } --- 447,478 ---- * @param memo (out) this is the place where all the projects will e available. */ ! public static void getProjectsRecursively(IProject project, boolean referenced, HashSet<IProject> memo) { ! IProject[] projects = null; ! try { ! if(referenced){ ! projects = project.getReferencedProjects(); ! }else{ ! projects = project.getReferencingProjects(); ! } ! } catch (CoreException e) { ! //ignore (it's closed) ! } ! ! ! HashSet<IProject> newFound = new HashSet<IProject>(); ! ! if(projects != null){ ! for (IProject p : projects) { ! if(!memo.contains(p)){ ! memo.add(p); ! newFound.add(p); ! } ! } ! } ! ! for (IProject p : newFound) { ! getProjectsRecursively(p, referenced, memo); ! } ! } *************** *** 483,503 **** */ private void addModuleManagers(ArrayList<IModulesManager> list, Collection<IProject> projects) { ! for(IProject project:projects){ ! PythonNature nature = PythonNature.getPythonNature(project); ! if(nature!=null){ ! ICodeCompletionASTManager otherProjectAstManager = nature.getAstManager(); ! if(otherProjectAstManager != null){ ! IModulesManager projectModulesManager = otherProjectAstManager.getModulesManager(); ! if(projectModulesManager != null){ ! list.add((IModulesManager) projectModulesManager); ! } ! }else{ ! Log.log(IStatus.WARNING, "No ast manager configured for :"+project.getName(), null); ! } } - IModulesManager javaModulesManagerForProject = JavaProjectModulesManagerCreator.createJavaProjectModulesManagerIfPossible(project); - if(javaModulesManagerForProject != null){ - list.add(javaModulesManagerForProject); - } } } --- 482,502 ---- */ private void addModuleManagers(ArrayList<IModulesManager> list, Collection<IProject> projects) { ! for(IProject project:projects){ ! PythonNature nature = PythonNature.getPythonNature(project); ! if(nature!=null){ ! ICodeCompletionASTManager otherProjectAstManager = nature.getAstManager(); ! if(otherProjectAstManager != null){ ! IModulesManager projectModulesManager = otherProjectAstManager.getModulesManager(); ! if(projectModulesManager != null){ ! list.add((IModulesManager) projectModulesManager); ! } ! }else{ ! Log.log(IStatus.WARNING, "No ast manager configured for :"+project.getName(), null); ! } ! } ! IModulesManager javaModulesManagerForProject = JavaProjectModulesManagerCreator.createJavaProjectModulesManagerIfPossible(project); ! if(javaModulesManagerForProject != null){ ! list.add(javaModulesManagerForProject); } } } |