Thread: [Pydev-cvs] org.python.pydev.core/src/org/python/pydev/core/docutils WordUtils.java, 1.5, 1.6 Parsi
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-06-15 16:45:14
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1941/src/org/python/pydev/core/docutils Modified Files: WordUtils.java ParsingUtils.java PySelection.java ImportHandle.java Log Message: Minors: ParsingUtils accepts null instead of buffer (so, objects that don't need the actual values can just use it to skip comments, parenthesis, etc). Index: PySelection.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/PySelection.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** PySelection.java 19 May 2008 00:58:28 -0000 1.62 --- PySelection.java 15 Jun 2008 16:45:20 -0000 1.63 *************** *** 29,32 **** --- 29,33 ---- import org.python.pydev.core.ICodeCompletionASTManager.ImportInfo; import org.python.pydev.core.log.Log; + import org.python.pydev.core.structure.FastStringBuffer; /** *************** *** 179,183 **** */ public int getLineAvailableForImport() { ! StringBuffer multiLineBuf = new StringBuffer(); int[] firstGlobalLiteral = getFirstGlobalLiteral(multiLineBuf, 0); --- 180,184 ---- */ public int getLineAvailableForImport() { ! FastStringBuffer multiLineBuf = new FastStringBuffer(); int[] firstGlobalLiteral = getFirstGlobalLiteral(multiLineBuf, 0); *************** *** 232,236 **** if(importInfo != null && importInfo.importsTipperStr != null && importInfo.importsTipperStr.trim().length() > 0){ if((i = str.indexOf('(')) != -1){ - StringBuffer buf = new StringBuffer(); //start of a multiline import int lineOffset = -1; --- 233,236 ---- *************** *** 240,244 **** throw new RuntimeException(e1); } ! int j = ParsingUtils.eatPar(document, lineOffset+i, buf); try { line = document.getLineOfOffset(j); --- 240,244 ---- throw new RuntimeException(e1); } ! int j = ParsingUtils.eatPar(document, lineOffset+i, null); try { line = document.getLineOfOffset(j); *************** *** 268,272 **** * @return a tuple with the offset of the start and end of the first multiline comment found */ ! public int[] getFirstGlobalLiteral(StringBuffer buf, int initialOffset){ try { IDocument d = getDoc(); --- 268,272 ---- * @return a tuple with the offset of the start and end of the first multiline comment found */ ! public int[] getFirstGlobalLiteral(FastStringBuffer buf, int initialOffset){ try { IDocument d = getDoc(); *************** *** 327,331 **** public static String getLineWithoutCommentsOrLiterals(String l) { ! StringBuffer buf = new StringBuffer(l); ParsingUtils.removeCommentsWhitespacesAndLiterals(buf, false); return buf.toString(); --- 327,331 ---- public static String getLineWithoutCommentsOrLiterals(String l) { ! FastStringBuffer buf = new FastStringBuffer(l, 2); ParsingUtils.removeCommentsWhitespacesAndLiterals(buf, false); return buf.toString(); *************** *** 337,341 **** public static String getLineWithoutLiterals(String line) { ! StringBuffer buf = new StringBuffer(line); ParsingUtils.removeLiterals(buf); return buf.toString(); --- 337,341 ---- public static String getLineWithoutLiterals(String line) { ! FastStringBuffer buf = new FastStringBuffer(line, 2); ParsingUtils.removeLiterals(buf); return buf.toString(); *************** *** 851,858 **** } int lineOffset = getStartLineOffset(); - StringBuffer buf = new StringBuffer(); String docContents = doc.get(); int i = lineOffset + openParIndex; ! int j = ParsingUtils.eatPar(docContents, i, buf); String insideParentesisTok = docContents.substring(i + 1, j); --- 851,857 ---- } int lineOffset = getStartLineOffset(); String docContents = doc.get(); int i = lineOffset + openParIndex; ! int j = ParsingUtils.eatPar(docContents, i, null); String insideParentesisTok = docContents.substring(i + 1, j); Index: ParsingUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ParsingUtils.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** ParsingUtils.java 18 May 2008 20:02:26 -0000 1.19 --- ParsingUtils.java 15 Jun 2008 16:45:20 -0000 1.20 *************** *** 11,14 **** --- 11,15 ---- import org.eclipse.jface.text.IDocumentPartitionerExtension2; import org.python.pydev.core.IPythonPartitions; + import org.python.pydev.core.structure.FastStringBuffer; *************** *** 22,26 **** * @return the : position */ ! public static int eatToColon(char[] cs, StringBuffer buf, int i) { while(i < cs.length && cs[i] != ':'){ buf.append(cs[i]); --- 23,27 ---- * @return the : position */ ! public static int eatToColon(char[] cs, FastStringBuffer buf, int i) { while(i < cs.length && cs[i] != ':'){ buf.append(cs[i]); *************** *** 35,49 **** /** * @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(Object cs, StringBuffer buf, int i) { while(i < len(cs) && charAt(cs,i) != '\n' && charAt(cs,i) != '\r'){ ! buf.append(charAt(cs,i)); i++; } if(i < len(cs)) ! buf.append(charAt(cs,i)); return i; --- 36,55 ---- /** * @param cs the char array we are parsing ! * @param buf used to add the comments contents (out) -- if it's null, it'll simply advance to the position and ! * return it. * @param i the # position * @return the end of the comments position (end of document or new line char) */ ! 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)); ! } return i; *************** *** 70,74 **** * @return the end of the token position (end of document or new line char or whitespace) */ ! public static int eatToken(char[] cs, StringBuffer buf, int i) { while(i < cs.length && !Character.isWhitespace(cs[i])){ buf.append(cs[i]); --- 76,80 ---- * @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]); *************** *** 87,91 **** * @return the end of the literal position (or end of document) */ ! public static int eatLiterals(Object cs, StringBuffer buf, int i) { //ok, current pos is ' or " //check if we're starting a single or multiline comment... --- 93,97 ---- * @return the end of the literal position (or end of document) */ ! public static int eatLiterals(Object cs, FastStringBuffer buf, int i) { //ok, current pos is ' or " //check if we're starting a single or multiline comment... *************** *** 131,139 **** * @return the end of the literal position (or end of document) */ ! public static int eatPar(Object cs, int i, StringBuffer buf) { return eatPar(cs, i, buf, '('); } ! public static int eatPar(Object cs, int i, StringBuffer buf, char par) { char c = ' '; --- 137,148 ---- * @return the end of the literal position (or end of document) */ ! public static int eatPar(Object cs, int i, FastStringBuffer buf) { return eatPar(cs, i, buf, '('); } ! /** ! * @param buf if null, it'll simply advance without adding anything to the buffer. ! */ ! public static int eatPar(Object cs, int i, FastStringBuffer buf, char par) { char c = ' '; *************** *** 146,160 **** if(c == '\'' || c == '"'){ //ignore comments or multiline comments... ! j = ParsingUtils.eatLiterals( cs, new StringBuffer(), j-1)+1; }else if(c == '#'){ ! j = ParsingUtils.eatComments(cs, new StringBuffer(), j-1)+1; }else if( c == par){ //open another par. ! j = eatPar(cs, j-1, new StringBuffer(), par)+1; }else{ ! ! buf.append(c); } } --- 155,170 ---- if(c == '\'' || c == '"'){ //ignore comments or multiline comments... ! j = ParsingUtils.eatLiterals( cs, null, j-1)+1; }else if(c == '#'){ ! j = ParsingUtils.eatComments(cs, null, j-1)+1; }else if( c == par){ //open another par. ! j = eatPar(cs, j-1, null, par)+1; }else{ ! if(buf != null){ ! buf.append(c); ! } } } *************** *** 213,216 **** --- 223,229 ---- return ((char[]) o)[i]; } + if (o instanceof FastStringBuffer) { + return ((FastStringBuffer) o).charAt(i); + } if (o instanceof StringBuffer) { return ((StringBuffer) o).charAt(i); *************** *** 233,236 **** --- 246,252 ---- return ((char[]) o).length; } + if (o instanceof FastStringBuffer) { + return ((FastStringBuffer) o).length(); + } if (o instanceof StringBuffer) { return ((StringBuffer) o).length(); *************** *** 269,273 **** } ! public static int eatWhitespaces(StringBuffer buf, int i) { while(i < buf.length() && Character.isWhitespace(buf.charAt(i))){ i++; --- 285,289 ---- } ! public static int eatWhitespaces(FastStringBuffer buf, int i) { while(i < buf.length() && Character.isWhitespace(buf.charAt(i))){ i++; *************** *** 276,284 **** } ! public static void removeCommentsWhitespacesAndLiterals(StringBuffer buf) { removeCommentsWhitespacesAndLiterals(buf, true); } /** ! * Removes all the comments, whitespaces and literals from a stringbuffer (might be useful when * just finding matches for something). * --- 292,300 ---- } ! public static void removeCommentsWhitespacesAndLiterals(FastStringBuffer buf) { removeCommentsWhitespacesAndLiterals(buf, true); } /** ! * Removes all the comments, whitespaces and literals from a FastStringBuffer (might be useful when * just finding matches for something). * *************** *** 288,292 **** * @param whitespacesToo: are you sure about the whitespaces? */ ! public static void removeCommentsWhitespacesAndLiterals(StringBuffer buf, boolean whitespacesToo) { for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); --- 304,308 ---- * @param whitespacesToo: are you sure about the whitespaces? */ ! public static void removeCommentsWhitespacesAndLiterals(FastStringBuffer buf, boolean whitespacesToo) { for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); *************** *** 323,327 **** } } ! public static void removeLiterals(StringBuffer buf) { for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); --- 339,343 ---- } } ! public static void removeLiterals(FastStringBuffer buf) { for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); *************** *** 348,352 **** ! public static void removeCommentsAndWhitespaces(StringBuffer buf) { for (int i = 0; i < buf.length(); i++) { --- 364,368 ---- ! public static void removeCommentsAndWhitespaces(FastStringBuffer buf) { for (int i = 0; i < buf.length(); i++) { *************** *** 372,376 **** } ! public static void removeToClosingPar(StringBuffer buf) { int length = buf.length(); for (int i = length -1; i >= 0; i--) { --- 388,392 ---- } ! public static void removeToClosingPar(FastStringBuffer buf) { int length = buf.length(); for (int i = length -1; i >= 0; i--) { *************** *** 398,402 **** */ public static String getContentType(String initial, int currPos) { ! StringBuffer buf = new StringBuffer(initial); String curr = PY_DEFAULT; --- 414,418 ---- */ public static String getContentType(String initial, int currPos) { ! FastStringBuffer buf = new FastStringBuffer(initial, 0); String curr = PY_DEFAULT; *************** *** 449,453 **** public static String makePythonParseable(String code, String delimiter) { ! return makePythonParseable(code, delimiter, new StringBuffer()); } --- 465,469 ---- public static String makePythonParseable(String code, String delimiter) { ! return makePythonParseable(code, delimiter, new FastStringBuffer()); } *************** *** 458,464 **** * @return a String that can be passed to the shell */ ! public static String makePythonParseable(String code, String delimiter, StringBuffer lastLine) { ! StringBuffer buffer = new StringBuffer(); ! StringBuffer currLine = new StringBuffer(); //we may have line breaks with \r\n, or only \n or \r --- 474,480 ---- * @return a String that can be passed to the shell */ ! public static String makePythonParseable(String code, String delimiter, FastStringBuffer lastLine) { ! FastStringBuffer buffer = new FastStringBuffer(); ! FastStringBuffer currLine = new FastStringBuffer(); //we may have line breaks with \r\n, or only \n or \r *************** *** 498,507 **** buffer.append(currLine); lastLine = currLine; ! currLine = new StringBuffer(); buffer.append(delimiter); foundNewLine = true; }else{ //found a line only with whitespaces ! currLine = new StringBuffer(); } } --- 514,523 ---- buffer.append(currLine); lastLine = currLine; ! currLine = new FastStringBuffer(); buffer.append(delimiter); foundNewLine = true; }else{ //found a line only with whitespaces ! currLine = new FastStringBuffer(); } } Index: ImportHandle.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ImportHandle.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ImportHandle.java 11 Jun 2008 00:00:09 -0000 1.6 --- ImportHandle.java 15 Jun 2008 16:45:20 -0000 1.7 *************** *** 8,11 **** --- 8,12 ---- import org.eclipse.jface.text.IDocument; import org.python.pydev.core.Tuple; + import org.python.pydev.core.structure.FastStringBuffer; /** *************** *** 131,146 **** ArrayList<String> importComments = new ArrayList<String>(); ! StringBuffer alias = new StringBuffer(); for(int i=0;i<importedStr.length();i++){ char c = importedStr.charAt(i); if(c == '#'){ ! StringBuffer comments = new StringBuffer(); i = ParsingUtils.eatComments(importedStr, comments, i); addImportAlias(lst, importComments, alias, comments.toString()); ! alias = new StringBuffer(); }else if(c == ',' || c == '\r' || c == '\n'){ addImportAlias(lst, importComments, alias, ""); ! alias = new StringBuffer(); }else if(c == '(' || c == ')' || c == '\\'){ --- 132,148 ---- ArrayList<String> importComments = new ArrayList<String>(); ! FastStringBuffer alias = new FastStringBuffer(); ! FastStringBuffer comments = new FastStringBuffer(); for(int i=0;i<importedStr.length();i++){ char c = importedStr.charAt(i); if(c == '#'){ ! comments = comments.clear(); i = ParsingUtils.eatComments(importedStr, comments, i); addImportAlias(lst, importComments, alias, comments.toString()); ! alias = alias.clear(); }else if(c == ',' || c == '\r' || c == '\n'){ addImportAlias(lst, importComments, alias, ""); ! alias = alias.clear(); }else if(c == '(' || c == ')' || c == '\\'){ *************** *** 180,184 **** * @param importComment the comment related to the import */ ! private void addImportAlias(ArrayList<String> lst, ArrayList<String> importComments, StringBuffer alias, String importComment) { --- 182,186 ---- * @param importComment the comment related to the import */ ! private void addImportAlias(ArrayList<String> lst, ArrayList<String> importComments, FastStringBuffer alias, String importComment) { *************** *** 332,336 **** boolean startedInMiddle = false; ! StringBuffer imp = new StringBuffer(); for(int i=0;i<importFound.length();i++){ char c = importFound.charAt(i); --- 334,338 ---- boolean startedInMiddle = false; ! FastStringBuffer imp = new FastStringBuffer(); for(int i=0;i<importFound.length();i++){ char c = importFound.charAt(i); *************** *** 348,352 **** //that's ok, not a valid import (at least, we couldn't parse it) } ! imp = new StringBuffer(); startedInMiddle = true; }else{ --- 350,354 ---- //that's ok, not a valid import (at least, we couldn't parse it) } ! imp = imp.clear(); startedInMiddle = true; }else{ Index: WordUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/WordUtils.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WordUtils.java 11 Jun 2006 18:29:06 -0000 1.5 --- WordUtils.java 15 Jun 2008 16:45:20 -0000 1.6 *************** *** 1,4 **** --- 1,6 ---- package org.python.pydev.core.docutils; + import org.python.pydev.core.structure.FastStringBuffer; + *************** *** 521,524 **** --- 523,536 ---- } + public static boolean endsWith(FastStringBuffer str, char c) { + if(str.length() == 0){ + return false; + } + if(str.charAt(str.length()-1) == c){ + return true; + } + return false; + } + } |