[Pydev-cvs] org.python.pydev.parser/src/org/python/pydev/parser/visitors FindLastLineVisitor.java,
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-09-27 19:58:54
|
Update of /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/visitors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20472/src/org/python/pydev/parser/visitors Modified Files: FindLastLineVisitor.java NodeUtils.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: NodeUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/visitors/NodeUtils.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** NodeUtils.java 8 Apr 2008 23:05:44 -0000 1.52 --- NodeUtils.java 27 Sep 2008 19:58:42 -0000 1.53 *************** *** 84,101 **** */ private static String discoverRep(Object o){ ! if(o instanceof String){ ! return (String) o; ! } ! if(o instanceof NameTok){ ! return ((NameTok) o).id; ! } ! if(o instanceof SimpleNode){ ! return getRepresentationString((SimpleNode) o); ! } ! throw new RuntimeException("Expecting a String or a SimpleNode"); } public static String getRepresentationString(SimpleNode node) { ! return getRepresentationString(node, false); } --- 84,101 ---- */ private static String discoverRep(Object o){ ! if(o instanceof String){ ! return (String) o; ! } ! if(o instanceof NameTok){ ! return ((NameTok) o).id; ! } ! if(o instanceof SimpleNode){ ! return getRepresentationString((SimpleNode) o); ! } ! throw new RuntimeException("Expecting a String or a SimpleNode"); } public static String getRepresentationString(SimpleNode node) { ! return getRepresentationString(node, false); } *************** *** 148,154 **** String val = "[]"; if(useTypeRepr){ ! val = getBuiltinType(val); } ! return val; } --- 148,154 ---- String val = "[]"; if(useTypeRepr){ ! val = getBuiltinType(val); } ! return val; } *************** *** 156,164 **** String val; if(useTypeRepr){ ! val = getBuiltinType("''"); }else{ val = "'"+((Str)node).s+"'"; } ! return val; } --- 156,164 ---- String val; if(useTypeRepr){ ! val = getBuiltinType("''"); }else{ val = "'"+((Str)node).s+"'"; } ! return val; } *************** *** 177,183 **** String val = "("+buf+")"; if(useTypeRepr){ ! val = getBuiltinType(val); } ! return val; } --- 177,183 ---- String val = "("+buf+")"; if(useTypeRepr){ ! val = getBuiltinType(val); } ! return val; } *************** *** 185,189 **** String val = ((Num)node).n.toString(); if(useTypeRepr){ ! val = getBuiltinType(val); } return val; --- 185,189 ---- String val = ((Num)node).n.toString(); if(useTypeRepr){ ! val = getBuiltinType(val); } return val; *************** *** 221,227 **** */ public static String getNodeDocString(SimpleNode node) { ! Str s = getNodeDocStringNode(node); if(s != null){ ! return s.s; } return null; --- 221,227 ---- */ public static String getNodeDocString(SimpleNode node) { ! Str s = getNodeDocStringNode(node); if(s != null){ ! return s.s; } return null; *************** *** 229,234 **** ! public static Str getNodeDocStringNode(SimpleNode node) { ! Str s = null; stmtType body[] = null; if(node instanceof FunctionDef){ --- 229,234 ---- ! public static Str getNodeDocStringNode(SimpleNode node) { ! Str s = null; stmtType body[] = null; if(node instanceof FunctionDef){ *************** *** 248,253 **** } } ! return s; ! } --- 248,253 ---- } } ! return s; ! } *************** *** 258,265 **** public static String getFullRepresentationString(SimpleNode node, boolean fullOnSubscriptOrCall) { ! if (node instanceof Dict){ ! return "dict"; ! } ! if (node instanceof Str || node instanceof Num){ return getRepresentationString(node, true); --- 258,265 ---- public static String getFullRepresentationString(SimpleNode node, boolean fullOnSubscriptOrCall) { ! if (node instanceof Dict){ ! return "dict"; ! } ! if (node instanceof Str || node instanceof Num){ return getRepresentationString(node, true); *************** *** 285,307 **** if (node instanceof Attribute){ ! //attributes are tricky because we only have backwards access initially, so, we have to: ! ! //get it forwards ! List<SimpleNode> attributeParts = getAttributeParts((Attribute) node); ! StringBuffer buf = new StringBuffer(); ! for (Object part : attributeParts) { ! if(part instanceof Call){ //stop on a call (that's what we usually want, since the end will depend on the things that //return from the call). ! if(!fullOnSubscriptOrCall){ ! return buf.toString(); }else{ buf.append("()");//call } ! ! }else if (part instanceof Subscript){ ! if(!fullOnSubscriptOrCall){ ! //stop on a subscript : e.g.: in bb.cc[10].d we only want the bb.cc part ! return getFullRepresentationString(((Subscript)part).value); }else{ buf.append(getFullRepresentationString(((Subscript)part).value)); --- 285,307 ---- if (node instanceof Attribute){ ! //attributes are tricky because we only have backwards access initially, so, we have to: ! ! //get it forwards ! List<SimpleNode> attributeParts = getAttributeParts((Attribute) node); ! StringBuffer buf = new StringBuffer(); ! for (Object part : attributeParts) { ! if(part instanceof Call){ //stop on a call (that's what we usually want, since the end will depend on the things that //return from the call). ! if(!fullOnSubscriptOrCall){ ! return buf.toString(); }else{ buf.append("()");//call } ! ! }else if (part instanceof Subscript){ ! if(!fullOnSubscriptOrCall){ ! //stop on a subscript : e.g.: in bb.cc[10].d we only want the bb.cc part ! return getFullRepresentationString(((Subscript)part).value); }else{ buf.append(getFullRepresentationString(((Subscript)part).value)); *************** *** 309,322 **** } ! }else{ ! //otherwise, just add another dot and keep going. ! if(buf.length() > 0){ ! buf.append("."); ! } ! buf.append(getRepresentationString((SimpleNode) part, true)); ! } ! } ! return buf.toString(); ! } --- 309,322 ---- } ! }else{ ! //otherwise, just add another dot and keep going. ! if(buf.length() > 0){ ! buf.append("."); ! } ! buf.append(getRepresentationString((SimpleNode) part, true)); ! } ! } ! return buf.toString(); ! } *************** *** 329,354 **** */ public static boolean isWithin(int line, int col, SimpleNode node){ ! int colDefinition = NodeUtils.getColDefinition(node); ! int lineDefinition = NodeUtils.getLineDefinition(node); ! int[] colLineEnd = NodeUtils.getColLineEnd(node, false); ! ! if(lineDefinition <= line && colDefinition <= col && ! colLineEnd[0] >= line && colLineEnd[1] >= col){ ! return true; ! } ! return false; } public static SimpleNode getNameTokFromNode(SimpleNode ast2){ ! if (ast2 instanceof ClassDef){ ! ClassDef c = (ClassDef) ast2; ! return c.name; ! } ! if (ast2 instanceof FunctionDef){ ! FunctionDef c = (FunctionDef) ast2; ! return c.name; ! } ! return ast2; ! } --- 329,354 ---- */ public static boolean isWithin(int line, int col, SimpleNode node){ ! int colDefinition = NodeUtils.getColDefinition(node); ! int lineDefinition = NodeUtils.getLineDefinition(node); ! int[] colLineEnd = NodeUtils.getColLineEnd(node, false); ! ! if(lineDefinition <= line && colDefinition <= col && ! colLineEnd[0] >= line && colLineEnd[1] >= col){ ! return true; ! } ! return false; } public static SimpleNode getNameTokFromNode(SimpleNode ast2){ ! if (ast2 instanceof ClassDef){ ! ClassDef c = (ClassDef) ast2; ! return c.name; ! } ! if (ast2 instanceof FunctionDef){ ! FunctionDef c = (FunctionDef) ast2; ! return c.name; ! } ! return ast2; ! } *************** *** 418,423 **** ! public static int getClassOrFuncColDefinition(SimpleNode ast2) { ! if(ast2 instanceof ClassDef){ ClassDef def = (ClassDef) ast2; return def.name.beginColumn; --- 418,423 ---- ! public static int getClassOrFuncColDefinition(SimpleNode ast2) { ! if(ast2 instanceof ClassDef){ ClassDef def = (ClassDef) ast2; return def.name.beginColumn; *************** *** 428,436 **** } return ast2.beginColumn; ! } public static int[] getColLineEnd(SimpleNode v) { ! return getColLineEnd(v, true); } --- 428,436 ---- } return ast2.beginColumn; ! } public static int[] getColLineEnd(SimpleNode v) { ! return getColLineEnd(v, true); } *************** *** 480,487 **** if(getOnlyToFirstDot){ ! int i; ! if((i = representationString.indexOf('.') ) != -1){ ! representationString = representationString.substring(0,i); ! } } --- 480,487 ---- if(getOnlyToFirstDot){ ! int i; ! if((i = representationString.indexOf('.') ) != -1){ ! representationString = representationString.substring(0,i); ! } } *************** *** 591,619 **** * in the grammar. */ ! public static List<SimpleNode> getAttributeParts(Attribute node) { ! ArrayList<SimpleNode> nodes = new ArrayList<SimpleNode>(); ! ! nodes.add(node.attr); ! SimpleNode s = node.value; ! ! while(true){ ! if(s instanceof Attribute){ ! nodes.add(s); ! s = ((Attribute) s).value; ! ! }else if(s instanceof Call){ ! nodes.add(s); ! s = ((Call) s).func; ! ! }else{ ! nodes.add(s); ! break; ! } ! } ! ! Collections.reverse(nodes); ! ! return nodes; ! } --- 591,619 ---- * in the grammar. */ ! public static List<SimpleNode> getAttributeParts(Attribute node) { ! ArrayList<SimpleNode> nodes = new ArrayList<SimpleNode>(); ! ! nodes.add(node.attr); ! SimpleNode s = node.value; ! ! while(true){ ! if(s instanceof Attribute){ ! nodes.add(s); ! s = ((Attribute) s).value; ! ! }else if(s instanceof Call){ ! nodes.add(s); ! s = ((Call) s).func; ! ! }else{ ! nodes.add(s); ! break; ! } ! } ! ! Collections.reverse(nodes); ! ! return nodes; ! } *************** *** 640,680 **** * @return true if the node is an import node (and false otherwise). */ ! public static boolean isImport(SimpleNode ast) { if(ast instanceof Import || ast instanceof ImportFrom){ return true; } return false; ! } /** * @return true if the node is a comment import node (and false otherwise). */ ! public static boolean isComment(SimpleNode ast) { if(ast instanceof commentType) { return true; } return false; ! } ! public static NameTok getNameForAlias(aliasType t) { ! if(t.asname != null){ ! return (NameTok) t.asname; ! }else{ ! return (NameTok) t.name; ! } ! } ! public static NameTok getNameForRep(aliasType[] names, String representation) { ! for (aliasType name : names) { ! NameTok nameForAlias = getNameForAlias(name); ! String aliasRep = NodeUtils.getRepresentationString(nameForAlias); ! if(representation.equals(aliasRep)){ ! return nameForAlias; ! } ! } ! return null; ! } --- 640,680 ---- * @return true if the node is an import node (and false otherwise). */ ! public static boolean isImport(SimpleNode ast) { if(ast instanceof Import || ast instanceof ImportFrom){ return true; } return false; ! } /** * @return true if the node is a comment import node (and false otherwise). */ ! public static boolean isComment(SimpleNode ast) { if(ast instanceof commentType) { return true; } return false; ! } ! public static NameTok getNameForAlias(aliasType t) { ! if(t.asname != null){ ! return (NameTok) t.asname; ! }else{ ! return (NameTok) t.name; ! } ! } ! public static NameTok getNameForRep(aliasType[] names, String representation) { ! for (aliasType name : names) { ! NameTok nameForAlias = getNameForAlias(name); ! String aliasRep = NodeUtils.getRepresentationString(nameForAlias); ! if(representation.equals(aliasRep)){ ! return nameForAlias; ! } ! } ! return null; ! } *************** *** 718,722 **** } } ! return null; } --- 718,722 ---- } } ! return null; } *************** *** 752,771 **** public static boolean isIfMAinNode(If node) { if (node.test instanceof Compare) { ! Compare compareNode = (Compare)node.test; ! // handcrafted structure walking ! if (compareNode.left instanceof Name ! && ((Name)compareNode.left).id.equals("__name__") ! && compareNode.ops != null ! && compareNode.ops.length == 1 ! && compareNode.ops[0] == Compare.Eq){ ! if ( compareNode.comparators != null ! && compareNode.comparators.length == 1 ! && compareNode.comparators[0] instanceof Str ! && ((Str)compareNode.comparators[0]).s.equals("__main__")){ ! return true; } ! } ! } return false; } --- 752,771 ---- public static boolean isIfMAinNode(If node) { if (node.test instanceof Compare) { ! Compare compareNode = (Compare)node.test; ! // handcrafted structure walking ! if (compareNode.left instanceof Name ! && ((Name)compareNode.left).id.equals("__name__") ! && compareNode.ops != null ! && compareNode.ops.length == 1 ! && compareNode.ops[0] == Compare.Eq){ ! if ( compareNode.comparators != null ! && compareNode.comparators.length == 1 ! && compareNode.comparators[0] instanceof Str ! && ((Str)compareNode.comparators[0]).s.equals("__main__")){ ! return true; } ! } ! } return false; } Index: FindLastLineVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/visitors/FindLastLineVisitor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FindLastLineVisitor.java 28 Feb 2007 19:29:20 -0000 1.2 --- FindLastLineVisitor.java 27 Sep 2008 19:58:42 -0000 1.3 *************** *** 24,32 **** @Override public Object visitAttribute(Attribute node) throws Exception { ! check(node.specialsBefore); ! if (node.attr != null) ! node.attr.accept(this); if (node.value != null) ! node.value.accept(this); check(node.specialsAfter); return null; --- 24,32 ---- @Override public Object visitAttribute(Attribute node) throws Exception { ! check(node.specialsBefore); ! if (node.attr != null) ! node.attr.accept(this); if (node.value != null) ! node.value.accept(this); check(node.specialsAfter); return null; |