[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited IASTManager.java,1
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2005-01-25 16:05:10
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22165/src/org/python/pydev/editor/codecompletion/revisited Modified Files: IASTManager.java PyCodeCompletionVisitor.java ASTManager.java Log Message: Version 2.4 support (kind of) Index: PyCodeCompletionVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited/PyCodeCompletionVisitor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyCodeCompletionVisitor.java 17 Jan 2005 14:47:44 -0000 1.4 --- PyCodeCompletionVisitor.java 25 Jan 2005 16:04:25 -0000 1.5 *************** *** 40,44 **** if (astManager != null){ IPath location = resource.getLocation(); ! astManager.rebuildModule(new File(location.toOSString()), document, resource.getProject(), new NullProgressMonitor()); } --- 40,44 ---- if (astManager != null){ IPath location = resource.getLocation(); ! astManager.rebuildModule(new File(location.toOSString()), document, resource.getProject(), new NullProgressMonitor(), pythonNature); } Index: ASTManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited/ASTManager.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ASTManager.java 20 Jan 2005 14:48:00 -0000 1.13 --- ASTManager.java 25 Jan 2005 16:04:25 -0000 1.14 *************** *** 32,35 **** --- 32,36 ---- import org.python.pydev.parser.PyParser; import org.python.pydev.plugin.PydevPlugin; + import org.python.pydev.plugin.PythonNature; /** *************** *** 149,156 **** * @see org.python.pydev.editor.codecompletion.revisited.IASTManager#rebuildModule(java.io.File, org.eclipse.jface.text.IDocument, org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IProgressMonitor) */ ! public void rebuildModule(File f, IDocument doc, final IProject project, IProgressMonitor monitor) { final String m = pythonPathHelper.resolveModule(f.getAbsolutePath()); if (m != null) { ! final AbstractModule value = AbstractModule.createModuleFromDoc(m, f, doc); final ModulesKey key = new ModulesKey(m, f); modules.put(key, value); --- 150,157 ---- * @see org.python.pydev.editor.codecompletion.revisited.IASTManager#rebuildModule(java.io.File, org.eclipse.jface.text.IDocument, org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IProgressMonitor) */ ! public void rebuildModule(File f, IDocument doc, final IProject project, IProgressMonitor monitor, PythonNature nature) { final String m = pythonPathHelper.resolveModule(f.getAbsolutePath()); if (m != null) { ! final AbstractModule value = AbstractModule.createModuleFromDoc(m, f, doc, nature); final ModulesKey key = new ModulesKey(m, f); modules.put(key, value); *************** *** 236,240 **** * @return a Set with the imports as tuples with the name, the docstring. */ ! public IToken[] getCompletionsForImport(final String original) { String initial = original; if (initial.endsWith(".")) { --- 237,241 ---- * @return a Set with the imports as tuples with the name, the docstring. */ ! public IToken[] getCompletionsForImport(final String original, PythonNature nature) { String initial = original; if (initial.endsWith(".")) { *************** *** 288,292 **** } ! Object object = getModule(nameInCache); if (object instanceof AbstractModule) { AbstractModule m = (AbstractModule) object; --- 289,293 ---- } ! Object object = getModule(nameInCache, nature); if (object instanceof AbstractModule) { AbstractModule m = (AbstractModule) object; *************** *** 324,330 **** * @return the module represented by the file. */ ! private AbstractModule getModule(File file) { String name = pythonPathHelper.resolveModule(file.getAbsolutePath()); ! return getModule(name); } --- 325,331 ---- * @return the module represented by the file. */ ! private AbstractModule getModule(File file, PythonNature nature) { String name = pythonPathHelper.resolveModule(file.getAbsolutePath()); ! return getModule(name, nature); } *************** *** 335,339 **** * @return the module represented by this name */ ! private AbstractModule getModule(String name) { AbstractModule n = (AbstractModule) modules.get(new ModulesKey(name, null)); if (n == null){ --- 336,340 ---- * @return the module represented by this name */ ! private AbstractModule getModule(String name, PythonNature nature) { AbstractModule n = (AbstractModule) modules.get(new ModulesKey(name, null)); if (n == null){ *************** *** 350,354 **** if(e.f != null){ try{ ! n = AbstractModule.createModule(name, e.f); }catch(FileNotFoundException exc){ this.modules.remove(new ModulesKey(name, e.f)); --- 351,355 ---- if(e.f != null){ try{ ! n = AbstractModule.createModule(name, e.f, nature); }catch(FileNotFoundException exc){ this.modules.remove(new ModulesKey(name, e.f)); *************** *** 398,404 **** * @return */ ! public IToken[] getCompletionsForToken(File file, IDocument doc, int line, int col, String activationToken, String qualifier) { ! AbstractModule module = AbstractModule.createModuleFromDoc("", file, doc); ! return getCompletionsForModule(activationToken, qualifier, module, line, col); } --- 399,405 ---- * @return */ ! public IToken[] getCompletionsForToken(File file, IDocument doc, int line, int col, String activationToken, String qualifier, PythonNature nature) { ! AbstractModule module = AbstractModule.createModuleFromDoc("", file, doc, nature); ! return getCompletionsForModule(activationToken, qualifier, module, line, col, nature); } *************** *** 412,424 **** * @return */ ! public IToken[] getCompletionsForToken(IDocument doc, int line, int col, String activationToken, String qualifier) { ! Object[] obj = PyParser.reparseDocument(doc, true); SimpleNode n = (SimpleNode) obj[0]; AbstractModule module = AbstractModule.createModule(n); ! return getCompletionsForModule( activationToken, qualifier, module, line, col); } ! public IToken[] getCompletionsForModule(String activationToken, String qualifier, AbstractModule module, int line, int col) { ! return getCompletionsForModule(activationToken, qualifier, module, line, col, false); } --- 413,425 ---- * @return */ ! public IToken[] getCompletionsForToken(IDocument doc, int line, int col, String activationToken, String qualifier, PythonNature nature) { ! Object[] obj = PyParser.reparseDocument(doc, true, nature); SimpleNode n = (SimpleNode) obj[0]; AbstractModule module = AbstractModule.createModule(n); ! return getCompletionsForModule( activationToken, qualifier, module, line, col, nature); } ! public IToken[] getCompletionsForModule(String activationToken, String qualifier, AbstractModule module, int line, int col, PythonNature nature) { ! return getCompletionsForModule(activationToken, qualifier, module, line, col, false, nature); } *************** *** 431,435 **** * @param line */ ! private IToken[] getCompletionsForModule(String activationToken, String qualifier, AbstractModule module, int line, int col, boolean recursing) { if (module != null) { --- 432,436 ---- * @param line */ ! private IToken[] getCompletionsForModule(String activationToken, String qualifier, AbstractModule module, int line, int col, boolean recursing, PythonNature nature) { if (module != null) { *************** *** 442,446 **** if (activationToken.length() == 0) { ! List completions = getGlobalCompletions(activationToken, qualifier, line, col, recursing, globalTokens, importedModules, wildImportedModules); return (IToken[]) completions.toArray(new IToken[0]); --- 443,447 ---- if (activationToken.length() == 0) { ! List completions = getGlobalCompletions(activationToken, qualifier, line, col, recursing, globalTokens, importedModules, wildImportedModules, nature); return (IToken[]) completions.toArray(new IToken[0]); *************** *** 451,455 **** //from a module, so, first we check if it is a module or module token. ! final IToken[] t = searchOnImportedMods(activationToken, importedModules, line, col); if(t != null && t.length > 0){ return t; --- 452,456 ---- //from a module, so, first we check if it is a module or module token. ! final IToken[] t = searchOnImportedMods(activationToken, importedModules, line, col, nature); if(t != null && t.length > 0){ return t; *************** *** 460,471 **** IToken name = wildImportedModules[i]; ! AbstractModule mod = getModule(name.getCompletePath()); if (mod == null) { ! mod = getModule(name.getRepresentation()); } if (mod != null) { ! IToken[] completionsForModule = getCompletionsForModule(activationToken, qualifier, mod, line, col, true); if(completionsForModule.length > 0) return completionsForModule; --- 461,472 ---- IToken name = wildImportedModules[i]; ! AbstractModule mod = getModule(name.getCompletePath(), nature); if (mod == null) { ! mod = getModule(name.getRepresentation(), nature); } if (mod != null) { ! IToken[] completionsForModule = getCompletionsForModule(activationToken, qualifier, mod, line, col, true, nature); if(completionsForModule.length > 0) return completionsForModule; *************** *** 476,480 **** //it was not a module (would have returned already), so, try to get the completions for a global token defined. ! IToken[] tokens = module.getGlobalTokens(activationToken, this, line, col); if (tokens.length > 0){ return tokens; --- 477,481 ---- //it was not a module (would have returned already), so, try to get the completions for a global token defined. ! IToken[] tokens = module.getGlobalTokens(activationToken, this, line, col, nature); if (tokens.length > 0){ return tokens; *************** *** 482,488 **** //If it was still not found, go to builtins. ! AbstractModule builtinsMod = getModule("__builtin__"); if(builtinsMod != null){ ! tokens = getCompletionsForModule(activationToken, qualifier, builtinsMod, line, col, true); if (tokens.length > 0){ if (tokens[0].getRepresentation().equals("ERROR:") == false){ --- 483,489 ---- //If it was still not found, go to builtins. ! AbstractModule builtinsMod = getModule("__builtin__", nature); if(builtinsMod != null){ ! tokens = getCompletionsForModule(activationToken, qualifier, builtinsMod, line, col, true, nature); if (tokens.length > 0){ if (tokens[0].getRepresentation().equals("ERROR:") == false){ *************** *** 492,496 **** } ! return getAssignCompletions(activationToken, qualifier, module, line, col); } --- 493,497 ---- } ! return getAssignCompletions(activationToken, qualifier, module, line, col, nature); } *************** *** 525,529 **** * @return */ ! private IToken[] getAssignCompletions(String activationToken, String qualifier, AbstractModule module, int line, int col) { if (module instanceof SourceModule) { SourceModule s = (SourceModule) module; --- 526,530 ---- * @return */ ! private IToken[] getAssignCompletions(String activationToken, String qualifier, AbstractModule module, int line, int col, PythonNature nature) { if (module instanceof SourceModule) { SourceModule s = (SourceModule) module; *************** *** 532,536 **** if(defs.length > 0){ for (int i = 0; i < defs.length; i++) { ! IToken[] tks = getCompletionsForModule(defs[i].value,qualifier, module, defs[i].line, defs[i].col); if(tks.length > 0) return tks; --- 533,537 ---- if(defs.length > 0){ for (int i = 0; i < defs.length; i++) { ! IToken[] tks = getCompletionsForModule(defs[i].value,qualifier, module, defs[i].line, defs[i].col, nature); if(tks.length > 0) return tks; *************** *** 553,557 **** * @param wildImportedModules */ ! private List getGlobalCompletions(String activationToken, String qualifier, int line, int col, boolean recursing, IToken[] globalTokens, IToken[] importedModules, IToken[] wildImportedModules) { List completions = new ArrayList(); --- 554,558 ---- * @param wildImportedModules */ ! private List getGlobalCompletions(String activationToken, String qualifier, int line, int col, boolean recursing, IToken[] globalTokens, IToken[] importedModules, IToken[] wildImportedModules, PythonNature nature) { List completions = new ArrayList(); *************** *** 570,581 **** IToken name = wildImportedModules[i]; ! AbstractModule mod = getModule(name.getCompletePath()); if (mod == null) { ! mod = getModule(name.getRepresentation()); } if (mod != null) { ! IToken[] completionsForModule = getCompletionsForModule(activationToken, qualifier, mod, line, col, true); for (int j = 0; j < completionsForModule.length; j++) { completions.add(completionsForModule[j]); --- 571,582 ---- IToken name = wildImportedModules[i]; ! AbstractModule mod = getModule(name.getCompletePath(), nature); if (mod == null) { ! mod = getModule(name.getRepresentation(), nature); } if (mod != null) { ! IToken[] completionsForModule = getCompletionsForModule(activationToken, qualifier, mod, line, col, true, nature); for (int j = 0; j < completionsForModule.length; j++) { completions.add(completionsForModule[j]); *************** *** 588,592 **** if(!recursing){ //last thing: get completions from module __builtin__ ! AbstractModule builtMod = getModule("__builtin__"); if(builtMod != null){ IToken[] toks = builtMod.getGlobalTokens(); --- 589,593 ---- if(!recursing){ //last thing: get completions from module __builtin__ ! AbstractModule builtMod = getModule("__builtin__", nature); if(builtMod != null){ IToken[] toks = builtMod.getGlobalTokens(); *************** *** 604,608 **** * @return */ ! private IToken[] searchOnImportedMods(String activationToken, IToken[] importedModules, int line, int col) { for (int i = 0; i < importedModules.length; i++) { final String modRep = importedModules[i].getRepresentation(); --- 605,609 ---- * @return */ ! private IToken[] searchOnImportedMods(String activationToken, IToken[] importedModules, int line, int col, PythonNature nature) { for (int i = 0; i < importedModules.length; i++) { final String modRep = importedModules[i].getRepresentation(); *************** *** 610,614 **** String rep = importedModules[i].getCompletePath(); ! Object [] o = findModuleFromPath(rep); AbstractModule mod = (AbstractModule) o[0]; String tok = (String) o[1]; --- 611,615 ---- String rep = importedModules[i].getCompletePath(); ! Object [] o = findModuleFromPath(rep, nature); AbstractModule mod = (AbstractModule) o[0]; String tok = (String) o[1]; *************** *** 616,622 **** if(tok.length() == 0){ //the activation token corresponds to an imported module. We have to get its global tokens and return them. ! return getCompletionsForModule("", "", mod, line, col, true); }else if (mod != null){ ! return mod.getGlobalTokens(tok, this, line, col); } --- 617,623 ---- if(tok.length() == 0){ //the activation token corresponds to an imported module. We have to get its global tokens and return them. ! return getCompletionsForModule("", "", mod, line, col, true, nature); }else if (mod != null){ ! return mod.getGlobalTokens(tok, this, line, col, nature); } *************** *** 630,634 **** //so, we have to find the qt module and then go for the token. String subst = activationToken.substring(modRep.length()); ! Object [] o = findModuleFromPath(importedModules[i].getCompletePath() + subst); AbstractModule mod = (AbstractModule) o[0]; String tok = (String) o[1]; --- 631,635 ---- //so, we have to find the qt module and then go for the token. String subst = activationToken.substring(modRep.length()); ! Object [] o = findModuleFromPath(importedModules[i].getCompletePath() + subst, nature); AbstractModule mod = (AbstractModule) o[0]; String tok = (String) o[1]; *************** *** 637,643 **** if(tok.length() == 0){ //the activation token corresponds to an imported module. We have to get its global tokens and return them. ! return getCompletionsForModule("", "", mod, line, col, true); }else if (mod != null){ ! return mod.getGlobalTokens(tok, this, line, col); } } --- 638,644 ---- if(tok.length() == 0){ //the activation token corresponds to an imported module. We have to get its global tokens and return them. ! return getCompletionsForModule("", "", mod, line, col, true, nature); }else if (mod != null){ ! return mod.getGlobalTokens(tok, this, line, col, nature); } } *************** *** 655,661 **** * order to find the module. */ ! private Object [] findModuleFromPath(String rep){ String tok = ""; ! AbstractModule mod = getModule(rep); String mRep = rep; int index; --- 656,662 ---- * order to find the module. */ ! private Object [] findModuleFromPath(String rep, PythonNature nature){ String tok = ""; ! AbstractModule mod = getModule(rep, nature); String mRep = rep; int index; *************** *** 663,667 **** tok = mRep.substring(index+1) + "."+tok; mRep = mRep.substring(0,index); ! mod = getModule(mRep); } if (tok.endsWith(".")){ --- 664,668 ---- tok = mRep.substring(index+1) + "."+tok; mRep = mRep.substring(0,index); ! mod = getModule(mRep, nature); } if (tok.endsWith(".")){ *************** *** 670,672 **** --- 671,674 ---- return new Object[]{mod, tok}; } + } \ No newline at end of file Index: IASTManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited/IASTManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IASTManager.java 20 Jan 2005 10:24:59 -0000 1.3 --- IASTManager.java 25 Jan 2005 16:04:25 -0000 1.4 *************** *** 12,15 **** --- 12,16 ---- import org.eclipse.jface.text.IDocument; import org.python.pydev.editor.codecompletion.revisited.modules.ModulesKey; + import org.python.pydev.plugin.PythonNature; /** *************** *** 36,40 **** * @param monitor: monitor for progress. */ ! public abstract void rebuildModule(final File file, final IDocument doc, final IProject project, IProgressMonitor monitor); /** --- 37,41 ---- * @param monitor: monitor for progress. */ ! public abstract void rebuildModule(final File file, final IDocument doc, final IProject project, IProgressMonitor monitor, PythonNature nature); /** *************** *** 77,81 **** * @return a Set with the imports as tuples with the name, the docstring. */ ! public abstract IToken[] getCompletionsForImport(final String original); /** --- 78,82 ---- * @return a Set with the imports as tuples with the name, the docstring. */ ! public abstract IToken[] getCompletionsForImport(final String original, PythonNature nature); /** *************** *** 107,112 **** * @param activationToken * @param qualifier * @return */ ! public abstract IToken[] getCompletionsForToken(File file, IDocument doc, int line, int col, String activationToken, String qualifier); } \ No newline at end of file --- 108,114 ---- * @param activationToken * @param qualifier + * @param nature * @return */ ! public abstract IToken[] getCompletionsForToken(File file, IDocument doc, int line, int col, String activationToken, String qualifier, PythonNature nature); } \ No newline at end of file |