pydev-cvs Mailing List for PyDev for Eclipse (Page 10)
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-19 20:18:06
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/nature In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5510/src/org/python/pydev/plugin/nature Modified Files: PythonNatureStore.java Log Message: Applied patch that fixes race condition in PythonNatureStore: https://sourceforge.net/tracker/index.php?func=detail&aid=2019499&group_id=85796&atid=577329 Index: PythonNatureStore.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/nature/PythonNatureStore.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** PythonNatureStore.java 14 Jun 2008 22:14:55 -0000 1.19 --- PythonNatureStore.java 19 Jul 2008 20:18:14 -0000 1.20 *************** *** 11,14 **** --- 11,16 ---- import java.io.IOException; import java.util.ArrayList; + import java.util.Collections; + import java.util.LinkedList; import java.util.List; *************** *** 50,60 **** /** ! * This class stores PythonNature and PythonPathNature properties inside the project in a file instead of persistent properties. This allows PYTHONPATH and Python project version to be checked in into ! * version control systems. * * @author Gergely Kis <ger...@gm...> * */ - class PythonNatureStore implements IResourceChangeListener, IPythonNatureStore { --- 52,61 ---- /** ! * This class stores PythonNature and PythonPathNature properties inside the project in a file instead of persistent ! * properties. This allows PYTHONPATH and Python project version to be checked in into version control systems. * * @author Gergely Kis <ger...@gm...> * */ class PythonNatureStore implements IResourceChangeListener, IPythonNatureStore { *************** *** 65,87 **** */ private final class PythonNatureStoreJob extends Job { - private final ByteArrayInputStream is; ! private PythonNatureStoreJob(String name, ByteArrayInputStream is) { super(name); - this.is = is; } @Override protected IStatus run(IProgressMonitor monitor) { ! synchronized(xmlFile){ try{ onIgnoreRefresh++; if (!xmlFile.exists()) { xmlFile.create(is, true, monitor); - modStamp = xmlFile.getModificationStamp(); } else { xmlFile.setContents(is, true, false, monitor); - modStamp = xmlFile.getModificationStamp(); } xmlFile.refreshLocal(IResource.DEPTH_ZERO, monitor); }catch(Exception e){ --- 66,86 ---- */ private final class PythonNatureStoreJob extends Job { ! private PythonNatureStoreJob(String name) { super(name); } @Override protected IStatus run(IProgressMonitor monitor) { ! synchronized(saveLock){ ! ByteArrayInputStream is = (ByteArrayInputStream)pydevprojectStreams.remove(0); // remove() when it becomes queue try{ onIgnoreRefresh++; if (!xmlFile.exists()) { xmlFile.create(is, true, monitor); } else { xmlFile.setContents(is, true, false, monitor); } + modStamp = xmlFile.getModificationStamp(); xmlFile.refreshLocal(IResource.DEPTH_ZERO, monitor); }catch(Exception e){ *************** *** 115,118 **** --- 114,123 ---- private volatile int onIgnoreRefresh = 0; + private final Object saveLock = new Object(); + + // use Queue and ConcurrentLinkedQueue with 1.5 + private final List<ByteArrayInputStream> pydevprojectStreams = + Collections.synchronizedList(new LinkedList<ByteArrayInputStream>()); + /** * 0 means we're not in a store job *************** *** 157,161 **** * @see org.python.pydev.plugin.nature.IPythonNatureStore#setProject(org.eclipse.core.resources.IProject) */ ! public synchronized void setProject(IProject project) { synchronized (this) { if(project == null){ --- 162,166 ---- * @see org.python.pydev.plugin.nature.IPythonNatureStore#setProject(org.eclipse.core.resources.IProject) */ ! public void setProject(IProject project) { synchronized (this) { if(project == null){ *************** *** 196,204 **** private synchronized void checkLoad(String function) { traceFunc("checkLoad"); - synchronized (this) { if(!loaded){ PydevPlugin.log(new RuntimeException(StringUtils.format("%s still not loaded and '%s' already called.", xmlFile, function))); } - } traceFunc("END checkLoad"); } --- 201,207 ---- *************** *** 212,221 **** } traceFunc("getPathProperty - ", key); - synchronized (this) { checkLoad("getPathProperty"); String ret = getPathStringFromArray(getPathPropertyFromXml(key)); traceFunc("END getPathProperty - ", ret); return ret; - } } --- 215,222 ---- *************** *** 225,232 **** public synchronized void setPathProperty(QualifiedName key, String value) throws CoreException { traceFunc("setPathProperty"); - synchronized (this) { checkLoad("setPathProperty"); setPathPropertyToXml(key, getArrayFromPathString(value), true); - } traceFunc("END setPathProperty"); } --- 226,231 ---- *************** *** 246,250 **** traceFunc("loadFromFile"); boolean ret; - synchronized (this) { try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); --- 245,248 ---- *************** *** 292,296 **** throw new CoreException(status); } - } traceFunc("END loadFromFile"); --- 290,293 ---- *************** *** 313,317 **** private synchronized void migratePath(QualifiedName key) throws CoreException { traceFunc("migratePath"); - synchronized (this) { // Try to migrate from persistent property String[] propertyVal = getArrayFromPathString(project.getPersistentProperty(key)); --- 310,313 ---- *************** *** 322,326 **** project.setPersistentProperty(key, (String) null); } - } traceFunc("END migratePath"); } --- 318,321 ---- *************** *** 334,338 **** private synchronized Node getRootNodeInXml() { traceFunc("getRootNodeInXml"); - synchronized (this) { Assert.isNotNull(document); NodeList nodeList = document.getElementsByTagName(PYDEV_PROJECT_DESCRIPTION); --- 329,332 ---- *************** *** 348,352 **** throw new RuntimeException(StringUtils.format("Error. Unable to get the %s tag by its name. Project: %s", PYDEV_PROJECT_DESCRIPTION, project)); } - } /** --- 342,345 ---- *************** *** 358,362 **** private synchronized String getKeyString(QualifiedName key) { traceFunc("getKeyString"); - synchronized (this) { String keyString = key.getQualifier() != null ? key.getQualifier() : ""; String ret = keyString + "." + key.getLocalName(); --- 351,354 ---- *************** *** 364,368 **** return ret; } - } /** --- 356,359 ---- *************** *** 376,380 **** private synchronized Node findPropertyNodeInXml(String type, QualifiedName key) { traceFunc("findPropertyNodeInXml"); - synchronized (this) { Node root = getRootNodeInXml(); NodeList childNodes = root.getChildNodes(); --- 367,370 ---- *************** *** 398,402 **** return null; } - } /** --- 388,391 ---- *************** *** 407,413 **** * @return the array of strings with the text contents or null if the node has no children. */ ! private synchronized String[] getChildValuesWithType(Node node, String type) { traceFunc("getChildValuesWithType"); - synchronized (this) { NodeList childNodes = node.getChildNodes(); if (childNodes != null && childNodes.getLength() > 0) { --- 396,401 ---- * @return the array of strings with the text contents or null if the node has no children. */ ! private String[] getChildValuesWithType(Node node, String type) { traceFunc("getChildValuesWithType"); NodeList childNodes = node.getChildNodes(); if (childNodes != null && childNodes.getLength() > 0) { *************** *** 426,430 **** return null; } - } /** --- 414,417 ---- *************** *** 435,441 **** * @param values */ ! private synchronized void addChildValuesWithType(Node node, String type, String[] values) { traceFunc("addChildValuesWithType"); - synchronized (this) { assert (node != null); assert (values != null); --- 422,427 ---- * @param values */ ! private void addChildValuesWithType(Node node, String type, String[] values) { traceFunc("addChildValuesWithType"); assert (node != null); assert (values != null); *************** *** 446,450 **** node.appendChild(child); } - } traceFunc("END addChildValuesWithType"); } --- 432,435 ---- *************** *** 456,462 **** * @return the assembled string of paths or null if the input was null */ ! private synchronized String getPathStringFromArray(String[] pathArray) { traceFunc("getPathStringFromArray"); - synchronized (this) { if (pathArray != null) { FastStringBuffer s = new FastStringBuffer(); --- 441,446 ---- * @return the assembled string of paths or null if the input was null */ ! private String getPathStringFromArray(String[] pathArray) { traceFunc("getPathStringFromArray"); if (pathArray != null) { FastStringBuffer s = new FastStringBuffer(); *************** *** 472,476 **** traceFunc("END getPathStringFromArray (null)"); return null; - } } --- 456,459 ---- *************** *** 481,494 **** * @return the splitted array of strings or null if the input was null */ ! private synchronized String[] getArrayFromPathString(String pathString) { traceFunc("getArrayFromPathString"); ! synchronized (this) { ! if (pathString != null) { ! traceFunc("END getArrayFromPathString"); ! return pathString.split("\\|"); ! } ! traceFunc("END getArrayFromPathString (null)"); ! return null; } } --- 464,477 ---- * @return the splitted array of strings or null if the input was null */ ! private String[] getArrayFromPathString(String pathString) { ! traceFunc("getArrayFromPathString"); ! ! if (pathString != null) { ! traceFunc("END getArrayFromPathString"); ! return pathString.split("\\|"); } + traceFunc("END getArrayFromPathString (null)"); + return null; } *************** *** 568,574 **** * is not available in java 1.4 */ ! private synchronized void setTextContent(String textContent, Node self) throws DOMException { traceFunc("setTextContent"); - synchronized (this) { // get rid of any existing children Node child; --- 551,556 ---- * is not available in java 1.4 */ ! private void setTextContent(String textContent, Node self) throws DOMException { traceFunc("setTextContent"); // get rid of any existing children Node child; *************** *** 580,591 **** self.appendChild(document.createTextNode(textContent)); } - } traceFunc("END setTextContent"); } ! private synchronized String getTextContent(Node self) throws DOMException { traceFunc("getTextContent"); - synchronized (this) { FastStringBuffer fBufferStr = new FastStringBuffer(); Node child = self.getFirstChild(); --- 562,571 ---- self.appendChild(document.createTextNode(textContent)); } traceFunc("END setTextContent"); } ! private String getTextContent(Node self) throws DOMException { traceFunc("getTextContent"); FastStringBuffer fBufferStr = new FastStringBuffer(); Node child = self.getFirstChild(); *************** *** 610,614 **** traceFunc("END getTextContent - EMPTY"); return ""; - } } --- 590,593 ---- *************** *** 630,641 **** // internal method returning whether to take the given node's text content ! private synchronized boolean hasTextContent(Node child) { traceFunc("hasTextContent"); - synchronized (this) { boolean ret = child.getNodeType() != Node.COMMENT_NODE && child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE; traceFunc("END hasTextContent ", ret); return ret; - } } --- 609,618 ---- // internal method returning whether to take the given node's text content ! private boolean hasTextContent(Node child) { traceFunc("hasTextContent"); boolean ret = child.getNodeType() != Node.COMMENT_NODE && child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE; traceFunc("END hasTextContent ", ret); return ret; } *************** *** 649,653 **** * @throws CoreException */ ! private synchronized String[] getPathPropertyFromXml(QualifiedName key) throws CoreException { traceFunc("getPathPropertyFromXml"); synchronized (this) { --- 626,630 ---- * @throws CoreException */ ! private String[] getPathPropertyFromXml(QualifiedName key) throws CoreException { traceFunc("getPathPropertyFromXml"); synchronized (this) { *************** *** 677,681 **** * @throws CoreException */ ! private synchronized void setPathPropertyToXml(QualifiedName key, String[] paths, boolean store) throws CoreException { traceFunc("setPathPropertyToXml"); synchronized (this) { --- 654,658 ---- * @throws CoreException */ ! private void setPathPropertyToXml(QualifiedName key, String[] paths, boolean store) throws CoreException { traceFunc("setPathPropertyToXml"); synchronized (this) { *************** *** 719,723 **** * @throws TransformerException */ ! private synchronized byte[] serializeDocument(Document doc) throws IOException, TransformerException { traceFunc("serializeDocument"); synchronized (this) { --- 696,700 ---- * @throws TransformerException */ ! private byte[] serializeDocument(Document doc) throws IOException, TransformerException { traceFunc("serializeDocument"); synchronized (this) { *************** *** 840,846 **** } ! final ByteArrayInputStream is = new ByteArrayInputStream(serializeDocument(document)); ! PythonNatureStoreJob job = new PythonNatureStoreJob("Save .pydevproject", is); if (ProjectModulesManager.IN_TESTS){ --- 817,823 ---- } ! pydevprojectStreams.add(new ByteArrayInputStream(serializeDocument(document))); ! PythonNatureStoreJob job = new PythonNatureStoreJob("Save .pydevproject"); if (ProjectModulesManager.IN_TESTS){ |
From: Fabio Z. <fa...@us...> - 2008-07-19 19:53:29
|
Update of /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28721/tests/org/python/pydev/core/docutils Modified Files: ParsingUtilsTest.java Log Message: - Improved code formatter to deal with operators (+, -, *, etc) - Improved code formatter to handle '=' differently inside function calls / keyword args Index: ParsingUtilsTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/docutils/ParsingUtilsTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ParsingUtilsTest.java 14 Jul 2008 23:02:23 -0000 1.9 --- ParsingUtilsTest.java 19 Jul 2008 19:53:36 -0000 1.10 *************** *** 44,47 **** --- 44,96 ---- } + public void testEatComments() { + String str = "" + + "#comm1\n" + + "pass\n" + + ""; + ParsingUtils parsingUtils = ParsingUtils.create(str); + int i = parsingUtils.eatComments(null, 0); + assertEquals('\n', parsingUtils.charAt(i)); + } + + public void testEatLiterals() { + String str = "" + + "'''\n" + + "pass\n" + + "'''" + + "w" + + ""; + ParsingUtils parsingUtils = ParsingUtils.create(str); + int i = parsingUtils.eatLiterals(null, 0); + assertEquals(11, i); + assertEquals('\'', parsingUtils.charAt(i)); + } + + public void testEatWhitespaces() { + String str = "" + + " #comm\n" + + "pass\n" + + ""; + ParsingUtils parsingUtils = ParsingUtils.create(str); + FastStringBuffer buf = new FastStringBuffer(); + int i = parsingUtils.eatWhitespaces(buf, 0); + assertEquals(3, i); + assertEquals(" ", buf.toString()); + assertEquals(' ', parsingUtils.charAt(i)); + } + + + public void testEatWhitespaces2() { + String str = "" + + " "; + ParsingUtils parsingUtils = ParsingUtils.create(str); + FastStringBuffer buf = new FastStringBuffer(); + int i = parsingUtils.eatWhitespaces(buf, 0); + assertEquals(" ", buf.toString()); + assertEquals(' ', parsingUtils.charAt(i)); + assertEquals(3, i); + } + + public void testIterator() throws Exception { String str = "" + *************** *** 51,55 **** ""; Document d = new Document(str); ! Iterator it = ParsingUtils.getNoLiteralsOrCommentsIterator(d); assertEquals("\n",it.next()); assertEquals(true,it.hasNext()); --- 100,104 ---- ""; Document d = new Document(str); ! Iterator<String> it = ParsingUtils.getNoLiteralsOrCommentsIterator(d); assertEquals("\n",it.next()); assertEquals(true,it.hasNext()); |
From: Fabio Z. <fa...@us...> - 2008-07-19 19:53:29
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28721/src/org/python/pydev/core/docutils Modified Files: ParsingUtils.java Log Message: - Improved code formatter to deal with operators (+, -, *, etc) - Improved code formatter to handle '=' differently inside function calls / keyword args Index: ParsingUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ParsingUtils.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** ParsingUtils.java 14 Jul 2008 23:02:23 -0000 1.25 --- ParsingUtils.java 19 Jul 2008 19:53:36 -0000 1.26 *************** *** 163,167 **** * return it. * @param i the # position ! * @return the end of the comments position (end of document or new line char) */ public int eatComments(FastStringBuffer buf, int i) { --- 163,168 ---- * return it. * @param i the # position ! * @return the end of the comments position (end of document or new line char) ! * @note the new line char (\r or \n) will be added as a part of the comment. */ public int eatComments(FastStringBuffer buf, int i) { *************** *** 186,194 **** /** * @param cs the char array we are parsing * @param buf used to add the literal contents (out) * @param i the ' or " position ! * @return the end of the literal position (or end of document) */ public int eatLiterals(FastStringBuffer buf, int i) { --- 187,226 ---- + + + /** + * @param cs the char array we are parsing + * @param buf used to add the spaces (out) -- if it's null, it'll simply advance to the position and + * return it. + * @param i the first ' ' position + * @return the position of the last space found + */ + public int eatWhitespaces(FastStringBuffer buf, int i) { + int len = len(); + char c; + + while(i < len && (c = charAt(i)) == ' '){ + if(buf != null){ + buf.append(c); + } + i++; + } + + //go back to the last space found + i--; + + return i; + } + + + + + + /** * @param cs the char array we are parsing * @param buf used to add the literal contents (out) * @param i the ' or " position ! * @return the end of the literal position (or end of document) -- so, the final char is the ' or " position */ public int eatLiterals(FastStringBuffer buf, int i) { *************** *** 655,657 **** --- 687,691 ---- + + } |
From: Fabio Z. <fa...@us...> - 2008-07-19 19:53:24
|
Update of /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28692/tests/org/python/pydev/editor/actions Modified Files: PyFormatStdTest.java Log Message: - Improved code formatter to deal with operators (+, -, *, etc) - Improved code formatter to handle '=' differently inside function calls / keyword args Index: PyFormatStdTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions/PyFormatStdTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PyFormatStdTest.java 19 Jul 2008 11:57:58 -0000 1.12 --- PyFormatStdTest.java 19 Jul 2008 19:53:31 -0000 1.13 *************** *** 17,20 **** --- 17,22 ---- private FormatStd std; + + private static boolean DEBUG = false; public static void main(String[] args) { *************** *** 22,26 **** PyFormatStdTest n = new PyFormatStdTest(); n.setUp(); ! n.testFormatNotLinesOnlyWithParentesis(); n.tearDown(); --- 24,29 ---- PyFormatStdTest n = new PyFormatStdTest(); n.setUp(); ! // DEBUG = true; ! n.testDontDisturbWildImport(); n.tearDown(); *************** *** 39,42 **** --- 42,103 ---- super.setUp(); std = new PyFormatStd.FormatStd(); + std.operatorsWithSpace = true; + } + + public void testNoCloseList(){ + + std.operatorsWithSpace = true; + std.assignWithSpaceInsideParens = true; + std.spaceAfterComma = true; + std.parametersWithSpace = false; + + String s = ""+ + "constants = [\n"+ + " (qt.Qt.Key_Escape, ''), \n"+ + " (qt.Qt.Key_Tab, '\t'), \n"+ + "\n"; + + String s1 = ""+ + "constants = [\n"+ + " (qt.Qt.Key_Escape, ''),\n"+ + " (qt.Qt.Key_Tab, '\t'),\n"+ + "\n"; + + checkFormatResults(s, s1); + } + + public void testDontDisturbWildImport(){ + std.operatorsWithSpace = true; + std.assignWithSpaceInsideParens = true; + std.spaceAfterComma = true; + std.parametersWithSpace = false; + + checkFormatResults("from x import *\n\n"); + } + + public void testDontDisturbWildImport2(){ + std.operatorsWithSpace = true; + std.assignWithSpaceInsideParens = true; + std.spaceAfterComma = true; + std.parametersWithSpace = false; + + checkFormatResults("import *"); + } + + public void testDontDisturbVarArgsAndKwArgs(){ + std.operatorsWithSpace = true; + std.assignWithSpaceInsideParens = true; + std.spaceAfterComma = true; + std.parametersWithSpace = false; + + String s = ""+ + "def a( a,b, *args, **kwargs ):\n"+ + " call( *args, **kwargs)\n"; + + String s1 = ""+ + "def a(a, b, *args, **kwargs):\n"+ + " call(*args, **kwargs)\n"; + + checkFormatResults(s, s1); } *************** *** 164,167 **** --- 225,229 ---- std.spaceAfterComma = true; std.parametersWithSpace = false; + std.operatorsWithSpace = true; String s = ""+ *************** *** 171,175 **** String s1 = ""+ "def a(a, b):\n"+ ! " return ((a+b) + (a+b)) \n"; checkFormatResults(s, s1); --- 233,237 ---- String s1 = ""+ "def a(a, b):\n"+ ! " return ((a + b) + (a + b)) \n"; checkFormatResults(s, s1); *************** *** 179,183 **** String s2 = ""+ "def a( a, b ):\n"+ ! " return ( ( a+b ) + ( a+b ) ) \n"; checkFormatResults(s, s2); --- 241,245 ---- String s2 = ""+ "def a( a, b ):\n"+ ! " return ( ( a + b ) + ( a + b ) ) \n"; checkFormatResults(s, s2); *************** *** 187,190 **** --- 249,253 ---- std.spaceAfterComma = true; std.parametersWithSpace = true; + std.operatorsWithSpace = false; String s = ""+ *************** *** 194,198 **** String s1 = ""+ "def a( a, b ):\n"+ ! " return ( callA() + callB( b+b ) ) \n"; checkFormatResults(s, s1); --- 257,261 ---- String s1 = ""+ "def a( a, b ):\n"+ ! " return ( callA()+callB( b+b ) ) \n"; checkFormatResults(s, s1); *************** *** 249,252 **** --- 312,316 ---- std.spaceAfterComma = true; std.parametersWithSpace = true; + std.operatorsWithSpace = true; String s = ""+ *************** *** 260,264 **** "nothing 'changes() ((aa) )\n"+ "'''\n" + ! "thisChanges( a+b + ( a+b ) )"; checkFormatResults(s, s2); --- 324,328 ---- "nothing 'changes() ((aa) )\n"+ "'''\n" + ! "thisChanges( a + b + ( a + b ) )"; checkFormatResults(s, s2); *************** *** 332,339 **** "methodCall(a,b,c))\n"; - checkFormatResults(s, "methodCall(a, b, c))\n"); } /** --- 396,569 ---- "methodCall(a,b,c))\n"; checkFormatResults(s, "methodCall(a, b, c))\n"); } + public void testOperators(){ + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.operatorsWithSpace = true; + + String s = "" + + "i=i+1\n" + + "submitted +=1\n" + + "x = x*2 - 1\n" + + "hypot2 = x*x + y*y\n" + + "c = (a+b) * (a-b)\n" + + ""; + + String s1 = "" + + "i = i + 1\n" + + "submitted += 1\n" + + "x = x * 2 - 1\n" + + "hypot2 = x * x + y * y\n" + + "c = (a + b) * (a - b)\n" + + ""; + + checkFormatResults(s, s1); + + } + + + public void testEqualsWithSpaceInFunctionCall(){ + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.assignWithSpaceInsideParens = true; + std.operatorsWithSpace = true; + + + + String s = "" + + "a(xxx=10)\n" + + "call(yyy = 20)\n"; + + String s1 = "" + + "a(xxx = 10)\n" + + "call(yyy = 20)\n"; + + checkFormatResults(s, s1); + + s1 = "" + + "a(xxx = 10)\n" + + "call(yyy = 20)\n"; + checkFormatResults(StringUtils.replaceAll(s, "=", "!="), StringUtils.replaceAll(s1, "=", "!=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "<="), StringUtils.replaceAll(s1, "=", "<=")); + + std.assignWithSpaceInsideParens = false; + s1 = "" + + "a(xxx=10)\n" + + "call(yyy=20)\n"; + + checkFormatResults(s, s1); + + s1 = "" + + "a(xxx = 10)\n" + + "call(yyy = 20)\n"; + checkFormatResults(StringUtils.replaceAll(s, "=", "!="), StringUtils.replaceAll(s1, "=", "!=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "<="), StringUtils.replaceAll(s1, "=", "<=")); + } + + public void testNotValidCode(){ + //should not crash in these tests + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.operatorsWithSpace = false; + + checkFormatResults("=", "="); + checkFormatResults("==", "=="); + checkFormatResults("!", "!"); + checkFormatResults("!=", "!="); + } + + public void testCompare(){ + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.operatorsWithSpace = true; + + String s = "" + + "a==10\n" + + "b== 20\n" + + "c = 30\n" + + "d ==+1\n" + + "e !=+1\n" + + "e //=+1\n" + + ""; + + String s1 = "" + + "a == 10\n" + + "b == 20\n" + + "c = 30\n" + + "d == + 1\n" + + "e != + 1\n" + + "e //= + 1\n" + + ""; + + checkFormatResults(s, s1); + } + + + public void testEqualsWithSpace(){ + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.operatorsWithSpace = true; + + + String s = "" + + "a=10\n" + + "b= 20\n" + + "c = 30"; + + String s1 = "" + + "a = 10\n" + + "b = 20\n" + + "c = 30"; + + checkFormatResults(s, s1); + checkFormatResults(StringUtils.replaceAll(s, "=", "!="), StringUtils.replaceAll(s1, "=", "!=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "<="), StringUtils.replaceAll(s1, "=", "<=")); + + s = "" + + "a=\\n10\n" + + "b= 20\n" + + "c = 30"; + + s1 = "" + + "a = \\n10\n" + + "b = 20\n" + + "c = 30"; + + checkFormatResults(s, s1); + checkFormatResults(StringUtils.replaceAll(s, "=", "!="), StringUtils.replaceAll(s1, "=", "!=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "<="), StringUtils.replaceAll(s1, "=", "<=")); + + s = "" + + "a=10\n" + + "b= 20\n" + + "c = 30"; + + s1 = "" + + "a=10\n" + + "b=20\n" + + "c=30"; + + std.operatorsWithSpace = false; + checkFormatResults(s, s1); + checkFormatResults(StringUtils.replaceAll(s, "=", ">="), StringUtils.replaceAll(s1, "=", ">=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "+="), StringUtils.replaceAll(s1, "=", "+=")); + + s = "" + + "a=\\n" + + "10\n" + + "b= 20\n" + + "c = 30"; + + s1 = "" + + "a=\\n" + + "10\n" + + "b=20\n" + + "c=30"; + + checkFormatResults(s, s1); + } + /** *************** *** 356,359 **** --- 586,594 ---- //default check (defined with \n) String formatStr = new PyFormatStd().formatStr(s, std); + + if(DEBUG){ + System.out.println(">>"+s+"<<"); + System.out.println(">>"+formatStr+"<<"); + } assertEquals(expected, formatStr); |
From: Fabio Z. <fa...@us...> - 2008-07-19 19:53:23
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28692/src/org/python/pydev/editor/actions Modified Files: PyFormatStd.java Log Message: - Improved code formatter to deal with operators (+, -, *, etc) - Improved code formatter to handle '=' differently inside function calls / keyword args Index: PyFormatStd.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyFormatStd.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** PyFormatStd.java 19 Jul 2008 11:57:58 -0000 1.19 --- PyFormatStd.java 19 Jul 2008 19:53:31 -0000 1.20 *************** *** 41,44 **** --- 41,56 ---- */ public boolean parametersWithSpace; + + /** + * Defines whether = should be spaces surrounded when inside of a parens (function call) + * (as well as others related: *= +=, -=, !=, ==, etc). + */ + public boolean assignWithSpaceInsideParens; + + /** + * Defines whether operators should be spaces surrounded: + * + - * / // ** | & ^ ~ = + */ + public boolean operatorsWithSpace; } *************** *** 121,124 **** --- 133,138 ---- private FormatStd getFormat() { FormatStd formatStd = new FormatStd(); + formatStd.assignWithSpaceInsideParens = PyCodeFormatterPage.useAssignWithSpacesInsideParenthesis(); + formatStd.operatorsWithSpace = PyCodeFormatterPage.useOperatorsWithSpace(); formatStd.parametersWithSpace = PyCodeFormatterPage.useSpaceForParentesis(); formatStd.spaceAfterComma = PyCodeFormatterPage.useSpaceAfterComma(); *************** *** 134,137 **** --- 148,163 ---- */ public String formatStr(String str, FormatStd std) { + return formatStr(str, std, 0); + } + + /** + * This method formats a string given some standard. + * + * @param str the string to be formatted + * @param std the standard to be used + * @param parensLevel the level of the parenthesis available. + * @return a new (formatted) string + */ + private String formatStr(String str, FormatStd std, int parensLevel) { char[] cs = str.toCharArray(); FastStringBuffer buf = new FastStringBuffer(); *************** *** 141,175 **** char c = cs[i]; ! if (c == '\'' || c == '"') { //ignore comments or multiline comments... ! i = parsingUtils.eatLiterals(buf, i); ! } else if (c == '#') { ! i = parsingUtils.eatComments(buf, i); ! } else if (c == ',') { ! i = formatForComma(std, cs, buf, i); ! } else if (c == '(') { ! i = formatForPar(parsingUtils, cs, i, std, buf); ! } else { ! if (c == '\r' || c == '\n') { ! if (lastChar == ',' && std.spaceAfterComma && buf.lastChar() == ' ') { buf.deleteLast(); } ! } ! buf.append(c); } lastChar = c; } return buf.toString(); } /** * Formats the contents for when a parenthesis is found (so, go until the closing parens and format it accordingly) * @param cs * @param i */ ! private int formatForPar(ParsingUtils parsingUtils, char[] cs, int i, FormatStd std, FastStringBuffer buf) { char c = ' '; FastStringBuffer locBuf = new FastStringBuffer(); --- 167,384 ---- char c = cs[i]; ! switch(c){ ! case '\'': ! case '"': ! //ignore comments or multiline comments... ! i = parsingUtils.eatLiterals(buf, i); ! break; ! ! case '#': ! i = parsingUtils.eatComments(buf, i); ! break; ! case ',': ! i = formatForComma(std, cs, buf, i); ! break; ! case '(': ! i = formatForPar(parsingUtils, cs, i, std, buf, parensLevel+1); ! break; ! ! ! //Things to treat: ! //+, -, *, /, % ! //** // << >> ! //<, >, !=, <>, <=, >=, //=, *=, /=, ! //& ^ ~ | ! case '*': ! //for *, we also need to treat when it's used in varargs, kwargs and list expansion ! boolean isOperator = false; ! for(int j=buf.length()-1;j>=0;j--){ ! char localC = buf.charAt(j); ! if(Character.isWhitespace(localC)){ ! continue; ! } ! if(localC == '(' || localC == ','){ ! //it's not an operator, but vararg. kwarg or list expansion ! break; ! } ! if(Character.isJavaIdentifierPart(localC)){ ! //ok, there's a chance that it can be an operator, but we still have to check ! //the chance that it's a wild import ! FastStringBuffer localBufToCheckWildImport = new FastStringBuffer(); ! while(Character.isJavaIdentifierPart(localC)){ ! localBufToCheckWildImport.append(localC); ! j--; ! if(j < 0){ ! break; //break while ! } ! localC = buf.charAt(j); ! } ! if(!localBufToCheckWildImport.reverse().toString().equals("import")){ ! isOperator = true; ! } ! break; ! } ! } ! if(!isOperator){ ! buf.append('*'); ! break;//break switch ! } ! //Otherwise, FALLTHROUGH ! ! case '+': ! case '-': ! case '/': ! case '%': ! case '<': ! case '>': ! case '!': ! case '&': ! case '^': ! case '~': ! case '|': ! ! i = handleOperator(std, cs, buf, parsingUtils, i, c); ! c = cs[i]; ! break; ! ! //check for = and == (other cases that have an = as the operator should already be treated) ! case '=': ! if(i < cs.length-1 && cs[i+1] == '='){ ! //if == handle as if a regular operator ! i = handleOperator(std, cs, buf, parsingUtils, i, c); ! c = cs[i]; ! break; ! } ! ! while(buf.length() > 0 && buf.lastChar() == ' '){ buf.deleteLast(); } ! ! boolean surroundWithSpaces = std.operatorsWithSpace; ! if(parensLevel > 0){ ! surroundWithSpaces = std.assignWithSpaceInsideParens; ! } ! ! //add space before ! if(surroundWithSpaces){ ! buf.append(' '); ! } ! ! //add the operator and the '=' ! buf.append('='); ! ! //add space after ! if(surroundWithSpaces){ ! buf.append(' '); ! } ! ! i = parsingUtils.eatWhitespaces(null, i+1); ! break; ! ! default: ! if (c == '\r' || c == '\n') { ! if (lastChar == ',' && std.spaceAfterComma && buf.lastChar() == ' ') { ! buf.deleteLast(); ! } ! } ! buf.append(c); ! } lastChar = c; + } return buf.toString(); } + + /** + * Handles having an operator + * + * @param std the coding standard to be used + * @param cs the contents of the string + * @param buf the buffer where the contents should be added + * @param parsingUtils helper to get the contents + * @param i current index + * @param c current char + * @return the new index after handling the operator + */ + private int handleOperator(FormatStd std, char[] cs, FastStringBuffer buf, ParsingUtils parsingUtils, int i, char c) { + while(buf.length() > 0 && buf.lastChar() == ' '){ + buf.deleteLast(); + } + + boolean surroundWithSpaces = std.operatorsWithSpace; + + //add space before + if(surroundWithSpaces){ + buf.append(' '); + } + + char localC = c; + boolean backOne = true; + while(isOperatorPart(localC)){ + buf.append(localC); + i++; + if(i == cs.length){ + break; + } + localC = cs[i]; + if(localC == '='){ + //when we get to an assign, we have found a full stmt (with assign) -- e.g.: a \\= a += a == + buf.append(localC); + backOne = false; + break; + } + } + if(backOne){ + i--; + } + + //add space after + if(surroundWithSpaces){ + buf.append(' '); + } + + i = parsingUtils.eatWhitespaces(null, i+1); + return i; + } + + + /** + * @param c the char to be checked + * @return true if the passed char is part of an operator + */ + private boolean isOperatorPart(char c) { + switch(c){ + case '+': + case '-': + case '*': + case '/': + case '%': + case '<': + case '>': + case '!': + case '&': + case '^': + case '~': + case '|': + case '=': + return true; + } + return false; + } + + /** * Formats the contents for when a parenthesis is found (so, go until the closing parens and format it accordingly) * @param cs * @param i + * @param parensLevel */ ! private int formatForPar(ParsingUtils parsingUtils, char[] cs, int i, FormatStd std, FastStringBuffer buf, int parensLevel) { char c = ' '; FastStringBuffer locBuf = new FastStringBuffer(); *************** *** 187,191 **** } else if (c == '(') { //open another par. ! j = formatForPar(parsingUtils, cs, j - 1, std, locBuf) + 1; } else { --- 396,400 ---- } else if (c == '(') { //open another par. ! j = formatForPar(parsingUtils, cs, j - 1, std, locBuf, parensLevel+1) + 1; } else { *************** *** 211,215 **** } ! String formatStr = formatStr(trim(locBuf).toString(), std); FastStringBuffer formatStrBuf = trim(new FastStringBuffer(formatStr, 10)); --- 420,424 ---- } ! String formatStr = formatStr(trim(locBuf).toString(), std, parensLevel); FastStringBuffer formatStrBuf = trim(new FastStringBuffer(formatStr, 10)); |
From: Fabio Z. <fa...@us...> - 2008-07-19 19:53:23
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28692/src/org/python/pydev/plugin Modified Files: PyCodeFormatterPage.java PydevPrefsInitializer.java Log Message: - Improved code formatter to deal with operators (+, -, *, etc) - Improved code formatter to handle '=' differently inside function calls / keyword args Index: PyCodeFormatterPage.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/PyCodeFormatterPage.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PyCodeFormatterPage.java 24 Feb 2007 19:28:10 -0000 1.5 --- PyCodeFormatterPage.java 19 Jul 2008 19:53:31 -0000 1.6 *************** *** 17,27 **** --- 17,43 ---- public class PyCodeFormatterPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + //a, b, c public static final String USE_SPACE_AFTER_COMMA = "USE_SPACE_AFTER_COMMA"; public static final boolean DEFAULT_USE_SPACE_AFTER_COMMA = true; + + //call( a ) public static final String USE_SPACE_FOR_PARENTESIS = "USE_SPACE_FOR_PARENTESIS"; public static final boolean DEFAULT_USE_SPACE_FOR_PARENTESIS = false; + + + //call(a = 1) + public static final String USE_ASSIGN_WITH_PACES_INSIDER_PARENTESIS = "USE_ASSIGN_WITH_PACES_INSIDER_PARENTESIS"; + + public static final boolean DEFAULT_USE_ASSIGN_WITH_PACES_INSIDE_PARENTESIS = false; + + + //operators =, !=, <, >, //, etc. + public static final String USE_OPERATORS_WITH_SPACE = "USE_OPERATORS_WITH_SPACE"; + + public static final boolean DEFAULT_USE_OPERATORS_WITH_SPACE = true; + public PyCodeFormatterPage() { *************** *** 39,42 **** --- 55,62 ---- addField(new BooleanFieldEditor(USE_SPACE_FOR_PARENTESIS, "Use space before and after parenthesis?", p)); + + addField(new BooleanFieldEditor(USE_ASSIGN_WITH_PACES_INSIDER_PARENTESIS, "Use space before and after assign for keyword arguments?", p)); + + addField(new BooleanFieldEditor(USE_OPERATORS_WITH_SPACE, "Use space before and after operators? (+, -, /, *, //, **, etc.)", p)); } *************** *** 55,57 **** --- 75,85 ---- } + public static boolean useAssignWithSpacesInsideParenthesis() { + return PydevPrefs.getPreferences().getBoolean(USE_ASSIGN_WITH_PACES_INSIDER_PARENTESIS); + } + + public static boolean useOperatorsWithSpace() { + return PydevPrefs.getPreferences().getBoolean(USE_OPERATORS_WITH_SPACE); + } + } Index: PydevPrefsInitializer.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/PydevPrefsInitializer.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** PydevPrefsInitializer.java 18 May 2008 20:02:17 -0000 1.20 --- PydevPrefsInitializer.java 19 Jul 2008 19:53:31 -0000 1.21 *************** *** 110,113 **** --- 110,115 ---- //code formatting + node.putBoolean(PyCodeFormatterPage.USE_ASSIGN_WITH_PACES_INSIDER_PARENTESIS, PyCodeFormatterPage.DEFAULT_USE_ASSIGN_WITH_PACES_INSIDE_PARENTESIS); + node.putBoolean(PyCodeFormatterPage.USE_OPERATORS_WITH_SPACE, PyCodeFormatterPage.DEFAULT_USE_OPERATORS_WITH_SPACE); node.putBoolean(PyCodeFormatterPage.USE_SPACE_AFTER_COMMA, PyCodeFormatterPage.DEFAULT_USE_SPACE_AFTER_COMMA); node.putBoolean(PyCodeFormatterPage.USE_SPACE_FOR_PARENTESIS, PyCodeFormatterPage.DEFAULT_USE_SPACE_FOR_PARENTESIS); |
From: Fabio Z. <fa...@us...> - 2008-07-19 19:53:23
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28692 Modified Files: Changes.txt Log Message: - Improved code formatter to deal with operators (+, -, *, etc) - Improved code formatter to handle '=' differently inside function calls / keyword args Index: Changes.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/Changes.txt,v retrieving revision 1.406 retrieving revision 1.407 diff -C2 -d -r1.406 -r1.407 *** Changes.txt 9 Jul 2008 19:11:34 -0000 1.406 --- Changes.txt 19 Jul 2008 19:53:31 -0000 1.407 *************** *** 17,20 **** --- 17,22 ---- <li><strong>Debugger</strong>: Better inspection of internal variables for dict, list, tuple, set and frozenset</li> <li><strong>Console</strong>: When a parenthesis was being entered, the text to the end of the line was being deleted</li> + <li>Improved code formatter to deal with operators (+, -, *, etc)</li> + <li>Improved code formatter to handle '=' differently inside function calls / keyword args</li> </ul> |
From: Fabio Z. <fa...@us...> - 2008-07-19 11:57:50
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13369/src/org/python/pydev/editor/actions Modified Files: PyFormatStd.java Log Message: PyFormatStd changes: comments/ minor refactorings Index: PyFormatStd.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyFormatStd.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** PyFormatStd.java 6 Jul 2008 21:58:13 -0000 1.18 --- PyFormatStd.java 19 Jul 2008 11:57:58 -0000 1.19 *************** *** 25,31 **** --- 25,43 ---- public class PyFormatStd extends PyAction implements IFormatter { + /** + * Class that defines the format standard to be used + * + * @author Fabio + */ public static class FormatStd { + + /** + * Defines whether spaces should be added after a comma + */ public boolean spaceAfterComma; + /** + * Defines whether ( and ) should have spaces + */ public boolean parametersWithSpace; } *************** *** 61,97 **** } } public void formatSelection(IDocument doc, int startLine, int endLineIndex, IPyEdit edit, PySelection ps) { // Formatter formatter = new Formatter(); // formatter.formatSelection(doc, startLine, endLineIndex, edit, ps); ! performFormatSelection(doc, startLine, endLineIndex); ! } ! ! public void formatAll(IDocument doc, IPyEdit edit) { ! // Formatter formatter = new Formatter(); ! // formatter.formatAll(doc, edit); ! performFormatAll(doc); ! } ! ! /** ! * @param doc ! * @param endLineDelim ! * @param startLineIndex ! * @param endLineIndex ! */ ! public void performFormatSelection(IDocument doc, int startLineIndex, int endLineIndex) { try { ! IRegion start = doc.getLineInformation(startLineIndex); IRegion end = doc.getLineInformation(endLineIndex); ! int iStart = start.getOffset(); int iEnd = end.getOffset() + end.getLength(); ! String d = doc.get(iStart, iEnd - iStart); FormatStd formatStd = getFormat(); String formatted = formatStr(d, formatStd); ! doc.replace(iStart, iEnd - iStart, formatted); ! } catch (BadLocationException e) { e.printStackTrace(); --- 73,99 ---- } } + + /** + * Formats the given selection + * @see IFormatter + */ public void formatSelection(IDocument doc, int startLine, int endLineIndex, IPyEdit edit, PySelection ps) { // Formatter formatter = new Formatter(); // formatter.formatSelection(doc, startLine, endLineIndex, edit, ps); ! try { ! IRegion start = doc.getLineInformation(startLine); IRegion end = doc.getLineInformation(endLineIndex); ! int iStart = start.getOffset(); int iEnd = end.getOffset() + end.getLength(); ! String d = doc.get(iStart, iEnd - iStart); FormatStd formatStd = getFormat(); String formatted = formatStr(d, formatStd); ! doc.replace(iStart, iEnd - iStart, formatted); ! } catch (BadLocationException e) { e.printStackTrace(); *************** *** 99,114 **** } - private FormatStd getFormat() { - FormatStd formatStd = new FormatStd(); - formatStd.parametersWithSpace = PyCodeFormatterPage.useSpaceForParentesis(); - formatStd.spaceAfterComma = PyCodeFormatterPage.useSpaceAfterComma(); - return formatStd; - } - /** ! * @param doc ! * @param endLineDelim */ ! public void performFormatAll(IDocument doc) { String d = doc.get(); FormatStd formatStd = getFormat(); --- 101,112 ---- } /** ! * Formats the whole document ! * @see IFormatter */ ! public void formatAll(IDocument doc, IPyEdit edit) { ! // Formatter formatter = new Formatter(); ! // formatter.formatAll(doc, edit); ! String d = doc.get(); FormatStd formatStd = getFormat(); *************** *** 117,128 **** } /** * This method formats a string given some standard. * ! * @param str ! * @param std ! * @return */ ! public static String formatStr(String str, FormatStd std) { char[] cs = str.toCharArray(); FastStringBuffer buf = new FastStringBuffer(); --- 115,137 ---- } + + /** + * @return the format standard that should be used to do the formatting + */ + private FormatStd getFormat() { + FormatStd formatStd = new FormatStd(); + formatStd.parametersWithSpace = PyCodeFormatterPage.useSpaceForParentesis(); + formatStd.spaceAfterComma = PyCodeFormatterPage.useSpaceAfterComma(); + return formatStd; + } + /** * This method formats a string given some standard. * ! * @param str the string to be formatted ! * @param std the standard to be used ! * @return a new (formatted) string */ ! public String formatStr(String str, FormatStd std) { char[] cs = str.toCharArray(); FastStringBuffer buf = new FastStringBuffer(); *************** *** 142,151 **** } else if (c == '(') { - i = formatForPar(parsingUtils, cs, i, std, buf); } else { if (c == '\r' || c == '\n') { ! if (lastChar == ',' && std.spaceAfterComma) { buf.deleteLast(); } --- 151,159 ---- } else if (c == '(') { i = formatForPar(parsingUtils, cs, i, std, buf); } else { if (c == '\r' || c == '\n') { ! if (lastChar == ',' && std.spaceAfterComma && buf.lastChar() == ' ') { buf.deleteLast(); } *************** *** 159,166 **** /** * @param cs * @param i */ ! private static int formatForPar(ParsingUtils parsingUtils, char[] cs, int i, FormatStd std, FastStringBuffer buf) { char c = ' '; FastStringBuffer locBuf = new FastStringBuffer(); --- 167,175 ---- /** + * Formats the contents for when a parenthesis is found (so, go until the closing parens and format it accordingly) * @param cs * @param i */ ! private int formatForPar(ParsingUtils parsingUtils, char[] cs, int i, FormatStd std, FastStringBuffer buf) { char c = ' '; FastStringBuffer locBuf = new FastStringBuffer(); *************** *** 181,186 **** } else { - locBuf.append(c); } } --- 190,195 ---- } else { locBuf.append(c); + } } *************** *** 188,196 **** if (c == ')') { char c1; FastStringBuffer buf1 = new FastStringBuffer(); ! if (locBuf.indexOf('\n') != -1) { ! for (int k = locBuf.length(); k > 0 && (c1 = locBuf.charAt(k - 1)) != '\n'; k--) { buf1.insert(0, c1); } --- 197,210 ---- if (c == ')') { + //Now, when a closing parens is found, let's see the contents of the line where that parens was found + //and if it's only whitespaces, add all those whitespaces (to handle the following case: + //a(a, + // b + // ) <-- we don't want to change this one. char c1; FastStringBuffer buf1 = new FastStringBuffer(); ! if (locBuf.indexOf('\n') != -1 || locBuf.indexOf('\r') != -1) { ! for (int k = locBuf.length(); k > 0 && (c1 = locBuf.charAt(k - 1)) != '\n' && c1 != '\r'; k--) { buf1.insert(0, c1); } *************** *** 230,237 **** /** * We just want to trim whitespaces, not newlines! ! * @param locBuf ! * @return */ ! private static FastStringBuffer trim(FastStringBuffer locBuf) { while (locBuf.length() > 0 && locBuf.firstChar() == ' ') { locBuf.deleteCharAt(0); --- 244,251 ---- /** * We just want to trim whitespaces, not newlines! ! * @param locBuf the buffer to be trimmed ! * @return the same buffer passed as a parameter */ ! private FastStringBuffer trim(FastStringBuffer locBuf) { while (locBuf.length() > 0 && locBuf.firstChar() == ' ') { locBuf.deleteCharAt(0); *************** *** 244,254 **** /** ! * @param std ! * @param cs ! * @param buf ! * @param i ! * @return */ ! private static int formatForComma(FormatStd std, char[] cs, FastStringBuffer buf, int i) { while (i < cs.length - 1 && (cs[i + 1]) == ' ') { i++; --- 258,270 ---- /** ! * When a comma is found, it's formatted accordingly (spaces added after it). ! * ! * @param std the coding standard to be used ! * @param cs the contents of the document to be formatted ! * @param buf the buffer where the comma should be added ! * @param i the current index ! * @return the new index on the original doc. */ ! private int formatForComma(FormatStd std, char[] cs, FastStringBuffer buf, int i) { while (i < cs.length - 1 && (cs[i + 1]) == ' ') { i++; |
From: Fabio Z. <fa...@us...> - 2008-07-19 11:57:50
|
Update of /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13369/tests/org/python/pydev/editor/actions Modified Files: PyFormatStdTest.java Log Message: PyFormatStd changes: comments/ minor refactorings Index: PyFormatStdTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions/PyFormatStdTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** PyFormatStdTest.java 26 Feb 2008 16:33:01 -0000 1.11 --- PyFormatStdTest.java 19 Jul 2008 11:57:58 -0000 1.12 *************** *** 8,11 **** --- 8,12 ---- import junit.framework.TestCase; + import org.python.pydev.core.docutils.StringUtils; import org.python.pydev.editor.actions.PyFormatStd.FormatStd; *************** *** 21,25 **** PyFormatStdTest n = new PyFormatStdTest(); n.setUp(); ! n.testNoFormatCommaOnNewLine(); n.tearDown(); --- 22,26 ---- PyFormatStdTest n = new PyFormatStdTest(); n.setUp(); ! n.testFormatNotLinesOnlyWithParentesis(); n.tearDown(); *************** *** 52,56 **** " pass \n"; ! assertEquals(s1, PyFormatStd.formatStr(s, std)); std.spaceAfterComma = false; --- 53,57 ---- " pass \n"; ! checkFormatResults(s, s1); std.spaceAfterComma = false; *************** *** 60,64 **** " pass \n"; ! assertEquals(s2, PyFormatStd.formatStr(s, std)); } --- 61,65 ---- " pass \n"; ! checkFormatResults(s, s2); } *************** *** 78,82 **** " pass\n"; ! assertEquals(s1, PyFormatStd.formatStr(s, std)); } --- 79,83 ---- " pass\n"; ! checkFormatResults(s, s1); } *************** *** 88,96 **** "foo(bar(\"\\\"\"))"; ! assertEquals(s, PyFormatStd.formatStr(s, std)); s = ""+ "foo(bar('''\\''''))"; ! assertEquals(s, PyFormatStd.formatStr(s, std)); } --- 89,97 ---- "foo(bar(\"\\\"\"))"; ! checkFormatResults(s); s = ""+ "foo(bar('''\\''''))"; ! checkFormatResults(s); } *************** *** 108,112 **** " pass \n"; ! assertEquals(s1, PyFormatStd.formatStr(s, std)); } --- 109,113 ---- " pass \n"; ! checkFormatResults(s, s1); } *************** *** 124,128 **** " pass \n"; ! assertEquals(s1, PyFormatStd.formatStr(s, std)); std.spaceAfterComma = false; --- 125,129 ---- " pass \n"; ! checkFormatResults(s, s1); std.spaceAfterComma = false; *************** *** 132,136 **** " pass \n"; ! assertEquals(s2, PyFormatStd.formatStr(s, std)); } --- 133,137 ---- " pass \n"; ! checkFormatResults(s, s2); } *************** *** 149,153 **** " pass \n"; ! assertEquals(s1, PyFormatStd.formatStr(s, std)); std.spaceAfterComma = false; --- 150,154 ---- " pass \n"; ! checkFormatResults(s, s1); std.spaceAfterComma = false; *************** *** 157,161 **** " pass \n"; ! assertEquals(s2, PyFormatStd.formatStr(s, std)); } --- 158,162 ---- " pass \n"; ! checkFormatResults(s, s2); } *************** *** 172,176 **** " return ((a+b) + (a+b)) \n"; ! assertEquals(s1, PyFormatStd.formatStr(s, std)); --- 173,177 ---- " return ((a+b) + (a+b)) \n"; ! checkFormatResults(s, s1); *************** *** 180,184 **** " return ( ( a+b ) + ( a+b ) ) \n"; ! assertEquals(s2, PyFormatStd.formatStr(s, std)); } --- 181,185 ---- " return ( ( a+b ) + ( a+b ) ) \n"; ! checkFormatResults(s, s2); } *************** *** 195,199 **** " return ( callA() + callB( b+b ) ) \n"; ! assertEquals(s1, PyFormatStd.formatStr(s, std)); } --- 196,200 ---- " return ( callA() + callB( b+b ) ) \n"; ! checkFormatResults(s, s1); } *************** *** 208,212 **** "'''"; ! assertEquals(s, PyFormatStd.formatStr(s, std)); s = ""+ --- 209,213 ---- "'''"; ! checkFormatResults(s); s = ""+ *************** *** 215,219 **** ""; ! assertEquals(s, PyFormatStd.formatStr(s, std)); s = ""+ --- 216,220 ---- ""; ! checkFormatResults(s); s = ""+ *************** *** 222,226 **** ""; ! assertEquals(s, PyFormatStd.formatStr(s, std)); s = ""+ --- 223,227 ---- ""; ! checkFormatResults(s); s = ""+ *************** *** 229,233 **** ""; ! assertEquals(s, PyFormatStd.formatStr(s, std)); } --- 230,234 ---- ""; ! checkFormatResults(s); } *************** *** 242,246 **** "#'''"; ! assertEquals(s, PyFormatStd.formatStr(s, std)); } --- 243,247 ---- "#'''"; ! checkFormatResults(s); } *************** *** 261,265 **** "thisChanges( a+b + ( a+b ) )"; ! assertEquals(s2, PyFormatStd.formatStr(s, std)); //unfinished comment --- 262,266 ---- "thisChanges( a+b + ( a+b ) )"; ! checkFormatResults(s, s2); //unfinished comment *************** *** 270,274 **** "thisDoesNotChange()"; ! assertEquals(s, PyFormatStd.formatStr(s, std)); //unfinished comment at end of string --- 271,275 ---- "thisDoesNotChange()"; ! checkFormatResults(s); //unfinished comment at end of string *************** *** 278,282 **** "''"; ! assertEquals(s, PyFormatStd.formatStr(s, std)); } --- 279,283 ---- "''"; ! checkFormatResults(s); } *************** *** 287,291 **** String s = "methodname.split( '(' )"; ! assertEquals(s, PyFormatStd.formatStr(s, std)); } --- 288,292 ---- String s = "methodname.split( '(' )"; ! checkFormatResults(s); } *************** *** 297,302 **** " )"; ! String formatStr = PyFormatStd.formatStr(s, std); ! assertEquals(s, formatStr); } --- 298,302 ---- " )"; ! checkFormatResults(s); } *************** *** 308,313 **** ! String formatStr = PyFormatStd.formatStr(s, std); ! assertEquals(s, formatStr); } --- 308,312 ---- ! checkFormatResults(s); } *************** *** 322,327 **** ! String formatStr = PyFormatStd.formatStr(s, std); ! assertEquals(s, formatStr); } --- 321,375 ---- ! checkFormatResults(s); ! } ! ! ! public void testCommaOnParens(){ ! std.spaceAfterComma = true; ! std.parametersWithSpace = false; ! ! String s = "" + ! "methodCall(a,b,c))\n"; ! ! ! checkFormatResults(s, "methodCall(a, b, c))\n"); ! } ! ! ! /** ! * Checks the results with the default passed and then with '\r' and '\n' considering ! * that the result of formatting the input string will be the same as the input. ! * ! * @param s the string to be checked (and also the expected output) ! */ ! private void checkFormatResults(String s) { ! checkFormatResults(s, s); ! } ! ! ! /** ! * Checks the results with the default passed and then with '\r' and '\n' ! * @param s the string to be checked ! * @param expected the result of making the formatting in the string ! */ ! private void checkFormatResults(String s, String expected) { ! //default check (defined with \n) ! String formatStr = new PyFormatStd().formatStr(s, std); ! assertEquals(expected, formatStr); ! ! //second check (defined with \r) ! s = s.replace('\n', '\r'); ! expected = expected.replace('\n', '\r'); ! ! formatStr = new PyFormatStd().formatStr(s, std); ! assertEquals(expected, formatStr); ! ! //third check (defined with \r\n) ! s = StringUtils.replaceAll(s, "\r", "\r\n"); ! expected = StringUtils.replaceAll(expected, "\r", "\r\n"); ! ! formatStr = new PyFormatStd().formatStr(s, std); ! assertEquals(expected, formatStr); ! } |
From: Fabio Z. <fa...@us...> - 2008-07-16 00:38:53
|
Update of /cvsroot/pydev/org.python.pydev.jython/jysrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3433/jysrc Modified Files: assign_params_to_attributes_action.py Log Message: Fixed problems in assign to attributes. Index: assign_params_to_attributes_action.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.jython/jysrc/assign_params_to_attributes_action.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** assign_params_to_attributes_action.py 1 Jun 2006 17:44:26 -0000 1.1 --- assign_params_to_attributes_action.py 16 Jul 2008 00:38:57 -0000 1.2 *************** *** 14,18 **** from org.eclipse.jface.action import Action #@UnresolvedImport import re - from java.lang import StringBuffer from org.eclipse.jface.dialogs import MessageDialog #@UnresolvedImport from org.python.pydev.core.docutils import PySelection #@UnresolvedImport --- 14,17 ---- *************** *** 139,142 **** --- 138,143 ---- sIndent = self._indent(oSelection) + PyAction.getStaticIndentationString(self.editor) + parsingUtils = ParsingUtils.create(oDocument) + # Is there a docstring? In that case we need to skip past it. sDocstrFirstLine = oSelection.getLine(iClosingParLine + 1) *************** *** 149,154 **** iDocstrStartCol = min([i for i in li if i >= 0]) iDocstrStart = iDocstrLineOffset + iDocstrStartCol ! oDummy = StringBuffer() ! iDocstrEnd = ParsingUtils.eatLiterals(oDocument, oDummy, iDocstrStart) iInsertAfterLine = oSelection.getLineOfOffset(iDocstrEnd) sIndent = PySelection.getIndentationFromLine(sDocstrFirstLine) --- 150,154 ---- iDocstrStartCol = min([i for i in li if i >= 0]) iDocstrStart = iDocstrLineOffset + iDocstrStartCol ! iDocstrEnd = parsingUtils.eatLiterals(None, iDocstrStart) iInsertAfterLine = oSelection.getLineOfOffset(iDocstrEnd) sIndent = PySelection.getIndentationFromLine(sDocstrFirstLine) *************** *** 160,164 **** iDocLength = oDocument.getLength() iLastLine = oSelection.getLineOfOffset(iDocLength) ! sLastChar = str(ParsingUtils.charAt(oDocument, iDocLength - 1)) if (iInsertAfterLine == iLastLine and not self.getNewLineDelim().endswith(sLastChar)): --- 160,164 ---- iDocLength = oDocument.getLength() iLastLine = oSelection.getLineOfOffset(iDocLength) ! sLastChar = str(parsingUtils.charAt(iDocLength - 1)) if (iInsertAfterLine == iLastLine and not self.getNewLineDelim().endswith(sLastChar)): |
From: Fabio Z. <fa...@us...> - 2008-07-16 00:38:46
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3423 Modified Files: TODO.txt Log Message: Fixed problems in assign to attributes. Index: TODO.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/TODO.txt,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -d -r1.73 -r1.74 *** TODO.txt 15 Jul 2008 16:10:14 -0000 1.73 --- TODO.txt 16 Jul 2008 00:38:53 -0000 1.74 *************** *** 1,3 **** - - update assign_params_to_attributes_action.py for changes in ParsingUtils - Check: Context insensitive info being created twice??? (create a test case for that) - Add shortcut for running unit-test --- 1,2 ---- |
From: Fabio Z. <fa...@us...> - 2008-07-15 16:10:06
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5229 Modified Files: TODO.txt Log Message: Index: TODO.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/TODO.txt,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** TODO.txt 4 Jul 2008 00:54:47 -0000 1.72 --- TODO.txt 15 Jul 2008 16:10:14 -0000 1.73 *************** *** 1,2 **** --- 1,3 ---- + - update assign_params_to_attributes_action.py for changes in ParsingUtils - Check: Context insensitive info being created twice??? (create a test case for that) - Add shortcut for running unit-test |
From: Fabio Z. <fa...@us...> - 2008-07-14 23:02:15
|
Update of /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2410/tests/org/python/pydev/core/docutils Modified Files: ParsingUtilsTest.java Log Message: Better handling of assign on fast parsing. Index: ParsingUtilsTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/docutils/ParsingUtilsTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ParsingUtilsTest.java 15 Jun 2008 16:45:20 -0000 1.8 --- ParsingUtilsTest.java 14 Jul 2008 23:02:23 -0000 1.9 *************** *** 17,21 **** ParsingUtilsTest test = new ParsingUtilsTest(); test.setUp(); ! test.testMakeParseable(); test.tearDown(); junit.textui.TestRunner.run(ParsingUtilsTest.class); --- 17,21 ---- ParsingUtilsTest test = new ParsingUtilsTest(); test.setUp(); ! test.testGetFlattenedLine2(); test.tearDown(); junit.textui.TestRunner.run(ParsingUtilsTest.class); *************** *** 60,63 **** --- 60,98 ---- } + public void testGetFlattenedLine() throws Exception { + String str = "" + + "line #c\n" + + "start =\\\n" + + "10 \\\n" + + "30\n" + + "call(\n" + + " ttt,\n" + + ")\n"; + ParsingUtils parsing = ParsingUtils.create(str); + FastStringBuffer buf = new FastStringBuffer(); + assertEquals(8, parsing.getFullFlattenedLine(0, buf.clear())); + assertEquals("line ", buf.toString()); + + parsing.getFullFlattenedLine(1, buf.clear()); + assertEquals("ine ", buf.toString()); + + assertEquals(25, parsing.getFullFlattenedLine(8, buf.clear())); + assertEquals("start =10 30", buf.toString()); + + assertEquals(41, parsing.getFullFlattenedLine(25, buf.clear())); + assertEquals("call", buf.toString()); + } + + public void testGetFlattenedLine2() throws Exception { + String str = "" + + "line = '''\n" + + "bla bla bla''' = xxx\n" + + "what"; + ParsingUtils parsing = ParsingUtils.create(str); + FastStringBuffer buf = new FastStringBuffer(); + assertEquals(32, parsing.getFullFlattenedLine(0, buf.clear())); + assertEquals("line = = xxx", buf.toString()); + } + public void testIterator2() throws Exception { String str = "" + |
From: Fabio Z. <fa...@us...> - 2008-07-14 23:02:15
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2410/src/org/python/pydev/core/docutils Modified Files: ParsingUtils.java Log Message: Better handling of assign on fast parsing. Index: ParsingUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ParsingUtils.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** ParsingUtils.java 6 Jul 2008 21:58:28 -0000 1.24 --- ParsingUtils.java 14 Jul 2008 23:02:23 -0000 1.25 *************** *** 241,244 **** --- 241,290 ---- } + + /** + * @param i the index where we should start getting chars + * @param buf the buffer that should be filled with the contents gotten (if null, they're ignored) + * @return the index where the parsing stopped + */ + public int getFullFlattenedLine(int i, FastStringBuffer buf) { + char c = this.charAt(i); + int len = len(); + boolean ignoreNextNewLine = false; + while(i < len){ + c = charAt(i); + + i++; + + if(c == '\'' || c == '"'){ //ignore comments or multiline comments... + i = eatLiterals(null, i-1)+1; + + }else if(c == '#'){ + i = eatComments(null, i-1)+1; + break; + + }else if( c == '(' || c == '[' || c == '{'){ //open par. + i = eatPar(i-1, null, c)+1; + + }else if( c == '\r' || c == '\n' ){ + if(!ignoreNextNewLine){ + break; + } + + }else if( c == '\\' || c == '\\' ){ + ignoreNextNewLine = true; + continue; + + }else{ + if(buf != null){ + buf.append(c); + } + } + + ignoreNextNewLine = false; + } + return i; + } + + /** * @param buf if null, it'll simply advance without adding anything to the buffer. *************** *** 609,612 **** - } --- 655,657 ---- |
From: Fabio Z. <fa...@us...> - 2008-07-14 23:02:10
|
Update of /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2393/src/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParser.java Log Message: Better handling of assign on fast parsing. Index: FastDefinitionsParser.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser/FastDefinitionsParser.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FastDefinitionsParser.java 6 Jul 2008 21:58:08 -0000 1.6 --- FastDefinitionsParser.java 14 Jul 2008 23:02:18 -0000 1.7 *************** *** 182,225 **** 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.firstCharCol; ! 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.firstCharCol; - assign.beginLine = this.row; - addToPertinentScope(assign); } ! } } //No default --- 182,240 ---- case '=': ! if(currIndex < length-1 && cs[currIndex+1] != '='){ ! //should not be == ! //other cases such as !=, +=, -= are already treated because they don't constitute valid ! //chars for an identifier. ! if(DEBUG){ System.out.println("Found possible attribute:"+lineBuffer+" col:"+firstCharCol); } + //if we've an '=', let's get the whole line contents to analyze... + currIndex = parsingUtils.getFullFlattenedLine(currIndex, lineBuffer); + currIndex--; //step one back to get the new line and handle it correctly + String equalsLine = lineBuffer.toString().trim(); + lineBuffer.clear(); ! String[] splitted = StringUtils.split(equalsLine, '='); ! ArrayList<exprType> targets = new ArrayList<exprType>(); ! ! for(int j=0; j< splitted.length-1; j++){ //we don't want to get the last one. ! String lineContents = splitted[j].trim(); ! if(lineContents.length() == 0){ ! continue; } ! 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); ! targets.add(attribute); ! } ! ! }else{ ! Name name = new Name(lineContents, Name.Store); ! targets.add(name); ! } ! } ! } ! ! if(targets.size() > 0){ ! Assign assign = new Assign(targets.toArray(new exprType[targets.size()]), null); ! assign.beginColumn = this.firstCharCol; ! assign.beginLine = this.row; ! addToPertinentScope(assign); ! } } //No default |
From: Fabio Z. <fa...@us...> - 2008-07-14 23:02:10
|
Update of /cvsroot/pydev/org.python.pydev.parser/tests/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2393/tests/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParserTest.java Log Message: Better handling of assign on fast parsing. Index: FastDefinitionsParserTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/tests/org/python/pydev/parser/fastparser/FastDefinitionsParserTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FastDefinitionsParserTest.java 6 Jul 2008 13:10:42 -0000 1.6 --- FastDefinitionsParserTest.java 14 Jul 2008 23:02:18 -0000 1.7 *************** *** 29,33 **** FastDefinitionsParserTest test = new FastDefinitionsParserTest(); test.setUp(); ! // test.NotestGlobalAttributesWX(); --- 29,34 ---- FastDefinitionsParserTest test = new FastDefinitionsParserTest(); test.setUp(); ! test.testGlobalAttributes5(); ! test.NotestGlobalAttributesWX(); *************** *** 103,106 **** --- 104,125 ---- } + public void testMultipleAssignAttributes() { + Module m = (Module) FastDefinitionsParser.parse( + "class Bar:\n" + + " ATTRIBUTE1 = ATTRIBUTE2 = 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(2, assign.targets.length); + Name name = (Name) assign.targets[0]; + assertEquals("ATTRIBUTE1", name.id); + name = (Name) assign.targets[1]; + assertEquals("ATTRIBUTE2", name.id); + } + public void testAttributes2() { *************** *** 165,169 **** " 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" + ""); --- 184,188 ---- " 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" + ""); *************** *** 249,252 **** --- 268,284 ---- } + public void testGlobalAttributes5() { + Module m = (Module) FastDefinitionsParser.parse( + "GLOBAL_ATTRIBUTE = 10\n" + + "GLOBAL_ATTRIBUTE2 = 10\n" + + "\n" + + ""); + assertEquals(2, m.body.length); + Assign assign = ((Assign)m.body[0]); + assertEquals("GLOBAL_ATTRIBUTE", ((Name)assign.targets[0]).id); + assign = ((Assign)m.body[1]); + assertEquals("GLOBAL_ATTRIBUTE2", ((Name)assign.targets[0]).id); + } + public void testGlobalAttributes2() { String str = "import new\n" + *************** *** 494,501 **** --- 526,539 ---- " '''_setCallbackInfo(self, PyObject self, PyObject _class)'''\n" + " return _xrc.XmlSubclassFactory__setCallbackInfo(*args, **kwargs)\n" + + " Parent = property(GetParent,doc=\"See `GetParent`\") \n" + + " ParentAsWindow = property(GetParentAsWindow,doc=\"See `GetParentAsWindow`\") \n" + + " Resource = property(GetResource,doc=\"See `GetResource`\") \n" + "_xrc.XmlSubclassFactory_swigregister(XmlSubclassFactory)\n" + "#---------------------------------------------------------------------------\n" + "XML_ELEMENT_NODE = _xrc.XML_ELEMENT_NODE\n" + "XML_ATTRIBUTE_NODE = _xrc.XML_ATTRIBUTE_NODE\n" + + "_xrc.XmlResourceHandler_swigregister(XmlResourceHandler)\n" + + "\n" + + "\n" + "\n" + "\n" + |
From: Fabio Z. <fa...@us...> - 2008-07-09 19:11:29
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8517 Modified Files: Changes.txt Log Message: <li><strong>Console</strong>: When a parenthesis was being entered, the text to the end of the line was being deleted</li> Index: Changes.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/Changes.txt,v retrieving revision 1.405 retrieving revision 1.406 diff -C2 -d -r1.405 -r1.406 *** Changes.txt 5 Jul 2008 19:42:06 -0000 1.405 --- Changes.txt 9 Jul 2008 19:11:34 -0000 1.406 *************** *** 16,19 **** --- 16,20 ---- <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> + <li><strong>Console</strong>: When a parenthesis was being entered, the text to the end of the line was being deleted</li> </ul> |
From: Fabio Z. <fa...@us...> - 2008-07-09 19:11:29
|
Update of /cvsroot/pydev/org.python.pydev/src_dltk_console/org/python/pydev/dltk/console/ui/internal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8517/src_dltk_console/org/python/pydev/dltk/console/ui/internal Modified Files: ScriptConsoleDocumentListener.java Log Message: <li><strong>Console</strong>: When a parenthesis was being entered, the text to the end of the line was being deleted</li> Index: ScriptConsoleDocumentListener.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_dltk_console/org/python/pydev/dltk/console/ui/internal/ScriptConsoleDocumentListener.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ScriptConsoleDocumentListener.java 3 May 2008 13:20:11 -0000 1.11 --- ScriptConsoleDocumentListener.java 9 Jul 2008 19:11:34 -0000 1.12 *************** *** 414,423 **** String newText = text.substring(start, text.length()); if(addedParen){ ! Document parenDoc = new Document(getCommandLine()+"("); ! int currentOffset = parenDoc.getLength(); DocCmd docCmd = new DocCmd(currentOffset, 0, "("); docCmd.shiftsCaret = true; strategy.customizeParenthesis(parenDoc, docCmd); ! newText = docCmd.text; if(!docCmd.shiftsCaret){ shiftsCaret = false; --- 414,424 ---- String newText = text.substring(start, text.length()); if(addedParen){ ! String cmdLine = getCommandLine(); ! Document parenDoc = new Document(cmdLine+newText); ! int currentOffset = cmdLine.length()+1; DocCmd docCmd = new DocCmd(currentOffset, 0, "("); docCmd.shiftsCaret = true; strategy.customizeParenthesis(parenDoc, docCmd); ! newText = docCmd.text+newText.substring(1); if(!docCmd.shiftsCaret){ shiftsCaret = false; |
From: Fabio Z. <fa...@us...> - 2008-07-09 19:11:29
|
Update of /cvsroot/pydev/org.python.pydev/tests_dltk_console/org/python/pydev/dltk/console/ui/internal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8517/tests_dltk_console/org/python/pydev/dltk/console/ui/internal Modified Files: ScriptConsoleDocumentListenerTest.java Log Message: <li><strong>Console</strong>: When a parenthesis was being entered, the text to the end of the line was being deleted</li> Index: ScriptConsoleDocumentListenerTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests_dltk_console/org/python/pydev/dltk/console/ui/internal/ScriptConsoleDocumentListenerTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ScriptConsoleDocumentListenerTest.java 4 Apr 2008 02:54:50 -0000 1.6 --- ScriptConsoleDocumentListenerTest.java 9 Jul 2008 19:11:33 -0000 1.7 *************** *** 82,85 **** --- 82,101 ---- doc.replace(doc.getLength(), 0, ")"); assertEquals(">>> c())", doc.get()); + + doc.replace(doc.getLength()-4, 4, ""); + assertEquals(">>> ", doc.get()); + + doc.replace(doc.getLength(), 0, "tttbbb"); + assertEquals(">>> tttbbb", doc.get()); + + doc.replace(doc.getLength()-3, 0, "("); + assertEquals(">>> ttt(bbb", doc.get()); + + doc.replace(doc.getLength()-4, 1, ""); + assertEquals(">>> tttbbb", doc.get()); + + doc.replace(doc.getLength(), 0, "("); + assertEquals(">>> tttbbb()", doc.get()); + } } |
From: Fabio Z. <fa...@us...> - 2008-07-09 19:10:53
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/autoedit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8149/src/org/python/pydev/editor/autoedit Modified Files: PyAutoIndentStrategy.java Log Message: Minor refactoring Index: PyAutoIndentStrategy.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/autoedit/PyAutoIndentStrategy.java,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** PyAutoIndentStrategy.java 3 Jul 2008 01:04:04 -0000 1.70 --- PyAutoIndentStrategy.java 9 Jul 2008 19:11:00 -0000 1.71 *************** *** 495,502 **** boolean hasClassMethodDef = line.indexOf(" def ") != -1 || line.indexOf("\tdef ") != -1; boolean hasMethodDef = line.indexOf("def ") != -1; ! boolean hasNoDoublePoint = line.indexOf(":") == -1; command.shiftsCaret = false; ! if (hasNoDoublePoint && (hasClass || hasClassMethodDef || hasMethodDef)) { if (hasClass) { //command.text = "(object):"; //TODO: put some option in the interface for that --- 495,502 ---- boolean hasClassMethodDef = line.indexOf(" def ") != -1 || line.indexOf("\tdef ") != -1; boolean hasMethodDef = line.indexOf("def ") != -1; ! boolean hasDoublePoint = line.indexOf(":") != -1; command.shiftsCaret = false; ! if (!hasDoublePoint && (hasClass || hasClassMethodDef || hasMethodDef)) { if (hasClass) { //command.text = "(object):"; //TODO: put some option in the interface for that |
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7795/src/org/python/pydev/core/docutils Modified Files: ParsingUtils.java DocUtils.java PySelection.java PyDocIterator.java ImportHandle.java Log Message: Changes in the ParsingUtils interface (creating correct version with factory to properly adapt to the object being read). Index: DocUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/DocUtils.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** DocUtils.java 24 Mar 2008 15:57:35 -0000 1.13 --- DocUtils.java 6 Jul 2008 21:58:28 -0000 1.14 *************** *** 151,171 **** return newStr; } ! ! public static char getPeer(char c){ ! for (int i = 0; i < BRACKETS.length; i++) { ! if(c == BRACKETS[i]){ ! int mod = i % 2; ! if(mod == 0){ ! return BRACKETS[i + 1]; ! }else{ ! return BRACKETS[i - 1]; ! } ! } ! } ! ! throw new NoPeerAvailableException("Unable to find peer for :"+c); ! ! } ! /** * An array of Python pairs of characters that you will find in any Python code. --- 151,155 ---- return newStr; } ! /** * An array of Python pairs of characters that you will find in any Python code. *************** *** 179,182 **** --- 163,180 ---- public static final char[] BRACKETS = { '{', '}', '(', ')', '[', ']' }; + public static char getPeer(char c){ + switch(c){ + case '{':return '}'; + case '}':return '{'; + case '(':return ')'; + case ')':return '('; + case '[':return ']'; + case ']':return '['; + } + + throw new NoPeerAvailableException("Unable to find peer for :"+c); + + } + public static boolean isClosingPeer(char lastChar) { return lastChar == '}' || lastChar == ')' || lastChar == ']'; Index: PySelection.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/PySelection.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** PySelection.java 15 Jun 2008 16:45:20 -0000 1.63 --- PySelection.java 6 Jul 2008 21:58:28 -0000 1.64 *************** *** 217,220 **** --- 217,221 ---- IDocument document = getDoc(); int lines = document.getNumberOfLines(); + ParsingUtils parsingUtils = ParsingUtils.create(document); for (int line = startingAtLine; line < lines; line++) { String str = getLine(line); *************** *** 240,244 **** throw new RuntimeException(e1); } ! int j = ParsingUtils.eatPar(document, lineOffset+i, null); try { line = document.getLineOfOffset(j); --- 241,245 ---- throw new RuntimeException(e1); } ! int j = parsingUtils.eatPar(lineOffset+i, null); try { line = document.getLineOfOffset(j); *************** *** 273,294 **** String strDoc = d.get(initialOffset, d.getLength() - initialOffset); ! if(initialOffset > strDoc.length()-1){ return new int[]{-1, -1}; } char current = strDoc.charAt(initialOffset); ! //for checking if it is global, it must be in the beggining of a line (must be right after a \r or \n). ! while (current != '\'' && current != '"' && initialOffset < strDoc.length()-1) { //if it is inside a parenthesis, we will not take it into consideration. if(current == '('){ ! initialOffset = ParsingUtils.eatPar(strDoc, initialOffset, buf); } initialOffset += 1; ! if(initialOffset < strDoc.length()-1){ current = strDoc.charAt(initialOffset); } --- 274,297 ---- String strDoc = d.get(initialOffset, d.getLength() - initialOffset); ! int docLen = strDoc.length(); ! ! if(initialOffset > docLen-1){ return new int[]{-1, -1}; } char current = strDoc.charAt(initialOffset); ! ParsingUtils parsingUtils = ParsingUtils.create(strDoc); //for checking if it is global, it must be in the beggining of a line (must be right after a \r or \n). ! 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); } initialOffset += 1; ! if(initialOffset < docLen-1){ current = strDoc.charAt(initialOffset); } *************** *** 296,303 **** //either, we are at the end of the document or we found a literal ! if(initialOffset < strDoc.length()-1){ if(initialOffset == 0){ //first char of the document... this is ok ! int i = ParsingUtils.eatLiterals(strDoc, buf, initialOffset); return new int[]{initialOffset, i}; } --- 299,306 ---- //either, we are at the end of the document or we found a literal ! 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}; } *************** *** 306,310 **** //it is only global if after \r or \n if(lastChar == '\r' || lastChar == '\n'){ ! int i = ParsingUtils.eatLiterals(strDoc, buf, initialOffset); return new int[]{initialOffset, i}; } --- 309,313 ---- //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}; } *************** *** 853,857 **** String docContents = doc.get(); int i = lineOffset + openParIndex; ! int j = ParsingUtils.eatPar(docContents, i, null); String insideParentesisTok = docContents.substring(i + 1, j); --- 856,860 ---- String docContents = doc.get(); int i = lineOffset + openParIndex; ! int j = ParsingUtils.create(docContents).eatPar(i, null); String insideParentesisTok = docContents.substring(i + 1, j); *************** *** 1266,1279 **** */ public static int getBeforeParentesisCall(Object doc, int calltipOffset) { ! char c = ParsingUtils.charAt(doc, calltipOffset); while(calltipOffset > 0 && c != '('){ calltipOffset --; ! c = ParsingUtils.charAt(doc, calltipOffset); } if(c == '('){ while(calltipOffset > 0 && Character.isWhitespace(c)){ calltipOffset --; ! c = ParsingUtils.charAt(doc, calltipOffset); } return calltipOffset; --- 1269,1283 ---- */ public static int getBeforeParentesisCall(Object doc, int calltipOffset) { ! ParsingUtils parsingUtils = ParsingUtils.create(doc); ! char c = parsingUtils.charAt(calltipOffset); while(calltipOffset > 0 && c != '('){ calltipOffset --; ! c = parsingUtils.charAt(calltipOffset); } if(c == '('){ while(calltipOffset > 0 && Character.isWhitespace(c)){ calltipOffset --; ! c = parsingUtils.charAt(calltipOffset); } return calltipOffset; Index: ParsingUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ParsingUtils.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ParsingUtils.java 6 Jul 2008 17:10:39 -0000 1.23 --- ParsingUtils.java 6 Jul 2008 21:58:28 -0000 1.24 *************** *** 19,25 **** * @author Fabio */ ! public class ParsingUtils implements IPythonPartitions{ /** * @param cs the char array we are parsing --- 19,161 ---- * @author Fabio */ ! public abstract class ParsingUtils implements IPythonPartitions{ ! ! ! /** ! * Class that handles char[] ! * ! * @author Fabio ! */ ! private static class CharArrayParsingUtils extends ParsingUtils{ ! private char[] cs; ! public CharArrayParsingUtils(char[] cs) { ! this.cs = cs; ! } ! public int len() { ! return cs.length; ! } ! public char charAt(int i) { ! return cs[i]; ! } ! } ! ! ! /** ! * Class that handles FastStringBuffer ! * ! * @author Fabio ! */ ! private static class FastStringBufferParsingUtils extends ParsingUtils{ ! private FastStringBuffer cs; ! public FastStringBufferParsingUtils(FastStringBuffer cs) { ! this.cs = cs; ! } ! public int len() { ! return cs.length(); ! } ! public char charAt(int i) { ! return cs.charAt(i); ! } ! } ! ! /** ! * Class that handles StringBuffer ! * ! * @author Fabio ! */ ! private static class StringBufferParsingUtils extends ParsingUtils{ ! private StringBuffer cs; ! public StringBufferParsingUtils(StringBuffer cs) { ! this.cs = cs; ! } ! public int len() { ! return cs.length(); ! } ! public char charAt(int i) { ! return cs.charAt(i); ! } ! } ! ! /** ! * Class that handles String ! * ! * @author Fabio ! */ ! private static class StringParsingUtils extends ParsingUtils{ ! private String cs; ! public StringParsingUtils(String cs) { ! this.cs = cs; ! } ! public int len() { ! return cs.length(); ! } ! public char charAt(int i) { ! return cs.charAt(i); ! } ! } ! ! /** ! * Class that handles String ! * ! * @author Fabio ! */ ! private static class IDocumentParsingUtils extends ParsingUtils{ ! private IDocument cs; ! public IDocumentParsingUtils(IDocument cs) { ! this.cs = cs; ! } ! public int len() { ! return cs.getLength(); ! } ! public char charAt(int i) { ! try { ! return cs.getChar(i); ! } catch (BadLocationException e) { ! throw new RuntimeException(e); ! } ! } ! } ! ! /** ! * Factory method to create it. ! */ ! public static ParsingUtils create(Object cs) { ! if(cs instanceof char[]){ ! return new CharArrayParsingUtils((char[])cs); ! } ! if(cs instanceof FastStringBuffer){ ! return new FastStringBufferParsingUtils((FastStringBuffer)cs); ! } ! if(cs instanceof StringBuffer){ ! return new StringBufferParsingUtils((StringBuffer)cs); ! } ! if(cs instanceof String){ ! return new StringParsingUtils((String)cs); ! } ! if(cs instanceof IDocument){ ! return new IDocumentParsingUtils((IDocument)cs); ! } ! throw new RuntimeException("Don't know how to create instance for: "+cs.getClass()); ! } ! + //Abstract interfaces ------------------------------------------------------------- + + /** + * @return the char at a given position of the object + */ + public abstract char charAt(int i); + + + /** + * @return the length of the contained object + */ + public abstract int len(); + + + //API methods -------------------------------------------------------------------- + + /** * @param cs the char array we are parsing *************** *** 29,37 **** * @return the end of the comments position (end of document or new line char) */ ! 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); --- 165,173 ---- * @return the end of the comments position (end of document or new line char) */ ! public int eatComments(FastStringBuffer buf, int i) { ! int len = len(); char c; ! while(i < len && (c = charAt(i)) != '\n' && c != '\r'){ if(buf != null){ buf.append(c); *************** *** 42,46 **** if(i < len){ if(buf != null){ ! buf.append(charAt(cs,i)); } } --- 178,182 ---- if(i < len){ if(buf != null){ ! buf.append(charAt(i)); } } *************** *** 56,63 **** * @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... ! char curr = charAt(cs, i); if(curr != '"' && curr != '\''){ --- 192,199 ---- * @return the end of the literal position (or end of document) */ ! public int eatLiterals(FastStringBuffer buf, int i) { //ok, current pos is ' or " //check if we're starting a single or multiline comment... ! char curr = charAt(i); if(curr != '"' && curr != '\''){ *************** *** 65,74 **** } ! int j = getLiteralEnd(cs, i, curr); if(buf != null){ ! int len = len(cs); for (int k = i; k < len && k <= j; k++) { ! buf.append(charAt(cs, k)); } } --- 201,210 ---- } ! int j = getLiteralEnd(i, curr); if(buf != null){ ! int len = len(); for (int k = i; k < len && k <= j; k++) { ! buf.append(charAt(k)); } } *************** *** 83,94 **** * @return the end of the multiline literal */ ! public static int getLiteralEnd(Object cs, int i, char curr) { ! boolean multi = isMultiLiteral(cs, i, curr); int j; if(multi){ ! j = findNextMulti(cs, i+3, curr); }else{ ! j = findNextSingle(cs, i+1, curr); } return j; --- 219,230 ---- * @return the end of the multiline literal */ ! public int getLiteralEnd(int i, char curr) { ! boolean multi = isMultiLiteral(i, curr); int j; if(multi){ ! j = findNextMulti(i+3, curr); }else{ ! j = findNextSingle(i+1, curr); } return j; *************** *** 101,106 **** * @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, '('); } --- 237,242 ---- * @return the end of the literal position (or end of document) */ ! public int eatPar(int i, FastStringBuffer buf) { ! return eatPar(i, buf, '('); } *************** *** 108,112 **** * @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 = ' '; --- 244,248 ---- * @param buf if null, it'll simply advance without adding anything to the buffer. */ ! public int eatPar(int i, FastStringBuffer buf, char par) { char c = ' '; *************** *** 114,130 **** int j = i+1; ! int len = len(cs); ! while(j < len && (c = charAt(cs,j)) != closingPar){ j++; 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{ --- 250,266 ---- int j = i+1; ! int len = len(); ! while(j < len && (c = charAt(j)) != closingPar){ j++; if(c == '\'' || c == '"'){ //ignore comments or multiline comments... ! j = eatLiterals(null, j-1)+1; }else if(c == '#'){ ! j = eatComments(null, j-1)+1; }else if( c == par){ //open another par. ! j = eatPar(j-1, null, par)+1; }else{ *************** *** 141,149 **** * discover the position of the closing quote */ ! 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); --- 277,285 ---- * discover the position of the closing quote */ ! public int findNextSingle(int i, char curr) { boolean ignoreNext = false; ! int len = len(); while(i < len){ ! char c = charAt(i); *************** *** 168,176 **** * check the end of the multiline quote */ ! 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){ break; } --- 304,312 ---- * check the end of the multiline quote */ ! public int findNextMulti(int i, char curr) { ! int len = len(); while(i+2 < len){ ! char c = charAt(i); ! if (c == curr && charAt(i+1) == curr && charAt(i+2) == curr){ break; } *************** *** 186,230 **** } ! public static char charAt(Object o, int i){ ! if (o instanceof char[]) { ! return ((char[]) o)[i]; ! } ! if (o instanceof FastStringBuffer) { ! return ((FastStringBuffer) o).charAt(i); ! } ! if (o instanceof StringBuffer) { ! return ((StringBuffer) o).charAt(i); ! } ! if (o instanceof String) { ! return ((String) o).charAt(i); ! } ! if (o instanceof IDocument) { ! try { ! return ((IDocument) o).getChar(i); ! } catch (BadLocationException e) { ! throw new RuntimeException(e); ! } ! } ! throw new RuntimeException("unable to get char at of "+o.getClass()); ! } - public static int len(Object o){ - if (o instanceof char[]) { - return ((char[]) o).length; - } - if (o instanceof FastStringBuffer) { - return ((FastStringBuffer) o).length(); - } - if (o instanceof StringBuffer) { - return ((StringBuffer) o).length(); - } - if (o instanceof String) { - return ((String) o).length(); - } - if (o instanceof IDocument) { - return ((IDocument) o).getLength(); - } - throw new RuntimeException("unable to get len of "+o.getClass()); - } /** --- 322,347 ---- } ! ! ! ! ! ! ! ! ! ! ! ! ! //STATIC INTERFACES FROM NOW ON ---------------------------------------------------------------- ! //STATIC INTERFACES FROM NOW ON ---------------------------------------------------------------- ! //STATIC INTERFACES FROM NOW ON ---------------------------------------------------------------- ! //STATIC INTERFACES FROM NOW ON ---------------------------------------------------------------- ! //STATIC INTERFACES FROM NOW ON ---------------------------------------------------------------- ! ! ! ! /** *************** *** 235,244 **** * @return whether we are at the start of a multi line literal or not. */ ! public static boolean isMultiLiteral(Object cs, int i, char curr){ ! int len = len(cs); if(len <= i + 2){ return false; } ! if(charAt(cs, i+1) == curr && charAt(cs,i+2) == curr){ return true; } --- 352,361 ---- * @return whether we are at the start of a multi line literal or not. */ ! public boolean isMultiLiteral(int i, char curr){ ! int len = len(); if(len <= i + 2){ return false; } ! if(charAt(i+1) == curr && charAt(i+2) == curr){ return true; } *************** *** 250,253 **** --- 367,371 ---- removeCommentsWhitespacesAndLiterals(buf, true); } + /** * Removes all the comments, whitespaces and literals from a FastStringBuffer (might be useful when *************** *** 260,263 **** --- 378,382 ---- */ public static void removeCommentsWhitespacesAndLiterals(FastStringBuffer buf, boolean whitespacesToo) { + ParsingUtils parsingUtils = create(buf); for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); *************** *** 273,277 **** if(ch == '\'' || ch == '"'){ ! int j = getLiteralEnd(buf, i, ch); if(whitespacesToo){ buf.delete(i, j+1); --- 392,396 ---- if(ch == '\'' || ch == '"'){ ! int j = parsingUtils.getLiteralEnd(i, ch); if(whitespacesToo){ buf.delete(i, j+1); *************** *** 295,298 **** --- 414,418 ---- } public static void removeLiterals(FastStringBuffer buf) { + ParsingUtils parsingUtils = create(buf); for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); *************** *** 306,310 **** if(ch == '\'' || ch == '"'){ ! int j = getLiteralEnd(buf, i, ch); for (int k = 0; i+k < j+1; k++) { buf.replace(i+k, i+k+1, " "); --- 426,430 ---- if(ch == '\'' || ch == '"'){ ! int j = parsingUtils.getLiteralEnd(i, ch); for (int k = 0; i+k < j+1; k++) { buf.replace(i+k, i+k+1, " "); *************** *** 356,359 **** --- 476,480 ---- public static String getContentType(String initial, int currPos) { FastStringBuffer buf = new FastStringBuffer(initial, 0); + ParsingUtils parsingUtils = create(initial); String curr = PY_DEFAULT; *************** *** 381,385 **** curr = PY_SINGLELINE_STRING2; } ! i = getLiteralEnd(buf, i, ch); } } --- 502,506 ---- curr = PY_SINGLELINE_STRING2; } ! i = parsingUtils.getLiteralEnd(i, ch); } } Index: ImportHandle.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ImportHandle.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ImportHandle.java 15 Jun 2008 16:45:20 -0000 1.7 --- ImportHandle.java 6 Jul 2008 21:58:28 -0000 1.8 *************** *** 138,142 **** if(c == '#'){ comments = comments.clear(); ! i = ParsingUtils.eatComments(importedStr, comments, i); addImportAlias(lst, importComments, alias, comments.toString()); alias = alias.clear(); --- 138,142 ---- if(c == '#'){ comments = comments.clear(); ! i = ParsingUtils.create(importedStr).eatComments(comments, i); addImportAlias(lst, importComments, alias, comments.toString()); alias = alias.clear(); *************** *** 339,343 **** if(c == '#'){ ! i = ParsingUtils.eatComments(importFound, imp, i); }else if(c == ';'){ --- 339,343 ---- if(c == '#'){ ! i = ParsingUtils.create(importFound).eatComments(imp, i); }else if(c == ';'){ Index: PyDocIterator.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/PyDocIterator.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PyDocIterator.java 17 May 2008 14:26:57 -0000 1.8 --- PyDocIterator.java 6 Jul 2008 21:58:28 -0000 1.9 *************** *** 132,140 **** char ch = 0; ! while(ch != '\r' && ch != '\n' && offset < doc.getLength()){ ch = doc.getChar(offset); if (ch == '#') { ! while (offset < doc.getLength() && ch != '\n' && ch != '\r') { ch = doc.getChar(offset); if(addComments && ch != '\n' && ch != '\r'){ --- 132,142 ---- 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'){ *************** *** 147,151 **** if(returnNewLinesOnLiterals){ inLiteral = true; ! literalEnd = ParsingUtils.getLiteralEnd(doc, offset, ch); String ret = nextInLiteral(); if(ret.length() > 0){ --- 149,153 ---- if(returnNewLinesOnLiterals){ inLiteral = true; ! literalEnd = parsingUtils.getLiteralEnd(offset, ch); String ret = nextInLiteral(); if(ret.length() > 0){ *************** *** 164,168 **** throw new RuntimeException("Not supported in this case."); } ! offset = ParsingUtils.getLiteralEnd(doc, offset, ch); offset++; } --- 166,170 ---- throw new RuntimeException("Not supported in this case."); } ! offset = parsingUtils.getLiteralEnd(offset, ch); offset++; } *************** *** 183,187 **** } if(ch == '\r'){ ! if(offset < doc.getLength() && doc.getChar(offset) == '\n'){ offset++; if(addNewLinesToRet){ --- 185,189 ---- } if(ch == '\r'){ ! if(offset < docLen && doc.getChar(offset) == '\n'){ offset++; if(addNewLinesToRet){ |
From: Fabio Z. <fa...@us...> - 2008-07-06 21:58:20
|
Update of /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7795/tests/org/python/pydev/core/docutils Modified Files: DocUtilsTest.java Log Message: Changes in the ParsingUtils interface (creating correct version with factory to properly adapt to the object being read). Index: DocUtilsTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/docutils/DocUtilsTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DocUtilsTest.java 17 Oct 2005 16:59:04 -0000 1.1 --- DocUtilsTest.java 6 Jul 2008 21:58:28 -0000 1.2 *************** *** 20,23 **** --- 20,29 ---- assertEquals('(', DocUtils.getPeer(')')); assertEquals(')', DocUtils.getPeer('(')); + + assertEquals('{', DocUtils.getPeer('}')); + assertEquals('}', DocUtils.getPeer('{')); + + assertEquals('[', DocUtils.getPeer(']')); + assertEquals(']', DocUtils.getPeer('[')); } } |
From: Fabio Z. <fa...@us...> - 2008-07-06 21:58:05
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7764/src/org/python/pydev/editor/actions Modified Files: PyFormatStd.java Log Message: Changes in the ParsingUtils interface (creating correct version with factory to properly adapt to the object being read). Index: PyFormatStd.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyFormatStd.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** PyFormatStd.java 15 Jun 2008 16:45:26 -0000 1.17 --- PyFormatStd.java 6 Jul 2008 21:58:13 -0000 1.18 *************** *** 127,130 **** --- 127,131 ---- char[] cs = str.toCharArray(); FastStringBuffer buf = new FastStringBuffer(); + ParsingUtils parsingUtils = ParsingUtils.create(cs); char lastChar = '\0'; for (int i = 0; i < cs.length; i++) { *************** *** 132,139 **** if (c == '\'' || c == '"') { //ignore comments or multiline comments... ! i = ParsingUtils.eatLiterals(cs, buf, i); } else if (c == '#') { ! i = ParsingUtils.eatComments(cs, buf, i); } else if (c == ',') { --- 133,140 ---- if (c == '\'' || c == '"') { //ignore comments or multiline comments... ! i = parsingUtils.eatLiterals(buf, i); } else if (c == '#') { ! i = parsingUtils.eatComments(buf, i); } else if (c == ',') { *************** *** 142,146 **** } else if (c == '(') { ! i = formatForPar(cs, i, std, buf); } else { --- 143,147 ---- } else if (c == '(') { ! i = formatForPar(parsingUtils, cs, i, std, buf); } else { *************** *** 161,165 **** * @param i */ ! private static int formatForPar(char[] cs, int i, FormatStd std, FastStringBuffer buf) { char c = ' '; FastStringBuffer locBuf = new FastStringBuffer(); --- 162,166 ---- * @param i */ ! private static int formatForPar(ParsingUtils parsingUtils, char[] cs, int i, FormatStd std, FastStringBuffer buf) { char c = ' '; FastStringBuffer locBuf = new FastStringBuffer(); *************** *** 171,181 **** if (c == '\'' || c == '"') { //ignore comments or multiline comments... ! j = ParsingUtils.eatLiterals(cs, locBuf, j - 1) + 1; } else if (c == '#') { ! j = ParsingUtils.eatComments(cs, locBuf, j - 1) + 1; } else if (c == '(') { //open another par. ! j = formatForPar(cs, j - 1, std, locBuf) + 1; } else { --- 172,182 ---- if (c == '\'' || c == '"') { //ignore comments or multiline comments... ! j = parsingUtils.eatLiterals(locBuf, j - 1) + 1; } else if (c == '#') { ! j = parsingUtils.eatComments(locBuf, j - 1) + 1; } else if (c == '(') { //open another par. ! j = formatForPar(parsingUtils, cs, j - 1, std, locBuf) + 1; } else { |
From: Fabio Z. <fa...@us...> - 2008-07-06 21:58:05
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/copiedfromeclipsesrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7764/src/org/python/copiedfromeclipsesrc Modified Files: PythonCodeReader.java Log Message: Changes in the ParsingUtils interface (creating correct version with factory to properly adapt to the object being read). Index: PythonCodeReader.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/copiedfromeclipsesrc/PythonCodeReader.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PythonCodeReader.java 15 Jun 2008 16:45:26 -0000 1.10 --- PythonCodeReader.java 6 Jul 2008 21:58:13 -0000 1.11 *************** *** 110,113 **** --- 110,114 ---- private int readForwards() throws BadLocationException { + ParsingUtils parsingUtils = ParsingUtils.create(fDocument); while (fOffset < fEnd) { char current= fDocument.getChar(fOffset++); *************** *** 115,124 **** switch (current) { case '#': ! fOffset = ParsingUtils.eatComments(fDocument, null, fOffset); return current; case '"': case '\'': ! fOffset = ParsingUtils.eatLiterals(fDocument, null, fOffset-1)+1; continue; } --- 116,125 ---- switch (current) { case '#': ! fOffset = parsingUtils.eatComments(null, fOffset); return current; case '"': case '\'': ! fOffset = parsingUtils.eatLiterals(null, fOffset-1)+1; continue; } |
From: Fabio Z. <fa...@us...> - 2008-07-06 21:58:05
|
Update of /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7764/src_completions/org/python/pydev/editor/codecompletion Modified Files: PyContextInformationValidator.java Log Message: Changes in the ParsingUtils interface (creating correct version with factory to properly adapt to the object being read). Index: PyContextInformationValidator.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/PyContextInformationValidator.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PyContextInformationValidator.java 15 Jun 2008 16:45:26 -0000 1.5 --- PyContextInformationValidator.java 6 Jul 2008 21:58:12 -0000 1.6 *************** *** 20,24 **** import org.eclipse.swt.custom.StyleRange; import org.python.pydev.core.docutils.ParsingUtils; - import org.python.pydev.core.structure.FastStringBuffer; import org.python.pydev.plugin.PydevPlugin; --- 20,23 ---- *************** *** 208,211 **** --- 207,211 ---- int charCount = 0; int offset = start; + ParsingUtils parsingUtils = ParsingUtils.create(document); while (offset < end) { char curr = document.getChar(offset++); *************** *** 219,223 **** case '"': case '\'': ! int eaten = ParsingUtils.eatLiterals(document, null, offset - 1) + 1; if (eaten > offset) { offset = eaten; --- 219,223 ---- case '"': case '\'': ! int eaten = parsingUtils.eatLiterals(null, offset - 1) + 1; if (eaten > offset) { offset = eaten; |