pydev-cvs Mailing List for PyDev for Eclipse (Page 11)
Brought to you by:
fabioz
You can subscribe to this list here.
2004 |
Jan
|
Feb
(4) |
Mar
(48) |
Apr
(56) |
May
(64) |
Jun
(27) |
Jul
(66) |
Aug
(81) |
Sep
(148) |
Oct
(194) |
Nov
(78) |
Dec
(46) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(125) |
Feb
(126) |
Mar
(163) |
Apr
(133) |
May
(115) |
Jun
(307) |
Jul
(387) |
Aug
(417) |
Sep
(283) |
Oct
(148) |
Nov
(45) |
Dec
(53) |
2006 |
Jan
(240) |
Feb
(200) |
Mar
(267) |
Apr
(231) |
May
(245) |
Jun
(361) |
Jul
(142) |
Aug
(12) |
Sep
(210) |
Oct
(99) |
Nov
(7) |
Dec
(30) |
2007 |
Jan
(161) |
Feb
(511) |
Mar
(265) |
Apr
(74) |
May
(147) |
Jun
(151) |
Jul
(94) |
Aug
(68) |
Sep
(98) |
Oct
(144) |
Nov
(26) |
Dec
(36) |
2008 |
Jan
(98) |
Feb
(107) |
Mar
(199) |
Apr
(113) |
May
(119) |
Jun
(112) |
Jul
(92) |
Aug
(71) |
Sep
(101) |
Oct
(16) |
Nov
|
Dec
|
From: Fabio Z. <fa...@us...> - 2008-07-06 21:58:00
|
Update of /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7754/src/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParser.java Log Message: Changes in the ParsingUtils interface (creating correct version with factory to properly adapt to the object being read). Index: FastDefinitionsParser.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser/FastDefinitionsParser.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FastDefinitionsParser.java 6 Jul 2008 13:10:42 -0000 1.5 --- FastDefinitionsParser.java 6 Jul 2008 21:58:08 -0000 1.6 *************** *** 117,120 **** --- 117,121 ---- currIndex=0; } + ParsingUtils parsingUtils = ParsingUtils.create(cs); for (;currIndex < length; currIndex++, col++) { *************** *** 129,133 **** } //go to the end of the literal ! currIndex = ParsingUtils.getLiteralEnd(cs, currIndex, c); break; --- 130,134 ---- } //go to the end of the literal ! currIndex = parsingUtils.getLiteralEnd(currIndex, c); break; *************** *** 165,169 **** case '(': //starting some call, dict, list, tuple... those don't count on getting some actual definition ! currIndex = ParsingUtils.eatPar(cs, currIndex, null, c); break; --- 166,170 ---- case '(': //starting some call, dict, list, tuple... those don't count on getting some actual definition ! currIndex = parsingUtils.eatPar(currIndex, null, c); break; |
Update of /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/refactor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6994/PySrc/ThirdParty/brm/bike/refactor Modified Files: rename.py inlineVariable.py extractVariable.py utils.py extractMethod.py moveToModule.py Log Message: Added tags to ignore pydev code analysis. Index: inlineVariable.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/refactor/inlineVariable.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** inlineVariable.py 14 Sep 2004 17:42:08 -0000 1.1 --- inlineVariable.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from bike.query.findDefinition import findAllPossibleDefinitionsByCoords from bike.query.findReferences import findReferences Index: extractVariable.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/refactor/extractVariable.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** extractVariable.py 14 Sep 2004 17:42:08 -0000 1.1 --- extractVariable.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from bike.parsing.parserutils import maskStringsAndRemoveComments from bike.transformer.undo import getUndoStack Index: moveToModule.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/refactor/moveToModule.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** moveToModule.py 14 Sep 2004 17:42:08 -0000 1.1 --- moveToModule.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore import bike.globals from bike.parsing.load import getSourceNode Index: extractMethod.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/refactor/extractMethod.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** extractMethod.py 14 Sep 2004 17:42:08 -0000 1.1 --- extractMethod.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore import re import compiler Index: utils.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/refactor/utils.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** utils.py 14 Sep 2004 17:42:08 -0000 1.1 --- utils.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore import re Index: rename.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/refactor/rename.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** rename.py 14 Sep 2004 17:42:08 -0000 1.1 --- rename.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from bike.transformer.WordRewriter import WordRewriter from bike.query.findReferences import findReferencesIncludingDefn |
From: Fabio Z. <fa...@us...> - 2008-07-06 21:56:44
|
Update of /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6994/PySrc/ThirdParty/brm/bike Modified Files: bikefacade.py Log Message: Added tags to ignore pydev code analysis. Index: bikefacade.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/bikefacade.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** bikefacade.py 14 Jan 2008 10:06:03 -0000 1.2 --- bikefacade.py 6 Jul 2008 21:56:50 -0000 1.3 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore import os import sys |
From: Fabio Z. <fa...@us...> - 2008-07-06 21:56:44
|
Update of /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/transformer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6994/PySrc/ThirdParty/brm/bike/transformer Modified Files: WordRewriter.py save.py undo.py Log Message: Added tags to ignore pydev code analysis. Index: WordRewriter.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/transformer/WordRewriter.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WordRewriter.py 14 Sep 2004 17:42:14 -0000 1.1 --- WordRewriter.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from bike.parsing.load import getSourceNode from bike.transformer.undo import getUndoStack Index: save.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/transformer/save.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** save.py 14 Sep 2004 17:42:14 -0000 1.1 --- save.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from bike import log Index: undo.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/transformer/undo.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** undo.py 14 Sep 2004 17:42:14 -0000 1.1 --- undo.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from bike import log from bike.transformer.save import queueFileToSave |
From: Fabio Z. <fa...@us...> - 2008-07-06 21:56:44
|
Update of /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/parsing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6994/PySrc/ThirdParty/brm/bike/parsing Modified Files: newstuff.py parserutils.py load.py pathutils.py fastparser.py fastparserast.py Log Message: Added tags to ignore pydev code analysis. Index: fastparserast.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/parsing/fastparserast.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fastparserast.py 14 Sep 2004 17:42:07 -0000 1.1 --- fastparserast.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from __future__ import generators from parserutils import generateLogicalLines, maskStringsAndComments, maskStringsAndRemoveComments Index: pathutils.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/parsing/pathutils.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pathutils.py 14 Sep 2004 17:42:07 -0000 1.1 --- pathutils.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore # A some of this code is take from Pythius - Index: parserutils.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/parsing/parserutils.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** parserutils.py 1 Dec 2004 16:59:13 -0000 1.2 --- parserutils.py 6 Jul 2008 21:56:51 -0000 1.3 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from __future__ import generators import re Index: newstuff.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/parsing/newstuff.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** newstuff.py 14 Sep 2004 17:42:07 -0000 1.1 --- newstuff.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from __future__ import generators # Holding module for scaffolding needed to transition parsing package Index: fastparser.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/parsing/fastparser.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fastparser.py 14 Sep 2004 17:42:07 -0000 1.1 --- fastparser.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore #!/usr/bin/env python from bike.parsing.fastparserast import * Index: load.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/parsing/load.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** load.py 1 Dec 2004 16:59:13 -0000 1.2 --- load.py 6 Jul 2008 21:56:51 -0000 1.3 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from bike.globals import * import os |
Update of /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6994/PySrc/ThirdParty/brm/bike/query Modified Files: findReferences.py relationships.py findDefinition.py common.py getReferencesToModule.py getTypeOf.py Log Message: Added tags to ignore pydev code analysis. Index: findDefinition.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query/findDefinition.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** findDefinition.py 14 Sep 2004 17:42:08 -0000 1.1 --- findDefinition.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from __future__ import generators from bike.query.common import Match, MatchFinder, \ Index: findReferences.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query/findReferences.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** findReferences.py 14 Jan 2008 10:06:03 -0000 1.2 --- findReferences.py 6 Jul 2008 21:56:51 -0000 1.3 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from __future__ import generators from bike.globals import * Index: relationships.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query/relationships.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** relationships.py 14 Sep 2004 17:42:08 -0000 1.1 --- relationships.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore # queries to do with module/class/function relationships from __future__ import generators Index: common.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query/common.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** common.py 17 Sep 2004 19:22:02 -0000 1.3 --- common.py 6 Jul 2008 21:56:51 -0000 1.4 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from __future__ import generators from bike.globals import * Index: getReferencesToModule.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query/getReferencesToModule.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** getReferencesToModule.py 14 Sep 2004 17:42:08 -0000 1.1 --- getReferencesToModule.py 6 Jul 2008 21:56:51 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore from __future__ import generators from bike.query.common import Match, globalScanForMatches, getScopeForLine, MatchFinder Index: getTypeOf.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query/getTypeOf.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** getTypeOf.py 17 Sep 2004 19:22:03 -0000 1.2 --- getTypeOf.py 6 Jul 2008 21:56:51 -0000 1.3 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore # getTypeOf(scope,fqn) and getTypeOfExpr(scope,ast) |
From: Fabio Z. <fa...@us...> - 2008-07-06 17:10:31
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29951/src/org/python/pydev/core/docutils Modified Files: ParsingUtils.java Log Message: Minor changes in parsing utilities (removed unused methods / minor refactorings) Index: ParsingUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ParsingUtils.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ParsingUtils.java 5 Jul 2008 21:53:05 -0000 1.22 --- ParsingUtils.java 6 Jul 2008 17:10:39 -0000 1.23 *************** *** 14,36 **** ! public class ParsingUtils implements IPythonPartitions{ - /** - * @param cs the char array we are parsing - * @param buf used to add the comments contents (out) - * @param i the position - * @return the : position - */ - public static int eatToColon(char[] cs, FastStringBuffer buf, int i) { - while(i < cs.length && cs[i] != ':'){ - buf.append(cs[i]); - i++; - } - if(i < cs.length) - buf.append(cs[i]); - - return i; - } /** --- 14,24 ---- ! /** ! * Helper class for parsing python code. ! * ! * @author Fabio ! */ public class ParsingUtils implements IPythonPartitions{ /** *************** *** 42,53 **** */ public static int eatComments(Object cs, FastStringBuffer buf, int i) { ! while(i < len(cs) && charAt(cs,i) != '\n' && charAt(cs,i) != '\r'){ if(buf != null){ ! buf.append(charAt(cs,i)); } i++; } ! if(i < len(cs)){ if(buf != null){ buf.append(charAt(cs,i)); --- 30,44 ---- */ public static int eatComments(Object cs, FastStringBuffer buf, int i) { ! int len = len(cs); ! char c; ! ! while(i < len && (c = charAt(cs,i)) != '\n' && c != '\r'){ if(buf != null){ ! buf.append(c); } i++; } ! if(i < len){ if(buf != null){ buf.append(charAt(cs,i)); *************** *** 58,91 **** } - /** - * @param cs the char array we are parsing - * @param buf used to add the comments contents (out) - * @param i the # position - * @return the end of the comments position (end of document or new line char) - */ - public static int eatComments(char[] cs, int i) { - while(i < cs.length && cs[i] != '\n' && cs[i] != '\r'){ - i++; - } - - return i; - } - - /** - * @param cs the char array we are parsing - * @param buf used to add the token contents (out) - * @param i the start of the token - * @return the end of the token position (end of document or new line char or whitespace) - */ - public static int eatToken(char[] cs, FastStringBuffer buf, int i) { - while(i < cs.length && !Character.isWhitespace(cs[i])){ - buf.append(cs[i]); - i++; - } - if(i < cs.length) - buf.append(cs[i]); - - return i; - } /** --- 49,52 ---- *************** *** 107,111 **** if(buf != null){ ! for (int k = i; k < len(cs) && k <= j; k++) { buf.append(charAt(cs, k)); } --- 68,73 ---- if(buf != null){ ! int len = len(cs); ! for (int k = i; k < len && k <= j; k++) { buf.append(charAt(cs, k)); } *************** *** 152,156 **** int j = i+1; ! while(j < len(cs) && (c = charAt(cs,j)) != closingPar){ j++; --- 114,119 ---- int j = i+1; ! int len = len(cs); ! while(j < len && (c = charAt(cs,j)) != closingPar){ j++; *************** *** 180,184 **** public static int findNextSingle(Object cs, int i, char curr) { boolean ignoreNext = false; ! while(i < len(cs)){ char c = charAt(cs,i); --- 143,148 ---- public static int findNextSingle(Object cs, int i, char curr) { boolean ignoreNext = false; ! int len = len(cs); ! while(i < len){ char c = charAt(cs,i); *************** *** 205,209 **** */ public static int findNextMulti(Object cs, int i, char curr) { ! while(i+2 < len(cs)){ char c = charAt(cs,i); if (c == curr && charAt(cs,i+1) == curr && charAt(cs,i+2) == curr){ --- 169,174 ---- */ public static int findNextMulti(Object cs, int i, char curr) { ! int len = len(cs); ! while(i+2 < len){ char c = charAt(cs,i); if (c == curr && charAt(cs,i+1) == curr && charAt(cs,i+2) == curr){ *************** *** 215,220 **** } } ! if(len(cs) < i+2){ ! return len(cs); } return i+2; --- 180,185 ---- } } ! if(len < i+2){ ! return len; } return i+2; *************** *** 271,275 **** */ public static boolean isMultiLiteral(Object cs, int i, char curr){ ! if(len(cs) <= i + 2){ return false; } --- 236,241 ---- */ public static boolean isMultiLiteral(Object cs, int i, char curr){ ! int len = len(cs); ! if(len <= i + 2){ return false; } *************** *** 280,296 **** } - public static int eatWhitespaces(char cs[], int i) { - while(i < cs.length && Character.isWhitespace(cs[i])){ - i++; - } - return i; - } - - public static int eatWhitespaces(FastStringBuffer buf, int i) { - while(i < buf.length() && Character.isWhitespace(buf.charAt(i))){ - i++; - } - return i; - } public static void removeCommentsWhitespacesAndLiterals(FastStringBuffer buf) { --- 246,249 ---- *************** *** 390,407 **** } - public static void removeToClosingPar(FastStringBuffer buf) { - int length = buf.length(); - for (int i = length -1; i >= 0; i--) { - char ch = buf.charAt(i); - if(ch != ')'){ - buf.deleteCharAt(i); - }else{ - buf.deleteCharAt(i); - return; - - } - } - } - /** --- 343,346 ---- *************** *** 539,557 **** } - public static String getLastLine(String code) { - int i = code.lastIndexOf('\r'); - int j = code.lastIndexOf('\n'); - if(i == -1 && j == -1){ - return code; - } - - char toSplit = '\n'; - if(i > j){ - toSplit = '\r'; - } - - String[] strings = StringUtils.split(code, toSplit); - return strings[strings.length-1]; - } public static String removeComments(String line) { --- 478,481 ---- |
From: Fabio Z. <fa...@us...> - 2008-07-06 14:11:33
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27663/src/org/python/pydev/core Modified Files: REF.java Log Message: Changes in REF so that we can get the contents available in a suitable format / Using FastDefinitionsParser for gathering global definitions Index: REF.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/REF.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** REF.java 28 Jun 2008 12:35:47 -0000 1.40 --- REF.java 6 Jul 2008 14:11:40 -0000 1.41 *************** *** 38,45 **** import org.eclipse.core.filebuffers.ITextFileBufferManager; import org.eclipse.core.filebuffers.LocationKind; - import org.eclipse.core.internal.resources.ResourceException; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; --- 38,45 ---- import org.eclipse.core.filebuffers.ITextFileBufferManager; import org.eclipse.core.filebuffers.LocationKind; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; *************** *** 52,55 **** --- 52,56 ---- import org.eclipse.osgi.service.environment.Constants; import org.python.pydev.core.log.Log; + import org.python.pydev.core.structure.FastStringBuffer; *************** *** 59,62 **** --- 60,67 ---- public class REF { + + /** + * @return true if the passed object has a field with the name passed. + */ public static boolean hasAttr(Object o, String attr){ try { *************** *** 70,74 **** } ! public static Field getAttrFromClass(Class c, String attr){ try { return c.getDeclaredField(attr); --- 75,83 ---- } ! ! /** ! * @return the field from a class that matches the passed attr name (or null if it couldn't be found) ! */ ! public static Field getAttrFromClass(Class<? extends Object> c, String attr){ try { return c.getDeclaredField(attr); *************** *** 79,82 **** --- 88,96 ---- } + + /** + * @return the field from a class that matches the passed attr name (or null if it couldn't be found) + * @see #getAttrObj(Object, String) to get the actual value of the field. + */ public static Field getAttr(Object o, String attr){ try { *************** *** 88,91 **** --- 102,109 ---- } + + /** + * @return the value of some attribute in the given object + */ public static Object getAttrObj(Object o, String attr){ try { *************** *** 109,113 **** try { stream = new FileInputStream(file); ! return getStreamContents(stream, null, null); } catch (Exception e) { throw new RuntimeException(e); --- 127,131 ---- try { stream = new FileInputStream(file); ! return (String) getStreamContents(stream, null, null, String.class); } catch (Exception e) { throw new RuntimeException(e); *************** *** 119,128 **** /** * Get the contents from a given stream. */ ! public static String getStreamContents(InputStream contentStream, String encoding, IProgressMonitor monitor) throws IOException { Reader in= null; try{ final int DEFAULT_FILE_SIZE= 15 * 1024; if (encoding == null){ in= new BufferedReader(new InputStreamReader(contentStream), DEFAULT_FILE_SIZE); --- 137,156 ---- /** * Get the contents from a given stream. + * @param returnType the class that specifies the return type of this method. + * If null, it'll return in the fastest possible way available. + * Valid options are: + * String.class + * IDocument.class + * FastStringBuffer.class + * */ ! private static Object getStreamContents(InputStream contentStream, String encoding, IProgressMonitor monitor, ! Class<? extends Object> returnType) throws IOException { ! Reader in= null; try{ final int DEFAULT_FILE_SIZE= 15 * 1024; + //discover how to actually read the passed input stream. if (encoding == null){ in= new BufferedReader(new InputStreamReader(contentStream), DEFAULT_FILE_SIZE); *************** *** 137,151 **** } ! StringBuffer buffer= new StringBuffer(DEFAULT_FILE_SIZE); char[] readBuffer= new char[2048]; int n= in.read(readBuffer); while (n > 0) { ! if (monitor != null && monitor.isCanceled()) return null; buffer.append(readBuffer, 0, n); ! n= in.read(readBuffer); } ! return buffer.toString(); }finally{ --- 165,197 ---- } ! //fill a buffer with the contents ! FastStringBuffer buffer= new FastStringBuffer(DEFAULT_FILE_SIZE); char[] readBuffer= new char[2048]; int n= in.read(readBuffer); while (n > 0) { ! if (monitor != null && monitor.isCanceled()){ return null; + } buffer.append(readBuffer, 0, n); ! n = in.read(readBuffer); } ! ! ! //return it in the way specified by the user ! if(returnType == null || returnType == FastStringBuffer.class){ ! return buffer; ! ! }else if(returnType == IDocument.class){ ! Document doc = new Document(buffer.toString()); ! return doc; ! ! }else if(returnType == String.class){ ! return buffer.toString(); ! ! }else{ ! throw new RuntimeException("Don't know how to handle return type: "+returnType); ! } ! }finally{ *************** *** 153,156 **** --- 199,204 ---- } } + + /** * @param o the object we want as a string *************** *** 171,174 **** --- 219,225 ---- } + /** + * @return the contents of the passed ByteArrayOutputStream as a byte[] encoded with base64. + */ public static byte[] encodeBase64(ByteArrayOutputStream out) { byte[] byteArray = out.toByteArray(); *************** *** 176,209 **** } public static byte[] encodeBase64(byte[] byteArray) { return Base64.encodeBase64(byteArray); } /** - * * @param persisted the base64 string that should be converted to an object. ! * @param readFromFileMethod should be the calback from the plugin that is calling this function * * * The callback should be something as: ! ! new ICallback<Object, ObjectInputStream>(){ ! ! public Object call(ObjectInputStream arg) { ! try { ! return arg.readObject(); ! } catch (IOException e) { ! throw new RuntimeException(e); ! } catch (ClassNotFoundException e) { ! throw new RuntimeException(e); ! } ! }}; ! * ! * @return ! * @throws IOException ! * @throws ClassNotFoundException */ ! public static Object getStrAsObj(String persisted, ICallback<Object, ObjectInputStream> readFromFileMethod) throws IOException, ClassNotFoundException { InputStream input = new ByteArrayInputStream(decodeBase64(persisted)); Object o = readFromInputStreamAndCloseIt(readFromFileMethod, input); --- 227,264 ---- } + + /** + * @return the contents of the passed byteArray[] as a byte[] encoded with base64. + */ public static byte[] encodeBase64(byte[] byteArray) { return Base64.encodeBase64(byteArray); } + /** * @param persisted the base64 string that should be converted to an object. ! * @param readFromFileMethod should be the calback from the plugin that is calling this function (this is needed ! * because from one plugin we cannot load the contents of objects defined in another plugin) * * * The callback should be something as: ! * ! * new ICallback<Object, ObjectInputStream>(){ ! * ! * public Object call(ObjectInputStream arg) { ! * try { ! * return arg.readObject(); ! * } catch (IOException e) { ! * throw new RuntimeException(e); ! * } catch (ClassNotFoundException e) { ! * throw new RuntimeException(e); ! * } ! * }}; * ! * @return the object that was previously serialized in the passed base64 string. */ ! public static Object getStrAsObj(String persisted, ICallback<Object, ObjectInputStream> readFromFileMethod) ! throws IOException, ClassNotFoundException { ! InputStream input = new ByteArrayInputStream(decodeBase64(persisted)); Object o = readFromInputStreamAndCloseIt(readFromFileMethod, input); *************** *** 212,221 **** /** ! * @param readFromFileMethod ! * @param input ! * @return ! * @throws IOException */ ! public static Object readFromInputStreamAndCloseIt(ICallback<Object, ObjectInputStream> readFromFileMethod, InputStream input) { ObjectInputStream in = null; Object o = null; --- 267,280 ---- /** ! * This method loads the contents of an object that was serialized. ! * ! * @param readFromFileMethod: see {@link #getStrAsObj(String, ICallback)} ! * @param input is the input stream that contains the serialized object ! * ! * @return the object that was previously serialized in the passed input stream. */ ! public static Object readFromInputStreamAndCloseIt(ICallback<Object, ObjectInputStream> readFromFileMethod, ! InputStream input) { ! ObjectInputStream in = null; Object o = null; *************** *** 236,247 **** } public static byte[] decodeBase64(String persisted) { return Base64.decodeBase64(persisted.getBytes()); } - public static void writeStrToFile(String str, String file) { - writeStrToFile(str, new File(file)); - } public static void appendStrToFile(String str, String file) { try { --- 295,310 ---- } + + /** + * Decodes some string that was encoded as base64 + */ public static byte[] decodeBase64(String persisted) { return Base64.decodeBase64(persisted.getBytes()); } + /** + * Appends the contents of the passed string to the given file. + */ public static void appendStrToFile(String str, String file) { try { *************** *** 259,262 **** --- 322,336 ---- } + /** + * Writes the contents of the passed string to the given file. + */ + public static void writeStrToFile(String str, String file) { + writeStrToFile(str, new File(file)); + } + + + /** + * Writes the contents of the passed string to the given file. + */ public static void writeStrToFile(String str, File file) { try { *************** *** 276,281 **** /** ! * @param file ! * @param astManager */ public static void writeToFile(Object o, File file) { --- 350,354 ---- /** ! * Writes the contents of the passed string to the given file. */ public static void writeToFile(Object o, File file) { *************** *** 289,296 **** /** * @param o the object to be written to some stream * @param out the output stream to be used - * - * @throws IOException */ public static void writeToStreamAndCloseIt(Object o, OutputStream out) throws IOException { --- 362,369 ---- /** + * Serializes some object to the given stream + * * @param o the object to be written to some stream * @param out the output stream to be used */ public static void writeToStreamAndCloseIt(Object o, OutputStream out) throws IOException { *************** *** 317,321 **** /** ! * Reads some object from a file * @param file the file from where we should read * @return the object that was read (or null if some error happened while reading) --- 390,398 ---- /** ! * Reads some object from a file (an object that was previously serialized) ! * ! * Important: can only deserialize objects that are defined in this plugin -- ! * see {@link #getStrAsObj(String, ICallback)} if you want to deserialize objects defined in another plugin. ! * * @param file the file from where we should read * @return the object that was read (or null if some error happened while reading) *************** *** 342,346 **** } ! public static String getFileAbsolutePath(String f) { return getFileAbsolutePath(new File(f)); --- 419,429 ---- } ! /** ! * Get the absolute path in the filesystem for the given file. ! * ! * @param f the file we're interested in ! * ! * @return the absolute (canonical) path to the file ! */ public static String getFileAbsolutePath(String f) { return getFileAbsolutePath(new File(f)); *************** *** 348,353 **** /** ! * @param f the file we're interested in ! * @return the absolute (canonical) path to the file */ public static String getFileAbsolutePath(File f) { --- 431,435 ---- /** ! * @see #getFileAbsolutePath(String) */ public static String getFileAbsolutePath(File f) { *************** *** 359,362 **** --- 441,445 ---- } + /** * Calls a method for an object *************** *** 366,369 **** --- 449,454 ---- * @param args the arguments received for the call * @return the return of the method + * + * @throws RuntimeException if the object could not be invoked */ public static Object invoke(Object obj, String name, Object... args) { *************** *** 375,378 **** --- 460,466 ---- + /** + * @see #invoke(Object, String, Object...) + */ public static Object invoke(Object obj, Method m, Object... args) { try { *************** *** 383,400 **** } public static Method findMethod(Object obj, String name, Object... args) { return findMethod(obj.getClass(), name, args); } ! public static Method findMethod(Class class_, String name, Object... args) { try { Method[] methods = class_.getMethods(); for (Method method : methods) { ! Class[] parameterTypes = method.getParameterTypes(); if(method.getName().equals(name) && parameterTypes.length == args.length){ //check the parameters int i = 0; ! for (Class param : parameterTypes) { if(!param.isInstance(args[i])){ continue; --- 471,498 ---- } + + /** + * @return a method that has the given name and arguments + * @throws RuntimeException if the method could not be found + */ public static Method findMethod(Object obj, String name, Object... args) { return findMethod(obj.getClass(), name, args); } + ! /** ! * @return a method that has the given name and arguments ! * @throws RuntimeException if the method could not be found ! */ ! public static Method findMethod(Class<? extends Object> class_, String name, Object... args) { try { Method[] methods = class_.getMethods(); for (Method method : methods) { ! Class<? extends Object>[] parameterTypes = method.getParameterTypes(); if(method.getName().equals(name) && parameterTypes.length == args.length){ //check the parameters int i = 0; ! for (Class<? extends Object> param : parameterTypes) { if(!param.isInstance(args[i])){ continue; *************** *** 409,415 **** throw new RuntimeException(e); } ! throw new RuntimeException("The method with name: "+name+" was not found (or maybe it was found but the parameters didn't match)."); } public static char [] INVALID_FILESYSTEM_CHARS = { '!', '@', '#', '$', '%', '^', '&', '*', --- 507,517 ---- throw new RuntimeException(e); } ! throw new RuntimeException("The method with name: "+name+ ! " was not found (or maybe it was found but the parameters didn't match)."); } + /** + * Characters that files in the filesystem cannot have. + */ public static char [] INVALID_FILESYSTEM_CHARS = { '!', '@', '#', '$', '%', '^', '&', '*', *************** *** 417,422 **** --- 519,531 ---- '.', ' ', '`', '~', '\'', '"', ',', ';'}; + /** + * Determines if we're in tests: When in tests, some warnings may be supressed. + */ public static boolean IN_TESTS = false; + + /** + * @return a valid name for a project so that the returned name can be used to create a file in the filesystem + */ public static String getValidProjectName(IProject project) { String name = project.getName(); *************** *** 430,434 **** /** ! * Makes an equal comparisson taking into account that one of the parameters may be null. */ public static boolean nullEq(Object o1, Object o2){ --- 539,543 ---- /** ! * Makes an equal comparison taking into account that one of the parameters may be null. */ public static boolean nullEq(Object o1, Object o2){ *************** *** 447,459 **** /** * @return a document with the contents from a path within a zip file. */ public static IDocument getDocFromZip(File f, String pathInZip) throws Exception { ZipFile zipFile = new ZipFile(f, ZipFile.OPEN_READ); try { InputStream inputStream = zipFile.getInputStream(zipFile.getEntry(pathInZip)); try { ! Document doc = new Document(REF.getStreamContents(inputStream, null, null)); ! return doc; } finally { inputStream.close(); --- 556,593 ---- /** + * @return a string with the contents from a path within a zip file. + */ + public static String getStringFromZip(File f, String pathInZip) throws Exception { + return (String) getCustomReturnFromZip(f, pathInZip, String.class); + } + + /** * @return a document with the contents from a path within a zip file. */ public static IDocument getDocFromZip(File f, String pathInZip) throws Exception { + return (IDocument) getCustomReturnFromZip(f, pathInZip, IDocument.class); + } + + /** + * @param f the zip file that should be opened + * @param pathInZip the path within the zip file that should be gotten + * @param returnType the class that specifies the return type of this method. + * If null, it'll return in the fastest possible way available. + * Valid options are: + * String.class + * IDocument.class + * FastStringBuffer.class + * + * @return an object with the contents from a path within a zip file, having the return type + * of the object specified by the parameter returnType. + */ + public static Object getCustomReturnFromZip(File f, String pathInZip, Class<? extends Object> returnType) + throws Exception { + ZipFile zipFile = new ZipFile(f, ZipFile.OPEN_READ); try { InputStream inputStream = zipFile.getInputStream(zipFile.getEntry(pathInZip)); try { ! return REF.getStreamContents(inputStream, null, null, returnType); } finally { inputStream.close(); *************** *** 463,499 **** } } /** * @return the document given its 'filesystem' file - * @throws IOException */ public static IDocument getDocFromFile(java.io.File f, boolean loadIfNotInWorkspace) throws IOException { IPath path = Path.fromOSString(getFileAbsolutePath(f)); IDocument doc = getDocFromPath(path); if (doc == null && loadIfNotInWorkspace) { ! return getPythonDocFromFile(f); } return doc; } ! /** ! * @return the document given its 'filesystem' file (checks for the declared python encoding in the file) ! * @throws IOException ! */ ! private static IDocument getPythonDocFromFile(java.io.File f) throws IOException { ! IDocument docFromPath = getDocFromPath(Path.fromOSString(getFileAbsolutePath(f))); ! if(docFromPath != null){ ! return docFromPath; ! } ! ! FileInputStream stream = new FileInputStream(f); ! String fileContents = ""; ! try { ! String encoding = getPythonFileEncoding(f); ! fileContents = getStreamContents(stream, encoding, null); ! } finally { ! try { if(stream != null) stream.close(); } catch (Exception e) {Log.log(e);} ! } ! return new Document(fileContents); ! } --- 597,663 ---- } } + + + /** + * @return a string with the contents of the passed file + */ + public static String getStringFromFile(java.io.File f, boolean loadIfNotInWorkspace) throws IOException { + return (String) getCustomReturnFromFile(f, loadIfNotInWorkspace, String.class); + } + /** * @return the document given its 'filesystem' file */ public static IDocument getDocFromFile(java.io.File f, boolean loadIfNotInWorkspace) throws IOException { + return (IDocument) getCustomReturnFromFile(f, loadIfNotInWorkspace, IDocument.class); + } + + /** + * @param f the file from where we want to get the contents + * @param returnType the class that specifies the return type of this method. + * If null, it'll return in the fastest possible way available. + * Valid options are: + * String.class + * IDocument.class + * FastStringBuffer.class + * + * + * @return an object with the contents from the file, having the return type + * of the object specified by the parameter returnType. + */ + public static Object getCustomReturnFromFile(java.io.File f, boolean loadIfNotInWorkspace, + Class<? extends Object> returnType) throws IOException { + IPath path = Path.fromOSString(getFileAbsolutePath(f)); IDocument doc = getDocFromPath(path); + + if(doc != null){ + if(returnType == null || returnType == IDocument.class){ + return doc; + + }else if(returnType == String.class){ + return doc.get(); + + }else if(returnType == FastStringBuffer.class){ + return new FastStringBuffer(doc.get(), 16); + + }else{ + throw new RuntimeException("Don't know how to treat requested return type: "+returnType); + } + } + if (doc == null && loadIfNotInWorkspace) { ! FileInputStream stream = new FileInputStream(f); ! try { ! String encoding = getPythonFileEncoding(f); ! return getStreamContents(stream, encoding, null, returnType); ! } finally { ! try { if(stream != null) stream.close(); } catch (Exception e) {Log.log(e);} ! } } return doc; } ! *************** *** 502,505 **** --- 666,670 ---- * @return a file buffer to be used. */ + @SuppressWarnings("deprecation") public static ITextFileBuffer getBufferFromPath(IPath path) { //TODO: make this better for 3.3/ 3.2 (and check if behaviour is correct now) *************** *** 563,566 **** --- 728,732 ---- * and if that fails, it creates one reading the file. */ + @SuppressWarnings("restriction") public static IDocument getDocFromResource(IResource resource) { IProject project = resource.getProject(); *************** *** 578,593 **** if(doc == null){ //can this actually happen?... yeap, it can ! InputStream contents = file.getContents(); ! try { ! int i = contents.available(); ! byte b[] = new byte[i]; ! contents.read(b); ! doc = new Document(new String(b)); ! } finally{ ! contents.close(); ! } } return doc; ! }catch(ResourceException e){ //it may stop existing from the initial exists check to the getContents call return null; --- 744,751 ---- if(doc == null){ //can this actually happen?... yeap, it can ! doc = (IDocument) REF.getStreamContents(file.getContents(), null, null, IDocument.class); } return doc; ! }catch(CoreException e){ //it may stop existing from the initial exists check to the getContents call return null; *************** *** 633,639 **** * * Will close the reader. ! * @param fileLocation the file we want to get the encoding from (just passed for giving a better message if it fails -- may be null). */ ! public static String getPythonFileEncoding(Reader inputStreamReader, String fileLocation) throws IllegalCharsetNameException{ String ret = null; BufferedReader reader = new BufferedReader(inputStreamReader); --- 791,800 ---- * * Will close the reader. ! * @param fileLocation the file we want to get the encoding from (just passed for giving a better message ! * if it fails -- may be null). */ ! public static String getPythonFileEncoding(Reader inputStreamReader, String fileLocation) ! throws IllegalCharsetNameException{ ! String ret = null; BufferedReader reader = new BufferedReader(inputStreamReader); *************** *** 674,678 **** } ! StringBuffer buffer = new StringBuffer(); while(lEnc.length() > 0 && ((c = lEnc.charAt(0)) != ' ' || c == '-' || c == '*')) { --- 835,839 ---- } ! FastStringBuffer buffer = new FastStringBuffer(); while(lEnc.length() > 0 && ((c = lEnc.charAt(0)) != ' ' || c == '-' || c == '*')) { |
From: Fabio Z. <fa...@us...> - 2008-07-06 14:11:32
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/structure In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27663/src/org/python/pydev/core/structure Modified Files: FastStringBuffer.java Log Message: Changes in REF so that we can get the contents available in a suitable format / Using FastDefinitionsParser for gathering global definitions Index: FastStringBuffer.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/structure/FastStringBuffer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FastStringBuffer.java 15 Jun 2008 16:45:20 -0000 1.4 --- FastStringBuffer.java 6 Jul 2008 14:11:40 -0000 1.5 *************** *** 181,185 **** /** ! * @return a new stringt with the contents of this buffer. */ @Override --- 181,185 ---- /** ! * @return a new string with the contents of this buffer. */ @Override *************** *** 189,192 **** --- 189,202 ---- /** + * @return a new char array with the contents of this buffer. + */ + public char[] toCharArray() { + char[] v = new char[count]; + System.arraycopy(value, 0, v, 0, count); + return v; + } + + + /** * Erases the last char in this buffer */ *************** *** 312,315 **** --- 322,326 ---- } + } |
From: Fabio Z. <fa...@us...> - 2008-07-06 14:11:32
|
Update of /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/structure In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27663/tests/org/python/pydev/core/structure Modified Files: FastStringBufferTest.java Log Message: Changes in REF so that we can get the contents available in a suitable format / Using FastDefinitionsParser for gathering global definitions Index: FastStringBufferTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/structure/FastStringBufferTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FastStringBufferTest.java 15 Jun 2008 16:45:20 -0000 1.3 --- FastStringBufferTest.java 6 Jul 2008 14:11:40 -0000 1.4 *************** *** 38,41 **** --- 38,49 ---- fastString.delete(0,1); assertEquals("xx.22aabbcccdddddddddddddddddddddddddddddd$", fastString.toString()); + + char[] charArray = fastString.toString().toCharArray(); + char[] charArray2 = fastString.toCharArray(); + assertEquals(charArray.length, charArray2.length); + for (int i = 0; i < charArray2.length; i++) { + assertEquals(charArray[i], charArray2[i]); + + } } |
From: Fabio Z. <fa...@us...> - 2008-07-06 13:10:35
|
Update of /cvsroot/pydev/org.python.pydev.parser/tests/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2497/tests/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParserTest.java Log Message: Improved attribute recognition. Index: FastDefinitionsParserTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/tests/org/python/pydev/parser/fastparser/FastDefinitionsParserTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FastDefinitionsParserTest.java 5 Jul 2008 21:53:00 -0000 1.5 --- FastDefinitionsParserTest.java 6 Jul 2008 13:10:42 -0000 1.6 *************** *** 29,33 **** FastDefinitionsParserTest test = new FastDefinitionsParserTest(); test.setUp(); ! test.testDefinitionsParser11(); --- 29,33 ---- FastDefinitionsParserTest test = new FastDefinitionsParserTest(); test.setUp(); ! // test.NotestGlobalAttributesWX(); *************** *** 239,242 **** --- 239,515 ---- } + public void testGlobalAttributes() { + Module m = (Module) FastDefinitionsParser.parse( + "GLOBAL_ATTRIBUTE = 10\n" + + "\n" + + ""); + assertEquals(1, m.body.length); + Assign assign = ((Assign)m.body[0]); + assertEquals("GLOBAL_ATTRIBUTE", ((Name)assign.targets[0]).id); + } + + public void testGlobalAttributes2() { + String str = "import new\n" + + "new_a = new.a\n"; + checkSingleGlobalAttr((Module) FastDefinitionsParser.parse(str)); + checkSingleGlobalAttr((Module) FastDefinitionsParser.parse(str.replaceAll("\n", "\r\n"))); + } + + public void testGlobalAttributes3() { + String str = "#c\n" + + "'m'\n" + + "new_a= new.a\n" + + ""; + checkSingleGlobalAttr((Module) FastDefinitionsParser.parse(str)); + checkSingleGlobalAttr((Module) FastDefinitionsParser.parse(str.replaceAll("\n", "\r\n"))); + } + + public void testGlobalAttributes4() { + String str = + "class A:\n" + + " pass\n" + + "GLOBAL_ATTR = 10\n" + + ""; + Module m = (Module) FastDefinitionsParser.parse(str); + assertEquals(2, m.body.length); + Assign assign = ((Assign)m.body[1]); + assertEquals("GLOBAL_ATTR", ((Name)assign.targets[0]).id); + } + + public void NotestGlobalAttributesWX() { + String str = + "# This file was created automatically by SWIG 1.3.29.\n" + + "# Don't modify this file, modify the SWIG interface instead.\n" + + "'''\n" + + "The `XmlResource` class allows program resources defining menus, layout of\n" + + "controls on a panel, etc. to be loaded from an XML file.\n" + + "'''\n" + + "import _xrc\n" + + "import new\n" + + "new_instancemethod = new.instancemethod\n" + + "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n" + + " if (name == 'thisown'): return self.this.own(value)\n" + + " if (name == 'this'):\n" + + " if type(value).__name__ == 'PySwigObject':\n" + + " self.__dict__[name] = value\n" + + " return\n" + + " method = class_type.__swig_setmethods__.get(name,None)\n" + + " if method: return method(self,value)\n" + + " if (not static) or hasattr(self,name):\n" + + " self.__dict__[name] = value\n" + + " else:\n" + + " raise AttributeError('You cannot add attributes to %s' % self)\n" + + "def _swig_setattr(self,class_type,name,value):\n" + + " return _swig_setattr_nondynamic(self,class_type,name,value,0)\n" + + "def _swig_getattr(self,class_type,name):\n" + + " if (name == 'thisown'): return self.this.own()\n" + + " method = class_type.__swig_getmethods__.get(name,None)\n" + + " if method: return method(self)\n" + + " raise AttributeError,name\n" + + "def _swig_repr(self):\n" + + " try: strthis = 'proxy of ' + self.this.__repr__()\n" + + " except: strthis = ''\n" + + " return '<%s.%s; %s >' % (self.__class__.__module__, self.__class__.__name__, strthis,)\n" + + "import types\n" + + "try:\n" + + " _object = types.ObjectType\n" + + " _newclass = 1\n" + + "except AttributeError:\n" + + " class _object : pass\n" + + " _newclass = 0\n" + + "del types\n" + + "def _swig_setattr_nondynamic_method(set):\n" + + " def set_attr(self,name,value):\n" + + " if (name == 'thisown'): return self.this.own(value)\n" + + " if hasattr(self,name) or (name == 'this'):\n" + + " set(self,name,value)\n" + + " else:\n" + + " raise AttributeError('You cannot add attributes to %s' % self)\n" + + " return set_attr\n" + + "import _core\n" + + "wx = _core \n" + + "__docfilter__ = wx.__DocFilter(globals()) \n" + + "#---------------------------------------------------------------------------\n" + + "WX_XMLRES_CURRENT_VERSION_MAJOR = _xrc.WX_XMLRES_CURRENT_VERSION_MAJOR\n" + + "WX_XMLRES_CURRENT_VERSION_MINOR = _xrc.WX_XMLRES_CURRENT_VERSION_MINOR\n" + + "WX_XMLRES_CURRENT_VERSION_RELEASE = _xrc.WX_XMLRES_CURRENT_VERSION_RELEASE\n" + + "WX_XMLRES_CURRENT_VERSION_REVISION = _xrc.WX_XMLRES_CURRENT_VERSION_REVISION\n" + + "XRC_USE_LOCALE = _xrc.XRC_USE_LOCALE\n" + + "XRC_NO_SUBCLASSING = _xrc.XRC_NO_SUBCLASSING\n" + + "XRC_NO_RELOADING = _xrc.XRC_NO_RELOADING\n" + + "class XmlResource(_core.Object):\n" + + " '''Proxy of C++ XmlResource class'''\n" + + " thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')\n" + + " __repr__ = _swig_repr\n" + + " def __init__(self, *args, **kwargs): \n" + + " '''__init__(self, String filemask, int flags=XRC_USE_LOCALE, String domain=wxEmptyString) -> XmlResource'''\n" + + " _xrc.XmlResource_swiginit(self,_xrc.new_XmlResource(*args, **kwargs))\n" + + " self.InitAllHandlers()\n" + + " __swig_destroy__ = _xrc.delete_XmlResource\n" + + " __del__ = lambda self : None;\n" + + " def Load(*args, **kwargs):\n" + + " '''Load(self, String filemask) -> bool'''\n" + + " return _xrc.XmlResource_Load(*args, **kwargs)\n" + + " def LoadFromString(*args, **kwargs):\n" + + " '''LoadFromString(self, String data) -> bool'''\n" + + " return _xrc.XmlResource_LoadFromString(*args, **kwargs)\n" + + " def Unload(*args, **kwargs):\n" + + " '''Unload(self, String filename) -> bool'''\n" + + " return _xrc.XmlResource_Unload(*args, **kwargs)\n" + + " def InitAllHandlers(*args, **kwargs):\n" + + " '''InitAllHandlers(self)'''\n" + + " return _xrc.XmlResource_InitAllHandlers(*args, **kwargs)\n" + + " def AddHandler(*args, **kwargs):\n" + + " '''AddHandler(self, XmlResourceHandler handler)'''\n" + + " return _xrc.XmlResource_AddHandler(*args, **kwargs)\n" + + " def InsertHandler(*args, **kwargs):\n" + + " '''InsertHandler(self, XmlResourceHandler handler)'''\n" + + " return _xrc.XmlResource_InsertHandler(*args, **kwargs)\n" + + " def ClearHandlers(*args, **kwargs):\n" + + " '''ClearHandlers(self)'''\n" + + " return _xrc.XmlResource_ClearHandlers(*args, **kwargs)\n" + + " def AddSubclassFactory(*args, **kwargs):\n" + + " '''AddSubclassFactory(XmlSubclassFactory factory)'''\n" + + " return _xrc.XmlResource_AddSubclassFactory(*args, **kwargs)\n" + + " AddSubclassFactory = staticmethod(AddSubclassFactory)\n" + + " def LoadMenu(*args, **kwargs):\n" + + " '''LoadMenu(self, String name) -> Menu'''\n" + + " return _xrc.XmlResource_LoadMenu(*args, **kwargs)\n" + + " def LoadMenuBar(*args, **kwargs):\n" + + " '''LoadMenuBar(self, String name) -> MenuBar'''\n" + + " return _xrc.XmlResource_LoadMenuBar(*args, **kwargs)\n" + + " def LoadMenuBarOnFrame(*args, **kwargs):\n" + + " '''LoadMenuBarOnFrame(self, Window parent, String name) -> MenuBar'''\n" + + " return _xrc.XmlResource_LoadMenuBarOnFrame(*args, **kwargs)\n" + + " def LoadToolBar(*args, **kwargs):\n" + + " '''LoadToolBar(self, Window parent, String name) -> wxToolBar'''\n" + + " return _xrc.XmlResource_LoadToolBar(*args, **kwargs)\n" + + " def LoadDialog(*args, **kwargs):\n" + + " '''LoadDialog(self, Window parent, String name) -> wxDialog'''\n" + + " return _xrc.XmlResource_LoadDialog(*args, **kwargs)\n" + + " def LoadOnDialog(*args, **kwargs):\n" + + " '''LoadOnDialog(self, wxDialog dlg, Window parent, String name) -> bool'''\n" + + " return _xrc.XmlResource_LoadOnDialog(*args, **kwargs)\n" + + " def LoadPanel(*args, **kwargs):\n" + + " '''LoadPanel(self, Window parent, String name) -> wxPanel'''\n" + + " return _xrc.XmlResource_LoadPanel(*args, **kwargs)\n" + + " def LoadOnPanel(*args, **kwargs):\n" + + " '''LoadOnPanel(self, wxPanel panel, Window parent, String name) -> bool'''\n" + + " return _xrc.XmlResource_LoadOnPanel(*args, **kwargs)\n" + + " def LoadFrame(*args, **kwargs):\n" + + " '''LoadFrame(self, Window parent, String name) -> wxFrame'''\n" + + " return _xrc.XmlResource_LoadFrame(*args, **kwargs)\n" + + " def LoadOnFrame(*args, **kwargs):\n" + + " '''LoadOnFrame(self, wxFrame frame, Window parent, String name) -> bool'''\n" + + " return _xrc.XmlResource_LoadOnFrame(*args, **kwargs)\n" + + " def LoadObject(*args, **kwargs):\n" + + " '''LoadObject(self, Window parent, String name, String classname) -> Object'''\n" + + " return _xrc.XmlResource_LoadObject(*args, **kwargs)\n" + + " def LoadOnObject(*args, **kwargs):\n" + + " '''LoadOnObject(self, Object instance, Window parent, String name, String classname) -> bool'''\n" + + " return _xrc.XmlResource_LoadOnObject(*args, **kwargs)\n" + + " def LoadBitmap(*args, **kwargs):\n" + + " '''LoadBitmap(self, String name) -> Bitmap'''\n" + + " return _xrc.XmlResource_LoadBitmap(*args, **kwargs)\n" + + " def LoadIcon(*args, **kwargs):\n" + + " '''LoadIcon(self, String name) -> Icon'''\n" + + " return _xrc.XmlResource_LoadIcon(*args, **kwargs)\n" + + " def AttachUnknownControl(*args, **kwargs):\n" + + " '''AttachUnknownControl(self, String name, Window control, Window parent=None) -> bool'''\n" + + " return _xrc.XmlResource_AttachUnknownControl(*args, **kwargs)\n" + + " def GetXRCID(*args, **kwargs):\n" + + " '''GetXRCID(String str_id, int value_if_not_found=ID_NONE) -> int'''\n" + + " return _xrc.XmlResource_GetXRCID(*args, **kwargs)\n" + + " GetXRCID = staticmethod(GetXRCID)\n" + + " def GetVersion(*args, **kwargs):\n" + + " '''GetVersion(self) -> long'''\n" + + " return _xrc.XmlResource_GetVersion(*args, **kwargs)\n" + + " def CompareVersion(*args, **kwargs):\n" + + " '''CompareVersion(self, int major, int minor, int release, int revision) -> int'''\n" + + " return _xrc.XmlResource_CompareVersion(*args, **kwargs)\n" + + " def Get(*args, **kwargs):\n" + + " '''Get() -> XmlResource'''\n" + + " return _xrc.XmlResource_Get(*args, **kwargs)\n" + + " Get = staticmethod(Get)\n" + + " def Set(*args, **kwargs):\n" + + " '''Set(XmlResource res) -> XmlResource'''\n" + + " return _xrc.XmlResource_Set(*args, **kwargs)\n" + + " Set = staticmethod(Set)\n" + + " def GetFlags(*args, **kwargs):\n" + + " '''GetFlags(self) -> int'''\n" + + " return _xrc.XmlResource_GetFlags(*args, **kwargs)\n" + + " def SetFlags(*args, **kwargs):\n" + + " '''SetFlags(self, int flags)'''\n" + + " return _xrc.XmlResource_SetFlags(*args, **kwargs)\n" + + " def GetDomain(*args, **kwargs):\n" + + " '''GetDomain(self) -> String'''\n" + + " return _xrc.XmlResource_GetDomain(*args, **kwargs)\n" + + " def SetDomain(*args, **kwargs):\n" + + " '''SetDomain(self, String domain)'''\n" + + " return _xrc.XmlResource_SetDomain(*args, **kwargs)\n" + + " Domain = property(GetDomain,SetDomain,doc='See `GetDomain` and `SetDomain`') \n" + + " Flags = property(GetFlags,SetFlags,doc='See `GetFlags` and `SetFlags`') \n" + + " Version = property(GetVersion,doc='See `GetVersion`') \n" + + "_xrc.XmlResource_swigregister(XmlResource)\n" + + "cvar = _xrc.cvar\n" + + "UTF8String = cvar.UTF8String\n" + + "StyleString = cvar.StyleString\n" + + "SizeString = cvar.SizeString\n" + + "PosString = cvar.PosString\n" + + "BitmapString = cvar.BitmapString\n" + + "IconString = cvar.IconString\n" + + "FontString = cvar.FontString\n" + + "AnimationString = cvar.AnimationString\n" + + "def EmptyXmlResource(*args, **kwargs):\n" + + " '''EmptyXmlResource(int flags=XRC_USE_LOCALE, String domain=wxEmptyString) -> XmlResource'''\n" + + " val = _xrc.new_EmptyXmlResource(*args, **kwargs)\n" + + " val.InitAllHandlers()\n" + + " return val\n" + + "def XmlResource_AddSubclassFactory(*args, **kwargs):\n" + + " '''XmlResource_AddSubclassFactory(XmlSubclassFactory factory)'''\n" + + " return _xrc.XmlResource_AddSubclassFactory(*args, **kwargs)\n" + + "def XmlResource_GetXRCID(*args, **kwargs):\n" + + " '''XmlResource_GetXRCID(String str_id, int value_if_not_found=ID_NONE) -> int'''\n" + + " return _xrc.XmlResource_GetXRCID(*args, **kwargs)\n" + + "def XmlResource_Get(*args):\n" + + " '''XmlResource_Get() -> XmlResource'''\n" + + " return _xrc.XmlResource_Get(*args)\n" + + "def XmlResource_Set(*args, **kwargs):\n" + + " '''XmlResource_Set(XmlResource res) -> XmlResource'''\n" + + " return _xrc.XmlResource_Set(*args, **kwargs)\n" + + "def XRCID(str_id, value_if_not_found = wx.ID_NONE):\n" + + " return XmlResource_GetXRCID(str_id, value_if_not_found)\n" + + "def XRCCTRL(window, str_id, *ignoreargs):\n" + + " return window.FindWindowById(XRCID(str_id))\n" + + "#---------------------------------------------------------------------------\n" + + "class XmlSubclassFactory(object):\n" + + " '''Proxy of C++ XmlSubclassFactory class'''\n" + + " thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')\n" + + " __repr__ = _swig_repr\n" + + " def __init__(self, *args, **kwargs): \n" + + " '''__init__(self) -> XmlSubclassFactory'''\n" + + " _xrc.XmlSubclassFactory_swiginit(self,_xrc.new_XmlSubclassFactory(*args, **kwargs))\n" + + " XmlSubclassFactory._setCallbackInfo(self, self, XmlSubclassFactory)\n" + + " def _setCallbackInfo(*args, **kwargs):\n" + + " '''_setCallbackInfo(self, PyObject self, PyObject _class)'''\n" + + " return _xrc.XmlSubclassFactory__setCallbackInfo(*args, **kwargs)\n" + + "_xrc.XmlSubclassFactory_swigregister(XmlSubclassFactory)\n" + + "#---------------------------------------------------------------------------\n" + + "XML_ELEMENT_NODE = _xrc.XML_ELEMENT_NODE\n" + + "XML_ATTRIBUTE_NODE = _xrc.XML_ATTRIBUTE_NODE\n" + + "\n" + + "\n" + + "\n" + + ""; + Module m = (Module) FastDefinitionsParser.parse(str); + System.out.println("OK"); + } + + private void checkSingleGlobalAttr(Module m) { + assertEquals(1, m.body.length); + Assign assign = ((Assign)m.body[0]); + assertEquals("new_a", ((Name)assign.targets[0]).id); + } + public void testDefinitionsParser() { Module m = (Module) FastDefinitionsParser.parse("class Bar:pass"); |
From: Fabio Z. <fa...@us...> - 2008-07-06 13:10:35
|
Update of /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2497/src/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParser.java Log Message: Improved attribute recognition. Index: FastDefinitionsParser.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser/FastDefinitionsParser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FastDefinitionsParser.java 5 Jul 2008 21:53:01 -0000 1.4 --- FastDefinitionsParser.java 6 Jul 2008 13:10:42 -0000 1.5 *************** *** 113,116 **** --- 113,120 ---- handleNewLine(); } + //in the 1st attempt to handle the 1st line, if it had nothing we could actually go backward 1 char + if(currIndex < 0){ + currIndex=0; + } for (;currIndex < length; currIndex++, col++) { *************** *** 152,156 **** //after a comment, we'll always be in a new line - currIndex++; handleNewLine(); --- 156,159 ---- *************** *** 204,208 **** Assign assign = new Assign(targets, null); ! assign.beginColumn = this.col; assign.beginLine = this.row; addToPertinentScope(assign); --- 207,211 ---- Assign assign = new Assign(targets, null); ! assign.beginColumn = this.firstCharCol; assign.beginLine = this.row; addToPertinentScope(assign); *************** *** 213,217 **** exprType[] targets = new exprType[]{name}; Assign assign = new Assign(targets, null); ! assign.beginColumn = this.col; assign.beginLine = this.row; addToPertinentScope(assign); --- 216,220 ---- exprType[] targets = new exprType[]{name}; Assign assign = new Assign(targets, null); ! assign.beginColumn = this.firstCharCol; assign.beginLine = this.row; addToPertinentScope(assign); *************** *** 246,253 **** lineBuffer.clear(); char c = cs[currIndex]; - boolean walkedIndex = false; while(currIndex < length-1 && Character.isWhitespace(c) && c != '\r' && c != '\n'){ - walkedIndex = true; currIndex ++; col++; --- 249,254 ---- *************** *** 270,276 **** startMethod(getNextIdentifier(c), row, startMethodCol); } ! if(walkedIndex){ ! currIndex --; ! } firstCharCol = col; } --- 271,275 ---- startMethod(getNextIdentifier(c), row, startMethodCol); } ! currIndex --; firstCharCol = col; } *************** *** 377,380 **** --- 376,380 ---- }else if (newStmt instanceof Assign){ Assign assign = (Assign) newStmt; + exprType target = assign.targets[0]; //an assign could be in a method or in a class depending on where we're right now... *************** *** 382,387 **** if(size > 0){ stmtType existing = peek.get(size-1); ! if(existing.beginColumn < newStmt.beginColumn){ ! exprType target = assign.targets[0]; //add the assign to the correct place if(existing instanceof FunctionDef){ --- 382,386 ---- if(size > 0){ stmtType existing = peek.get(size-1); ! if(existing.beginColumn < assign.beginColumn){ //add the assign to the correct place if(existing instanceof FunctionDef){ *************** *** 389,412 **** if(target instanceof Attribute){ ! //if it's an attribute at this point, it'll always start with self! ! if(functionDef.body == null){ ! if(functionDef.specialsAfter == null){ ! functionDef.specialsAfter = new ArrayList<Object>(); ! } ! functionDef.body = new stmtType[10]; ! functionDef.body[0] = newStmt; ! functionDef.specialsAfter.add(1); //real len ! }else{ ! //already exists... let's add it... as it's an array, we may have to reallocate it ! Integer currLen = (Integer) functionDef.specialsAfter.get(0); ! currLen += 1; ! functionDef.specialsAfter.set(0, currLen); ! if(functionDef.body.length < currLen){ ! stmtType[] newBody = new stmtType[functionDef.body.length*2]; ! System.arraycopy(functionDef.body, 0, newBody, 0, functionDef.body.length); ! functionDef.body = newBody; ! } ! functionDef.body[currLen-1] = newStmt; ! } } return; --- 388,392 ---- if(target instanceof Attribute){ ! addAssignToFunctionDef(assign, functionDef); } return; *************** *** 415,418 **** --- 395,402 ---- } + //if it still hasn't returned and it's a name, add it to the global scope. + if(target instanceof Name){ + + } } peek.add(newStmt); *************** *** 425,428 **** --- 409,442 ---- this.body.add(newStmt); } + + + /** + * Adds an assign statement to the given function definition. + * + * @param assign the assign to be added + * @param functionDef the function definition where it should be added + */ + private void addAssignToFunctionDef(Assign assign, FunctionDef functionDef) { + //if it's an attribute at this point, it'll always start with self! + if(functionDef.body == null){ + if(functionDef.specialsAfter == null){ + functionDef.specialsAfter = new ArrayList<Object>(); + } + functionDef.body = new stmtType[10]; + functionDef.body[0] = assign; + functionDef.specialsAfter.add(1); //real len + }else{ + //already exists... let's add it... as it's an array, we may have to reallocate it + Integer currLen = (Integer) functionDef.specialsAfter.get(0); + currLen += 1; + functionDef.specialsAfter.set(0, currLen); + if(functionDef.body.length < currLen){ + stmtType[] newBody = new stmtType[functionDef.body.length*2]; + System.arraycopy(functionDef.body, 0, newBody, 0, functionDef.body.length); + functionDef.body = newBody; + } + functionDef.body[currLen-1] = assign; + } + } |
From: Fabio Z. <fa...@us...> - 2008-07-05 21:52:57
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22132/src/org/python/pydev/core/docutils Modified Files: ParsingUtils.java StringUtils.java Log Message: FastParser handling attributes (still needs more testing). Index: ParsingUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ParsingUtils.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** ParsingUtils.java 23 Jun 2008 01:18:25 -0000 1.21 --- ParsingUtils.java 5 Jul 2008 21:53:05 -0000 1.22 *************** *** 157,161 **** if(c == '\'' || c == '"'){ //ignore comments or multiline comments... ! j = ParsingUtils.eatLiterals( cs, null, j-1)+1; }else if(c == '#'){ --- 157,161 ---- if(c == '\'' || c == '"'){ //ignore comments or multiline comments... ! j = ParsingUtils.eatLiterals(cs, null, j-1)+1; }else if(c == '#'){ Index: StringUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/StringUtils.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** StringUtils.java 23 Jun 2008 01:18:25 -0000 1.15 --- StringUtils.java 5 Jul 2008 21:53:05 -0000 1.16 *************** *** 57,63 **** int j = 0; ! for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); ! if (c == '%' && i + 1 < str.length()) { char nextC = str.charAt(i + 1); if (nextC == 's') { --- 57,64 ---- int j = 0; ! int len = str.length(); ! for (int i = 0; i < len; i++) { char c = str.charAt(i); ! if (c == '%' && i + 1 < len) { char nextC = str.charAt(i + 1); if (nextC == 's') { |
From: Fabio Z. <fa...@us...> - 2008-07-05 21:52:54
|
Update of /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21875/src/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParser.java Log Message: FastParser handling attributes (still needs more testing). Index: FastDefinitionsParser.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser/FastDefinitionsParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FastDefinitionsParser.java 2 Jul 2008 20:38:39 -0000 1.3 --- FastDefinitionsParser.java 5 Jul 2008 21:53:01 -0000 1.4 *************** *** 5,15 **** --- 5,20 ---- import org.python.pydev.core.docutils.ParsingUtils; + import org.python.pydev.core.docutils.StringUtils; import org.python.pydev.core.structure.FastStack; import org.python.pydev.core.structure.FastStringBuffer; import org.python.pydev.parser.jython.SimpleNode; + import org.python.pydev.parser.jython.ast.Assign; + import org.python.pydev.parser.jython.ast.Attribute; import org.python.pydev.parser.jython.ast.ClassDef; import org.python.pydev.parser.jython.ast.FunctionDef; import org.python.pydev.parser.jython.ast.Module; + import org.python.pydev.parser.jython.ast.Name; import org.python.pydev.parser.jython.ast.NameTok; + import org.python.pydev.parser.jython.ast.exprType; import org.python.pydev.parser.jython.ast.stmtType; *************** *** 27,31 **** * @author Fabio */ ! public class FastDefinitionsParser { /** --- 32,36 ---- * @author Fabio */ ! public final class FastDefinitionsParser { /** *************** *** 44,52 **** /** - * Last char we found - */ - private char lastChar = '\n'; - - /** * Current iteration index */ --- 49,52 ---- *************** *** 158,162 **** ! case '\r': if(currIndex < length-1 && cs[currIndex+1] == '\n'){ --- 158,168 ---- ! case '{': ! case '[': ! case '(': ! //starting some call, dict, list, tuple... those don't count on getting some actual definition ! currIndex = ParsingUtils.eatPar(cs, currIndex, null, c); ! break; ! case '\r': if(currIndex < length-1 && cs[currIndex+1] == '\n'){ *************** *** 170,178 **** break; //No default - } lineBuffer.append(c); - lastChar = c; } --- 176,225 ---- break; + + case '=': + if(currIndex < length-1 && cs[currIndex+1] != '='){ + if(DEBUG){ + System.out.println("Found possible attribute:"+lineBuffer+" col:"+firstCharCol); + } + + + + String lineContents = lineBuffer.toString().trim(); + boolean add=true; + for(int i=0;i<lineContents.length();i++){ + char lineC = lineContents.charAt(i); + //can only be made of valid java chars (no spaces or similar things) + if(lineC != '.' && !Character.isJavaIdentifierPart(lineC)){ + add=false; + break; + } + } + if(add){ + //only add if it was something valid + if(lineContents.indexOf('.') != -1){ + String[] dotSplit = StringUtils.dotSplit(lineContents); + if(dotSplit.length == 2 && dotSplit[0].equals("self")){ + Attribute attribute = new Attribute(new Name("self", Name.Load), new NameTok(dotSplit[1], NameTok.Attrib), Attribute.Load); + exprType[] targets = new exprType[]{attribute}; + Assign assign = new Assign(targets, null); + + assign.beginColumn = this.col; + assign.beginLine = this.row; + addToPertinentScope(assign); + } + + }else{ + Name name = new Name(lineContents, Name.Store); + exprType[] targets = new exprType[]{name}; + Assign assign = new Assign(targets, null); + assign.beginColumn = this.col; + assign.beginLine = this.row; + addToPertinentScope(assign); + } + } + } //No default } lineBuffer.append(c); } *************** *** 199,204 **** --- 246,253 ---- lineBuffer.clear(); char c = cs[currIndex]; + boolean walkedIndex = false; while(currIndex < length-1 && Character.isWhitespace(c) && c != '\r' && c != '\n'){ + walkedIndex = true; currIndex ++; col++; *************** *** 221,225 **** startMethod(getNextIdentifier(c), row, startMethodCol); } ! currIndex --; } --- 270,277 ---- startMethod(getNextIdentifier(c), row, startMethodCol); } ! if(walkedIndex){ ! currIndex --; ! } ! firstCharCol = col; } *************** *** 304,321 **** * It'll find a correct scope based on the column it has to be added to. * ! * @param def the definition to be added */ ! private void addToPertinentScope(stmtType def) { //see where it should be added (global or class scope) while(stack.size() > 0){ ClassDef parent = stack.peek(); ! if(parent.beginColumn < def.beginColumn){ List<stmtType> peek = stackBody.peek(); ! if(def instanceof FunctionDef){ int size = peek.size(); if(size > 0){ stmtType existing = peek.get(size-1); ! if(existing.beginColumn < def.beginColumn){ //we don't want to add a method inside a method at this point. //all the items added should have the same column. --- 356,373 ---- * It'll find a correct scope based on the column it has to be added to. * ! * @param newStmt the definition to be added */ ! private void addToPertinentScope(stmtType newStmt) { //see where it should be added (global or class scope) while(stack.size() > 0){ ClassDef parent = stack.peek(); ! if(parent.beginColumn < newStmt.beginColumn){ List<stmtType> peek = stackBody.peek(); ! if(newStmt instanceof FunctionDef){ int size = peek.size(); if(size > 0){ stmtType existing = peek.get(size-1); ! if(existing.beginColumn < newStmt.beginColumn){ //we don't want to add a method inside a method at this point. //all the items added should have the same column. *************** *** 323,328 **** } } } ! peek.add(def); return; }else{ --- 375,420 ---- } } + }else if (newStmt instanceof Assign){ + Assign assign = (Assign) newStmt; + + //an assign could be in a method or in a class depending on where we're right now... + int size = peek.size(); + if(size > 0){ + stmtType existing = peek.get(size-1); + if(existing.beginColumn < newStmt.beginColumn){ + exprType target = assign.targets[0]; + //add the assign to the correct place + if(existing instanceof FunctionDef){ + FunctionDef functionDef = (FunctionDef) existing; + + if(target instanceof Attribute){ + //if it's an attribute at this point, it'll always start with self! + if(functionDef.body == null){ + if(functionDef.specialsAfter == null){ + functionDef.specialsAfter = new ArrayList<Object>(); + } + functionDef.body = new stmtType[10]; + functionDef.body[0] = newStmt; + functionDef.specialsAfter.add(1); //real len + }else{ + //already exists... let's add it... as it's an array, we may have to reallocate it + Integer currLen = (Integer) functionDef.specialsAfter.get(0); + currLen += 1; + functionDef.specialsAfter.set(0, currLen); + if(functionDef.body.length < currLen){ + stmtType[] newBody = new stmtType[functionDef.body.length*2]; + System.arraycopy(functionDef.body, 0, newBody, 0, functionDef.body.length); + functionDef.body = newBody; + } + functionDef.body[currLen-1] = newStmt; + } + } + return; + } + } + } + } ! peek.add(newStmt); return; }else{ *************** *** 331,335 **** } //if it still hasn't returned, add it to the global ! this.body.add(def); } --- 423,427 ---- } //if it still hasn't returned, add it to the global ! this.body.add(newStmt); } |
From: Fabio Z. <fa...@us...> - 2008-07-05 21:52:53
|
Update of /cvsroot/pydev/org.python.pydev.parser/tests/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21875/tests/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParserTest.java Log Message: FastParser handling attributes (still needs more testing). Index: FastDefinitionsParserTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/tests/org/python/pydev/parser/fastparser/FastDefinitionsParserTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FastDefinitionsParserTest.java 5 Jul 2008 19:50:16 -0000 1.4 --- FastDefinitionsParserTest.java 5 Jul 2008 21:53:00 -0000 1.5 *************** *** 6,13 **** import org.python.pydev.core.REF; ! import org.python.pydev.core.performanceeval.Timer; import org.python.pydev.parser.jython.ast.ClassDef; import org.python.pydev.parser.jython.ast.FunctionDef; import org.python.pydev.parser.jython.ast.Module; import org.python.pydev.parser.jython.ast.NameTok; --- 6,15 ---- import org.python.pydev.core.REF; ! import org.python.pydev.parser.jython.ast.Assign; ! import org.python.pydev.parser.jython.ast.Attribute; import org.python.pydev.parser.jython.ast.ClassDef; import org.python.pydev.parser.jython.ast.FunctionDef; import org.python.pydev.parser.jython.ast.Module; + import org.python.pydev.parser.jython.ast.Name; import org.python.pydev.parser.jython.ast.NameTok; *************** *** 28,31 **** --- 30,47 ---- test.setUp(); test.testDefinitionsParser11(); + + + //only loading files + //java6: time elapsed: 0.593 + //java5: time elapsed: 0.984 + + //fast parser + //java6: time elapsed: 0.844 + //java5: time elapsed: 1.375 + + //regular parser + //java6: time elapsed: 9.25 + //java5: time elapsed: 6.89 + // Timer timer = new Timer(); // test.parseFilesInDir(new File("D:/bin/Python251/Lib/site-packages/wx-2.8-msw-unicode"), true); *************** *** 57,61 **** if(f.getAbsolutePath().toLowerCase().endsWith(".py")){ String fileContents = REF.getFileContents(f); ! FastDefinitionsParser.parse(fileContents); }else if(recursive && f.isDirectory()){ --- 73,82 ---- if(f.getAbsolutePath().toLowerCase().endsWith(".py")){ String fileContents = REF.getFileContents(f); ! try{ ! FastDefinitionsParser.parse(fileContents); ! }catch(Exception e){ ! System.out.println("Error parsing:"+f); ! // e.printStackTrace(); ! } }else if(recursive && f.isDirectory()){ *************** *** 66,69 **** --- 87,242 ---- + public void testAttributes() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " ATTRIBUTE = 10\n" + + "\n" + + ""); + assertEquals(1, m.body.length); + ClassDef classDef = ((ClassDef)m.body[0]); + assertEquals("Bar", ((NameTok)classDef.name).id); + assertEquals(1, classDef.body.length); + Assign assign = (Assign) classDef.body[0]; + assertEquals(1, assign.targets.length); + Name name = (Name) assign.targets[0]; + assertEquals("ATTRIBUTE", name.id); + } + + + public void testAttributes2() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " XXX.ATTRIBUTE = 10\n" + //we're assigning an attribute, that's not related to the class + "\n" + + ""); + assertEquals(1, m.body.length); + ClassDef classDef = ((ClassDef)m.body[0]); + assertEquals("Bar", ((NameTok)classDef.name).id); + assertEquals(0, classDef.body.length); //no attribute + } + + + public void testAttributes3() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " def m1(self):\n" + + " ATTRIBUTE = 10\n" + //local scope: don't get it + "\n" + + ""); + assertEquals(1, m.body.length); + ClassDef classDef = ((ClassDef)m.body[0]); + assertEquals("Bar", ((NameTok)classDef.name).id); + assertEquals(1, classDef.body.length); //method + + FunctionDef funcDef = (FunctionDef)classDef.body[0]; + assertEquals("m1", ((NameTok)funcDef.name).id); + assertNull(funcDef.body); + } + + + + public void testAttributes4() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " def m1(self):\n" + + " self.ATTRIBUTE = 10\n" + //local scope: get it because of self. + "\n" + + ""); + assertEquals(1, m.body.length); + ClassDef classDef = ((ClassDef)m.body[0]); + assertEquals("Bar", ((NameTok)classDef.name).id); + assertEquals(1, classDef.body.length); //method + + FunctionDef funcDef = (FunctionDef)classDef.body[0]; + assertEquals("m1", ((NameTok)funcDef.name).id); + + assertNull(funcDef.body[1]); + Assign assign = (Assign) funcDef.body[0]; + assertEquals(1, assign.targets.length); + Attribute attribute = (Attribute) assign.targets[0]; + NameTok attr = (NameTok) attribute.attr; + assertEquals("ATTRIBUTE", attr.id.toString()); + } + + public void testAttributes5() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " def m1(self):\n" + + " self.ATTRIBUTE0 = 10\n" + //local scope: get it because of self. + " self.ATTRIBUTE1 = 10\n" + //local scope: get it because of self. + " self.ATTRIBUTE2 = 10\n" + //local scope: get it because of self. + "\n" + + ""); + assertEquals(1, m.body.length); + ClassDef classDef = ((ClassDef)m.body[0]); + assertEquals("Bar", ((NameTok)classDef.name).id); + assertEquals(1, classDef.body.length); //method + + FunctionDef funcDef = (FunctionDef)classDef.body[0]; + assertEquals("m1", ((NameTok)funcDef.name).id); + + for(int i=0;i<3;i++){ + Assign assign = (Assign) funcDef.body[i]; + assertEquals(1, assign.targets.length); + Attribute attribute = (Attribute) assign.targets[0]; + NameTok attr = (NameTok) attribute.attr; + assertEquals("ATTRIBUTE"+i, attr.id.toString()); + } + assertNull(funcDef.body[3]); + } + + + public void testAttributes6() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " def m1(self):\n" + + " call(ATTRIBUTE = 10)\n" + //inside function call: don't get it + "\n" + + ""); + assertEquals(1, m.body.length); + ClassDef classDef = ((ClassDef)m.body[0]); + assertEquals("Bar", ((NameTok)classDef.name).id); + assertEquals(1, classDef.body.length); //method + + FunctionDef funcDef = (FunctionDef)classDef.body[0]; + assertEquals("m1", ((NameTok)funcDef.name).id); + assertNull(funcDef.body); + } + + public void testAttributes7() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " call(ATTRIBUTE = 10)\n" + //inside function call: don't get it + "\n" + + ""); + assertEquals(1, m.body.length); + ClassDef classDef = ((ClassDef)m.body[0]); + assertEquals("Bar", ((NameTok)classDef.name).id); + assertEquals(0, classDef.body.length); //method + + } + + public void testAttributes8() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " ATTRIBUTE = dict(\n" + //inside function call: don't get it + " b=20,\n" + + " c=30\n" + + " )\n" + + "\n" + + "\n" + + "\n" + + "\n" + + ""); + assertEquals(1, m.body.length); + ClassDef classDef = ((ClassDef)m.body[0]); + assertEquals("Bar", ((NameTok)classDef.name).id); + assertEquals(1, classDef.body.length); + Assign assign = (Assign) classDef.body[0]; + assertEquals(1, assign.targets.length); + Name name = (Name) assign.targets[0]; + assertEquals("ATTRIBUTE", name.id); + } + public void testDefinitionsParser() { Module m = (Module) FastDefinitionsParser.parse("class Bar:pass"); *************** *** 269,272 **** --- 442,454 ---- } + public void testEmpty() { + Module m = (Module) FastDefinitionsParser.parse( + "# This file was created automatically by SWIG 1.3.29.\n" + + "" + + "" //empty + ); + assertEquals(0, m.body.length); + } + |
From: Fabio Z. <fa...@us...> - 2008-07-05 21:52:53
|
Update of /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21875/src/org/python/pydev/parser/prettyprinter Modified Files: PrettyPrinter.java Log Message: FastParser handling attributes (still needs more testing). Index: PrettyPrinter.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinter/PrettyPrinter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PrettyPrinter.java 13 Jun 2007 00:20:54 -0000 1.2 --- PrettyPrinter.java 5 Jul 2008 21:53:00 -0000 1.3 *************** *** 731,735 **** for(SimpleNode n: node.body){ ! n.accept(this); } --- 731,737 ---- for(SimpleNode n: node.body){ ! if(n != null){ ! n.accept(this); ! } } |
From: Fabio Z. <fa...@us...> - 2008-07-05 21:52:52
|
Update of /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/visitors/scope In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21875/src/org/python/pydev/parser/visitors/scope Modified Files: ReturnVisitor.java Log Message: FastParser handling attributes (still needs more testing). Index: ReturnVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/visitors/scope/ReturnVisitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ReturnVisitor.java 25 Feb 2007 12:07:27 -0000 1.1 --- ReturnVisitor.java 5 Jul 2008 21:53:00 -0000 1.2 *************** *** 18,22 **** try { for(stmtType b:functionDef.body){ ! b.accept(visitor); } } catch (Exception e) { --- 18,24 ---- try { for(stmtType b:functionDef.body){ ! if(b != null){ ! b.accept(visitor); ! } } } catch (Exception e) { |
From: Fabio Z. <fa...@us...> - 2008-07-05 21:52:48
|
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-serv21864/src_completions/org/python/pydev/editor/codecompletion/revisited/visitors Modified Files: LocalScope.java Log Message: FastParser handling attributes (still needs more testing). 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.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** LocalScope.java 9 Apr 2008 00:17:19 -0000 1.7 --- LocalScope.java 5 Jul 2008 21:52:55 -0000 1.8 *************** *** 157,161 **** for (int i = 0; i < body.length; i++) { GlobalModelVisitor visitor = new GlobalModelVisitor(GlobalModelVisitor.GLOBAL_TOKENS, ""); ! body[i].accept(visitor); List<IToken> t = visitor.tokens; for (Iterator<IToken> iterator = t.iterator(); iterator.hasNext();) { --- 157,165 ---- for (int i = 0; i < body.length; i++) { GlobalModelVisitor visitor = new GlobalModelVisitor(GlobalModelVisitor.GLOBAL_TOKENS, ""); ! stmtType stmt = body[i]; ! if(stmt == null){ ! continue; ! } ! stmt.accept(visitor); List<IToken> t = visitor.tokens; for (Iterator<IToken> iterator = t.iterator(); iterator.hasNext();) { *************** *** 229,234 **** FunctionDef f = (FunctionDef) element; for (int i = 0; i < f.body.length; i++) { ! ! importedModules.addAll(GlobalModelVisitor.getTokens(f.body[i], GlobalModelVisitor.ALIAS_MODULES, moduleName, null)); } } --- 233,240 ---- FunctionDef f = (FunctionDef) element; for (int i = 0; i < f.body.length; i++) { ! stmtType stmt = f.body[i]; ! if(stmt != null){ ! importedModules.addAll(GlobalModelVisitor.getTokens(stmt, GlobalModelVisitor.ALIAS_MODULES, moduleName, null)); ! } } } |
From: Fabio Z. <fa...@us...> - 2008-07-05 19:50:09
|
Update of /cvsroot/pydev/org.python.pydev.parser/tests/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9092/tests/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParserTest.java Log Message: test Index: FastDefinitionsParserTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/tests/org/python/pydev/parser/fastparser/FastDefinitionsParserTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FastDefinitionsParserTest.java 2 Jul 2008 20:38:39 -0000 1.3 --- FastDefinitionsParserTest.java 5 Jul 2008 19:50:16 -0000 1.4 *************** *** 72,75 **** --- 72,82 ---- } + + public void testDefinitionsAttributesParser() { + Module m = (Module) FastDefinitionsParser.parse("class Bar:pass"); + assertEquals(1, m.body.length); + assertEquals("Bar", ((NameTok)((ClassDef)m.body[0]).name).id); + } + public void testDefinitionsParser2() { Module m = (Module) FastDefinitionsParser.parse("class Bar"); |
From: Fabio Z. <fa...@us...> - 2008-07-05 19:42:06
|
Update of /cvsroot/pydev/org.python.pydev.debug/pysrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6084/pysrc Modified Files: pydevd_comm.py pydevd_vars.py pydevd_resolver.py Log Message: <li><strong>Debugger</strong>: Better inspection of internal variables for dict, list, tuple, set and frozenset</li> Index: pydevd_resolver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/pysrc/pydevd_resolver.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pydevd_resolver.py 18 Mar 2008 02:55:03 -0000 1.5 --- pydevd_resolver.py 5 Jul 2008 19:42:13 -0000 1.6 *************** *** 8,12 **** --- 8,24 ---- __builtin__.True = 1 __builtin__.False = 0 + + + + #======================================================================================================================= + # UnableToResolveVariableException + #======================================================================================================================= + class UnableToResolveVariableException(Exception): + pass + + #======================================================================================================================= + # InspectStub + #======================================================================================================================= class InspectStub: def isbuiltin(self, _args): *************** *** 27,36 **** #types does not include a MethodWrapperType try: ! MethodWrapperType = type([].__str__) except: ! MethodWrapperType = None ! class Resolver: def resolve(self, var, attribute): --- 39,87 ---- #types does not include a MethodWrapperType try: ! MethodWrapperType = type([].__str__) except: ! MethodWrapperType = None ! #======================================================================================================================= ! # AbstractResolver ! #======================================================================================================================= ! class AbstractResolver: ! ''' ! This class exists only for documentation purposes to explain how to create a resolver. ! ! Some examples on how to resolve things: ! - list: getDictionary could return a dict with index->item and use the index to resolve it later ! - set: getDictionary could return a dict with id(object)->object and reiterate in that array to resolve it later ! - arbitrary instance: getDictionary could return dict with attr_name->attr and use getattr to resolve it later ! ''' ! ! def resolve(self, var, attribute): ! ''' ! In this method, we'll resolve some child item given the string representation of the item in the key ! representing the previously asked dictionary. ! ! @param var: this is the actual variable to be resolved. ! @param attribute: this is the string representation of a key previously returned in getDictionary. ! ''' ! raise NotImplementedError ! ! def getDictionary(self, var): ! ''' ! @param var: this is the variable that should have its children gotten. ! ! @return: a dictionary where each pair key, value should be shown to the user as children items ! in the variables view for the given var. ! ''' ! raise NotImplementedError ! ! ! #======================================================================================================================= ! # DefaultResolver ! #======================================================================================================================= ! class DefaultResolver: ! ''' ! DefaultResolver is the class that'll actually resolve how to show some variable. ! ''' def resolve(self, var, attribute): *************** *** 97,102 **** pass - ret['type'] = type(obj).__name__ - return ret --- 148,151 ---- *************** *** 144,159 **** d[ n ] = attr - d['type'] = type(var).__name__ return d ! class DictResolver(Resolver): def resolve(self, dict, key): ! return dict[key] def getDictionary(self, dict): ! return dict - class TupleResolver(Resolver): #to enumerate tuples and lists def resolve(self, var, attribute): return var[int(attribute)] --- 193,247 ---- d[ n ] = attr return d + ! #======================================================================================================================= ! # DictResolver ! #======================================================================================================================= ! class DictResolver: ! def resolve(self, dict, key): ! if key == '__len__': ! return None ! ! if '(' not in key: ! #we have to treat that because the dict resolver is also used to directly resolve the global and local ! #scopes (which already have the items directly) ! return dict[key] ! ! #ok, we have to iterate over the items to find the one that matches the id, because that's the only way ! #to actually find the reference from the string we have before. ! expected_id = int(key.split('(')[-1][:-1]) ! for key, val in dict.items(): ! if id(key) == expected_id: ! return val ! ! raise UnableToResolveVariableException() def getDictionary(self, dict): ! ret = {} ! ! for key, val in dict.items(): ! #we need to add the id because otherwise we cannot find the real object to get its contents later on. ! key = '%s (%s)' % (key, id(key)) ! ret[key] = val ! ! ret['__len__'] = len(dict) ! return ret ! ! ! ! #======================================================================================================================= ! # TupleResolver ! #======================================================================================================================= ! class TupleResolver: #to enumerate tuples and lists def resolve(self, var, attribute): + ''' + @param var: that's the original attribute + @param attribute: that's the key passed in the dict (as a string) + ''' + if attribute == '__len__': + return None return var[int(attribute)] *************** *** 163,170 **** d = {} for i, item in zip(range(len(var)), var): ! d[ i ] = item return d ! class InstanceResolver(Resolver): def resolve(self, var, attribute): field = var.__class__.getDeclaredField( attribute ) --- 251,292 ---- d = {} for i, item in zip(range(len(var)), var): ! d[ i ] = item ! d['__len__'] = len(var) return d ! ! ! #======================================================================================================================= ! # SetResolver ! #======================================================================================================================= ! class SetResolver: ! ''' ! Resolves a set as dict id(object)->object ! ''' ! ! def resolve(self, var, attribute): ! if attribute == '__len__': ! return None ! ! attribute = int(attribute) ! for v in var: ! if id(v) == attribute: ! return v ! ! raise UnableToResolveVariableException('Unable to resolve %s in %s' % (attribute, var)) ! ! def getDictionary(self, var): ! d = {} ! for item in var: ! d[ id(item) ] = item ! d['__len__'] = len(var) ! return d ! ! ! #======================================================================================================================= ! # InstanceResolver ! #======================================================================================================================= ! class InstanceResolver: ! def resolve(self, var, attribute): field = var.__class__.getDeclaredField( attribute ) *************** *** 184,194 **** traceback.print_exc() - ret['type'] = type(obj).__name__ return ret ! class JyArrayResolver(Resolver): ! def resolve(self, var, _attribute): ! return var def getDictionary(self,obj): --- 306,324 ---- traceback.print_exc() return ret ! #======================================================================================================================= ! # JyArrayResolver ! #======================================================================================================================= ! class JyArrayResolver: ! ''' ! This resolves a regular Object[] array from java ! ''' ! ! def resolve(self, var, attribute): ! if attribute == '__len__': ! return None ! return var[int(attribute)] def getDictionary(self,obj): *************** *** 196,212 **** for i in range(len(obj)): ! try: ! ret[ obj[i] ] = obj[i] ! except: ! traceback.print_exc() ! # I don't know why I'm getting an exception ! pass ! ret['type'] = type(obj).__name__ return ret ! defaultResolver = Resolver() dictResolver = DictResolver() tupleResolver = TupleResolver() instanceResolver = InstanceResolver() jyArrayResolver = JyArrayResolver() --- 326,338 ---- for i in range(len(obj)): ! ret[ i ] = obj[i] ! ret['__len__'] = len(obj) return ret ! defaultResolver = DefaultResolver() dictResolver = DictResolver() tupleResolver = TupleResolver() instanceResolver = InstanceResolver() jyArrayResolver = JyArrayResolver() + setResolver = SetResolver() Index: pydevd_comm.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/pysrc/pydevd_comm.py,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** pydevd_comm.py 12 Apr 2008 16:19:51 -0000 1.40 --- pydevd_comm.py 5 Jul 2008 19:42:13 -0000 1.41 *************** *** 100,103 **** --- 100,106 ---- #--------------------------------------------------------------------------------------------------- UTILITIES + #======================================================================================================================= + # PydevdLog + #======================================================================================================================= def PydevdLog(level, *args): """ levels are: *************** *** 114,118 **** #======================================================================================================================= ! # GlobacDbgHolder #======================================================================================================================= class GlobalDebuggerHolder: --- 117,121 ---- #======================================================================================================================= ! # GlobalDebuggerHolder #======================================================================================================================= class GlobalDebuggerHolder: *************** *** 122,128 **** --- 125,137 ---- globalDbg = None + #======================================================================================================================= + # GetGlobalDebugger + #======================================================================================================================= def GetGlobalDebugger(): return GlobalDebuggerHolder.globalDbg + #======================================================================================================================= + # SetGlobalDebugger + #======================================================================================================================= def SetGlobalDebugger(dbg): GlobalDebuggerHolder.globalDbg = dbg *************** *** 131,134 **** --- 140,146 ---- #------------------------------------------------------------------- ACTUAL COMM + #======================================================================================================================= + # PyDBDaemonThread + #======================================================================================================================= class PyDBDaemonThread(threading.Thread): *************** *** 160,163 **** --- 172,178 ---- # pass + #======================================================================================================================= + # ReaderThread + #======================================================================================================================= class ReaderThread(PyDBDaemonThread): """ reader thread reads and dispatches commands in an infinite loop """ *************** *** 191,194 **** --- 206,212 ---- #----------------------------------------------------------------------------------- SOCKET UTILITIES - WRITER + #======================================================================================================================= + # WriterThread + #======================================================================================================================= class WriterThread(PyDBDaemonThread): """ writer thread writes out the commands in an infinite loop """ *************** *** 236,239 **** --- 254,260 ---- #--------------------------------------------------- CREATING THE SOCKET THREADS + #======================================================================================================================= + # StartServer + #======================================================================================================================= def StartServer(port): """ binds to a port, waits for the debugger to connect """ *************** *** 244,247 **** --- 265,271 ---- return newSock + #======================================================================================================================= + # StartClient + #======================================================================================================================= def StartClient(host, port): """ connects to a host/port """ *************** *** 262,265 **** --- 286,292 ---- #------------------------------------------------------------------------------------ MANY COMMUNICATION STUFF + #======================================================================================================================= + # NetCommand + #======================================================================================================================= class NetCommand: """ Commands received/sent over the network. *************** *** 293,296 **** --- 320,326 ---- return str(cmd) + '\t' + str(seq) + '\t' + encoded + "\n" + #======================================================================================================================= + # NetCommandFactory + #======================================================================================================================= class NetCommandFactory: *************** *** 432,435 **** --- 462,468 ---- + #======================================================================================================================= + # InternalThreadCommand + #======================================================================================================================= class InternalThreadCommand: """ internal commands are generated/executed by the debugger. *************** *** 448,451 **** --- 481,487 ---- raise NotImplementedError("you have to override doIt") + #======================================================================================================================= + # InternalTerminateThread + #======================================================================================================================= class InternalTerminateThread(InternalThreadCommand): def __init__(self, thread_id): *************** *** 463,466 **** --- 499,505 ---- sys.exit(0) + #======================================================================================================================= + # InternalGetVariable + #======================================================================================================================= class InternalGetVariable(InternalThreadCommand): """ gets the value of a variable """ *************** *** 490,493 **** --- 529,535 ---- + #======================================================================================================================= + # InternalChangeVariable + #======================================================================================================================= class InternalChangeVariable(InternalThreadCommand): """ changes the value of a variable """ *************** *** 509,512 **** --- 551,557 ---- + #======================================================================================================================= + # InternalGetFrame + #======================================================================================================================= class InternalGetFrame(InternalThreadCommand): """ gets the value of a variable """ *************** *** 539,542 **** --- 584,590 ---- + #======================================================================================================================= + # InternalEvaluateExpression + #======================================================================================================================= class InternalEvaluateExpression(InternalThreadCommand): """ gets the value of a variable """ *************** *** 565,568 **** --- 613,619 ---- + #======================================================================================================================= + # PydevdFindThreadById + #======================================================================================================================= def PydevdFindThreadById(thread_id): try: Index: pydevd_vars.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/pysrc/pydevd_vars.py,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** pydevd_vars.py 12 Apr 2008 18:09:10 -0000 1.45 --- pydevd_vars.py 5 Jul 2008 19:42:13 -0000 1.46 *************** *** 27,66 **** #------------------------------------------------------------------------------------------------------ resolvers in map ! typeMap = {} ! try: ! #jython does not have this types try: ! typeMap[BooleanType] = (BooleanType, BooleanType.__name__, None) ! except NameError: ! pass #early versions of python do not have it. ! typeMap[BufferType] = (BufferType, BufferType.__name__, None) ! typeMap = { ! NoneType : (NoneType, NoneType.__name__, None), ! IntType : (IntType, IntType.__name__, None), ! LongType : (LongType, LongType.__name__, None), ! FloatType : (FloatType, FloatType.__name__, None), ! ComplexType : (ComplexType, ComplexType.__name__, None), ! StringType : (StringType, StringType.__name__, None), ! UnicodeType : (UnicodeType, UnicodeType.__name__, None), ! TupleType : (TupleType, TupleType.__name__, pydevd_resolver.tupleResolver), ! ListType : (ListType, ListType.__name__, pydevd_resolver.tupleResolver), ! DictType : (DictType, DictType.__name__, pydevd_resolver.dictResolver) ! } ! except: from org.python import core #@UnresolvedImport ! typeMap = { ! core.PyNone : ( core.PyNone, core.PyNone.__name__, None), ! core.PyInteger : ( core.PyInteger, core.PyInteger.__name__, None), ! core.PyLong : ( core.PyLong, core.PyLong.__name__, None), ! core.PyFloat : ( core.PyFloat, core.PyFloat.__name__, None), ! core.PyComplex : ( core.PyComplex, core.PyComplex.__name__, None), ! core.PyString : ( core.PyString, core.PyString.__name__, None), ! core.PyTuple : ( core.PyTuple, core.PyTuple.__name__, pydevd_resolver.tupleResolver), ! core.PyList : ( core.PyList, core.PyList.__name__, pydevd_resolver.tupleResolver), ! core.PyDictionary: (core.PyDictionary, core.PyDictionary.__name__, pydevd_resolver.dictResolver), ! core.PyJavaInstance: (core.PyJavaInstance, core.PyJavaInstance.__name__, pydevd_resolver.instanceResolver), ! core.PyStringMap: (core.PyStringMap, core.PyStringMap.__name__, pydevd_resolver.dictResolver) ! } --- 27,68 ---- #------------------------------------------------------------------------------------------------------ resolvers in map ! if not sys.platform.startswith("java"): ! typeMap = [ ! #None means that it should not be treated as a compound variable ! ! #isintance does not accept a tuple on some versions of python, so, we must declare it expanded ! (NoneType, None,), ! (IntType, None), ! (LongType, None), ! (FloatType, None), ! (ComplexType, None), ! (StringType, None), ! (UnicodeType, None), ! (TupleType, pydevd_resolver.tupleResolver), ! (ListType, pydevd_resolver.tupleResolver), ! (DictType, pydevd_resolver.dictResolver), ! ] ! try: ! typeMap.append(set, pydevd_resolver.setResolver) ! typeMap.append(frozenset, pydevd_resolver.setResolver) ! except: ! pass #not available on all python versions ! else: #platform is java from org.python import core #@UnresolvedImport ! typeMap = [ ! (core.PyNone, None), ! (core.PyInteger, None), ! (core.PyLong, None), ! (core.PyFloat, None), ! (core.PyComplex, None), ! (core.PyString, None), ! (core.PyTuple, pydevd_resolver.tupleResolver), ! (core.PyList, pydevd_resolver.tupleResolver), ! (core.PyDictionary, pydevd_resolver.dictResolver), ! (core.PyStringMap, pydevd_resolver.dictResolver), ! (core.PyJavaInstance, pydevd_resolver.instanceResolver), ! ] *************** *** 74,98 **** """ try: - if type(o).__name__=='org.python.core.PyJavaInstance': - return (type(o), type(o).__name__, pydevd_resolver.instanceResolver) ! if type(o).__name__=='org.python.core.PyArray': ! return (type(o), type(o).__name__, pydevd_resolver.jyArrayResolver) ! for t in typeMap.keys(): ! if isinstance(o, t): ! return typeMap[t] except: traceback.print_exc() - print typeMap - print typeMap.__class__ - print dir( typeMap ) #no match return default ! return (type(o), type(o).__name__, pydevd_resolver.defaultResolver) ! def makeValidXmlValue( s): return s.replace('<', '<').replace('>', '>') --- 76,105 ---- """ + try: + type_object = type(o) + type_name = type_object.__name__ + except: + #This happens for org.python.core.InitModule + return 'Unable to get Type', 'Unable to get Type', None + try: ! if type_name =='org.python.core.PyJavaInstance': ! return (type_object, type_name, pydevd_resolver.instanceResolver) ! if type_name =='org.python.core.PyArray': ! return (type_object, type_name, pydevd_resolver.jyArrayResolver) ! ! for t in typeMap: ! if isinstance(o, t[0]): ! return (type_object, type_name, t[1]) except: traceback.print_exc() #no match return default ! return (type_object, type_name, pydevd_resolver.defaultResolver) ! def makeValidXmlValue(s): return s.replace('<', '<').replace('>', '>') *************** *** 174,178 **** except Exception, e: traceback.print_exc() ! print >>sys.stderr,"unexpected error, recovered safely", str(e) return xml --- 181,185 ---- except Exception, e: traceback.print_exc() ! print >>sys.stderr, "unexpected error, recovered safely", str(e) return xml *************** *** 255,268 **** for k in attrList: ! type, typeName, resolver = getType(var) var = resolver.resolve(var, k) try: ! type, typeName, resolver = getType(var) return resolver.getDictionary(var) except: traceback.print_exc() ! def evaluateExpression( thread_id, frame_id, expression, doExec ): '''returns the result of the evaluated expression @param doExec: determines if we should do an exec or an eval --- 262,275 ---- for k in attrList: ! type, _typeName, resolver = getType(var) var = resolver.resolve(var, k) try: ! type, _typeName, resolver = getType(var) return resolver.getDictionary(var) except: traceback.print_exc() ! def evaluateExpression(thread_id, frame_id, expression, doExec): '''returns the result of the evaluated expression @param doExec: determines if we should do an exec or an eval *************** *** 279,283 **** exec expression in frame.f_globals, frame.f_locals else: ! result = eval( compiled, frame.f_globals, frame.f_locals ) print result return --- 286,290 ---- exec expression in frame.f_globals, frame.f_locals else: ! result = eval(compiled, frame.f_globals, frame.f_locals) print result return *************** *** 286,295 **** result = None try: ! result = eval( expression, frame.f_globals, frame.f_locals ) except Exception, e: ! result = str( e ) return result ! def changeAttrExpression( thread_id, frame_id, attr, expression ): '''Changes some attribute in a given frame. @note: it will not (currently) work if we're not in the topmost frame (that's a python --- 293,302 ---- result = None try: ! result = eval(expression, frame.f_globals, frame.f_locals) except Exception, e: ! result = str(e) return result ! def changeAttrExpression(thread_id, frame_id, attr, expression): '''Changes some attribute in a given frame. @note: it will not (currently) work if we're not in the topmost frame (that's a python |
From: Fabio Z. <fa...@us...> - 2008-07-05 19:41:58
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6011 Modified Files: Changes.txt Log Message: <li><strong>Debugger</strong>: Better inspection of internal variables for dict, list, tuple, set and frozenset</li> Index: Changes.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/Changes.txt,v retrieving revision 1.404 retrieving revision 1.405 diff -C2 -d -r1.404 -r1.405 *** Changes.txt 3 Jul 2008 01:04:04 -0000 1.404 --- Changes.txt 5 Jul 2008 19:42:06 -0000 1.405 *************** *** 15,18 **** --- 15,19 ---- <li><strong>Pydev package explorer</strong>: Link working with compare editor</li> <li><strong>Auto-indent</strong>: Fixed problem when smart indent was turned off</li> + <li><strong>Debugger</strong>: Better inspection of internal variables for dict, list, tuple, set and frozenset</li> </ul> |
From: Fabio Z. <fa...@us...> - 2008-07-04 00:54:39
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15495 Modified Files: TODO.txt Log Message: Index: TODO.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/TODO.txt,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** TODO.txt 23 Jun 2008 20:52:23 -0000 1.71 --- TODO.txt 4 Jul 2008 00:54:47 -0000 1.72 *************** *** 1,3 **** --- 1,4 ---- - Check: Context insensitive info being created twice??? (create a test case for that) + - Add shortcut for running unit-test - Context insensitive completions: |
From: Fabio Z. <fa...@us...> - 2008-07-03 01:03:58
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/autoedit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28865/src/org/python/pydev/editor/autoedit Modified Files: PyAutoIndentStrategy.java Log Message: Fixed problem when smart indent was off. Index: PyAutoIndentStrategy.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/autoedit/PyAutoIndentStrategy.java,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** PyAutoIndentStrategy.java 15 Jun 2008 16:45:26 -0000 1.69 --- PyAutoIndentStrategy.java 3 Jul 2008 01:04:04 -0000 1.70 *************** *** 564,568 **** }else{ PySelection selection = new PySelection(document, command.offset); ! if(selection.getCursorLineContents().trim().endsWith(":")){ command.text += prefs.getIndentationString(); } --- 564,568 ---- }else{ PySelection selection = new PySelection(document, command.offset); ! if(selection.getLineContentsToCursor().trim().endsWith(":")){ command.text += prefs.getIndentationString(); } |
From: Fabio Z. <fa...@us...> - 2008-07-03 01:03:57
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28865 Modified Files: Changes.txt Log Message: Fixed problem when smart indent was off. Index: Changes.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/Changes.txt,v retrieving revision 1.403 retrieving revision 1.404 diff -C2 -d -r1.403 -r1.404 *** Changes.txt 30 Jun 2008 00:29:06 -0000 1.403 --- Changes.txt 3 Jul 2008 01:04:04 -0000 1.404 *************** *** 14,17 **** --- 14,18 ---- <li><strong>raw_input() and input()</strong>: functions are now changed when a program is launched from eclipse to consider a trailing '\r'</li> <li><strong>Pydev package explorer</strong>: Link working with compare editor</li> + <li><strong>Auto-indent</strong>: Fixed problem when smart indent was turned off</li> </ul> |
From: Fabio Z. <fa...@us...> - 2008-07-03 01:03:57
|
Update of /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28865/tests/org/python/pydev/editor Modified Files: PyAutoIndentStrategyTest.java Log Message: Fixed problem when smart indent was off. Index: PyAutoIndentStrategyTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/PyAutoIndentStrategyTest.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** PyAutoIndentStrategyTest.java 6 Apr 2008 19:51:34 -0000 1.65 --- PyAutoIndentStrategyTest.java 3 Jul 2008 01:04:04 -0000 1.66 *************** *** 26,30 **** PyAutoIndentStrategyTest s = new PyAutoIndentStrategyTest("testt"); s.setUp(); ! s.testCommentsIndent2(); s.tearDown(); junit.textui.TestRunner.run(PyAutoIndentStrategyTest.class); --- 26,30 ---- PyAutoIndentStrategyTest s = new PyAutoIndentStrategyTest("testt"); s.setUp(); ! s.testNoIndent(); s.tearDown(); junit.textui.TestRunner.run(PyAutoIndentStrategyTest.class); *************** *** 843,846 **** --- 843,859 ---- } + public void testNoIndent() { + TestIndentPrefs prefs = new TestIndentPrefs(true, 4); + prefs.smartIndentAfterPar = false; + strategy.setIndentPrefs(prefs); + + String doc = "" + + "def m1(): \n"; + DocCmd docCmd = new DocCmd(0, 0, "\n"); + strategy.customizeDocumentCommand(new Document(doc), docCmd); + String expected = "\n"; + assertEquals(expected, docCmd.text); + } + public void testDedent() { strategy.setIndentPrefs(new TestIndentPrefs(true, 4)); |