[Pydev-cvs] org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visit
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-09-28 12:48:19
|
Update of /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4313/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors Modified Files: GlobalModelVisitor.java HeuristicFindAttrs.java LocalScope.java FindDefinitionModelVisitor.java InnerModelVisitor.java FindScopeVisitor.java Definition.java KeywordParameterDefinition.java AbstractVisitor.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: Definition.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/Definition.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Definition.java 14 Jun 2008 22:14:56 -0000 1.4 --- Definition.java 28 Sep 2008 12:45:42 -0000 1.5 *************** *** 61,68 **** /** ! * The line and col are defined starting at 1 (and not 0) ! */ public Definition(int line, int col, String value, SimpleNode ast, ILocalScope scope, IModule module){ ! this(line, col, value, ast, scope, module, false); } /** --- 61,68 ---- /** ! * The line and col are defined starting at 1 (and not 0) ! */ public Definition(int line, int col, String value, SimpleNode ast, ILocalScope scope, IModule module){ ! this(line, col, value, ast, scope, module, false); } /** *************** *** 73,78 **** */ public Definition(int line, int col, String value, SimpleNode ast, ILocalScope scope, IModule module, boolean foundAsLocal){ ! Assert.isNotNull(value, "Invalid value."); ! Assert.isNotNull(module, "Invalid Module."); this.line = line; --- 73,78 ---- */ public Definition(int line, int col, String value, SimpleNode ast, ILocalScope scope, IModule module, boolean foundAsLocal){ ! Assert.isNotNull(value, "Invalid value."); ! Assert.isNotNull(module, "Invalid Module."); this.line = line; *************** *** 87,108 **** public Definition(org.python.pydev.core.IToken tok, ILocalScope scope, IModule module){ ! this(tok, scope, module, false); } public Definition(org.python.pydev.core.IToken tok, ILocalScope scope, IModule module, boolean foundAsLocal){ ! Assert.isNotNull(tok, "Invalid value."); ! Assert.isNotNull(module, "Invalid Module."); ! ! this.line = tok.getLineDefinition(); ! this.col = tok.getColDefinition(); ! this.value = tok.getRepresentation(); ! if(tok instanceof SourceToken){ ! this.ast = ((SourceToken)tok).getAst(); ! } ! this.scope = scope; ! this.module = module; } ! /** * @see java.lang.Object#toString() */ --- 87,108 ---- public Definition(org.python.pydev.core.IToken tok, ILocalScope scope, IModule module){ ! this(tok, scope, module, false); } public Definition(org.python.pydev.core.IToken tok, ILocalScope scope, IModule module, boolean foundAsLocal){ ! Assert.isNotNull(tok, "Invalid value."); ! Assert.isNotNull(module, "Invalid Module."); ! ! this.line = tok.getLineDefinition(); ! this.col = tok.getColDefinition(); ! this.value = tok.getRepresentation(); ! if(tok instanceof SourceToken){ ! this.ast = ((SourceToken)tok).getAst(); ! } ! this.scope = scope; ! this.module = module; } ! /** * @see java.lang.Object#toString() */ *************** *** 140,147 **** if(scope == d.scope){ ! return true; } if(scope == null || d.scope == null){ ! return false; } --- 140,147 ---- if(scope == d.scope){ ! return true; } if(scope == null || d.scope == null){ ! return false; } Index: FindDefinitionModelVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/FindDefinitionModelVisitor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FindDefinitionModelVisitor.java 14 Feb 2008 09:57:38 -0000 1.5 --- FindDefinitionModelVisitor.java 28 Sep 2008 12:45:42 -0000 1.6 *************** *** 71,77 **** public String moduleImported; ! private int line; ! private int col; private boolean foundAsDefinition = false; --- 71,77 ---- public String moduleImported; ! private int line; ! private int col; private boolean foundAsDefinition = false; *************** *** 82,86 **** * Call is stored for the context for a keyword parameter */ ! private Stack<Call> call = new Stack<Call>(); /** --- 82,86 ---- * Call is stored for the context for a keyword parameter */ ! private Stack<Call> call = new Stack<Call>(); /** *************** *** 101,133 **** @Override public Object visitImportFrom(ImportFrom node) throws Exception { ! String modRep = NodeUtils.getRepresentationString(node.module); ! if( NodeUtils.isWithin(line, col, node.module) ){ ! //it is a token in the definition of a module ! int startingCol = node.module.beginColumn; ! int endingCol = startingCol; ! while(endingCol < this.col){ ! endingCol++; ! } ! int lastChar = endingCol-startingCol; ! moduleImported = modRep.substring(0, lastChar); ! int i = lastChar; ! while(i < modRep.length()){ ! if(Character.isJavaIdentifierPart(modRep.charAt(i))){ ! i++; ! }else{ ! break; ! } ! } ! moduleImported += modRep.substring(lastChar, i); ! }else{ ! //it was not the module, so, we have to check for each name alias imported ! for (aliasType alias: node.names){ ! //we do not check the 'as' because if it is some 'as', it will be gotten as a global in the module ! if( NodeUtils.isWithin(line, col, alias.name) ){ ! moduleImported = modRep + "." + NodeUtils.getRepresentationString(alias.name); ! } ! } ! } ! return super.visitImportFrom(node); } --- 101,133 ---- @Override public Object visitImportFrom(ImportFrom node) throws Exception { ! String modRep = NodeUtils.getRepresentationString(node.module); ! if( NodeUtils.isWithin(line, col, node.module) ){ ! //it is a token in the definition of a module ! int startingCol = node.module.beginColumn; ! int endingCol = startingCol; ! while(endingCol < this.col){ ! endingCol++; ! } ! int lastChar = endingCol-startingCol; ! moduleImported = modRep.substring(0, lastChar); ! int i = lastChar; ! while(i < modRep.length()){ ! if(Character.isJavaIdentifierPart(modRep.charAt(i))){ ! i++; ! }else{ ! break; ! } ! } ! moduleImported += modRep.substring(lastChar, i); ! }else{ ! //it was not the module, so, we have to check for each name alias imported ! for (aliasType alias: node.names){ ! //we do not check the 'as' because if it is some 'as', it will be gotten as a global in the module ! if( NodeUtils.isWithin(line, col, alias.name) ){ ! moduleImported = modRep + "." + NodeUtils.getRepresentationString(alias.name); ! } ! } ! } ! return super.visitImportFrom(node); } *************** *** 170,178 **** if(node.args != null && node.args.args != null){ ! for(exprType arg:node.args.args){ ! if(arg instanceof Name){ ! checkParam((Name) arg); ! } ! } } node.traverse(this); --- 170,178 ---- if(node.args != null && node.args.args != null){ ! for(exprType arg:node.args.args){ ! if(arg instanceof Name){ ! checkParam((Name) arg); ! } ! } } node.traverse(this); *************** *** 190,217 **** */ private void checkParam(Name name) { ! String rep = NodeUtils.getRepresentationString(name); ! if(rep.equals(tokenToFind) && line == name.beginLine && col >= name.beginColumn && col <= name.beginColumn+rep.length()){ ! foundAsDefinition = true; ! // if it is found as a definition it is an 'exact' match, so, erase all the others. ! ILocalScope scope = new LocalScope(this.defsStack); ! for (Iterator<Definition> it = definitions.iterator(); it.hasNext();) { ! Definition d = it.next(); ! if(!d.scope.equals(scope)){ ! it.remove(); ! } ! } ! ! ! definitionFound = new Definition(line, name.beginColumn, rep, name, scope, module.get()); ! definitions.add(definitionFound); ! } } @Override public Object visitCall(Call node) throws Exception { ! this.call.push(node); ! Object r = super.visitCall(node); ! this.call.pop(); ! return r; } --- 190,217 ---- */ private void checkParam(Name name) { ! String rep = NodeUtils.getRepresentationString(name); ! if(rep.equals(tokenToFind) && line == name.beginLine && col >= name.beginColumn && col <= name.beginColumn+rep.length()){ ! foundAsDefinition = true; ! // if it is found as a definition it is an 'exact' match, so, erase all the others. ! ILocalScope scope = new LocalScope(this.defsStack); ! for (Iterator<Definition> it = definitions.iterator(); it.hasNext();) { ! Definition d = it.next(); ! if(!d.scope.equals(scope)){ ! it.remove(); ! } ! } ! ! ! definitionFound = new Definition(line, name.beginColumn, rep, name, scope, module.get()); ! definitions.add(definitionFound); ! } } @Override public Object visitCall(Call node) throws Exception { ! this.call.push(node); ! Object r = super.visitCall(node); ! this.call.pop(); ! return r; } *************** *** 219,246 **** @Override public Object visitNameTok(NameTok node) throws Exception { ! if(node.ctx == NameTok.KeywordName){ ! if(this.line == node.beginLine){ ! String rep = NodeUtils.getRepresentationString(node); ! if(PySelection.isInside(col, node.beginColumn, rep.length())){ ! foundAsDefinition = true; ! // if it is found as a definition it is an 'exact' match, so, erase all the others. ! ILocalScope scope = new LocalScope(this.defsStack); ! for (Iterator<Definition> it = definitions.iterator(); it.hasNext();) { ! Definition d = it.next(); ! if(!d.scope.equals(scope)){ ! it.remove(); ! } ! } ! ! definitions.clear(); ! ! definitionFound = new KeywordParameterDefinition(line, node.beginColumn, rep, node, scope, module.get(), this.call.peek()); ! definitions.add(definitionFound); ! throw new StopVisitingException(); ! } ! } ! } ! return null; } --- 219,246 ---- @Override public Object visitNameTok(NameTok node) throws Exception { ! if(node.ctx == NameTok.KeywordName){ ! if(this.line == node.beginLine){ ! String rep = NodeUtils.getRepresentationString(node); ! if(PySelection.isInside(col, node.beginColumn, rep.length())){ ! foundAsDefinition = true; ! // if it is found as a definition it is an 'exact' match, so, erase all the others. ! ILocalScope scope = new LocalScope(this.defsStack); ! for (Iterator<Definition> it = definitions.iterator(); it.hasNext();) { ! Definition d = it.next(); ! if(!d.scope.equals(scope)){ ! it.remove(); ! } ! } ! ! definitions.clear(); ! ! definitionFound = new KeywordParameterDefinition(line, node.beginColumn, rep, node, scope, module.get(), this.call.peek()); ! definitions.add(definitionFound); ! throw new StopVisitingException(); ! } ! } ! } ! return null; } *************** *** 296,314 **** } String rep = NodeUtils.getFullRepresentationString(target); ! if(tokenToFind.equals(rep)){ //note, order of equals is important (because one side may be null). ! exprType nodeValue = node.value; String value = NodeUtils.getFullRepresentationString(nodeValue); if(value == null){ value = ""; } ! //get the line and column correspondent to the target ! int line = NodeUtils.getLineDefinition(target); ! int col = NodeUtils.getColDefinition(target); ! AssignDefinition definition = new AssignDefinition(value, rep, i, node, line, col, scope, module.get()); ! //mark it as global (if it was found as global in some of the previous contexts). for(Set<String> globals: globalDeclarationsStack){ if(globals.contains(rep)){ --- 296,314 ---- } String rep = NodeUtils.getFullRepresentationString(target); ! if(tokenToFind.equals(rep)){ //note, order of equals is important (because one side may be null). ! exprType nodeValue = node.value; String value = NodeUtils.getFullRepresentationString(nodeValue); if(value == null){ value = ""; } ! //get the line and column correspondent to the target ! int line = NodeUtils.getLineDefinition(target); ! int col = NodeUtils.getColDefinition(target); ! AssignDefinition definition = new AssignDefinition(value, rep, i, node, line, col, scope, module.get()); ! //mark it as global (if it was found as global in some of the previous contexts). for(Set<String> globals: globalDeclarationsStack){ if(globals.contains(rep)){ *************** *** 317,322 **** } ! definitions.add(definition); ! } } --- 317,322 ---- } ! definitions.add(definition); ! } } Index: LocalScope.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/LocalScope.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** LocalScope.java 17 Aug 2008 00:26:46 -0000 1.9 --- LocalScope.java 28 Sep 2008 12:45:42 -0000 1.10 *************** *** 246,268 **** * @see org.python.pydev.core.ILocalScope#getClassDef() */ ! public ClassDef getClassDef() { ! for(Iterator<SimpleNode> it = this.scope.topDownIterator(); it.hasNext();){ SimpleNode node = it.next(); ! if(node instanceof ClassDef){ ! return (ClassDef) node; ! } ! } ! return null; ! } ! /** * @see org.python.pydev.core.ILocalScope#isLastClassDef() */ ! public boolean isLastClassDef() { ! if(this.scope.size() > 0 && this.scope.peek() instanceof ClassDef){ ! return true; ! } ! return false; ! } @SuppressWarnings("unchecked") --- 246,268 ---- * @see org.python.pydev.core.ILocalScope#getClassDef() */ ! public ClassDef getClassDef() { ! for(Iterator<SimpleNode> it = this.scope.topDownIterator(); it.hasNext();){ SimpleNode node = it.next(); ! if(node instanceof ClassDef){ ! return (ClassDef) node; ! } ! } ! return null; ! } ! /** * @see org.python.pydev.core.ILocalScope#isLastClassDef() */ ! public boolean isLastClassDef() { ! if(this.scope.size() > 0 && this.scope.peek() instanceof ClassDef){ ! return true; ! } ! return false; ! } @SuppressWarnings("unchecked") Index: InnerModelVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/InnerModelVisitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InnerModelVisitor.java 25 Mar 2007 16:09:05 -0000 1.1 --- InnerModelVisitor.java 28 Sep 2008 12:45:42 -0000 1.2 *************** *** 30,36 **** public InnerModelVisitor(String moduleName, ICompletionState state){ ! this.moduleName = moduleName; attrsHeuristics.add(new HeuristicFindAttrs(HeuristicFindAttrs.WHITIN_METHOD_CALL, HeuristicFindAttrs.IN_KEYWORDS, "properties.create", moduleName, state)); ! attrsHeuristics.add(new HeuristicFindAttrs(HeuristicFindAttrs.WHITIN_ANY , HeuristicFindAttrs.IN_ASSIGN , "", moduleName, state)); } --- 30,36 ---- public InnerModelVisitor(String moduleName, ICompletionState state){ ! this.moduleName = moduleName; attrsHeuristics.add(new HeuristicFindAttrs(HeuristicFindAttrs.WHITIN_METHOD_CALL, HeuristicFindAttrs.IN_KEYWORDS, "properties.create", moduleName, state)); ! attrsHeuristics.add(new HeuristicFindAttrs(HeuristicFindAttrs.WHITIN_ANY , HeuristicFindAttrs.IN_ASSIGN , "", moduleName, state)); } *************** *** 68,73 **** if(visiting == VISITING_NOTHING){ visiting = VISITING_CLASS; ! node.traverse(this); ! }else if(visiting == VISITING_CLASS){ //that's a class within the class we're visiting --- 68,73 ---- if(visiting == VISITING_NOTHING){ visiting = VISITING_CLASS; ! node.traverse(this); ! }else if(visiting == VISITING_CLASS){ //that's a class within the class we're visiting *************** *** 100,108 **** //iterate heuristics to find attributes ! for (Iterator iter = attrsHeuristics.iterator(); iter.hasNext();) { ! HeuristicFindAttrs element = (HeuristicFindAttrs) iter.next(); ! element.visitAssign(node); ! addElementTokens(element); ! } } return null; --- 100,108 ---- //iterate heuristics to find attributes ! for (Iterator iter = attrsHeuristics.iterator(); iter.hasNext();) { ! HeuristicFindAttrs element = (HeuristicFindAttrs) iter.next(); ! element.visitAssign(node); ! addElementTokens(element); ! } } return null; *************** *** 116,124 **** //iterate heuristics to find attributes ! for (Iterator iter = attrsHeuristics.iterator(); iter.hasNext();) { ! HeuristicFindAttrs element = (HeuristicFindAttrs) iter.next(); ! element.visitCall(node); ! addElementTokens(element); ! } } return null; --- 116,124 ---- //iterate heuristics to find attributes ! for (Iterator iter = attrsHeuristics.iterator(); iter.hasNext();) { ! HeuristicFindAttrs element = (HeuristicFindAttrs) iter.next(); ! element.visitCall(node); ! addElementTokens(element); ! } } return null; Index: AbstractVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/AbstractVisitor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AbstractVisitor.java 17 Aug 2008 00:26:46 -0000 1.5 --- AbstractVisitor.java 28 Sep 2008 12:45:42 -0000 1.6 *************** *** 101,117 **** public static List<IToken> makeImportToken(SimpleNode node, List<IToken> tokens, String moduleName, boolean allowForMultiple) { ! if(node instanceof Import){ ! return makeImportToken((Import)node, tokens, moduleName, allowForMultiple); ! } ! if(node instanceof ImportFrom){ ! ImportFrom i = (ImportFrom) node; ! if(isWildImport(i)){ ! makeWildImportToken(i, tokens, moduleName); ! return tokens; ! } ! return makeImportToken((ImportFrom)node, tokens, moduleName, allowForMultiple); ! } ! ! throw new RuntimeException("Unable to create token for the passed import ("+node+")"); } --- 101,117 ---- public static List<IToken> makeImportToken(SimpleNode node, List<IToken> tokens, String moduleName, boolean allowForMultiple) { ! if(node instanceof Import){ ! return makeImportToken((Import)node, tokens, moduleName, allowForMultiple); ! } ! if(node instanceof ImportFrom){ ! ImportFrom i = (ImportFrom) node; ! if(isWildImport(i)){ ! makeWildImportToken(i, tokens, moduleName); ! return tokens; ! } ! return makeImportToken((ImportFrom)node, tokens, moduleName, allowForMultiple); ! } ! ! throw new RuntimeException("Unable to create token for the passed import ("+node+")"); } *************** *** 151,155 **** if(initialImportName.length() > 0){ ! initialImportName = initialImportName+"."; } --- 151,155 ---- if(initialImportName.length() > 0){ ! initialImportName = initialImportName+"."; } *************** *** 237,241 **** */ public static List<IToken> getTokens(SimpleNode ast, int which, String moduleName, ICompletionState state, ! boolean onlyAllowTokensIn__all__) { AbstractVisitor modelVisitor; if(which == INNER_DEFS){ --- 237,241 ---- */ public static List<IToken> getTokens(SimpleNode ast, int which, String moduleName, ICompletionState state, ! boolean onlyAllowTokensIn__all__) { AbstractVisitor modelVisitor; if(which == INNER_DEFS){ *************** *** 257,260 **** --- 257,283 ---- } } + + /** + * This method traverses the ast and returns a model visitor that has the list of found tokens (and other related info, such as __all__, etc.) + */ + public static GlobalModelVisitor getGlobalModuleVisitorWithTokens(SimpleNode ast, int which, String moduleName, ICompletionState state, + boolean onlyAllowTokensIn__all__) { + if(which == INNER_DEFS){ + throw new RuntimeException("Only globals for getting the GlobalModelVisitor"); + } + GlobalModelVisitor modelVisitor = new GlobalModelVisitor(which, moduleName, onlyAllowTokensIn__all__); + + if (ast != null){ + try { + ast.accept(modelVisitor); + } catch (Exception e) { + throw new RuntimeException(e); + } + modelVisitor.finishVisit(); + return modelVisitor; + }else{ + return modelVisitor; + } + } *************** *** 263,269 **** * returned. */ ! protected void finishVisit() { ! /**Empty**/ ! } --- 286,292 ---- * returned. */ ! protected void finishVisit() { ! /**Empty**/ ! } Index: GlobalModelVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/GlobalModelVisitor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GlobalModelVisitor.java 17 Aug 2008 00:26:46 -0000 1.4 --- GlobalModelVisitor.java 28 Sep 2008 12:45:42 -0000 1.5 *************** *** 32,37 **** private SourceToken __all__; private Assign __all__Assign; private Assign lastAssign; ! private boolean onlyAllowTokensIn__all__; /** --- 32,38 ---- private SourceToken __all__; private Assign __all__Assign; + private exprType[] __all__AssignTargets; private Assign lastAssign; ! private boolean onlyAllowTokensIn__all__; /** *************** *** 78,82 **** */ public Object visitAssign(Assign node) throws Exception { ! lastAssign = node; node.traverse(this); return null; --- 79,83 ---- */ public Object visitAssign(Assign node) throws Exception { ! lastAssign = node; node.traverse(this); return null; *************** *** 93,99 **** if (node.ctx == Name.Store) { SourceToken added = addToken(node); ! if(onlyAllowTokensIn__all__ && added.getRepresentation().equals("__all__")){ ! __all__ = added; ! __all__Assign = lastAssign; } } --- 94,107 ---- if (node.ctx == Name.Store) { SourceToken added = addToken(node); ! if(added.getRepresentation().equals("__all__") && __all__Assign == null){ ! __all__ = added; ! __all__Assign = lastAssign; ! __all__AssignTargets = lastAssign.targets; ! } ! }else if(node.ctx == Name.Load){ ! if(node.id.equals("__all__")){ ! //if we find __all__ more than once, let's clear it (we can only have __all__ = list of strings... if later ! //an append, extend, etc is done in it, we have to skip this heuristic). ! __all__AssignTargets = null; } } *************** *** 147,178 **** @Override protected void finishVisit() { ! if(__all__ != null){ ! SimpleNode ast = __all__.getAst(); ! //just checking it ! if(__all__Assign.targets != null && __all__Assign.targets.length == 1 && __all__Assign.targets[0] == ast){ ! HashSet<String> validTokensInAll = new HashSet<String>(); ! exprType value = __all__Assign.value; ! if(value instanceof List){ ! List valueList = (List) value; ! if(valueList.elts != null){ ! for(exprType elt:valueList.elts){ ! if(elt instanceof Str){ ! Str str = (Str) elt; ! validTokensInAll.add(str.s); ! } ! } ! } ! } ! ! if(validTokensInAll.size() > 0){ ! for(Iterator<IToken> it = tokens.iterator();it.hasNext();){ ! IToken tok = it.next(); ! if(!validTokensInAll.contains(tok.getRepresentation())){ ! it.remove(); ! } ! } ! } ! } ! } } } \ No newline at end of file --- 155,198 ---- @Override protected void finishVisit() { ! if(onlyAllowTokensIn__all__){ ! filterAll(this.tokens); ! } ! } ! ! ! /** ! * This method will filter the passed tokens given the __all__ that was found when visiting. ! * ! * @param tokens the tokens to be filtered (IN and OUT parameter) ! */ ! public void filterAll(java.util.List<IToken> tokens) { ! if(__all__ != null){ ! SimpleNode ast = __all__.getAst(); ! //just checking it ! if(__all__AssignTargets != null && __all__AssignTargets.length == 1 && __all__AssignTargets[0] == ast){ ! HashSet<String> validTokensInAll = new HashSet<String>(); ! exprType value = __all__Assign.value; ! if(value instanceof List){ ! List valueList = (List) value; ! if(valueList.elts != null){ ! for(exprType elt:valueList.elts){ ! if(elt instanceof Str){ ! Str str = (Str) elt; ! validTokensInAll.add(str.s); ! } ! } ! } ! } ! ! if(validTokensInAll.size() > 0){ ! for(Iterator<IToken> it = tokens.iterator();it.hasNext();){ ! IToken tok = it.next(); ! if(!validTokensInAll.contains(tok.getRepresentation())){ ! it.remove(); ! } ! } ! } ! } ! } } } \ No newline at end of file Index: KeywordParameterDefinition.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/KeywordParameterDefinition.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** KeywordParameterDefinition.java 12 Apr 2007 17:10:52 -0000 1.1 --- KeywordParameterDefinition.java 28 Sep 2008 12:45:42 -0000 1.2 *************** *** 16,25 **** public class KeywordParameterDefinition extends Definition{ ! public Call call; ! public KeywordParameterDefinition(int line, int col, String value, SimpleNode ast, ILocalScope scope, IModule module, Call call) { ! super(line, col, value, ast, scope, module, false); ! this.call = call; ! } } --- 16,25 ---- public class KeywordParameterDefinition extends Definition{ ! public Call call; ! public KeywordParameterDefinition(int line, int col, String value, SimpleNode ast, ILocalScope scope, IModule module, Call call) { ! super(line, col, value, ast, scope, module, false); ! this.call = call; ! } } Index: HeuristicFindAttrs.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/HeuristicFindAttrs.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** HeuristicFindAttrs.java 18 May 2008 20:02:16 -0000 1.3 --- HeuristicFindAttrs.java 28 Sep 2008 12:45:42 -0000 1.4 *************** *** 102,126 **** public Object visitCall(Call node) throws Exception { if(entryPointCorrect == false && methodCall.length() > 0){ ! entryPointCorrect = true; ! String[] c = StringUtils.dotSplit(methodCall); ! ! ! ! if (node.func instanceof Attribute){ ! Attribute func = (Attribute)node.func; ! if(((NameTok)func.attr).id.equals(c[1])){ ! ! if(func.value instanceof Name){ ! Name name = (Name) func.value; ! if(name.id.equals(c[0])){ ! for (int i=0; i<node.keywords.length; i++){ ! addToken(node.keywords[i]); ! } ! } ! } ! } ! } ! ! entryPointCorrect = false; } return null; --- 102,126 ---- public Object visitCall(Call node) throws Exception { if(entryPointCorrect == false && methodCall.length() > 0){ ! entryPointCorrect = true; ! String[] c = StringUtils.dotSplit(methodCall); ! ! ! ! if (node.func instanceof Attribute){ ! Attribute func = (Attribute)node.func; ! if(((NameTok)func.attr).id.equals(c[1])){ ! ! if(func.value instanceof Name){ ! Name name = (Name) func.value; ! if(name.id.equals(c[0])){ ! for (int i=0; i<node.keywords.length; i++){ ! addToken(node.keywords[i]); ! } ! } ! } ! } ! } ! ! entryPointCorrect = false; } return null; *************** *** 133,147 **** stack.push(node); if(entryPointCorrect == false){ ! entryPointCorrect = true; ! inFuncDef = true; ! ! if(where == WHITIN_ANY){ ! node.traverse(this); ! ! } else if(where == WHITIN_INIT && node.name.equals("__init__")){ ! node.traverse(this); ! } ! entryPointCorrect = false; ! inFuncDef = false; } stack.pop(); --- 133,147 ---- stack.push(node); if(entryPointCorrect == false){ ! entryPointCorrect = true; ! inFuncDef = true; ! ! if(where == WHITIN_ANY){ ! node.traverse(this); ! ! } else if(where == WHITIN_INIT && node.name.equals("__init__")){ ! node.traverse(this); ! } ! entryPointCorrect = false; ! inFuncDef = false; } stack.pop(); *************** *** 181,195 **** }else if(node.targets[i] instanceof Tuple && inFuncDef == false){ ! //that's for finding the definition: a,b,c = range(3) inside a class definition ! Tuple tuple = (Tuple) node.targets[i]; ! for(exprType t :tuple.elts){ ! if(t instanceof Name){ ! String id = ((Name)t).id; ! if(id != null){ ! addToken(t); ! } ! } ! } ! } } --- 181,195 ---- }else if(node.targets[i] instanceof Tuple && inFuncDef == false){ ! //that's for finding the definition: a,b,c = range(3) inside a class definition ! Tuple tuple = (Tuple) node.targets[i]; ! for(exprType t :tuple.elts){ ! if(t instanceof Name){ ! String id = ((Name)t).id; ! if(id != null){ ! addToken(t); ! } ! } ! } ! } } Index: FindScopeVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors/FindScopeVisitor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FindScopeVisitor.java 4 Aug 2007 23:14:59 -0000 1.3 --- FindScopeVisitor.java 28 Sep 2008 12:45:42 -0000 1.4 *************** *** 50,54 **** */ protected FindScopeVisitor(){ ! } --- 50,54 ---- */ protected FindScopeVisitor(){ ! } *************** *** 68,81 **** */ @SuppressWarnings("unchecked") ! protected Object unhandled_node(SimpleNode node) throws Exception { //the line passed in starts at 1 and the lines for the visitor nodes start at 0 if(! found && !(node instanceof Module)){ ! if(line <= node.beginLine ){ ! //scope is locked at this time. ! found = true; ! int original = scope.getIfMainLine(); ! scope = new LocalScope((FastStack<SimpleNode>) this.stackScope.createCopy()); ! scope.setIfMainLine(original); ! } }else{ if(scope.getScopeEndLine() == -1 && line < node.beginLine && col >= node.beginColumn){ --- 68,81 ---- */ @SuppressWarnings("unchecked") ! protected Object unhandled_node(SimpleNode node) throws Exception { //the line passed in starts at 1 and the lines for the visitor nodes start at 0 if(! found && !(node instanceof Module)){ ! if(line <= node.beginLine ){ ! //scope is locked at this time. ! found = true; ! int original = scope.getIfMainLine(); ! scope = new LocalScope((FastStack<SimpleNode>) this.stackScope.createCopy()); ! scope.setIfMainLine(original); ! } }else{ if(scope.getScopeEndLine() == -1 && line < node.beginLine && col >= node.beginColumn){ *************** *** 97,101 **** */ public Object visitIf(If node) throws Exception { ! checkIfMainNode(node); return super.visitIf(node); } --- 97,101 ---- */ public Object visitIf(If node) throws Exception { ! checkIfMainNode(node); return super.visitIf(node); } *************** *** 104,113 **** * Checks if we found an 'if' main node */ ! protected void checkIfMainNode(If node) { ! boolean isIfMainNode = NodeUtils.isIfMAinNode(node); if(isIfMainNode){ scope.setIfMainLine(node.beginLine); } ! } --- 104,113 ---- * Checks if we found an 'if' main node */ ! protected void checkIfMainNode(If node) { ! boolean isIfMainNode = NodeUtils.isIfMAinNode(node); if(isIfMainNode){ scope.setIfMainLine(node.beginLine); } ! } *************** *** 117,123 **** public Object visitClassDef(ClassDef node) throws Exception { if(!found){ ! stackScope.push(node); ! node.traverse(this); ! stackScope.pop(); } return super.visitClassDef(node); --- 117,123 ---- public Object visitClassDef(ClassDef node) throws Exception { if(!found){ ! stackScope.push(node); ! node.traverse(this); ! stackScope.pop(); } return super.visitClassDef(node); *************** *** 129,135 **** public Object visitFunctionDef(FunctionDef node) throws Exception { if(!found){ ! stackScope.push(node); ! node.traverse(this); ! stackScope.pop(); } return super.visitFunctionDef(node); --- 129,135 ---- public Object visitFunctionDef(FunctionDef node) throws Exception { if(!found){ ! stackScope.push(node); ! node.traverse(this); ! stackScope.pop(); } return super.visitFunctionDef(node); |