[Pydev-cvs] org.python.pydev.core/src/org/python/pydev/core/docutils DocUtils.java, 1.14, 1.15 NoPe
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-09-27 19:57:44
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19948/src/org/python/pydev/core/docutils Modified Files: DocUtils.java NoPeerAvailableException.java StringUtils.java WordUtils.java PySelection.java PyDocIterator.java ParsingUtils.java PyPartitionScanner.java Log Message: Synching to latest changes: Pydev <ul> <li><strong>Editor</strong>: Cursor settings no longer overridden</li> <li><strong>Code-completion</strong>: If __all__ is defined with runtime elements (and not only in a single assign statement), it's ignored for code-completion purposes</li> <li><strong>Debugger</strong>: Pythonpath the same in debug and regular modes (sys.path[0] is the same directory as the file run)</li> <li><strong>Debugger</strong>: Persist choices done in the debugger when files from the debugger are not found</li> <li><strong>Interpreter config</strong>: "email" automatically added to the "forced builtins"</li> <li><strong>Parser</strong>: Correctly recognizing absolute import with 3 or more levels</li> <li><strong>Syntax check</strong>: Option to do only on active editor</li> </ul> Also: tabs changed for spaces Index: ParsingUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ParsingUtils.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ParsingUtils.java 19 Jul 2008 19:53:36 -0000 1.26 --- ParsingUtils.java 27 Sep 2008 19:57:34 -0000 1.27 *************** *** 356,378 **** */ public int findNextSingle(int i, char curr) { ! boolean ignoreNext = false; int len = len(); while(i < len){ ! char c = charAt(i); ! ! ! if(!ignoreNext && c == curr){ ! break; ! } if(!ignoreNext){ ! if(c == '\\'){ //escaped quote, ignore the next char even if it is a ' or " ! ignoreNext = true; ! } }else{ ignoreNext = false; } ! i++; } return i; --- 356,378 ---- */ public int findNextSingle(int i, char curr) { ! boolean ignoreNext = false; int len = len(); while(i < len){ ! char c = charAt(i); ! ! ! if(!ignoreNext && c == curr){ ! break; ! } if(!ignoreNext){ ! if(c == '\\'){ //escaped quote, ignore the next char even if it is a ' or " ! ignoreNext = true; ! } }else{ ignoreNext = false; } ! i++; } return i; *************** *** 386,396 **** while(i+2 < len){ char c = charAt(i); ! if (c == curr && charAt(i+1) == curr && charAt(i+2) == curr){ break; } ! i++; ! if(c == '\\'){ //this is for escaped quotes ! i++; ! } } if(len < i+2){ --- 386,396 ---- while(i+2 < len){ char c = charAt(i); ! if (c == curr && charAt(i+1) == curr && charAt(i+2) == curr){ break; } ! i++; ! if(c == '\\'){ //this is for escaped quotes ! i++; ! } } if(len < i+2){ *************** *** 472,480 **** int j = parsingUtils.getLiteralEnd(i, ch); if(whitespacesToo){ ! buf.delete(i, j+1); }else{ ! for (int k = 0; i+k < j+1; k++) { ! buf.replace(i+k, i+k+1, " "); ! } } } --- 472,480 ---- int j = parsingUtils.getLiteralEnd(i, ch); if(whitespacesToo){ ! buf.delete(i, j+1); }else{ ! for (int k = 0; i+k < j+1; k++) { ! buf.replace(i+k, i+k+1, " "); ! } } } *************** *** 491,496 **** } } ! public static void removeLiterals(FastStringBuffer buf) { ! ParsingUtils parsingUtils = create(buf); for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); --- 491,496 ---- } } ! public static void removeLiterals(FastStringBuffer buf) { ! ParsingUtils parsingUtils = create(buf); for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); *************** *** 506,518 **** int j = parsingUtils.getLiteralEnd(i, ch); for (int k = 0; i+k < j+1; k++) { ! buf.replace(i+k, i+k+1, " "); ! } } } ! } ! public static Iterator<String> getNoLiteralsOrCommentsIterator(IDocument doc) { ! return new PyDocIterator(doc); ! } --- 506,518 ---- int j = parsingUtils.getLiteralEnd(i, ch); for (int k = 0; i+k < j+1; k++) { ! buf.replace(i+k, i+k+1, " "); ! } } } ! } ! public static Iterator<String> getNoLiteralsOrCommentsIterator(IDocument doc) { ! return new PyDocIterator(doc); ! } *************** *** 576,583 **** if(ch == '\'' || ch == '"'){ ! curr = PY_SINGLELINE_STRING1; ! if(ch == '"'){ ! curr = PY_SINGLELINE_STRING2; ! } i = parsingUtils.getLiteralEnd(i, ch); } --- 576,583 ---- if(ch == '\'' || ch == '"'){ ! curr = PY_SINGLELINE_STRING1; ! if(ch == '"'){ ! curr = PY_SINGLELINE_STRING2; ! } i = parsingUtils.getLiteralEnd(i, ch); } *************** *** 596,600 **** IDocumentExtension3 docExtension= (IDocumentExtension3) document; IDocumentPartitionerExtension2 partitioner = (IDocumentPartitionerExtension2) ! docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); if(partitioner != null){ --- 596,600 ---- IDocumentExtension3 docExtension= (IDocumentExtension3) document; IDocumentPartitionerExtension2 partitioner = (IDocumentPartitionerExtension2) ! docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); if(partitioner != null){ Index: NoPeerAvailableException.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/NoPeerAvailableException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NoPeerAvailableException.java 24 Mar 2008 15:57:35 -0000 1.1 --- NoPeerAvailableException.java 27 Sep 2008 19:57:34 -0000 1.2 *************** *** 3,9 **** public class NoPeerAvailableException extends RuntimeException { ! public NoPeerAvailableException(String message) { ! super(message); ! } } --- 3,9 ---- public class NoPeerAvailableException extends RuntimeException { ! public NoPeerAvailableException(String message) { ! super(message); ! } } Index: PyPartitionScanner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/PyPartitionScanner.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyPartitionScanner.java 30 May 2006 00:21:11 -0000 1.1 --- PyPartitionScanner.java 27 Sep 2008 19:57:34 -0000 1.2 *************** *** 39,108 **** public class PyPartitionScanner extends RuleBasedPartitionScanner implements IPythonPartitions { public PyPartitionScanner() { ! super(); ! List<IPredicateRule> rules = new ArrayList<IPredicateRule>(); ! addMultilineStringRule(rules); ! addSinglelineStringRule(rules); ! addReprRule(rules); ! addCommentRule(rules); ! ! setPredicateRules(rules.toArray(new IPredicateRule[0])); ! } ! private void addReprRule(List<IPredicateRule> rules) { ! rules.add(new SingleLineRule("`", "`", new Token(IPythonPartitions.PY_BACKQUOTES))); ! } ! private void addSinglelineStringRule(List<IPredicateRule> rules) { ! // IToken singleLineString = new Token(PY_SINGLELINE_STRING); ! // rules.add(new SingleLineRule("\"", "\"", singleLineString, '\\')); ! // rules.add(new SingleLineRule("'", "'", singleLineString, '\\')); -- changed to the construct below because we need to continue on escape ! ! IToken singleLineString1 = new Token(IPythonPartitions.PY_SINGLELINE_STRING1); ! IToken singleLineString2 = new Token(IPythonPartitions.PY_SINGLELINE_STRING2); ! // deal with "" and '' strings ! boolean breaksOnEOL = true; ! boolean breaksOnEOF = false; ! boolean escapeContinuesLine = true; ! rules.add(new PatternRule("'", "'", singleLineString1, '\\', breaksOnEOL, breaksOnEOF, escapeContinuesLine)); ! rules.add(new PatternRule("\"", "\"", singleLineString2, '\\', breaksOnEOL, breaksOnEOF, escapeContinuesLine)); ! } ! private void addMultilineStringRule(List<IPredicateRule> rules) { ! IToken multiLineString1 = new Token(IPythonPartitions.PY_MULTILINE_STRING1); ! IToken multiLineString2 = new Token(IPythonPartitions.PY_MULTILINE_STRING2); ! // deal with ''' and """ strings ! rules.add(new MultiLineRule("'''", "'''", multiLineString1, '\\')); ! rules.add(new MultiLineRule("\"\"\"", "\"\"\"", multiLineString2,'\\')); ! ! //there is a bug in this construct: When parsing a simple document such as: ! // ! //"""ttt""" ! //print 'a' ! // ! //if lines are feed after 'ttt', it ends up considering the whole document as a multiline string. ! //the bug is reported at: http://sourceforge.net/tracker/index.php?func=detail&aid=1402165&group_id=85796&atid=577329 ! // ! //some regards on the bug: ! //- it does not happen if the multiline has ''' instead of """ ! //- also, if we first add the """ rule and after the ''' rule, the bug happens with ''' and not """ ! //- if the user later changes the first line of that multiline or a line above it, it ends up parsing correctly again ! //- if we let just one of the constructs, no problem happens ! // ! //I also tried creating a new token for it, but it had problems too (not the same ones, but had other problems). ! } ! private void addCommentRule(List<IPredicateRule> rules) { ! IToken comment = new Token(IPythonPartitions.PY_COMMENT); ! rules.add(new EndOfLineRule("#", comment)); ! } ! ! /** ! * @return all types recognized by this scanner (used by doc partitioner) ! */ ! static public String[] getTypes() { ! return IPythonPartitions.types; ! } /** --- 39,108 ---- public class PyPartitionScanner extends RuleBasedPartitionScanner implements IPythonPartitions { public PyPartitionScanner() { ! super(); ! List<IPredicateRule> rules = new ArrayList<IPredicateRule>(); ! addMultilineStringRule(rules); ! addSinglelineStringRule(rules); ! addReprRule(rules); ! addCommentRule(rules); ! ! setPredicateRules(rules.toArray(new IPredicateRule[0])); ! } ! private void addReprRule(List<IPredicateRule> rules) { ! rules.add(new SingleLineRule("`", "`", new Token(IPythonPartitions.PY_BACKQUOTES))); ! } ! private void addSinglelineStringRule(List<IPredicateRule> rules) { ! // IToken singleLineString = new Token(PY_SINGLELINE_STRING); ! // rules.add(new SingleLineRule("\"", "\"", singleLineString, '\\')); ! // rules.add(new SingleLineRule("'", "'", singleLineString, '\\')); -- changed to the construct below because we need to continue on escape ! ! IToken singleLineString1 = new Token(IPythonPartitions.PY_SINGLELINE_STRING1); ! IToken singleLineString2 = new Token(IPythonPartitions.PY_SINGLELINE_STRING2); ! // deal with "" and '' strings ! boolean breaksOnEOL = true; ! boolean breaksOnEOF = false; ! boolean escapeContinuesLine = true; ! rules.add(new PatternRule("'", "'", singleLineString1, '\\', breaksOnEOL, breaksOnEOF, escapeContinuesLine)); ! rules.add(new PatternRule("\"", "\"", singleLineString2, '\\', breaksOnEOL, breaksOnEOF, escapeContinuesLine)); ! } ! private void addMultilineStringRule(List<IPredicateRule> rules) { ! IToken multiLineString1 = new Token(IPythonPartitions.PY_MULTILINE_STRING1); ! IToken multiLineString2 = new Token(IPythonPartitions.PY_MULTILINE_STRING2); ! // deal with ''' and """ strings ! rules.add(new MultiLineRule("'''", "'''", multiLineString1, '\\')); ! rules.add(new MultiLineRule("\"\"\"", "\"\"\"", multiLineString2,'\\')); ! ! //there is a bug in this construct: When parsing a simple document such as: ! // ! //"""ttt""" ! //print 'a' ! // ! //if lines are feed after 'ttt', it ends up considering the whole document as a multiline string. ! //the bug is reported at: http://sourceforge.net/tracker/index.php?func=detail&aid=1402165&group_id=85796&atid=577329 ! // ! //some regards on the bug: ! //- it does not happen if the multiline has ''' instead of """ ! //- also, if we first add the """ rule and after the ''' rule, the bug happens with ''' and not """ ! //- if the user later changes the first line of that multiline or a line above it, it ends up parsing correctly again ! //- if we let just one of the constructs, no problem happens ! // ! //I also tried creating a new token for it, but it had problems too (not the same ones, but had other problems). ! } ! private void addCommentRule(List<IPredicateRule> rules) { ! IToken comment = new Token(IPythonPartitions.PY_COMMENT); ! rules.add(new EndOfLineRule("#", comment)); ! } ! ! /** ! * @return all types recognized by this scanner (used by doc partitioner) ! */ ! static public String[] getTypes() { ! return IPythonPartitions.types; ! } /** *************** *** 110,128 **** * @return the partitioner that is set in the document */ ! public static IDocumentPartitioner checkPartitionScanner(IDocument document) { ! if(document == null){ ! return null; } IDocumentExtension3 docExtension= (IDocumentExtension3) document; ! IDocumentPartitioner partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); ! if (partitioner == null){ addPartitionScanner(document); //get it again for the next check partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); } ! if (!(partitioner instanceof PyPartitioner)){ Log.log("Partitioner should be subclass of PyPartitioner. It is "+partitioner.getClass()); ! } return partitioner; } --- 110,128 ---- * @return the partitioner that is set in the document */ ! public static IDocumentPartitioner checkPartitionScanner(IDocument document) { ! if(document == null){ ! return null; } IDocumentExtension3 docExtension= (IDocumentExtension3) document; ! IDocumentPartitioner partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); ! if (partitioner == null){ addPartitionScanner(document); //get it again for the next check partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); } ! if (!(partitioner instanceof PyPartitioner)){ Log.log("Partitioner should be subclass of PyPartitioner. It is "+partitioner.getClass()); ! } return partitioner; } Index: PyDocIterator.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/PyDocIterator.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PyDocIterator.java 6 Jul 2008 21:58:28 -0000 1.9 --- PyDocIterator.java 27 Sep 2008 19:57:34 -0000 1.10 *************** *** 8,15 **** public class PyDocIterator implements Iterator<String> { ! private int offset; ! private IDocument doc; ! ! private boolean addNewLinesToRet = true; private boolean returnNewLinesOnLiterals = false; private boolean inLiteral = false; --- 8,15 ---- public class PyDocIterator implements Iterator<String> { ! private int offset; ! private IDocument doc; ! ! private boolean addNewLinesToRet = true; private boolean returnNewLinesOnLiterals = false; private boolean inLiteral = false; *************** *** 18,22 **** private int lastReturned = -1; private boolean addComments = false; ! public PyDocIterator(IDocument doc, boolean addNewLinesToRet) { this(doc, addNewLinesToRet, false, false); --- 18,22 ---- private int lastReturned = -1; private boolean addComments = false; ! public PyDocIterator(IDocument doc, boolean addNewLinesToRet) { this(doc, addNewLinesToRet, false, false); *************** *** 34,76 **** * @param addComments if true, comments found will be yielded (otherwise, no comments will be shown) */ ! public PyDocIterator(IDocument doc, boolean addNewLinesToRet, boolean returnNewLinesOnLiterals, boolean changeLiteralsForSpaces, boolean addComments) { ! this(doc); ! this.addNewLinesToRet = addNewLinesToRet; this.returnNewLinesOnLiterals = returnNewLinesOnLiterals; this.changeLiteralsForSpaces = changeLiteralsForSpaces; this.addComments = addComments; ! } ! ! public PyDocIterator(IDocument doc) { ! this.doc = doc; ! } ! ! /** ! * Changes the current offset in the document. Note: this method is not safe for use after the iteration ! * started! ! * ! * @param offset the offset where this class should start parsing (note: the offset must be a ! * code partition, otherwise the yielded values will be wrong). ! */ ! public void setStartingOffset(int offset){ ! this.offset = offset; ! } ! public boolean hasNext() { ! return offset < doc.getLength(); ! } ! ! public int getLastReturnedLine(){ ! try { lastReturned = doc.getLineOfOffset(offset-1); ! } catch (BadLocationException e) { ! //ignore (keep the last one) ! } return lastReturned; ! } ! private String nextInLiteral() { ! StringBuffer buf = new StringBuffer(); ! try { char ch = doc.getChar(offset); --- 34,76 ---- * @param addComments if true, comments found will be yielded (otherwise, no comments will be shown) */ ! public PyDocIterator(IDocument doc, boolean addNewLinesToRet, boolean returnNewLinesOnLiterals, boolean changeLiteralsForSpaces, boolean addComments) { ! this(doc); ! this.addNewLinesToRet = addNewLinesToRet; this.returnNewLinesOnLiterals = returnNewLinesOnLiterals; this.changeLiteralsForSpaces = changeLiteralsForSpaces; this.addComments = addComments; ! } ! ! public PyDocIterator(IDocument doc) { ! this.doc = doc; ! } ! ! /** ! * Changes the current offset in the document. Note: this method is not safe for use after the iteration ! * started! ! * ! * @param offset the offset where this class should start parsing (note: the offset must be a ! * code partition, otherwise the yielded values will be wrong). ! */ ! public void setStartingOffset(int offset){ ! this.offset = offset; ! } ! public boolean hasNext() { ! return offset < doc.getLength(); ! } ! ! public int getLastReturnedLine(){ ! try { lastReturned = doc.getLineOfOffset(offset-1); ! } catch (BadLocationException e) { ! //ignore (keep the last one) ! } return lastReturned; ! } ! private String nextInLiteral() { ! StringBuffer buf = new StringBuffer(); ! try { char ch = doc.getChar(offset); *************** *** 106,150 **** } ! /** ! * @return the next line in the document ! */ ! public String next() { try { ! StringBuffer buf = new StringBuffer(); ! if(inLiteral){ ! int initialOffset = offset; ! String ret = nextInLiteral(); ! if(ret.length() > 0 && initialOffset < offset){ //if it didn't move in the offset, disregard the results if(WordUtils.endsWith(ret, '\r') || WordUtils.endsWith(ret, '\n')){ ! if(!addNewLinesToRet){ ! ret = ret.substring(0, ret.length() -1); ! } ! buf.append(ret); return ret; }else{ buf.append(ret); } ! } ! } ! char ch = 0; ! ! int docLen = doc.getLength(); ! ParsingUtils parsingUtils = ParsingUtils.create(doc); while(ch != '\r' && ch != '\n' && offset < docLen){ ! ch = doc.getChar(offset); ! if (ch == '#') { ! ! while (offset < docLen && ch != '\n' && ch != '\r') { ! ch = doc.getChar(offset); ! if(addComments && ch != '\n' && ch != '\r'){ ! buf.append(ch); ! } ! offset++; ! } ! ! }else if (ch == '\'' || ch == '"') { if(returnNewLinesOnLiterals){ inLiteral = true; --- 106,150 ---- } ! /** ! * @return the next line in the document ! */ ! public String next() { try { ! StringBuffer buf = new StringBuffer(); ! if(inLiteral){ ! int initialOffset = offset; ! String ret = nextInLiteral(); ! if(ret.length() > 0 && initialOffset < offset){ //if it didn't move in the offset, disregard the results if(WordUtils.endsWith(ret, '\r') || WordUtils.endsWith(ret, '\n')){ ! if(!addNewLinesToRet){ ! ret = ret.substring(0, ret.length() -1); ! } ! buf.append(ret); return ret; }else{ buf.append(ret); } ! } ! } ! char ch = 0; ! ! int docLen = doc.getLength(); ! ParsingUtils parsingUtils = ParsingUtils.create(doc); while(ch != '\r' && ch != '\n' && offset < docLen){ ! ch = doc.getChar(offset); ! if (ch == '#') { ! ! while (offset < docLen && ch != '\n' && ch != '\r') { ! ch = doc.getChar(offset); ! if(addComments && ch != '\n' && ch != '\r'){ ! buf.append(ch); ! } ! offset++; ! } ! ! }else if (ch == '\'' || ch == '"') { if(returnNewLinesOnLiterals){ inLiteral = true; *************** *** 153,160 **** if(ret.length() > 0){ if(WordUtils.endsWith(ret, '\r') || WordUtils.endsWith(ret, '\n')){ ! if(!addNewLinesToRet){ ! ret = ret.substring(0, ret.length() -1); ! } ! buf.append(ret); return buf.toString(); }else{ --- 153,160 ---- if(ret.length() > 0){ if(WordUtils.endsWith(ret, '\r') || WordUtils.endsWith(ret, '\n')){ ! if(!addNewLinesToRet){ ! ret = ret.substring(0, ret.length() -1); ! } ! buf.append(ret); return buf.toString(); }else{ *************** *** 169,207 **** offset++; } ! ! }else if(ch != '\n' && ch != '\r'){ ! //will be added later ! buf.append(ch); ! offset++; ! }else{ ! offset++; ! } ! } ! ! //handle the \r, \n or \r\n ! if(ch == '\n' || ch == '\r'){ ! if(addNewLinesToRet){ ! buf.append(ch); ! } ! if(ch == '\r'){ ! if(offset < docLen && doc.getChar(offset) == '\n'){ ! offset++; ! if(addNewLinesToRet){ ! buf.append('\n'); ! } ! } ! } ! } ! ! return buf.toString(); ! ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! } ! public void remove() { ! throw new RuntimeException("Not Impl."); ! } } --- 169,207 ---- offset++; } ! ! }else if(ch != '\n' && ch != '\r'){ ! //will be added later ! buf.append(ch); ! offset++; ! }else{ ! offset++; ! } ! } ! ! //handle the \r, \n or \r\n ! if(ch == '\n' || ch == '\r'){ ! if(addNewLinesToRet){ ! buf.append(ch); ! } ! if(ch == '\r'){ ! if(offset < docLen && doc.getChar(offset) == '\n'){ ! offset++; ! if(addNewLinesToRet){ ! buf.append('\n'); ! } ! } ! } ! } ! ! return buf.toString(); ! ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! } ! public void remove() { ! throw new RuntimeException("Not Impl."); ! } } Index: StringUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/StringUtils.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** StringUtils.java 28 Jul 2008 15:53:24 -0000 1.17 --- StringUtils.java 27 Sep 2008 19:57:34 -0000 1.18 *************** *** 352,354 **** --- 352,368 ---- } + /** + * Same as Python join: Go through all the paths in the string and join them with the passed delimiter. + */ + public static String join(String delimiter, String[] splitted) { + FastStringBuffer buf = new FastStringBuffer(splitted.length*100); + for (String string : splitted) { + if(buf.length() > 0){ + buf.append(delimiter); + } + buf.append(string); + } + return buf.toString(); + } + } Index: DocUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/DocUtils.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** DocUtils.java 6 Jul 2008 21:58:28 -0000 1.14 --- DocUtils.java 27 Sep 2008 19:57:34 -0000 1.15 *************** *** 23,27 **** */ public class DocUtils { ! /** * Field representing an empty string. --- 23,27 ---- */ public class DocUtils { ! /** * Field representing an empty string. *************** *** 96,110 **** if(tokSpaces != null && tokSpaces.length() > spaces.length()){ ! if(src.indexOf('(') != -1){ ! src = src.substring(0, src.indexOf('('))+Character.toString(':'); ! }else{ ! src = "class COMPLETION_HELPER_CLASS:"; ! } }else{ ! if(src.indexOf('(') != -1){ ! src = src.substring(0, src.indexOf('('))+":pass"; ! }else{ ! src = "class COMPLETION_HELPER_CLASS:pass"; ! } } --- 96,110 ---- if(tokSpaces != null && tokSpaces.length() > spaces.length()){ ! if(src.indexOf('(') != -1){ ! src = src.substring(0, src.indexOf('('))+Character.toString(':'); ! }else{ ! src = "class COMPLETION_HELPER_CLASS:"; ! } }else{ ! if(src.indexOf('(') != -1){ ! src = src.substring(0, src.indexOf('('))+":pass"; ! }else{ ! src = "class COMPLETION_HELPER_CLASS:pass"; ! } } *************** *** 139,146 **** */ public static String createSpaceString(int width) { ! String existing = widthToSpaceString.getObj(width); ! if(existing != null){ ! return existing; ! } StringBuffer b = new StringBuffer(width); while (width-- > 0){ --- 139,146 ---- */ public static String createSpaceString(int width) { ! String existing = widthToSpaceString.getObj(width); ! if(existing != null){ ! return existing; ! } StringBuffer b = new StringBuffer(width); while (width-- > 0){ *************** *** 182,192 **** ! public static boolean hasOpeningBracket(String trimmedLine) { ! return trimmedLine.indexOf('{') != -1 || trimmedLine.indexOf('(') != -1 || trimmedLine.indexOf('[') != -1; ! } ! ! public static boolean hasClosingBracket(String trimmedLine) { ! return trimmedLine.indexOf('}') != -1 || trimmedLine.indexOf(')') != -1 || trimmedLine.indexOf(']') != -1; ! } /** --- 182,192 ---- ! public static boolean hasOpeningBracket(String trimmedLine) { ! return trimmedLine.indexOf('{') != -1 || trimmedLine.indexOf('(') != -1 || trimmedLine.indexOf('[') != -1; ! } ! ! public static boolean hasClosingBracket(String trimmedLine) { ! return trimmedLine.indexOf('}') != -1 || trimmedLine.indexOf(')') != -1 || trimmedLine.indexOf(']') != -1; ! } /** Index: PySelection.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/PySelection.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** PySelection.java 6 Jul 2008 21:58:28 -0000 1.64 --- PySelection.java 27 Sep 2008 19:57:34 -0000 1.65 *************** *** 44,82 **** private IDocument doc; private ITextSelection textSelection; ! public static final String[] DEDENT_TOKENS = new String[]{ ! "return", ! "break", ! "continue", ! "pass", ! "raise", ! // "yield" -- https://sourceforge.net/tracker/index.php?func=detail&aid=1807411&group_id=85796&atid=577329 (doesn't really end scope) // after seeing the std lib, several cases use yield at the middle of the scope ! }; ! public static final String[] CLASS_AND_FUNC_TOKENS = new String[]{ ! "def" , ! "class" , }; - public static final String[] INDENT_TOKENS = new String[]{ - "if" , - "for" , - "except" , - "def" , - "class" , - "else" , - "elif" , - "while" , - "try" , - "with" , - "finally" - }; - /** ! * Alternate constructor for PySelection. Takes in a text editor from Eclipse. ! * ! * @param textEditor The text editor operating in Eclipse ! */ public PySelection(ITextEditor textEditor) { this(textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()), --- 44,82 ---- private IDocument doc; private ITextSelection textSelection; ! public static final String[] DEDENT_TOKENS = new String[]{ ! "return", ! "break", ! "continue", ! "pass", ! "raise", ! // "yield" -- https://sourceforge.net/tracker/index.php?func=detail&aid=1807411&group_id=85796&atid=577329 (doesn't really end scope) // after seeing the std lib, several cases use yield at the middle of the scope ! }; ! public static final String[] CLASS_AND_FUNC_TOKENS = new String[]{ ! "def" , ! "class" , ! }; ! ! public static final String[] INDENT_TOKENS = new String[]{ ! "if" , ! "for" , ! "except" , ! "def" , ! "class" , ! "else" , ! "elif" , ! "while" , ! "try" , ! "with" , ! "finally" }; /** ! * Alternate constructor for PySelection. Takes in a text editor from Eclipse. ! * ! * @param textEditor The text editor operating in Eclipse ! */ public PySelection(ITextEditor textEditor) { this(textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()), *************** *** 101,110 **** */ public PySelection(IDocument doc, int line, int col) { ! this(doc, line, col, 0); } public PySelection(IDocument doc, int line, int col, int len) { ! this.doc = doc; ! this.textSelection = new TextSelection(doc, getAbsoluteCursorOffset(line, col), len); } --- 101,110 ---- */ public PySelection(IDocument doc, int line, int col) { ! this(doc, line, col, 0); } public PySelection(IDocument doc, int line, int col, int len) { ! this.doc = doc; ! this.textSelection = new TextSelection(doc, getAbsoluteCursorOffset(line, col), len); } *************** *** 237,244 **** int lineOffset = -1; try { ! lineOffset = document.getLineOffset(line); ! } catch (BadLocationException e1) { ! throw new RuntimeException(e1); ! } int j = parsingUtils.eatPar(lineOffset+i, null); try { --- 237,244 ---- int lineOffset = -1; try { ! lineOffset = document.getLineOffset(line); ! } catch (BadLocationException e1) { ! throw new RuntimeException(e1); ! } int j = parsingUtils.eatPar(lineOffset+i, null); try { *************** *** 285,290 **** while (current != '\'' && current != '"' && initialOffset < docLen-1) { ! ! //if it is inside a parenthesis, we will not take it into consideration. if(current == '('){ initialOffset = parsingUtils.eatPar(initialOffset, buf); --- 285,290 ---- while (current != '\'' && current != '"' && initialOffset < docLen-1) { ! ! //if it is inside a parenthesis, we will not take it into consideration. if(current == '('){ initialOffset = parsingUtils.eatPar(initialOffset, buf); *************** *** 301,321 **** if(initialOffset < docLen-1){ ! if(initialOffset == 0){ //first char of the document... this is ok ! int i = parsingUtils.eatLiterals(buf, initialOffset); ! return new int[]{initialOffset, i}; ! } ! ! char lastChar = strDoc.charAt(initialOffset-1); ! //it is only global if after \r or \n ! if(lastChar == '\r' || lastChar == '\n'){ ! int i = parsingUtils.eatLiterals(buf, initialOffset); ! return new int[]{initialOffset, i}; ! } ! //ok, still not found, let's keep going ! return getFirstGlobalLiteral(buf, initialOffset+1); }else{ ! return new int[]{-1, -1}; ! } } catch (BadLocationException e) { --- 301,321 ---- if(initialOffset < docLen-1){ ! if(initialOffset == 0){ //first char of the document... this is ok ! int i = parsingUtils.eatLiterals(buf, initialOffset); ! return new int[]{initialOffset, i}; ! } ! ! char lastChar = strDoc.charAt(initialOffset-1); ! //it is only global if after \r or \n ! if(lastChar == '\r' || lastChar == '\n'){ ! int i = parsingUtils.eatLiterals(buf, initialOffset); ! return new int[]{initialOffset, i}; ! } ! //ok, still not found, let's keep going ! return getFirstGlobalLiteral(buf, initialOffset+1); }else{ ! return new int[]{-1, -1}; ! } } catch (BadLocationException e) { *************** *** 339,347 **** } ! public static String getLineWithoutLiterals(String line) { ! FastStringBuffer buf = new FastStringBuffer(line, 2); ! ParsingUtils.removeLiterals(buf); ! return buf.toString(); ! } /** --- 339,347 ---- } ! public static String getLineWithoutLiterals(String line) { ! FastStringBuffer buf = new FastStringBuffer(line, 2); ! ParsingUtils.removeLiterals(buf); ! return buf.toString(); ! } /** *************** *** 417,421 **** */ public int getLineOffset() { ! return getLineOffset(getCursorLine()); } --- 417,421 ---- */ public int getLineOffset() { ! return getLineOffset(getCursorLine()); } *************** *** 452,457 **** if(doc.getNumberOfLines() > i){ ! int nextLineOffset = doc.getLineInformation(i+1).getOffset(); ! length = nextLineOffset - offset; }else{ length = lineInformation.getLength(); --- 452,457 ---- if(doc.getNumberOfLines() > i){ ! int nextLineOffset = doc.getLineInformation(i+1).getOffset(); ! length = nextLineOffset - offset; }else{ length = lineInformation.getLength(); *************** *** 466,502 **** } ! public void deleteSpacesAfter(int offset) { ! try { ! final int len = countSpacesAfter(offset); ! if(len > 0){ ! doc.replace(offset, len, ""); ! } ! } catch (Exception e) { ! //ignore ! } ! } ! public int countSpacesAfter(int offset) throws BadLocationException { ! if(offset >= doc.getLength()){ ! return 0; ! } ! ! int initial = offset; ! String next = doc.get(offset, 1); ! ! //don't delete 'all' that is considered whitespace (as \n and \r) ! try { ! while (next.charAt(0) == ' ' || next.charAt(0) == '\t') { ! offset++; ! next = doc.get(offset, 1); ! } ! } catch (Exception e) { ! // ignore ! } ! ! return offset-initial; ! } ! --- 466,502 ---- } ! public void deleteSpacesAfter(int offset) { ! try { ! final int len = countSpacesAfter(offset); ! if(len > 0){ ! doc.replace(offset, len, ""); ! } ! } catch (Exception e) { ! //ignore ! } ! } ! public int countSpacesAfter(int offset) throws BadLocationException { ! if(offset >= doc.getLength()){ ! return 0; ! } ! ! int initial = offset; ! String next = doc.get(offset, 1); ! ! //don't delete 'all' that is considered whitespace (as \n and \r) ! try { ! while (next.charAt(0) == ' ' || next.charAt(0) == '\t') { ! offset++; ! next = doc.get(offset, 1); ! } ! } catch (Exception e) { ! // ignore ! } ! ! return offset-initial; ! } ! *************** *** 531,543 **** int offset = -1; if(doc.getNumberOfLines() > afterLine){ ! offset = doc.getLineInformation(afterLine+1).getOffset(); }else{ ! offset = doc.getLineInformation(afterLine).getOffset(); } if(doc.getNumberOfLines()-1 == afterLine){ ! contents = endLineDelim + contents; ! } --- 531,543 ---- int offset = -1; if(doc.getNumberOfLines() > afterLine){ ! offset = doc.getLineInformation(afterLine+1).getOffset(); }else{ ! offset = doc.getLineInformation(afterLine).getOffset(); } if(doc.getNumberOfLines()-1 == afterLine){ ! contents = endLineDelim + contents; ! } *************** *** 944,952 **** for (String dedent : indentTokens) { ! if(trimmed.startsWith(dedent)){ ! if(isCompleteToken(trimmed, dedent)){ ! return new Tuple3<String, String, String>(line, foundDedent, lowestStr); ! } ! } } //we have to check for the first condition (if a dedent is found, but we already found --- 944,952 ---- for (String dedent : indentTokens) { ! if(trimmed.startsWith(dedent)){ ! if(isCompleteToken(trimmed, dedent)){ ! return new Tuple3<String, String, String>(line, foundDedent, lowestStr); ! } ! } } //we have to check for the first condition (if a dedent is found, but we already found *************** *** 1003,1031 **** public static List<Integer> getLineStartOffsets(String replacementString) { ! ArrayList<Integer> ret = new ArrayList<Integer>(); ! ret.add(0);//there is always a starting one at 0 ! ! //we may have line breaks with \r\n, or only \n or \r ! for (int i = 0; i < replacementString.length(); i++) { ! char c = replacementString.charAt(i); ! if(c == '\r'){ ! i++; ! int foundAt = i; ! ! if(i < replacementString.length()){ ! c = replacementString.charAt(i); ! if(c == '\n'){ ! // i++; ! foundAt = i+1; ! } ! } ! ret.add(foundAt); ! }else if(c == '\n'){ ! ret.add(i+1); ! } ! } ! ! return ret; } --- 1003,1031 ---- public static List<Integer> getLineStartOffsets(String replacementString) { ! ArrayList<Integer> ret = new ArrayList<Integer>(); ! ret.add(0);//there is always a starting one at 0 ! ! //we may have line breaks with \r\n, or only \n or \r ! for (int i = 0; i < replacementString.length(); i++) { ! char c = replacementString.charAt(i); ! if(c == '\r'){ ! i++; ! int foundAt = i; ! if(i < replacementString.length()){ ! c = replacementString.charAt(i); ! if(c == '\n'){ ! // i++; ! foundAt = i+1; ! } ! } ! ret.add(foundAt); ! ! }else if(c == '\n'){ ! ret.add(i+1); ! } ! } ! ! return ret; } *************** *** 1041,1045 **** for (int i = 0; i < replacementString.length(); i++) { char c = replacementString.charAt(i); ! if(c == '\r'){ lineBreaks++; ret.add(i); --- 1041,1045 ---- for (int i = 0; i < replacementString.length(); i++) { char c = replacementString.charAt(i); ! if(c == '\r'){ lineBreaks++; ret.add(i); *************** *** 1068,1072 **** for (int i = 0; i < replacementString.length(); i++) { char c = replacementString.charAt(i); ! if(c == '\r'){ lineBreaks++; ignoreNextNAt = i + 1; --- 1068,1072 ---- for (int i = 0; i < replacementString.length(); i++) { char c = replacementString.charAt(i); ! if(c == '\r'){ lineBreaks++; ignoreNextNAt = i + 1; *************** *** 1191,1199 **** if(getFullQualifier == true){ ! //may have changed ! documentOffset = tupPrefix.o2; } ! String activationToken = tupPrefix.o1; documentOffset = documentOffset-activationToken.length()-1; --- 1191,1199 ---- if(getFullQualifier == true){ ! //may have changed ! documentOffset = tupPrefix.o2; } ! String activationToken = tupPrefix.o1; documentOffset = documentOffset-activationToken.length()-1; *************** *** 1296,1328 **** */ public static Tuple<String, Integer> extractActivationToken(IDocument document, int offset, boolean getFullQualifier) { ! try { ! if(getFullQualifier){ ! //if we have to get the full qualifier, we'll have to walk the offset (cursor) forward ! while(offset < document.getLength()){ ! char ch= document.getChar(offset); ! if (Character.isJavaIdentifierPart(ch)){ ! offset++; ! }else{ ! break; ! } ! ! } ! } ! int i= offset; ! ! if (i > document.getLength()) ! return new Tuple<String, Integer>("", document.getLength()); //$NON-NLS-1$ ! ! while (i > 0) { ! char ch= document.getChar(i - 1); ! if (!Character.isJavaIdentifierPart(ch)) ! break; ! i--; ! } ! return new Tuple<String, Integer>(document.get(i, offset - i), offset); ! } catch (BadLocationException e) { ! return new Tuple<String, Integer>("", offset); //$NON-NLS-1$ ! } } --- 1296,1328 ---- */ public static Tuple<String, Integer> extractActivationToken(IDocument document, int offset, boolean getFullQualifier) { ! try { ! if(getFullQualifier){ ! //if we have to get the full qualifier, we'll have to walk the offset (cursor) forward ! while(offset < document.getLength()){ ! char ch= document.getChar(offset); ! if (Character.isJavaIdentifierPart(ch)){ ! offset++; ! }else{ ! break; ! } ! ! } ! } ! int i= offset; ! ! if (i > document.getLength()) ! return new Tuple<String, Integer>("", document.getLength()); //$NON-NLS-1$ ! ! while (i > 0) { ! char ch= document.getChar(i - 1); ! if (!Character.isJavaIdentifierPart(ch)) ! break; ! i--; ! } ! return new Tuple<String, Integer>(document.get(i, offset - i), offset); ! } catch (BadLocationException e) { ! return new Tuple<String, Integer>("", offset); //$NON-NLS-1$ ! } } *************** *** 1376,1392 **** public static int getFirstCharPosition(String src) { int i = 0; ! boolean breaked = false; ! while (i < src.length()) { ! if (Character.isWhitespace(src.charAt(i)) == false && src.charAt(i) != '\t') { ! i++; ! breaked = true; ! break; ! } ! i++; ! } ! if (!breaked){ ! i++; ! } ! return (i - 1); } --- 1376,1392 ---- public static int getFirstCharPosition(String src) { int i = 0; ! boolean breaked = false; ! while (i < src.length()) { ! if (Character.isWhitespace(src.charAt(i)) == false && src.charAt(i) != '\t') { ! i++; ! breaked = true; ! break; ! } ! i++; ! } ! if (!breaked){ ! i++; ! } ! return (i - 1); } *************** *** 1400,1406 **** public static int getFirstCharRelativePosition(IDocument doc, IRegion region) throws BadLocationException { int offset = region.getOffset(); ! String src = doc.get(offset, region.getLength()); ! return getFirstCharPosition(src); } --- 1400,1406 ---- public static int getFirstCharRelativePosition(IDocument doc, IRegion region) throws BadLocationException { int offset = region.getOffset(); ! String src = doc.get(offset, region.getLength()); ! return getFirstCharPosition(src); } *************** *** 1414,1419 **** public static int getFirstCharRelativeLinePosition(IDocument doc, int line) throws BadLocationException { IRegion region; ! region = doc.getLineInformation(line); ! return getFirstCharRelativePosition(doc, region); } --- 1414,1419 ---- public static int getFirstCharRelativeLinePosition(IDocument doc, int line) throws BadLocationException { IRegion region; ! region = doc.getLineInformation(line); ! return getFirstCharRelativePosition(doc, region); } *************** *** 1427,1432 **** public static int getFirstCharRelativePosition(IDocument doc, int cursorOffset) throws BadLocationException { IRegion region; ! region = doc.getLineInformationOfOffset(cursorOffset); ! return getFirstCharRelativePosition(doc, region); } --- 1427,1432 ---- public static int getFirstCharRelativePosition(IDocument doc, int cursorOffset) throws BadLocationException { IRegion region; ! region = doc.getLineInformationOfOffset(cursorOffset); ! return getFirstCharRelativePosition(doc, region); } *************** *** 1437,1449 **** * @param cursorOffset * @return position of the first character of the line (returned as an absolute ! * offset) * @throws BadLocationException */ public static int getFirstCharPosition(IDocument doc, int cursorOffset) ! throws BadLocationException { IRegion region; ! region = doc.getLineInformationOfOffset(cursorOffset); ! int offset = region.getOffset(); ! return offset + getFirstCharRelativePosition(doc, cursorOffset); } --- 1437,1449 ---- * @param cursorOffset * @return position of the first character of the line (returned as an absolute ! * offset) * @throws BadLocationException */ public static int getFirstCharPosition(IDocument doc, int cursorOffset) ! throws BadLocationException { IRegion region; ! region = doc.getLineInformationOfOffset(cursorOffset); ! int offset = region.getOffset(); ! return offset + getFirstCharRelativePosition(doc, cursorOffset); } *************** *** 1462,1493 **** ! private static boolean isCompleteToken(String trimmedLine, String dedent) { ! if(dedent.length() < trimmedLine.length()){ ! char afterToken = trimmedLine.charAt(dedent.length()); ! if(afterToken == ' ' || afterToken == ':' || afterToken == ';' || afterToken == '('){ ! return true; ! } ! return false; ! }else{ ! return true; ! } ! } ! /** ! * Class to help iterating through the document ! */ public static class DocIterator implements Iterator<String>{ private int startingLine; private boolean forward; private boolean isFirst = true; ! private int numberOfLines; ! private int lastReturnedLine=-1; ! private PySelection ps; ! ! public DocIterator(boolean forward, PySelection ps){ this(forward, ps, ps.getCursorLine(), true); ! } ! public DocIterator(boolean forward, PySelection ps, int startingLine, boolean considerFirst){ this.startingLine = startingLine; --- 1462,1493 ---- ! private static boolean isCompleteToken(String trimmedLine, String dedent) { ! if(dedent.length() < trimmedLine.length()){ ! char afterToken = trimmedLine.charAt(dedent.length()); ! if(afterToken == ' ' || afterToken == ':' || afterToken == ';' || afterToken == '('){ ! return true; ! } ! return false; ! }else{ ! return true; ! } ! } ! /** ! * Class to help iterating through the document ! */ public static class DocIterator implements Iterator<String>{ private int startingLine; private boolean forward; private boolean isFirst = true; ! private int numberOfLines; ! private int lastReturnedLine=-1; ! private PySelection ps; ! ! public DocIterator(boolean forward, PySelection ps){ this(forward, ps, ps.getCursorLine(), true); ! } ! public DocIterator(boolean forward, PySelection ps, int startingLine, boolean considerFirst){ this.startingLine = startingLine; *************** *** 1501,1505 **** public int getCurrentLine(){ ! return startingLine; } --- 1501,1505 ---- public int getCurrentLine(){ ! return startingLine; } *************** *** 1517,1540 **** */ public String next() { ! try { ! String line; ! if (forward) { ! line = ps.getLine(startingLine); ! lastReturnedLine = startingLine; ! startingLine++; ! } else { ! if (isFirst) { ! line = ps.getLineContentsToCursor(); ! isFirst = false; ! }else{ ! line = ps.getLine(startingLine); ! } ! lastReturnedLine = startingLine; ! startingLine--; ! } ! return line; ! } catch (Exception e) { ! throw new RuntimeException(e); ! } } --- 1517,1540 ---- */ public String next() { ! try { ! String line; ! if (forward) { ! line = ps.getLine(startingLine); ! lastReturnedLine = startingLine; ! startingLine++; ! } else { ! if (isFirst) { ! line = ps.getLineContentsToCursor(); ! isFirst = false; ! }else{ ! line = ps.getLine(startingLine); ! } ! lastReturnedLine = startingLine; ! startingLine--; ! } ! return line; ! } catch (Exception e) { ! throw new RuntimeException(e); ! } } *************** *** 1552,1636 **** * @return if the offset is inside the region */ ! public static boolean isInside(int offset, IRegion region) { if(offset >= region.getOffset() && offset <= (region.getOffset() + region.getLength())){ ! return true; } return false; ! } ! ! /** ! * @return if the col is inside the initial col/len ! */ ! public static boolean isInside(int col, int initialCol, int len) { ! if(col >= initialCol && col <= (initialCol + len)){ ! return true; ! } ! return false; ! } ! /** ! * @return if the region passed is composed of a single line ! */ ! public static boolean endsInSameLine(IDocument document, IRegion region) { ! try { ! int startLine = document.getLineOfOffset(region.getOffset()); ! int end = region.getOffset() + region.getLength(); ! int endLine = document.getLineOfOffset(end); ! return startLine == endLine; ! } catch (BadLocationException e) { ! return false; ! } ! } ! /** ! * @param offset the offset we want info on ! * @return a tuple with the line, col of the passed offset in the document ! */ ! public Tuple<Integer, Integer> getLineAndCol(int offset) { ! try { ! IRegion region = doc.getLineInformationOfOffset(offset); ! int line = doc.getLineOfOffset(offset); ! int col = offset - region.getOffset(); ! return new Tuple<Integer, Integer>(line, col); ! } catch (BadLocationException e) { ! throw new RuntimeException(e); ! } ! } ! /** ! * @return the contents from the document starting at the cursor line until a colon is reached. ! */ ! public String getToColon() { ! StringBuffer buffer = new StringBuffer(); ! ! for(int i = getLineOffset(); i < doc.getLength();i++){ ! try { ! char c = doc.getChar(i); ! buffer.append(c); ! if(c == ':'){ ! return buffer.toString(); ! } ! } catch (BadLocationException e) { ! throw new RuntimeException(e); ! } ! } ! return ""; //unable to find a colon ! } ! ! public boolean isInFunctionLine() { return FunctionPattern.matcher(getToColon().trim()).matches(); ! } ! ! public static boolean isIdentifier(String str) { ! return IdentifierPattern.matcher(str).matches(); ! } ! public boolean isInClassLine() { ! return ClassPattern.matcher(getToColon().trim()).matches(); ! } ! ! //spaces* 'def' space+ identifier space* ( (space|char|.|,|=|*|(|)|'|")* ): private static final Pattern FunctionPattern = Pattern.compile("\\s*def\\s+\\w*.*"); --- 1552,1636 ---- * @return if the offset is inside the region */ ! public static boolean isInside(int offset, IRegion region) { if(offset >= region.getOffset() && offset <= (region.getOffset() + region.getLength())){ ! return true; } return false; ! } ! ! /** ! * @return if the col is inside the initial col/len ! */ ! public static boolean isInside(int col, int initialCol, int len) { ! if(col >= initialCol && col <= (initialCol + len)){ ! return true; ! } ! return false; ! } ! /** ! * @return if the region passed is composed of a single line ! */ ! public static boolean endsInSameLine(IDocument document, IRegion region) { ! try { ! int startLine = document.getLineOfOffset(region.getOffset()); ! int end = region.getOffset() + region.getLength(); ! int endLine = document.getLineOfOffset(end); ! return startLine == endLine; ! } catch (BadLocationException e) { ! return false; ! } ! } ! /** ! * @param offset the offset we want info on ! * @return a tuple with the line, col of the passed offset in the document ! */ ! public Tuple<Integer, Integer> getLineAndCol(int offset) { ! try { ! IRegion region = doc.getLineInformationOfOffset(offset); ! int line = doc.getLineOfOffset(offset); ! int col = offset - region.getO... [truncated message content] |