pydev-cvs Mailing List for PyDev for Eclipse (Page 16)
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-06-14 22:14:27
|
Update of /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27905/src/org/python/pydev/refactoring/core Modified Files: RefactoringInfo.java Log Message: Using faster version of StringBuffer: FastStrintgBuffer / Better icons for auto-import. Index: RefactoringInfo.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/RefactoringInfo.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RefactoringInfo.java 20 Oct 2007 19:31:00 -0000 1.6 --- RefactoringInfo.java 14 Jun 2008 22:14:34 -0000 1.7 *************** *** 21,24 **** --- 21,25 ---- import org.eclipse.ui.texteditor.ITextEditor; import org.python.pydev.core.IPythonNature; + import org.python.pydev.core.structure.FastStringBuffer; import org.python.pydev.parser.jython.ParseException; import org.python.pydev.refactoring.ast.PythonModuleManager; *************** *** 182,186 **** } if (bodyIndent > 0) { ! StringBuffer selectedCode = new StringBuffer(); for (String line : lines) { if (line.startsWith(indentation)) { --- 183,187 ---- } if (bodyIndent > 0) { ! FastStringBuffer selectedCode = new FastStringBuffer(); for (String line : lines) { if (line.startsWith(indentation)) { |
From: Fabio Z. <fa...@us...> - 2008-06-14 22:14:27
|
Update of /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/printer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27905/src/org/python/pydev/refactoring/ast/printer Modified Files: SyntaxHelper.java Log Message: Using faster version of StringBuffer: FastStrintgBuffer / Better icons for auto-import. Index: SyntaxHelper.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/printer/SyntaxHelper.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SyntaxHelper.java 20 Oct 2007 19:31:01 -0000 1.4 --- SyntaxHelper.java 14 Jun 2008 22:14:34 -0000 1.5 *************** *** 8,11 **** --- 8,13 ---- package org.python.pydev.refactoring.ast.printer; + import org.python.pydev.core.structure.FastStringBuffer; + public class SyntaxHelper { *************** *** 342,346 **** public String getStar(int i) { ! StringBuffer buf = new StringBuffer(); for (int j = 0; j < i; j++) buf.append(STAR); --- 344,348 ---- public String getStar(int i) { ! FastStringBuffer buf = new FastStringBuffer(i+1); for (int j = 0; j < i; j++) buf.append(STAR); |
From: Fabio Z. <fa...@us...> - 2008-06-14 22:14:27
|
Update of /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ui/controls/preview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27905/src/org/python/pydev/refactoring/ui/controls/preview Modified Files: PyPreviewConfiguration.java Log Message: Using faster version of StringBuffer: FastStrintgBuffer / Better icons for auto-import. Index: PyPreviewConfiguration.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ui/controls/preview/PyPreviewConfiguration.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyPreviewConfiguration.java 27 Feb 2007 12:24:53 -0000 1.2 --- PyPreviewConfiguration.java 14 Jun 2008 22:14:34 -0000 1.3 *************** *** 22,25 **** --- 22,26 ---- import org.eclipse.swt.widgets.Shell; import org.python.pydev.core.IPythonPartitions; + import org.python.pydev.core.structure.FastStringBuffer; import org.python.pydev.editor.PyCodeScanner; import org.python.pydev.editor.PyColoredScanner; *************** *** 107,111 **** Preferences prefs = PydevPlugin.getDefault().getPluginPreferences(); int tabWidth = prefs.getInt(PydevPrefs.TAB_WIDTH); ! StringBuffer spaces = new StringBuffer(8); for (int i = 0; i < tabWidth; i++) { --- 108,112 ---- Preferences prefs = PydevPlugin.getDefault().getPluginPreferences(); int tabWidth = prefs.getInt(PydevPrefs.TAB_WIDTH); ! FastStringBuffer spaces = new FastStringBuffer(8); for (int i = 0; i < tabWidth; i++) { |
From: Fabio Z. <fa...@us...> - 2008-06-14 22:14:27
|
Update of /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/codegenerator/generatedocstring In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27905/src/org/python/pydev/refactoring/codegenerator/generatedocstring Modified Files: GenerateDocstringOperation.java Log Message: Using faster version of StringBuffer: FastStrintgBuffer / Better icons for auto-import. Index: GenerateDocstringOperation.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/src/org/python/pydev/refactoring/codegenerator/generatedocstring/GenerateDocstringOperation.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenerateDocstringOperation.java 20 Oct 2007 19:31:04 -0000 1.1 --- GenerateDocstringOperation.java 14 Jun 2008 22:14:34 -0000 1.2 *************** *** 24,27 **** --- 24,28 ---- import org.python.pydev.core.Tuple; import org.python.pydev.core.docutils.PySelection; + import org.python.pydev.core.structure.FastStringBuffer; import org.python.pydev.editor.PyEdit; import org.python.pydev.editor.actions.PyAction; *************** *** 80,84 **** String inAndIndent = getInAndIndent(selection); ! StringBuffer buf = new StringBuffer(); String docStringMarker = DocstringsPrefPage.getDocstringMarker(); --- 81,85 ---- String inAndIndent = getInAndIndent(selection); ! FastStringBuffer buf = new FastStringBuffer(); String docStringMarker = DocstringsPrefPage.getDocstringMarker(); *************** *** 93,104 **** continue; } ! buf.append(inAndIndent + "@param " + paramName + ":"); if (DocstringsPrefPage.getTypeTagShouldBeGenerated(paramName)) { ! buf.append(inAndIndent + "@type " + paramName + ":"); } } } ! buf.append(inAndIndent + docStringMarker); try { --- 94,105 ---- continue; } ! buf.append(inAndIndent).append("@param ").append(paramName).append(":"); if (DocstringsPrefPage.getTypeTagShouldBeGenerated(paramName)) { ! buf.append(inAndIndent).append("@type ").append(paramName).append(":"); } } } ! buf.append(inAndIndent).append(docStringMarker); try { |
From: Fabio Z. <fa...@us...> - 2008-06-14 22:14:21
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/structure In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27891/src/org/python/pydev/core/structure Added Files: FastStringBuffer.java Log Message: Using faster version of StringBuffer: FastStrintgBuffer / Better icons for auto-import. --- NEW FILE: FastStringBuffer.java --- package org.python.pydev.core.structure; /** * This is a custom string that works around char[] objects to provide minimum allocation/garbage collection overhead. * To be used mostly when several small concatenations of strings are used and in local contexts while reusing the * same object to create multiple strings. * * @author Fabio */ public final class FastStringBuffer { /** * Holds the actual chars */ private char[] value; /** * Count for which chars are actually used */ private int count; /** * Initializes with a default initial size (128 chars) */ public FastStringBuffer() { this(128); } /** * An initial size can be specified (if available and given for no allocations it can be more efficient) */ public FastStringBuffer(int initialSize) { this.value = new char[initialSize]; this.count = 0; } /** * initializes from a string and the additional size for the buffer * * @param s string with the initial contents * @param additionalSize the additional size for the buffer */ public FastStringBuffer(String s, int additionalSize) { this.count = s.length(); value = new char[this.count + additionalSize]; s.getChars(0, this.count, value, 0); } /** * Appends a string to the buffer */ public FastStringBuffer append(String string) { int strLen = string.length(); if (this.count + strLen > this.value.length) { resizeForMinimum(this.count + strLen); } string.getChars(0, strLen, value, this.count); this.count += strLen; return this; } private void resizeForMinimum(int minimumCapacity) { int newCapacity = (value.length + 1) * 2; if (newCapacity < 0) { newCapacity = Integer.MAX_VALUE; } else if (minimumCapacity > newCapacity) { newCapacity = minimumCapacity; } char newValue[] = new char[newCapacity]; System.arraycopy(value, 0, newValue, 0, count); value = newValue; } public final FastStringBuffer append(int n) { append(String.valueOf(n)); return this; } public final FastStringBuffer append(char n) { if (count + 1 > value.length) { resizeForMinimum(count + 1); } value[count] = n; count += 1; return this; } public final FastStringBuffer append(long n) { append(String.valueOf(n)); return this; } public final FastStringBuffer append(boolean b) { append(String.valueOf(b)); return this; } public FastStringBuffer append(char[] chars) { if (count + chars.length > value.length) { resizeForMinimum(count + chars.length); } System.arraycopy(chars, 0, value, count, chars.length); count += chars.length; return this; } public FastStringBuffer append(FastStringBuffer other) { append(other.value, 0, other.count); return this; } public FastStringBuffer append(char[] chars, int offset, int len) { if (count + len > value.length) { resizeForMinimum(count + len); } System.arraycopy(chars, offset, value, count, len); count += len; return this; } public FastStringBuffer reverse() { final int limit = count / 2; for (int i = 0; i < limit; ++i) { char c = value[i]; value[i] = value[count - i - 1]; value[count - i - 1] = c; } return this; } public void clear() { this.count = 0; } public int length() { return this.count; } @Override public String toString() { return new String(value, 0, count); } public void deleteLast() { if (this.count > 0) { this.count -= 1; } } public char charAt(int i) { return this.value[i]; } public FastStringBuffer insert(int offset, String str) { int len = str.length(); int newCount = count + len; if (newCount > value.length){ resizeForMinimum(newCount); } System.arraycopy(value, offset, value, offset + len, count - offset); str.getChars(0, str.length(), value, offset); count = newCount; return this; } public FastStringBuffer appendObject(Object attribute) { return append(attribute != null?attribute.toString():"null"); } public void setCount(int newLen) { this.count = newLen; } } |
From: Fabio Z. <fa...@us...> - 2008-06-14 22:14:21
|
Update of /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/structure In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27891/tests/org/python/pydev/core/structure Added Files: FastStringBufferTest.java Log Message: Using faster version of StringBuffer: FastStrintgBuffer / Better icons for auto-import. --- NEW FILE: FastStringBufferTest.java --- package org.python.pydev.core.structure; import junit.framework.TestCase; public class FastStringBufferTest extends TestCase{ private static final int ITERATIONS = 10000; private static final int OUTER_ITERATIONS = 50; public void testFastString1() throws Exception { FastStringBuffer fastString = new FastStringBuffer(2); fastString.append("bbb"); assertEquals("bbb", fastString.toString()); fastString.append("ccc"); assertEquals("bbbccc", fastString.toString()); fastString.clear(); assertEquals("", fastString.toString()); fastString.append("abc"); assertEquals("abc", fastString.toString()); fastString.reverse(); assertEquals("cba", fastString.toString()); fastString.clear(); fastString.append("aaa"); FastStringBuffer other = new FastStringBuffer(3); other.append("bbcccdddddddddddddddddddddddddddddd"); fastString.append(other); assertEquals("aaabbcccdddddddddddddddddddddddddddddd", fastString.toString()); fastString.insert(1, "22"); assertEquals("a22aabbcccdddddddddddddddddddddddddddddd", fastString.toString()); fastString.append('$'); assertEquals("a22aabbcccdddddddddddddddddddddddddddddd$", fastString.toString()); } // public void testFastString() throws Exception { // // long total=0; // FastStringBuffer fastString = new FastStringBuffer(50); // for(int j=0;j<OUTER_ITERATIONS;j++){ // final long start = System.nanoTime(); // // // fastString.clear(); // for(int i=0;i<ITERATIONS;i++){ // fastString.append("test").append("bar").append("foo").append("foo").append("foo").append("foo"); // } // // final long end = System.nanoTime(); // long delta=(end-start)/1000000; // total+=delta; //// System.out.println("Fast: " + delta); // } // System.out.println("Fast Total:"+total); // } // // public void testStringBuffer() throws Exception { // // long total=0; // StringBuffer fastString = new StringBuffer(50); // for(int j=0;j<OUTER_ITERATIONS;j++){ // final long start = System.nanoTime(); // // // fastString.setLength(0); // for(int i=0;i<ITERATIONS;i++){ // fastString.append("test").append("bar").append("foo").append("foo").append("foo").append("foo"); // } // // final long end = System.nanoTime(); // long delta=(end-start)/1000000; // total+=delta; //// System.out.println("Buffer: " + delta); // } // System.out.println("Buffer Total:"+total); // } } |
From: Fabio Z. <fa...@us...> - 2008-06-11 00:01:02
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016/src/org/python/pydev/editor/actions Modified Files: PyOrganizeImports.java Log Message: Organize imports fixes. Index: PyOrganizeImports.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyOrganizeImports.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** PyOrganizeImports.java 2 Jun 2008 00:10:31 -0000 1.15 --- PyOrganizeImports.java 11 Jun 2008 00:00:00 -0000 1.16 *************** *** 243,246 **** --- 243,247 ---- if(addedParenForLine && i == importsAndComments.size()){ + addedParenForLine = false; line.append(")"); } |
From: Fabio Z. <fa...@us...> - 2008-06-11 00:00:57
|
Update of /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25170/tests/org/python/pydev/core/docutils Modified Files: ImportHandleTest.java Log Message: Organize imports fixes. Index: ImportHandleTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/tests/org/python/pydev/core/docutils/ImportHandleTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ImportHandleTest.java 19 May 2008 00:58:28 -0000 1.2 --- ImportHandleTest.java 11 Jun 2008 00:00:09 -0000 1.3 *************** *** 119,123 **** lst = new ArrayList<String>(); lst.add("BBB"); ! lst.add("CCC"); assertEquals(lst, importInfo.get(0).getImportedStr()); --- 119,123 ---- lst = new ArrayList<String>(); lst.add("BBB"); ! lst.add("DDD as CCC"); assertEquals(lst, importInfo.get(0).getImportedStr()); |
From: Fabio Z. <fa...@us...> - 2008-06-11 00:00:53
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25170/src/org/python/pydev/core/docutils Modified Files: ImportHandle.java Log Message: Organize imports fixes. Index: ImportHandle.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ImportHandle.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ImportHandle.java 1 Jun 2008 20:44:47 -0000 1.5 --- ImportHandle.java 11 Jun 2008 00:00:09 -0000 1.6 *************** *** 148,157 **** ! }else if(c == ' ' || c == '\t'){ ! String curr = alias.toString(); ! if(curr.endsWith(" as") | curr.endsWith("\tas")){ ! alias = new StringBuffer(); ! } ! alias.append(c); }else{ --- 148,159 ---- ! // commented out: we'll get the xxx as yyy all in the alias. Clients may treat it separately if needed. ! // }else if(c == ' ' || c == '\t'){ ! // ! // String curr = alias.toString(); ! // if(curr.endsWith(" as") | curr.endsWith("\tas")){ ! // alias = new StringBuffer(); ! // } ! // alias.append(c); }else{ |
From: Fabio Z. <fa...@us...> - 2008-06-11 00:00:53
|
Update of /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016/tests/org/python/pydev/editor/actions Modified Files: PyOrganizeImportsTest.java Log Message: Organize imports fixes. Index: PyOrganizeImportsTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions/PyOrganizeImportsTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PyOrganizeImportsTest.java 1 Jun 2008 20:44:41 -0000 1.6 --- PyOrganizeImportsTest.java 11 Jun 2008 00:00:00 -0000 1.7 *************** *** 20,24 **** PyOrganizeImportsTest test = new PyOrganizeImportsTest(); test.setUp(); ! test.testPerformGroupingWithWraps3(); test.tearDown(); junit.textui.TestRunner.run(PyOrganizeImportsTest.class); --- 20,24 ---- PyOrganizeImportsTest test = new PyOrganizeImportsTest(); test.setUp(); ! test.testPerformWithGroupingWithAs(); test.tearDown(); junit.textui.TestRunner.run(PyOrganizeImportsTest.class); *************** *** 119,122 **** --- 119,142 ---- assertEquals(result, doc.get()); } + + + public void testPerformWithGroupingWithAs() { + ImportsPreferencesPage.groupImportsForTests = true; + String d = ""+ + "from a import c as d\n"+ + "from a import f as g\n"+ + "import e as g\n"; + + Document doc = new Document(d); + PyOrganizeImports.performArrangeImports(doc, "\n", " "); + + String result = ""+ + "from a import c as d, f as g\n"+ + "import e as g\n"+ + ""; + + // System.out.println(">>"+doc.get()+"<<"); + assertEquals(result, doc.get()); + } *************** *** 186,189 **** --- 206,226 ---- + public void testPerformGroupingWithWraps4() { + ImportsPreferencesPage.groupImportsForTests = true; + String d = ""+ + "from cccccccccccccccccccccccccccccccccccccccccccccccccc import eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n"; //50 * 'c' + + Document doc = new Document(d); + PyOrganizeImports.performArrangeImports(doc, "\n", " "); + + String result = ""+ + "from cccccccccccccccccccccccccccccccccccccccccccccccccc import (\n" + + " eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)\n"; + + // System.out.println(">>"+doc.get()+"<<"); + assertEquals(result, doc.get()); + } + + public void testPerform2() { |
From: Fabio Z. <fa...@us...> - 2008-06-02 00:10:24
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3412/src/org/python/pydev/editor/actions Modified Files: IOrganizeImports.java PyOrganizeImports.java Log Message: Organize imports for undefined vars. Index: PyOrganizeImports.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyOrganizeImports.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PyOrganizeImports.java 1 Jun 2008 20:44:41 -0000 1.14 --- PyOrganizeImports.java 2 Jun 2008 00:10:31 -0000 1.15 *************** *** 51,55 **** String endLineDelim = ps.getEndLineDelim(); final IDocument doc = ps.getDoc(); ! DocumentRewriteSession session = startWrite(doc); try { --- 51,55 ---- String endLineDelim = ps.getEndLineDelim(); final IDocument doc = ps.getDoc(); ! DocumentRewriteSession session = null; try { *************** *** 57,74 **** //let's see if someone wants to make a better implementation in another plugin... List<IOrganizeImports> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_ORGANIZE_IMPORTS); ! if (participants.size() == 1) { ! participants.get(0).performArrangeImports(ps, pyEdit); ! } else { ! if (participants.size() > 1) { ! //let's issue a warning... this extension can only have 1 plugin implementing it ! PydevPlugin.log("The organize imports has more than one plugin with this extension point, therefore, the default is being used."); ! } ! performArrangeImports(doc, endLineDelim, pyEdit.getIndentPrefs().getIndentationString()); } } else { performSimpleSort(doc, endLineDelim, ps.getStartLineIndex(), ps.getEndLineIndex()); } } finally { ! endWrite(doc, session); } } --- 57,82 ---- //let's see if someone wants to make a better implementation in another plugin... List<IOrganizeImports> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_ORGANIZE_IMPORTS); ! ! for (IOrganizeImports organizeImports : participants) { ! if(!organizeImports.beforePerformArrangeImports(ps, pyEdit)){ ! return; ! } ! } ! ! session = startWrite(doc); ! ! performArrangeImports(doc, endLineDelim, pyEdit.getIndentPrefs().getIndentationString()); ! ! for (IOrganizeImports organizeImports : participants) { ! organizeImports.afterPerformArrangeImports(ps, pyEdit); } } else { + session = startWrite(doc); performSimpleSort(doc, endLineDelim, ps.getStartLineIndex(), ps.getEndLineIndex()); } } finally { ! if(session != null){ ! endWrite(doc, session); ! } } } *************** *** 80,83 **** --- 88,94 ---- } + /** + * Stop a rewrite session + */ private void endWrite(IDocument doc, DocumentRewriteSession session) { if(doc instanceof IDocumentExtension4){ *************** *** 87,90 **** --- 98,104 ---- } + /** + * Starts a rewrite session (keep things in a single undo/redo) + */ private DocumentRewriteSession startWrite(IDocument doc) { if(doc instanceof IDocumentExtension4){ *************** *** 160,210 **** //import from to the imports that should be grouped given its 'from' ! TreeMap<String, List<ImportHandleInfo>> m = new TreeMap<String, List<ImportHandleInfo>>(); List<ImportHandleInfo> importsWithoutFrom = new ArrayList<ImportHandleInfo>(); ! //fill the info ! for (Iterator<Tuple3<Integer, String, ImportHandle>> iter = list.iterator(); iter.hasNext();) { ! Tuple3<Integer, String, ImportHandle> element = iter.next(); ! ! List<ImportHandleInfo> importInfo = element.o3.getImportInfo(); ! for (ImportHandleInfo importHandleInfo : importInfo) { ! String fromImportStr = importHandleInfo.getFromImportStr(); ! if(fromImportStr == null){ ! importsWithoutFrom.add(importHandleInfo); ! }else{ ! List<ImportHandleInfo> lst = m.get(fromImportStr); ! if(lst == null){ ! lst = new ArrayList<ImportHandleInfo>(); ! m.put(fromImportStr, lst); ! } ! lst.add(importHandleInfo); ! } ! } ! } ! //preferences for multiline imports boolean multilineImports = ImportsPreferencesPage.getMultilineImports(); ! int maxCols = 80; ! if(multilineImports){ ! if(PydevPlugin.getDefault() != null){ ! IPreferenceStore chainedPrefStore = PydevPlugin.getChainedPrefStore(); ! maxCols = chainedPrefStore.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN); ! } ! }else{ ! maxCols = Integer.MAX_VALUE; ! } ! //preferences for how to break imports ! String breakIportMode = ImportsPreferencesPage.getBreakIportMode(); ! boolean breakWithParenthesis = true; ! if(!breakIportMode.equals(ImportsPreferencesPage.BREAK_IMPORTS_MODE_PARENTHESIS)){ ! breakWithParenthesis = false; ! } ! ! Set<Entry<String, List<ImportHandleInfo>>> entrySet = m.entrySet(); for (Entry<String, List<ImportHandleInfo>> entry : entrySet) { --- 174,191 ---- //import from to the imports that should be grouped given its 'from' ! TreeMap<String, List<ImportHandleInfo>> importsWithFrom = new TreeMap<String, List<ImportHandleInfo>>(); List<ImportHandleInfo> importsWithoutFrom = new ArrayList<ImportHandleInfo>(); ! fillImportStructures(list, importsWithFrom, importsWithoutFrom); //preferences for multiline imports boolean multilineImports = ImportsPreferencesPage.getMultilineImports(); ! int maxCols = getMaxCols(multilineImports); //preferences for how to break imports ! boolean breakWithParenthesis = getBreakImportsWithParenthesis(); ! Set<Entry<String, List<ImportHandleInfo>>> entrySet = importsWithFrom.entrySet(); for (Entry<String, List<ImportHandleInfo>> entry : entrySet) { *************** *** 213,231 **** ArrayList<Tuple<String, String>> importsAndNoComments = new ArrayList<Tuple<String, String>>(); ! for (ImportHandleInfo v : entry.getValue()) { ! List<String> importedStr = v.getImportedStr(); ! List<String> commentsForImports = v.getCommentsForImports(); ! for(int i=0;i<importedStr.size();i++){ ! String importedString = importedStr.get(i); ! String comment = commentsForImports.get(i); ! if(comment.length() > 0){ ! importsAndComments.add(new Tuple<String, String>(importedString, comment)); ! }else{ ! importsAndNoComments.add(new Tuple<String, String>(importedString, comment)); ! } ! } ! } ! ! --- 194,198 ---- ArrayList<Tuple<String, String>> importsAndNoComments = new ArrayList<Tuple<String, String>>(); ! fillImportFromInfo(entry, importsAndComments, importsAndNoComments); *************** *** 307,327 **** } ! //now, write the regular imports (no wrapping or tabbing here) ! for(ImportHandleInfo info:importsWithoutFrom){ ! ! List<String> importedStr = info.getImportedStr(); ! List<String> commentsForImports = info.getCommentsForImports(); ! for(int i=0;i<importedStr.size();i++){ ! all.append("import "); ! String importedString = importedStr.get(i); ! String comment = commentsForImports.get(i); ! all.append(importedString); ! if(comment.length() > 0){ ! all.append(" "); ! all.append(comment); ! } ! all.append(endLineDelim); ! } ! } } --- 274,278 ---- } ! writeImportsWithoutFrom(endLineDelim, all, importsWithoutFrom); } *************** *** 331,334 **** --- 282,386 ---- } + + /** + * Write the imports that don't have a 'from' in the beggining (regular imports) + */ + private static void writeImportsWithoutFrom(String endLineDelim, StringBuffer all, + List<ImportHandleInfo> importsWithoutFrom) { + //now, write the regular imports (no wrapping or tabbing here) + for(ImportHandleInfo info:importsWithoutFrom){ + + List<String> importedStr = info.getImportedStr(); + List<String> commentsForImports = info.getCommentsForImports(); + for(int i=0;i<importedStr.size();i++){ + all.append("import "); + String importedString = importedStr.get(i); + String comment = commentsForImports.get(i); + all.append(importedString); + if(comment.length() > 0){ + all.append(" "); + all.append(comment); + } + all.append(endLineDelim); + } + } + } + + /** + * Fills the lists passed based on the entry set, so that imports that have comments are contained in a list + * and imports without comments in another. + */ + private static void fillImportFromInfo(Entry<String, List<ImportHandleInfo>> entry, + ArrayList<Tuple<String, String>> importsAndComments, ArrayList<Tuple<String, String>> importsAndNoComments) { + for (ImportHandleInfo v : entry.getValue()) { + List<String> importedStr = v.getImportedStr(); + List<String> commentsForImports = v.getCommentsForImports(); + for(int i=0;i<importedStr.size();i++){ + String importedString = importedStr.get(i); + String comment = commentsForImports.get(i); + if(comment.length() > 0){ + importsAndComments.add(new Tuple<String, String>(importedString, comment)); + }else{ + importsAndNoComments.add(new Tuple<String, String>(importedString, comment)); + } + } + } + } + + /** + * @return true if the imports should be split with parenthesis (instead of escaping) + */ + private static boolean getBreakImportsWithParenthesis() { + String breakIportMode = ImportsPreferencesPage.getBreakIportMode(); + boolean breakWithParenthesis = true; + if(!breakIportMode.equals(ImportsPreferencesPage.BREAK_IMPORTS_MODE_PARENTHESIS)){ + breakWithParenthesis = false; + } + return breakWithParenthesis; + } + + /** + * @return the maximum number of columns that may be available in a line. + */ + private static int getMaxCols(boolean multilineImports) { + int maxCols = 80; + if(multilineImports){ + if(PydevPlugin.getDefault() != null){ + IPreferenceStore chainedPrefStore = PydevPlugin.getChainedPrefStore(); + maxCols = chainedPrefStore.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN); + } + }else{ + maxCols = Integer.MAX_VALUE; + } + return maxCols; + } + + /** + * Fills the import structure passed, so that the imports from will be grouped by the 'from' part and the regular + * imports will be in a separate list. + */ + private static void fillImportStructures(List<Tuple3<Integer, String, ImportHandle>> list, + TreeMap<String, List<ImportHandleInfo>> importsWithFrom, List<ImportHandleInfo> importsWithoutFrom) { + //fill the info + for (Iterator<Tuple3<Integer, String, ImportHandle>> iter = list.iterator(); iter.hasNext();) { + Tuple3<Integer, String, ImportHandle> element = iter.next(); + + List<ImportHandleInfo> importInfo = element.o3.getImportInfo(); + for (ImportHandleInfo importHandleInfo : importInfo) { + String fromImportStr = importHandleInfo.getFromImportStr(); + if(fromImportStr == null){ + importsWithoutFrom.add(importHandleInfo); + }else{ + List<ImportHandleInfo> lst = importsWithFrom.get(fromImportStr); + if(lst == null){ + lst = new ArrayList<ImportHandleInfo>(); + importsWithFrom.put(fromImportStr, lst); + } + lst.add(importHandleInfo); + } + } + } + } + /** * Performs a simple sort without taking into account the actual contents of the selection (aside from lines Index: IOrganizeImports.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/IOrganizeImports.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IOrganizeImports.java 25 Feb 2006 00:14:23 -0000 1.2 --- IOrganizeImports.java 2 Jun 2008 00:10:31 -0000 1.3 *************** *** 7,19 **** import org.python.pydev.editor.PyEdit; public interface IOrganizeImports { /** ! * This function should organize the imports in the current pyedit. * * @param ps this is the selection (contains the doc) * @param pyEdit this is the edit */ ! void performArrangeImports(PySelection ps, PyEdit pyEdit); } --- 7,39 ---- import org.python.pydev.editor.PyEdit; + /** + * Interface that makes it possible for clients to interact with the organize imports feature, so that they + * can change how it actually behaves. + * + * @author Fabio + */ public interface IOrganizeImports { /** ! * This function is called just before the actual organize imports function is called. ! * ! * @param ps this is the selection (contains the doc) ! * @param pyEdit this is the edit ! * ! * @return true if the organize imports should proceed, and false if the organize imports should not proceed ! * (so, false cancels the default organize imports) ! * ! * @note this function is always called within a write session in the document (because it should seem as a single ! * operation for the user -- which has a single undo). ! */ ! boolean beforePerformArrangeImports(PySelection ps, PyEdit pyEdit); ! ! /** ! * Called right after the whole import process is done. * * @param ps this is the selection (contains the doc) * @param pyEdit this is the edit */ ! void afterPerformArrangeImports(PySelection ps, PyEdit pyEdit); } |
From: Fabio Z. <fa...@us...> - 2008-06-01 20:44:40
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24295/src/org/python/pydev/core/docutils Modified Files: ImportHandle.java Log Message: Organize imports can group from xxx imports. Index: ImportHandle.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/ImportHandle.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ImportHandle.java 20 May 2008 02:20:23 -0000 1.4 --- ImportHandle.java 1 Jun 2008 20:44:47 -0000 1.5 *************** *** 7,10 **** --- 7,11 ---- import org.eclipse.jface.text.IDocument; + import org.python.pydev.core.Tuple; /** *************** *** 233,236 **** --- 234,248 ---- } + /** + * @return a list of tuples with the iported string and the comment that's attached to it. + */ + public List<Tuple<String, String>> getImportedStrAndComments() { + ArrayList<Tuple<String,String>> lst = new ArrayList<Tuple<String,String>>(); + for(int i=0;i<this.importedStr.size();i++){ + lst.add(new Tuple<String, String>(this.importedStr.get(i), this.importedStrComments.get(i))); + } + return lst; + } + } |
From: Fabio Z. <fa...@us...> - 2008-06-01 20:44:35
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24261/src/org/python/pydev/editor/actions Modified Files: PyOrganizeImports.java Log Message: Organize imports can group from xxx imports. Index: PyOrganizeImports.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyOrganizeImports.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PyOrganizeImports.java 17 May 2008 14:26:52 -0000 1.13 --- PyOrganizeImports.java 1 Jun 2008 20:44:41 -0000 1.14 *************** *** 11,16 **** --- 11,20 ---- import java.util.Iterator; import java.util.List; + import java.util.Set; + import java.util.TreeMap; + import java.util.Map.Entry; import org.eclipse.jface.action.IAction; + import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentRewriteSession; *************** *** 18,27 **** --- 22,36 ---- import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentExtension4; + import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; import org.python.pydev.core.ExtensionHelper; + import org.python.pydev.core.Tuple; + import org.python.pydev.core.Tuple3; import org.python.pydev.core.docutils.ImportHandle; import org.python.pydev.core.docutils.PyImportsHandling; import org.python.pydev.core.docutils.PySelection; + import org.python.pydev.core.docutils.ImportHandle.ImportHandleInfo; import org.python.pydev.editor.PyEdit; import org.python.pydev.plugin.PydevPlugin; + import org.python.pydev.ui.importsconf.ImportsPreferencesPage; /** *************** *** 37,41 **** try { ! PySelection ps = new PySelection ( getTextEditor ( )); String endLineDelim = ps.getEndLineDelim(); final IDocument doc = ps.getDoc(); --- 46,52 ---- try { ! PyEdit pyEdit = getPyEdit(); ! ! PySelection ps = new PySelection(pyEdit); String endLineDelim = ps.getEndLineDelim(); final IDocument doc = ps.getDoc(); *************** *** 47,51 **** List<IOrganizeImports> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_ORGANIZE_IMPORTS); if (participants.size() == 1) { - PyEdit pyEdit = getPyEdit(); participants.get(0).performArrangeImports(ps, pyEdit); } else { --- 58,61 ---- *************** *** 54,58 **** PydevPlugin.log("The organize imports has more than one plugin with this extension point, therefore, the default is being used."); } ! performArrangeImports(doc, endLineDelim); } } else { --- 64,68 ---- PydevPlugin.log("The organize imports has more than one plugin with this extension point, therefore, the default is being used."); } ! performArrangeImports(doc, endLineDelim, pyEdit.getIndentPrefs().getIndentationString()); } } else { *************** *** 92,103 **** */ @SuppressWarnings("unchecked") ! public static void performArrangeImports(IDocument doc, String endLineDelim){ ! ArrayList list = new ArrayList(); ! //Gather imports in a structure we can work on. PyImportsHandling pyImportsHandling = new PyImportsHandling(doc); int firstImport = -1; for(ImportHandle imp:pyImportsHandling){ ! list.add( new Object[]{imp.startFoundLine, imp.importFound} ); if(firstImport == -1){ --- 102,112 ---- */ @SuppressWarnings("unchecked") ! public static void performArrangeImports(IDocument doc, String endLineDelim, String indentStr){ ! List<Tuple3<Integer, String, ImportHandle>> list = new ArrayList<Tuple3<Integer, String, ImportHandle>>(); //Gather imports in a structure we can work on. PyImportsHandling pyImportsHandling = new PyImportsHandling(doc); int firstImport = -1; for(ImportHandle imp:pyImportsHandling){ ! list.add( new Tuple3<Integer, String, ImportHandle>(imp.startFoundLine, imp.importFound, imp) ); if(firstImport == -1){ *************** *** 112,165 **** } ! //sort in inverse order ! Collections.sort(list, new Comparator(){ ! public int compare(Object o1, Object o2) { ! Object[] c1 = (Object[])o1; ! Object[] c2 = (Object[])o2; ! Integer i1 = (Integer) c1[0]; ! Integer i2 = (Integer) c2[0]; ! return i2.compareTo(i1); } ! }); ! ! //ok, now we have to delete all lines with imports. ! for (Iterator iter = list.iterator(); iter.hasNext();) { ! Object[] element = (Object[]) iter.next(); ! String s = (String) element[1]; int i = PySelection.countLineBreaks(s); ! while(i >= 0){ ! PySelection.deleteLine(doc, ((Integer)element[0]).intValue()); i--; } } ! ! Collections.sort(list, new Comparator(){ ! public int compare(Object o1, Object o2) { ! Object[] c1 = (Object[])o1; ! Object[] c2 = (Object[])o2; ! String s1 = (String) c1[1]; ! String s2 = (String) c2[1]; ! return s1.compareTo(s2); } ! }); ! firstImport--; //add line after the the specified StringBuffer all = new StringBuffer(); ! for (Iterator iter = list.iterator(); iter.hasNext();) { ! Object[] element = (Object[]) iter.next(); ! all.append((String) element[1]); ! all.append(endLineDelim); } ! PySelection.addLine(doc, endLineDelim, all.toString(), firstImport); } /** * ! * @param doc ! * @param endLineDelim ! * @param startLine ! * @param endLine */ @SuppressWarnings("unchecked") --- 121,342 ---- } ! //sort in inverse order (for removal of the string of the document). ! Collections.sort(list, new Comparator<Tuple3<Integer, String, ImportHandle>>() { ! public int compare(Tuple3<Integer, String, ImportHandle> o1, Tuple3<Integer, String, ImportHandle> o2) { ! return o2.o1.compareTo(o1.o1); } ! }); ! //ok, now we have to delete all lines with imports. ! for (Iterator<Tuple3<Integer, String, ImportHandle>> iter = list.iterator(); iter.hasNext();) { ! Tuple3<Integer, String, ImportHandle> element = iter.next(); ! String s = element.o2; int i = PySelection.countLineBreaks(s); ! while (i >= 0) { ! PySelection.deleteLine(doc, (element.o1).intValue()); i--; } } ! Collections.sort(list, new Comparator<Tuple3<Integer, String, ImportHandle>>() { ! public int compare(Tuple3<Integer, String, ImportHandle> o1, Tuple3<Integer, String, ImportHandle> o2) { ! return o1.o2.compareTo(o2.o2); } ! }); firstImport--; //add line after the the specified + + //now, re-add the imports StringBuffer all = new StringBuffer(); ! ! ! if(!ImportsPreferencesPage.getGroupImports()){ ! //no grouping ! for (Iterator<Tuple3<Integer, String, ImportHandle>> iter = list.iterator(); iter.hasNext();) { ! Tuple3<Integer, String, ImportHandle> element = iter.next(); ! all.append(element.o2); ! all.append(endLineDelim); ! } ! }else{ //we have to group the imports! ! ! //import from to the imports that should be grouped given its 'from' ! TreeMap<String, List<ImportHandleInfo>> m = new TreeMap<String, List<ImportHandleInfo>>(); ! List<ImportHandleInfo> importsWithoutFrom = new ArrayList<ImportHandleInfo>(); ! ! //fill the info ! for (Iterator<Tuple3<Integer, String, ImportHandle>> iter = list.iterator(); iter.hasNext();) { ! Tuple3<Integer, String, ImportHandle> element = iter.next(); ! ! List<ImportHandleInfo> importInfo = element.o3.getImportInfo(); ! for (ImportHandleInfo importHandleInfo : importInfo) { ! String fromImportStr = importHandleInfo.getFromImportStr(); ! if(fromImportStr == null){ ! importsWithoutFrom.add(importHandleInfo); ! }else{ ! List<ImportHandleInfo> lst = m.get(fromImportStr); ! if(lst == null){ ! lst = new ArrayList<ImportHandleInfo>(); ! m.put(fromImportStr, lst); ! } ! lst.add(importHandleInfo); ! } ! } ! } ! ! ! //preferences for multiline imports ! boolean multilineImports = ImportsPreferencesPage.getMultilineImports(); ! int maxCols = 80; ! if(multilineImports){ ! if(PydevPlugin.getDefault() != null){ ! IPreferenceStore chainedPrefStore = PydevPlugin.getChainedPrefStore(); ! maxCols = chainedPrefStore.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN); ! } ! }else{ ! maxCols = Integer.MAX_VALUE; ! } ! ! ! //preferences for how to break imports ! String breakIportMode = ImportsPreferencesPage.getBreakIportMode(); ! boolean breakWithParenthesis = true; ! if(!breakIportMode.equals(ImportsPreferencesPage.BREAK_IMPORTS_MODE_PARENTHESIS)){ ! breakWithParenthesis = false; ! } ! ! ! ! Set<Entry<String, List<ImportHandleInfo>>> entrySet = m.entrySet(); ! for (Entry<String, List<ImportHandleInfo>> entry : entrySet) { ! ! //first, reorganize them in the order to be written (the ones with comments after the ones without) ! ArrayList<Tuple<String, String>> importsAndComments = new ArrayList<Tuple<String, String>>(); ! ArrayList<Tuple<String, String>> importsAndNoComments = new ArrayList<Tuple<String, String>>(); ! ! for (ImportHandleInfo v : entry.getValue()) { ! List<String> importedStr = v.getImportedStr(); ! List<String> commentsForImports = v.getCommentsForImports(); ! for(int i=0;i<importedStr.size();i++){ ! String importedString = importedStr.get(i); ! String comment = commentsForImports.get(i); ! if(comment.length() > 0){ ! importsAndComments.add(new Tuple<String, String>(importedString, comment)); ! }else{ ! importsAndNoComments.add(new Tuple<String, String>(importedString, comment)); ! } ! } ! } ! ! ! ! ! //ok, it's all filled, let's start rewriting it! ! boolean firstInLine = true; ! StringBuffer line = new StringBuffer(); ! StringBuffer lastFromXXXImportWritten = null; ! boolean addedParenForLine = false; ! ! //ok, write all the ones with comments after the ones without any comments (each one with comment ! //will be written as a new import) ! importsAndNoComments.addAll(importsAndComments); ! for(int i=0;i<importsAndNoComments.size();i++){ ! ! Tuple<String, String> tuple = importsAndNoComments.get(i); ! ! if(firstInLine){ ! lastFromXXXImportWritten = new StringBuffer(); ! lastFromXXXImportWritten.append("from "); ! lastFromXXXImportWritten.append(entry.getKey()); ! lastFromXXXImportWritten.append(" import "); ! line.append(lastFromXXXImportWritten); ! }else{ ! line.append(", "); ! } ! ! if(multilineImports){ ! if(line.length() + tuple.o1.length() + tuple.o2.length() > maxCols){ ! //we have to make the wrapping ! if(breakWithParenthesis){ ! if(!addedParenForLine){ ! line.insert(lastFromXXXImportWritten.length(), "("); ! addedParenForLine = true; ! } ! line.append(endLineDelim); ! line.append(indentStr); ! }else{ ! line.append("\\"); ! line.append(endLineDelim); ! line.append(indentStr); ! } ! all.append(line); ! line = new StringBuffer(); ! } ! } ! ! line.append(tuple.o1); ! ! if(addedParenForLine && i == importsAndComments.size()){ ! line.append(")"); ! } ! ! firstInLine = false; ! ! if(tuple.o2.length() > 0){ ! if(addedParenForLine){ ! addedParenForLine = false; ! line.append(")"); ! } ! line.append(" "); ! line.append(tuple.o2); ! line.append(endLineDelim); ! all.append(line); ! line = new StringBuffer(); ! firstInLine = true; ! } ! } ! ! ! if(!firstInLine){ ! if(addedParenForLine){ ! addedParenForLine = false; ! line.append(")"); ! } ! line.append(endLineDelim); ! all.append(line); ! line = new StringBuffer(); ! } ! } ! ! //now, write the regular imports (no wrapping or tabbing here) ! for(ImportHandleInfo info:importsWithoutFrom){ ! ! List<String> importedStr = info.getImportedStr(); ! List<String> commentsForImports = info.getCommentsForImports(); ! for(int i=0;i<importedStr.size();i++){ ! all.append("import "); ! String importedString = importedStr.get(i); ! String comment = commentsForImports.get(i); ! all.append(importedString); ! if(comment.length() > 0){ ! all.append(" "); ! all.append(comment); ! } ! all.append(endLineDelim); ! } ! } ! } ! ! ! PySelection.addLine(doc, endLineDelim, all.toString(), firstImport); } /** + * Performs a simple sort without taking into account the actual contents of the selection (aside from lines + * ending with '\' which are considered as a single line). * ! * @param doc the document to be sorted ! * @param endLineDelim the delimiter to be used ! * @param startLine the first line where the sort should happen ! * @param endLine the last line where the sort should happen */ @SuppressWarnings("unchecked") |
From: Fabio Z. <fa...@us...> - 2008-06-01 20:44:35
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/ui/importsconf In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24261/src/org/python/pydev/ui/importsconf Modified Files: ImportsPreferencesPage.java Log Message: Organize imports can group from xxx imports. Index: ImportsPreferencesPage.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/ui/importsconf/ImportsPreferencesPage.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ImportsPreferencesPage.java 19 May 2008 00:58:20 -0000 1.2 --- ImportsPreferencesPage.java 1 Jun 2008 20:44:41 -0000 1.3 *************** *** 74,82 **** public static boolean getGroupImports() { if(PydevPlugin.getDefault() == null){ ! return true; } return PydevPrefs.getPreferences().getBoolean(GROUP_IMPORTS); } } --- 74,119 ---- public static boolean getGroupImports() { if(PydevPlugin.getDefault() == null){ ! return groupImportsForTests; } return PydevPrefs.getPreferences().getBoolean(GROUP_IMPORTS); } + /** + * May be changed for testing purposes. + */ + public static boolean groupImportsForTests = true; + + + /** + * @return true if imports should be wrapped when they exceed the print margin. + */ + public static boolean getMultilineImports() { + if(PydevPlugin.getDefault() == null){ + return multilineImportsForTests; + } + return PydevPrefs.getPreferences().getBoolean(MULTILINE_IMPORTS); + } + + /** + * May be changed for testing purposes. + */ + public static boolean multilineImportsForTests = true; + + /** + * @return the way to break imports as the constants specified + * @see #BREAK_IMPORTS_MODE_ESCAPE + * @see #BREAK_IMPORTS_MODE_PARENTHESIS + */ + public static String getBreakIportMode() { + if(PydevPlugin.getDefault() == null){ + return breakImportModeForTests; + } + return PydevPrefs.getPreferences().getString(BREAK_IMPORTS_MODE); + } + + /** + * May be changed for testing purposes. + */ + public static String breakImportModeForTests = BREAK_IMPORTS_MODE_PARENTHESIS; } |
From: Fabio Z. <fa...@us...> - 2008-06-01 20:44:35
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24261 Modified Files: TODO.txt Changes.txt Log Message: Organize imports can group from xxx imports. Index: TODO.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/TODO.txt,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** TODO.txt 17 May 2008 14:26:52 -0000 1.69 --- TODO.txt 1 Jun 2008 20:44:41 -0000 1.70 *************** *** 1,5 **** - Context insensitive completions: - - Don't bring imports for completions already in the document - - Make new imports from the same module use the same from xxx import yyy (when xxx is the same) - Organize imports should pass all the not defined vars and show the imports available for them - Organize imports should merge imports with the same 'xxx' in from xxx import yyy, bbb, etc --- 1,3 ---- Index: Changes.txt =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/Changes.txt,v retrieving revision 1.392 retrieving revision 1.393 diff -C2 -d -r1.392 -r1.393 *** Changes.txt 12 May 2008 15:36:35 -0000 1.392 --- Changes.txt 1 Jun 2008 20:44:41 -0000 1.393 *************** *** 1,2 **** --- 1,18 ---- + after 1.3.17 + + + Pydev Extensions + <ul> + <li><strong>Auto-import</strong>: Groups imports when possible.</li> + <li><strong>Auto-import</strong>: Doesn't bring imports for completions already in the document even if a parse is not successful.</li> + </ul> + + Pydev + <ul> + <li><strong>Executing external programs</strong>: Using Runtime.exec(String[] cmdargs) instead of the version accepting only a string.</li> + <li><strong>Organize Imports (ctrl+shift+O)</strong>: Imports can be grouped.</li> + </ul> + + after 1.3.16 |
From: Fabio Z. <fa...@us...> - 2008-06-01 20:44:35
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24261/src/org/python/pydev/editor Modified Files: PyEdit.java Log Message: Organize imports can group from xxx imports. Index: PyEdit.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/PyEdit.java,v retrieving revision 1.129 retrieving revision 1.130 diff -C2 -d -r1.129 -r1.130 *** PyEdit.java 4 Feb 2008 02:01:35 -0000 1.129 --- PyEdit.java 1 Jun 2008 20:44:41 -0000 1.130 *************** *** 423,427 **** /** ! * @return the indentation preferences */ public IIndentPrefs getIndentPrefs() { --- 423,429 ---- /** ! * @return the indentation preferences. Any action writing something should use this one in the editor because ! * we want to make sure that the indent must be the one bounded to this editor (because tabs may be forced in a given ! * editor, even if does not match the global settings). */ public IIndentPrefs getIndentPrefs() { |
From: Fabio Z. <fa...@us...> - 2008-06-01 20:44:35
|
Update of /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24261/tests/org/python/pydev/editor/actions Modified Files: PyOrganizeImportsTest.java Log Message: Organize imports can group from xxx imports. Index: PyOrganizeImportsTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions/PyOrganizeImportsTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PyOrganizeImportsTest.java 4 Aug 2007 16:01:11 -0000 1.5 --- PyOrganizeImportsTest.java 1 Jun 2008 20:44:41 -0000 1.6 *************** *** 7,10 **** --- 7,11 ---- import org.eclipse.jface.text.Document; + import org.python.pydev.ui.importsconf.ImportsPreferencesPage; import junit.framework.TestCase; *************** *** 19,23 **** PyOrganizeImportsTest test = new PyOrganizeImportsTest(); test.setUp(); ! test.testPerformSort2(); test.tearDown(); junit.textui.TestRunner.run(PyOrganizeImportsTest.class); --- 20,24 ---- PyOrganizeImportsTest test = new PyOrganizeImportsTest(); test.setUp(); ! test.testPerformGroupingWithWraps3(); test.tearDown(); junit.textui.TestRunner.run(PyOrganizeImportsTest.class); *************** *** 32,36 **** --- 33,39 ---- protected void setUp() throws Exception { super.setUp(); + ImportsPreferencesPage.groupImportsForTests = false; } + /* *************** *** 39,42 **** --- 42,46 ---- protected void tearDown() throws Exception { super.tearDown(); + ImportsPreferencesPage.groupImportsForTests = true; //default } *************** *** 51,55 **** Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n"); String result = ""+ --- 55,59 ---- Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n", " "); String result = ""+ *************** *** 64,68 **** --- 68,189 ---- } + + public void testPerformWithGrouping() { + ImportsPreferencesPage.groupImportsForTests = true; + String d = ""+ + "import b\n"+ + "import a\n"+ + "\n"+ + "from a import c\n"+ + "from b import d\n"+ + "from a import b"; + + Document doc = new Document(d); + PyOrganizeImports.performArrangeImports(doc, "\n", " "); + + String result = ""+ + "from a import b, c\n"+ + "from b import d\n"+ + "import a\n"+ + "import b\n"+ + "\n"; + + assertEquals(result, doc.get()); + + } + + public void testPerformWithGroupingAndComments() { + ImportsPreferencesPage.groupImportsForTests = true; + String d = ""+ + "import b #comment\n"+ + "import a\n"+ + "\n"+ + "from a import c #comment\n"+ + "from a import f #comment2\n"+ + "from a import e\n"+ + "from b import d\n"+ + "from a import b"; + + Document doc = new Document(d); + PyOrganizeImports.performArrangeImports(doc, "\n", " "); + + String result = ""+ + "from a import b, e, c #comment\n"+ + "from a import f #comment2\n"+ + "from b import d\n"+ + "import a\n"+ + "import b #comment\n"+ + "\n"; + + assertEquals(result, doc.get()); + } + + + public void testPerformGroupingWithWraps() { + ImportsPreferencesPage.groupImportsForTests = true; + String d = ""+ + "from a import cccccccccccccccccccccccccccccccccccccccccccccccccc\n"+ //50 * 'c' + "from a import eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n"+ + "from a import ffffffffffffffffffffffffffffffffffffffffffffffffff"; + + Document doc = new Document(d); + PyOrganizeImports.performArrangeImports(doc, "\n", " "); + + String result = ""+ + "from a import (cccccccccccccccccccccccccccccccccccccccccccccccccc, \n" + + " eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, \n"+ + " ffffffffffffffffffffffffffffffffffffffffffffffffff)\n"; + + // System.out.println(">>"+doc.get()+"<<"); + assertEquals(result, doc.get()); + } + + + public void testPerformGroupingWithWraps3() { + ImportsPreferencesPage.groupImportsForTests = true; + String d = ""+ + "from a import cccccccccc\n"+ //10 * 'c' + "from a import bbbbbbbbbb\n"+ + "from a import aaaaaaaaaa\n"+ + "from a import dddddddddd\n"+ + "from a import eeeeeeeeee\n"+ + "from a import ffffffffff\n" + + "from a import gggggggggg\n" + + "from a import hhhhhhhhhh\n" + + ""; + + Document doc = new Document(d); + PyOrganizeImports.performArrangeImports(doc, "\n", " "); + + String result = ""+ + "from a import (aaaaaaaaaa, bbbbbbbbbb, cccccccccc, dddddddddd, eeeeeeeeee, \n"+ + " ffffffffff, gggggggggg, hhhhhhhhhh)\n"; + + // System.out.println(">>"+doc.get()+"<<"); + assertEquals(result, doc.get()); + } + + + public void testPerformGroupingWithWraps2() { + ImportsPreferencesPage.groupImportsForTests = true; + String d = ""+ + "from a import cccccccccccccccccccccccccccccccccccccccccccccccccc\n"+ //50 * 'c' + "from a import eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee #comment 1\n"+ + "from a import ffffffffffffffffffffffffffffffffffffffffffffffffff #comment 2"; + + Document doc = new Document(d); + PyOrganizeImports.performArrangeImports(doc, "\n", " "); + + String result = ""+ + "from a import (cccccccccccccccccccccccccccccccccccccccccccccccccc, \n" + + " eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee) #comment 1\n"+ + "from a import ffffffffffffffffffffffffffffffffffffffffffffffffff #comment 2\n"; + + // System.out.println(">>"+doc.get()+"<<"); + assertEquals(result, doc.get()); + } + + public void testPerform2() { *************** *** 83,87 **** Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n"); String result = ""+header+ --- 204,208 ---- Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n", " "); String result = ""+header+ *************** *** 114,118 **** Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n"); String result = ""+header+ --- 235,239 ---- Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n", " "); String result = ""+header+ *************** *** 143,147 **** Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n"); String result = ""+header+ --- 264,268 ---- Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n", " "); String result = ""+header+ *************** *** 167,171 **** Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n"); String result = ""+ --- 288,292 ---- Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n", " "); String result = ""+ *************** *** 188,192 **** Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n"); String result = ""+ --- 309,313 ---- Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n", " "); String result = ""+ *************** *** 207,211 **** Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n"); assertEquals(d, doc.get()); --- 328,332 ---- Document doc = new Document(d); ! PyOrganizeImports.performArrangeImports(doc, "\n", " "); assertEquals(d, doc.get()); |
From: Fabio Z. <fa...@us...> - 2008-05-28 11:10:28
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/refactoring In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13448/src/org/python/pydev/editor/refactoring Modified Files: PyRefactoring.java Log Message: Logging to eclipse and not stdout. Index: PyRefactoring.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/refactoring/PyRefactoring.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** PyRefactoring.java 21 Jan 2007 00:50:56 -0000 1.35 --- PyRefactoring.java 28 May 2008 11:10:34 -0000 1.36 *************** *** 20,23 **** --- 20,24 ---- import org.python.pydev.editor.model.ItemPointer; import org.python.pydev.editor.model.Location; + import org.python.pydev.plugin.PydevPlugin; /** *************** *** 56,60 **** AbstractShell.getServerShell(IPythonNature.PYTHON_RELATED, AbstractShell.OTHERS_SHELL).restartShell(); } catch (Exception e) { ! e.printStackTrace(); } } --- 57,61 ---- AbstractShell.getServerShell(IPythonNature.PYTHON_RELATED, AbstractShell.OTHERS_SHELL).restartShell(); } catch (Exception e) { ! PydevPlugin.log(e); } } *************** *** 67,71 **** AbstractShell.getServerShell(IPythonNature.PYTHON_RELATED, AbstractShell.OTHERS_SHELL).endIt(); } catch (Exception e) { ! e.printStackTrace(); } } --- 68,72 ---- AbstractShell.getServerShell(IPythonNature.PYTHON_RELATED, AbstractShell.OTHERS_SHELL).endIt(); } catch (Exception e) { ! PydevPlugin.log(e); } } *************** *** 91,100 **** return URLDecoder.decode(pytonShell.read(request.getMonitor()), "UTF-8"); } catch (Exception e) { ! e.printStackTrace(); pytonShell.restartShell(); } } catch (Exception e1) { ! e1.printStackTrace(); } return null; --- 92,101 ---- return URLDecoder.decode(pytonShell.read(request.getMonitor()), "UTF-8"); } catch (Exception e) { ! PydevPlugin.log("Error writing: "+str, e); pytonShell.restartShell(); } } catch (Exception e1) { ! PydevPlugin.log("Error writing: "+str, e1); } return null; |
From: Fabio Z. <fa...@us...> - 2008-05-21 01:38:08
|
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4564/src/org/python/pydev/debug/ui/launching Modified Files: PythonRunner.java PythonRunnerConfig.java Log Message: - No longer using Runtime.exec(String), only Runtime.exec(String[]) - Updating the markers in a better (faster) way Index: PythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunner.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** PythonRunner.java 28 Apr 2008 23:03:16 -0000 1.35 --- PythonRunner.java 21 May 2008 01:38:15 -0000 1.36 *************** *** 171,175 **** // Launch & connect to the debugger subMonitor.subTask("Constructing command_line..."); ! String commandLineAsString = SimpleRunner.getCommandLineAsString(cmdLine); //System.out.println("running command line: "+commandLineAsString); Map<Object, Object> processAttributes = new HashMap<Object, Object>(); --- 171,175 ---- // Launch & connect to the debugger subMonitor.subTask("Constructing command_line..."); ! String commandLineAsString = SimpleRunner.getArgumentsAsStr(cmdLine); //System.out.println("running command line: "+commandLineAsString); Map<Object, Object> processAttributes = new HashMap<Object, Object>(); Index: PythonRunnerConfig.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunnerConfig.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** PythonRunnerConfig.java 13 Apr 2008 16:55:17 -0000 1.65 --- PythonRunnerConfig.java 21 May 2008 01:38:15 -0000 1.66 *************** *** 612,616 **** ! private String[] getVMArguments(ILaunchConfiguration configuration) throws CoreException { String args = configuration.getAttribute(Constants.ATTR_VM_ARGUMENTS, (String) null); --- 612,619 ---- ! /** ! * @return an array with the vm arguments in the given configuration. ! * @throws CoreException ! */ private String[] getVMArguments(ILaunchConfiguration configuration) throws CoreException { String args = configuration.getAttribute(Constants.ATTR_VM_ARGUMENTS, (String) null); *************** *** 622,630 **** } public String getCommandLineAsString() throws JDTNotAvailableException { String[] args; try { args = getCommandLine(false); ! return SimpleRunner.getCommandLineAsString(args); } catch (CoreException e) { throw new RuntimeException(e); --- 625,638 ---- } + /** + * @return A command line to be shown to the user. Note that this command line should not actually be used for + * an execution (only String[] should be passed to Runtie.exec) + * @throws JDTNotAvailableException + */ public String getCommandLineAsString() throws JDTNotAvailableException { String[] args; try { args = getCommandLine(false); ! return SimpleRunner.getArgumentsAsStr(args); } catch (CoreException e) { throw new RuntimeException(e); |
From: Fabio Z. <fa...@us...> - 2008-05-21 01:38:08
|
Update of /cvsroot/pydev/org.python.pydev.debug/tests/org/python/pydev/debug/codecoverage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4564/tests/org/python/pydev/debug/codecoverage Modified Files: XmlRpcTest.java Log Message: - No longer using Runtime.exec(String), only Runtime.exec(String[]) - Updating the markers in a better (faster) way Index: XmlRpcTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/tests/org/python/pydev/debug/codecoverage/XmlRpcTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XmlRpcTest.java 30 Mar 2008 21:45:18 -0000 1.2 --- XmlRpcTest.java 21 May 2008 01:38:15 -0000 1.3 *************** *** 20,24 **** import org.python.pydev.debug.newconsole.PydevXmlRpcClient; import org.python.pydev.plugin.SocketUtil; - import org.python.pydev.runners.SimplePythonRunner; import org.python.pydev.runners.ThreadStreamReader; --- 20,23 ---- *************** *** 87,99 **** File f = new File(TestDependent.TEST_PYDEV_PLUGIN_LOC+"pysrc/pydevconsole.py"); ! String cmdLine; if(python){ ! cmdLine = SimplePythonRunner.getCommandLineAsString( ! new String[]{TestDependent.PYTHON_EXE, "-u", REF.getFileAbsolutePath(f), ""+port, ""+client_port}); }else{ ! cmdLine = SimplePythonRunner.getCommandLineAsString( ! new String[]{TestDependent.JAVA_LOCATION, "-classpath", TestDependent.JYTHON_JAR_LOCATION, "org.python.util.jython", ! REF.getFileAbsolutePath(f), ""+port, ""+client_port}); } --- 86,96 ---- File f = new File(TestDependent.TEST_PYDEV_PLUGIN_LOC+"pysrc/pydevconsole.py"); ! String[] cmdLine; if(python){ ! cmdLine = new String[]{TestDependent.PYTHON_EXE, "-u", REF.getFileAbsolutePath(f), ""+port, ""+client_port}; }else{ ! cmdLine = new String[]{TestDependent.JAVA_LOCATION, "-classpath", TestDependent.JYTHON_JAR_LOCATION, "org.python.util.jython", ! REF.getFileAbsolutePath(f), ""+port, ""+client_port}; } |
From: Fabio Z. <fa...@us...> - 2008-05-21 01:38:08
|
Update of /cvsroot/pydev/org.python.pydev.debug/src_console/org/python/pydev/debug/newconsole/env In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4564/src_console/org/python/pydev/debug/newconsole/env Modified Files: IProcessFactory.java Log Message: - No longer using Runtime.exec(String), only Runtime.exec(String[]) - Updating the markers in a better (faster) way Index: IProcessFactory.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src_console/org/python/pydev/debug/newconsole/env/IProcessFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** IProcessFactory.java 4 Apr 2008 02:54:42 -0000 1.5 --- IProcessFactory.java 21 May 2008 01:38:14 -0000 1.6 *************** *** 93,97 **** File scriptWithinPySrc = PydevPlugin.getScriptWithinPySrc("pydevconsole.py"); ! String commandLine; if(interpreterManager.isPython()){ commandLine = SimplePythonRunner.makeExecutableCommandStr(scriptWithinPySrc.getAbsolutePath(), --- 93,97 ---- File scriptWithinPySrc = PydevPlugin.getScriptWithinPySrc("pydevconsole.py"); ! String[] commandLine; if(interpreterManager.isPython()){ commandLine = SimplePythonRunner.makeExecutableCommandStr(scriptWithinPySrc.getAbsolutePath(), |
From: Fabio Z. <fa...@us...> - 2008-05-21 01:38:04
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4510/src/org/python/pydev/runners Modified Files: SimpleRunner.java SimplePythonRunner.java SimpleJythonRunner.java SimpleExeRunner.java Log Message: - No longer using Runtime.exec(String), only Runtime.exec(String[]) - Updating the markers in a better (faster) way Index: SimpleExeRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimpleExeRunner.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SimpleExeRunner.java 26 Jun 2006 23:40:46 -0000 1.1 --- SimpleExeRunner.java 21 May 2008 01:38:08 -0000 1.2 *************** *** 7,14 **** --- 7,16 ---- import java.io.File; import java.util.ArrayList; + import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; import org.eclipse.core.resources.IProject; + import org.eclipse.core.runtime.NullProgressMonitor; import org.python.pydev.core.Tuple; import org.python.pydev.core.docutils.StringUtils; *************** *** 16,24 **** public class SimpleExeRunner extends SimpleRunner{ - @Override - public Tuple<String, String> runAndGetOutput(String script, String[] args, File workingDir, IProject project) { - String executionString = getCommandLineAsString(new String[]{script}, args); - return runAndGetOutput(executionString, workingDir, project); - } /** --- 18,21 ---- *************** *** 72,76 **** ArrayList<String> ret = new ArrayList<String>(); ! Tuple<String, String> output = runAndGetOutput(cygpathLoc, paths, (File)null, (IProject)null); if(output.o2 != null && output.o2.length() > 0){ throw new RuntimeException("Error converting windows paths to cygwin paths: "+output.o2+".\nCygpath location:"+cygpathLoc); --- 69,76 ---- ArrayList<String> ret = new ArrayList<String>(); ! List<String> asList = new ArrayList<String>(Arrays.asList(paths)); ! asList.add(0, cygpathLoc); ! ! Tuple<String, String> output = runAndGetOutput(asList.toArray(new String[0]), (File)null, (IProject)null, new NullProgressMonitor()); if(output.o2 != null && output.o2.length() > 0){ throw new RuntimeException("Error converting windows paths to cygwin paths: "+output.o2+".\nCygpath location:"+cygpathLoc); Index: SimpleRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimpleRunner.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** SimpleRunner.java 12 May 2008 11:39:06 -0000 1.24 --- SimpleRunner.java 21 May 2008 01:38:08 -0000 1.25 *************** *** 34,45 **** /** ! * Just execute the string. Does nothing else. */ ! public Process createProcess(String executionString, File workingDir) throws IOException { ! return Runtime.getRuntime().exec(executionString, null, workingDir); ! } ! ! public Process createProcess(String[] parameters, File workingDir) throws IOException { ! return Runtime.getRuntime().exec(parameters, null, workingDir); } --- 34,41 ---- /** ! * Passes the commands directly to Runtime.exec (with a null envp) */ ! public static Process createProcess(String[] cmdarray, File workingDir) throws IOException { ! return Runtime.getRuntime().exec(cmdarray, null, workingDir); } *************** *** 146,150 **** * @return */ ! public static String getCommandLineAsString(String[] commandLine, String ... args) { if(args != null && args.length > 0){ String[] newCommandLine = new String[commandLine.length + args.length]; --- 142,146 ---- * @return */ ! public static String getArgumentsAsStr(String[] commandLine, String ... args) { if(args != null && args.length > 0){ String[] newCommandLine = new String[commandLine.length + args.length]; *************** *** 280,318 **** } /** ! * shortcut ! */ ! public Tuple<String,String> runAndGetOutput(String executionString, File workingDir, IProgressMonitor monitor) { ! return runAndGetOutput(executionString, workingDir, null, monitor); ! } ! ! /** ! * shortcut ! */ ! public Tuple<String,String> runAndGetOutput(String executionString, File workingDir) { ! return runAndGetOutput(executionString, workingDir, null, new NullProgressMonitor()); ! } ! ! /** ! * shortcut ! */ ! public Tuple<String,String> runAndGetOutput(String executionString, File workingDir, IProject project) { ! return runAndGetOutput(executionString, workingDir, project, new NullProgressMonitor()); ! } ! ! public Tuple<String,String> runAndGetOutput(String[] arguments, File workingDir, IProject project) { ! return runAndGetOutput(arguments, workingDir, project, new NullProgressMonitor()); ! } ! ! /** ! * shortcut */ ! public Tuple<String,String> runAndGetOutput(String script, String[] args, File workingDir) { ! return runAndGetOutput(script, args, workingDir, null); ! } ! ! ! public Tuple<String, String> runAndGetOutput(String[] arguments, File workingDir, IProject project, IProgressMonitor monitor) { ! String executionString = getCommandLineAsString(arguments); monitor.setTaskName("Executing: "+executionString); monitor.worked(5); --- 276,295 ---- } + /** ! * Runs the given command line and returns a tuple with the output (stdout and stderr) of executing it. ! * ! * @param cmdarray array with the commands to be passed to Runtime.exec ! * @param workingDir the working dir (may be null) ! * @param project the project (used to get the pythonpath and put it into the environment) -- if null, no environment is passed. ! * @param monitor the progress monitor to be used -- may be null ! * ! * @return a tuple with stdout and stderr */ ! public Tuple<String, String> runAndGetOutput(String[] cmdarray, File workingDir, IProject project, IProgressMonitor monitor) { ! if(monitor == null){ ! monitor = new NullProgressMonitor(); ! } ! String executionString = getArgumentsAsStr(cmdarray); monitor.setTaskName("Executing: "+executionString); monitor.worked(5); *************** *** 327,331 **** } } ! process = Runtime.getRuntime().exec(arguments, envp, workingDir); } catch (Exception e) { throw new RuntimeException(e); --- 304,308 ---- } } ! process = Runtime.getRuntime().exec(cmdarray, envp, workingDir); } catch (Exception e) { throw new RuntimeException(e); *************** *** 341,345 **** * @return a tuple with the output of stdout and stderr */ ! private Tuple<String, String> getProcessOutput(Process process, String executionString, IProgressMonitor monitor) { if (process != null) { --- 318,322 ---- * @return a tuple with the output of stdout and stderr */ ! protected Tuple<String, String> getProcessOutput(Process process, String executionString, IProgressMonitor monitor) { if (process != null) { *************** *** 390,437 **** - /** - * This is the method that actually does the running (all others are just 'shortcuts' to this one). - * - * @param executionString this is the string that will be executed - * @param workingDir this is the directory where the execution will happen - * @param project this is the project that is related to the run (it is used to get the environment for the shell we are going to - * execute with the correct pythonpath environment variable). - * @param monitor this is the monitor used to communicate the progress to the user - * - * @return the string that is the output of the process (stdout) and the stderr (o2) - */ - public Tuple<String,String> runAndGetOutput(String executionString, File workingDir, IProject project, IProgressMonitor monitor) { - monitor.setTaskName("Executing: "+executionString); - monitor.worked(5); - Process process = null; - - try { - monitor.setTaskName("Making pythonpath environment..."+executionString); - String[] envp = getEnvironment(PythonNature.getPythonNature(project), null); //should get the environment for the default interpreter and the given project - monitor.setTaskName("Making exec..."+executionString); - if(workingDir != null){ - if(!workingDir.isDirectory()){ - throw new RuntimeException(StringUtils.format("Working dir must be an existing directory (received: %s)", workingDir)); - } - } - process = Runtime.getRuntime().exec(executionString, envp, workingDir); - } catch (Exception e) { - throw new RuntimeException(e); - } - - return getProcessOutput(process, executionString, monitor); - } - - /** - * Execute the script specified with the interpreter for a given project - * - * @param script the script we will execute - * @param args the arguments to pass to the script - * @param workingDir the working directory - * @param project the project that is associated to this run - * - * @return a string with the output of the process (stdout) - */ - public abstract Tuple<String,String> runAndGetOutput(String script, String args[], File workingDir, IProject project); /** --- 367,370 ---- Index: SimpleJythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimpleJythonRunner.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** SimpleJythonRunner.java 7 Apr 2008 00:52:02 -0000 1.25 --- SimpleJythonRunner.java 21 May 2008 01:38:08 -0000 1.26 *************** *** 6,9 **** --- 6,12 ---- import java.io.File; import java.io.IOException; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.List; import org.eclipse.core.resources.IProject; *************** *** 57,78 **** ,script }; - String executionString = getCommandLineAsString(s); - - return runAndGetOutput(executionString, workingDir, project, monitor); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); - } - - } - @Override - public Tuple<String,String> runAndGetOutput(String script, String[] args, File workingDir, IProject project) { - //"java.exe" -classpath "C:\bin\jython21\jython.jar" -Dpython.path xxx;xxx;xxx org.python.util.jython script %ARGS% ! try { ! String executionString = makeExecutableCommandStr(script, ""); ! ! return runAndGetOutput(executionString, workingDir, project); } catch (RuntimeException e) { throw e; --- 60,65 ---- ,script }; ! return runAndGetOutput(s, workingDir, project, monitor); } catch (RuntimeException e) { throw e; *************** *** 83,87 **** } ! public static String makeExecutableCommandStr(String script, String basePythonPath, String ... args) throws IOException, JDTNotAvailableException { return makeExecutableCommandStrWithVMArgs(script, basePythonPath, "", args); } --- 70,74 ---- } ! public static String[] makeExecutableCommandStr(String script, String basePythonPath, String ... args) throws IOException, JDTNotAvailableException { return makeExecutableCommandStrWithVMArgs(script, basePythonPath, "", args); } *************** *** 92,96 **** * @throws IOException */ ! public static String makeExecutableCommandStrWithVMArgs(String script, String basePythonPath, String vmArgs, String ... args) throws IOException, JDTNotAvailableException { IInterpreterManager interpreterManager = PydevPlugin.getJythonInterpreterManager(); String javaLoc = JavaVmLocationFinder.findDefaultJavaExecutable().getCanonicalPath(); --- 79,83 ---- * @throws IOException */ ! public static String[] makeExecutableCommandStrWithVMArgs(String script, String basePythonPath, String vmArgs, String ... args) throws IOException, JDTNotAvailableException { IInterpreterManager interpreterManager = PydevPlugin.getJythonInterpreterManager(); String javaLoc = JavaVmLocationFinder.findDefaultJavaExecutable().getCanonicalPath(); *************** *** 147,153 **** script }; ! String executionString = getCommandLineAsString(s, args); ! ! return executionString; } --- 134,141 ---- script }; ! ! List<String> asList = new ArrayList<String>(Arrays.asList(s)); ! asList.addAll(Arrays.asList(args)); ! return asList.toArray(new String[0]); } Index: SimplePythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimplePythonRunner.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** SimplePythonRunner.java 12 May 2008 11:39:06 -0000 1.11 --- SimplePythonRunner.java 21 May 2008 01:38:08 -0000 1.12 *************** *** 8,14 **** --- 8,18 ---- import java.io.File; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; + import org.eclipse.core.runtime.NullProgressMonitor; import org.python.pydev.core.Tuple; import org.python.pydev.plugin.PydevPlugin; *************** *** 41,47 **** * @return a string with the output of the process (stdout) */ ! public Tuple<String,String> runAndGetOutput(String script, String[] args, File workingDir, IProject project) { String[] parameters = addInterpreterToArgs(script, args); ! return runAndGetOutput(parameters, workingDir, project); } --- 45,51 ---- * @return a string with the output of the process (stdout) */ ! public Tuple<String,String> runAndGetOutputFromPythonScript(String script, String[] args, File workingDir, IProject project) { String[] parameters = addInterpreterToArgs(script, args); ! return runAndGetOutput(parameters, workingDir, project, new NullProgressMonitor()); } *************** *** 51,57 **** * @return the string with the command to run the passed script with jython */ ! public static String makeExecutableCommandStr(String script, String[] args) { String[] s = addInterpreterToArgs(script, args); ! return getCommandLineAsString(s, args); } --- 55,65 ---- * @return the string with the command to run the passed script with jython */ ! public static String[] makeExecutableCommandStr(String script, String[] args) { String[] s = addInterpreterToArgs(script, args); ! ! List<String> asList = new ArrayList<String>(Arrays.asList(s)); ! asList.addAll(Arrays.asList(args)); ! ! return asList.toArray(new String[0]); } |
From: Fabio Z. <fa...@us...> - 2008-05-21 01:38:04
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/builder In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4510/src/org/python/pydev/builder Modified Files: PydevMarkerUtils.java Log Message: - No longer using Runtime.exec(String), only Runtime.exec(String[]) - Updating the markers in a better (faster) way Index: PydevMarkerUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/builder/PydevMarkerUtils.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** PydevMarkerUtils.java 20 Jun 2007 01:17:30 -0000 1.11 --- PydevMarkerUtils.java 21 May 2008 01:38:09 -0000 1.12 *************** *** 4,8 **** package org.python.pydev.builder; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; --- 4,7 ---- *************** *** 18,217 **** import org.python.pydev.plugin.PydevPlugin; public class PydevMarkerUtils { ! ! public static IMarker markerExists(IResource resource, String message, int charStart, int charEnd, String type) { ! return markerExists(resource, message, charStart, charEnd, type, null); ! } /** ! * Checks pre-existance of marker. */ ! public static IMarker markerExists(IResource resource, String message, int charStart, int charEnd, String type, List<IMarker> existingMarkers) { ! existingMarkers = checkExistingMarkers(resource, type, existingMarkers); ! try { ! for (IMarker task : existingMarkers) { ! Object msg = task.getAttribute(IMarker.MESSAGE); ! Object start = task.getAttribute(IMarker.CHAR_START); ! Object end = task.getAttribute(IMarker.CHAR_END); ! ! if(msg == null || start == null || end == null || message == null){ ! return null; ! } ! boolean eqMessage = msg.equals(message); ! boolean eqCharStart = (Integer) start == charStart; ! boolean eqCharEnd = (Integer) end == charEnd; ! if (eqMessage && eqCharStart && eqCharEnd) { ! return task; } } ! } catch (Exception e) { ! PydevPlugin.log(e); } ! return null; } ! public static IMarker markerExists(IResource resource, String message, int lineNumber, String type) { ! return markerExists(resource, message, lineNumber, lineNumber, type, null); ! } ! /** ! * Checks pre-existance of marker. * ! * @param resource resource in wich marker will searched ! * @param message message for marker ! * @param lineNumber line number where marker should exist ! * @return pre-existance of marker */ ! public static IMarker markerExists(IResource resource, String message, int lineNumber, String type, List<IMarker> existingMarkers) { ! existingMarkers = checkExistingMarkers(resource, type, existingMarkers); try { ! for (IMarker task : existingMarkers) { ! boolean eqLineNumber = (Integer)task.getAttribute(IMarker.LINE_NUMBER) == lineNumber; ! boolean eqMessage = task.getAttribute(IMarker.MESSAGE).equals(message); ! if (eqLineNumber && eqMessage){ ! return task; } } ! } catch (CoreException e) { ! throw new RuntimeException(e); } - return null; - } - - - public static void createMarker(IResource resource, IDocument doc, String message, - int lineStart, int colStart, int lineEnd, int colEnd, - String markerType, int severity) throws BadLocationException { - createMarker(resource, doc, message, lineStart, colStart, lineEnd, colEnd, markerType, severity, null); - } - - public static IMarker createMarker(IResource resource, IDocument doc, String message, - int lineStart, int colStart, int lineEnd, int colEnd, - String markerType, int severity, Map<String, Object> additionalInfo) throws BadLocationException { - return createMarker(resource, doc, message, lineStart, colStart, lineEnd, colEnd, markerType, severity, additionalInfo, null); - } - - public static IMarker createMarker(IResource resource, IDocument doc, String message, - int lineStart, int colStart, int lineEnd, int colEnd, - String markerType, int severity, Map<String, Object> additionalInfo, List<IMarker> existingMarkers) throws BadLocationException { - synchronized (resource) { - - existingMarkers = checkExistingMarkers(resource, markerType, existingMarkers); - - if(lineStart < 0){ - lineStart = 0; - } - - int startAbsolute; - int endAbsolute; - - try { - IRegion start = doc.getLineInformation(lineStart); - startAbsolute = start.getOffset() + colStart; - if (lineEnd >= 0 && colEnd >= 0) { - IRegion end = doc.getLineInformation(lineEnd); - endAbsolute = end.getOffset() + colEnd; - } else { - //ok, we have to calculate it based on the line contents... - String line = doc.get(start.getOffset(), start.getLength()); - int i; - StringBuffer buffer; - if((i = line.indexOf('#')) != -1){ - buffer = new StringBuffer(line.substring(0, i)); - }else{ - buffer = new StringBuffer(line); - } - while(buffer.length() > 0 && Character.isWhitespace(buffer.charAt(buffer.length() - 1))){ - buffer.deleteCharAt(buffer.length() -1); - } - endAbsolute = start.getOffset() + buffer.length(); - } - } catch (BadLocationException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); - } - - IMarker marker = markerExists(resource, message, startAbsolute, endAbsolute, markerType, existingMarkers); - if (marker == null) { - try { - - - HashMap<String, Object> map = new HashMap<String, Object>(); - map.put(IMarker.MESSAGE, message); - map.put(IMarker.LINE_NUMBER, lineStart); - map.put(IMarker.CHAR_START, startAbsolute); - map.put(IMarker.CHAR_END, endAbsolute); - map.put(IMarker.SEVERITY, severity); - - //add the additional info - if(additionalInfo != null){ - for (Map.Entry<String, Object> entry : additionalInfo.entrySet()) { - map.put(entry.getKey(), entry.getValue()); - } - } - - MarkerUtilities.createMarker(resource, map, markerType); - } catch (Exception e) { - PydevPlugin.log(e); - } - }else{ - //to check if it exists, we don't check all attributes, so, let's update those that we don't check (if needed). - try { - final Object lN = marker.getAttribute(IMarker.LINE_NUMBER); - if(lN == null || ((Integer)lN) != lineStart){ - marker.setAttribute(IMarker.LINE_NUMBER, new Integer(lineStart)); - } - - final Object mS = marker.getAttribute(IMarker.SEVERITY); - if(mS == null || ((Integer)mS) != severity){ - marker.setAttribute(IMarker.SEVERITY, severity); - } - - } catch (Exception e) { - PydevPlugin.log(e); - } - existingMarkers.remove(marker); - } - return marker; - } - } - /** - * @param resource - * @param markerType - * @param existingMarkers - * @return - */ - private static List<IMarker> checkExistingMarkers(IResource resource, String markerType, List<IMarker> existingMarkers) { - synchronized (resource) { - if(existingMarkers == null){ - try { - existingMarkers = new ArrayList<IMarker>(); - IMarker[] markers = resource.findMarkers(markerType, true, IResource.DEPTH_ZERO); - for (IMarker marker : markers) { - existingMarkers.add(marker); - } - } catch (CoreException e) { - existingMarkers = new ArrayList<IMarker>(); - PydevPlugin.log(e); - } - } - return existingMarkers; - } - } - - - - public static IMarker createMarker(IResource resource, IDocument doc, String message, int lineNumber, String markerType, int severity, boolean userEditable, boolean istransient, List<IMarker> existingMarkers) throws BadLocationException { - synchronized (resource) { - HashMap<String, Object> map = new HashMap<String, Object>(); - map.put(IMarker.USER_EDITABLE, userEditable); - map.put(IMarker.TRANSIENT, istransient); - return createMarker(resource, doc, message, lineNumber, 0, lineNumber, 0, markerType, severity, map, existingMarkers); - } } - } --- 17,186 ---- import org.python.pydev.plugin.PydevPlugin; + /** + * Helper class to deal with markers. + * + * It's main use is to replace the markers in a given resource for another set of markers. + * + * @author Fabio + */ public class PydevMarkerUtils { ! /** ! * This class represents the information to create a marker. ! * ! * @author Fabio */ ! public static class MarkerInfo{ ! public IDocument doc; ! public String message; ! public String markerType; ! public int severity; ! public boolean userEditable; ! public boolean isTransient; ! public int lineStart; ! public int colStart; ! public int lineEnd; ! public int absoluteStart=-1; ! public int absoluteEnd=-1; ! public int colEnd; ! public Map<String, Object> additionalInfo; ! ! /** ! * Constructor passing lines and relative positions ! */ ! public MarkerInfo(IDocument doc, String message, String markerType, int severity, boolean userEditable, ! boolean isTransient, int lineStart, int colStart, int lineEnd, int colEnd, ! Map<String, Object> additionalInfo) { ! super(); ! this.doc = doc; ! this.message = message; ! this.markerType = markerType; ! this.severity = severity; ! this.userEditable = userEditable; ! this.isTransient = isTransient; ! this.lineStart = lineStart; ! this.colStart = colStart; ! this.lineEnd = lineEnd; ! this.colEnd = colEnd; ! this.additionalInfo = additionalInfo; ! } ! ! ! /** ! * Constructor passing absolute position ! */ ! public MarkerInfo(IDocument doc, String message, String markerType, int severity, boolean userEditable, ! boolean isTransient, int line, int absoluteStart, int absoluteEnd, ! Map<String, Object> additionalInfo) { ! super(); ! this.doc = doc; ! this.message = message; ! this.markerType = markerType; ! this.severity = severity; ! this.userEditable = userEditable; ! this.isTransient = isTransient; ! this.lineStart = line; ! this.lineEnd = line; ! this.absoluteStart = absoluteStart; ! this.absoluteEnd = absoluteEnd; ! this.additionalInfo = additionalInfo; ! } ! /** ! * @return a map with the properties to be set in the marker ! * @throws BadLocationException ! */ ! private HashMap<String, Object> getAsMap() throws BadLocationException { ! ! if (lineStart < 0) { ! lineStart = 0; ! } ! ! if(absoluteStart == -1 || absoluteEnd == -1){ ! //if the absolute wasn't specified, let's calculate it ! IRegion start = doc.getLineInformation(lineStart); ! absoluteStart = start.getOffset() + colStart; ! if (lineEnd >= 0 && colEnd >= 0) { ! IRegion end = doc.getLineInformation(lineEnd); ! absoluteEnd = end.getOffset() + colEnd; ! } else { ! //ok, we have to calculate it based on the line contents... ! String line = doc.get(start.getOffset(), start.getLength()); ! int i; ! StringBuffer buffer; ! if ((i = line.indexOf('#')) != -1) { ! buffer = new StringBuffer(line.substring(0, i)); ! } else { ! buffer = new StringBuffer(line); ! } ! while (buffer.length() > 0 && Character.isWhitespace(buffer.charAt(buffer.length() - 1))) { ! buffer.deleteCharAt(buffer.length() - 1); ! } ! absoluteEnd = start.getOffset() + buffer.length(); } } ! ! HashMap<String, Object> map = new HashMap<String, Object>(); ! map.put(IMarker.MESSAGE, message); ! map.put(IMarker.LINE_NUMBER, lineStart); ! map.put(IMarker.CHAR_START, absoluteStart); ! map.put(IMarker.CHAR_END, absoluteEnd); ! map.put(IMarker.SEVERITY, severity); ! map.put(IMarker.USER_EDITABLE, userEditable); ! map.put(IMarker.TRANSIENT, isTransient); ! ! if(additionalInfo != null){ ! map.putAll(additionalInfo); ! } ! return map; } ! ! } ! ! /** ! * This method allows clients to rplace the existing markers of some type in a given resource for other markers. * ! * @param lst the new markers to be set in the resource ! * @param resource the resource were the markers should be replaced ! * @param markerType the type of the marker that'll be replaced */ ! public static void replaceMarkers(List<MarkerInfo> lst, IResource resource, String markerType) { ! IMarker[] existingMarkers; ! try { ! existingMarkers = resource.findMarkers(markerType, false, IResource.DEPTH_ZERO); ! } catch (CoreException e1) { ! PydevPlugin.log(e1); ! existingMarkers = new IMarker[0]; ! } + int lastExistingUsed = 0; try { ! for (MarkerInfo markerInfo : lst) { ! if(lastExistingUsed < existingMarkers.length){ ! IMarker marker = existingMarkers[lastExistingUsed]; ! marker.setAttributes(markerInfo.getAsMap()); ! lastExistingUsed += 1; ! }else{ ! MarkerUtilities.createMarker(resource, markerInfo.getAsMap(), markerType); } } ! } catch (Exception e) { ! PydevPlugin.log(e); ! } ! ! //erase the ones that weren't replaced. ! try { ! for(int i=lastExistingUsed; i < existingMarkers.length; i++){ ! //erase the ones we didn't use ! existingMarkers[i].delete(); ! } ! } catch (Exception e) { ! PydevPlugin.log(e); } } } |
From: Fabio Z. <fa...@us...> - 2008-05-21 01:38:03
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/builder/todo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4510/src/org/python/pydev/builder/todo Modified Files: PyTodoVisitor.java Log Message: - No longer using Runtime.exec(String), only Runtime.exec(String[]) - Updating the markers in a better (faster) way Index: PyTodoVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/builder/todo/PyTodoVisitor.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PyTodoVisitor.java 31 Jan 2006 13:04:38 -0000 1.12 --- PyTodoVisitor.java 21 May 2008 01:38:08 -0000 1.13 *************** *** 6,11 **** package org.python.pydev.builder.todo; ! import java.util.Iterator; import java.util.List; import org.eclipse.core.resources.IMarker; --- 6,12 ---- package org.python.pydev.builder.todo; ! import java.util.ArrayList; import java.util.List; + import java.util.Map; import org.eclipse.core.resources.IMarker; *************** *** 16,19 **** --- 17,21 ---- import org.python.pydev.builder.PyDevBuilderVisitor; import org.python.pydev.builder.PydevMarkerUtils; + import org.python.pydev.builder.PydevMarkerUtils.MarkerInfo; import org.python.pydev.plugin.PydevPlugin; *************** *** 30,34 **** public void visitChangedResource(IResource resource, IDocument document, IProgressMonitor monitor) { if (document != null) { ! List todoTags = PyTodoPrefPage.getTodoTags(); if(todoTags.size() > 0){ --- 32,36 ---- public void visitChangedResource(IResource resource, IDocument document, IProgressMonitor monitor) { if (document != null) { ! List<String> todoTags = PyTodoPrefPage.getTodoTags(); if(todoTags.size() > 0){ *************** *** 36,41 **** try { ! resource.deleteMarkers(IMarker.TASK, false, IResource.DEPTH_ZERO); ! int line = 0; while (line < numberOfLines) { --- 38,44 ---- try { ! //Timer timer = new Timer(); ! List<PydevMarkerUtils.MarkerInfo> lst = new ArrayList<PydevMarkerUtils.MarkerInfo>(); ! int line = 0; while (line < numberOfLines) { *************** *** 44,58 **** int index; ! for (Iterator iter = todoTags.iterator(); iter.hasNext();) { ! String element = (String) iter.next(); if ((index = tok.indexOf(element)) != -1) { ! PydevMarkerUtils.createMarker(resource, document, tok.substring(index).trim(), line, IMarker.TASK, IMarker.SEVERITY_WARNING, false, false, null); } - } - line++; } } catch (Exception e) { PydevPlugin.log(e); --- 47,74 ---- int index; ! for (String element : todoTags) { if ((index = tok.indexOf(element)) != -1) { ! ! String message=tok.substring(index).trim(); ! String markerType=IMarker.TASK; ! int severity=IMarker.SEVERITY_WARNING; ! boolean userEditable=false; ! boolean isTransient=false; ! int absoluteStart=region.getOffset()+index; ! int absoluteEnd=absoluteStart+message.length(); ! Map<String, Object> additionalInfo = null; ! ! ! MarkerInfo markerInfo = new PydevMarkerUtils.MarkerInfo(document, message, markerType, severity, userEditable, ! isTransient, line, absoluteStart, absoluteEnd, additionalInfo); ! lst.add(markerInfo); } } line++; } + + PydevMarkerUtils.replaceMarkers(lst, resource, IMarker.TASK); + //timer.printDiff("Total time to put markers: "+lst.size()); } catch (Exception e) { PydevPlugin.log(e); |
From: Fabio Z. <fa...@us...> - 2008-05-21 01:38:03
|
Update of /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/shell In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4510/src_completions/org/python/pydev/editor/codecompletion/shell Modified Files: JythonShell.java PythonShell.java Log Message: - No longer using Runtime.exec(String), only Runtime.exec(String[]) - Updating the markers in a better (faster) way Index: JythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/shell/JythonShell.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JythonShell.java 18 Mar 2008 17:03:07 -0000 1.3 --- JythonShell.java 21 May 2008 01:38:08 -0000 1.4 *************** *** 11,15 **** import org.python.pydev.plugin.PydevPlugin; import org.python.pydev.runners.SimpleJythonRunner; ! import org.python.pydev.runners.SimplePythonRunner; public class JythonShell extends AbstractShell{ --- 11,15 ---- import org.python.pydev.plugin.PydevPlugin; import org.python.pydev.runners.SimpleJythonRunner; ! import org.python.pydev.runners.SimpleRunner; public class JythonShell extends AbstractShell{ *************** *** 20,32 **** @Override protected synchronized String createServerProcess(int pWrite, int pRead) throws IOException, JDTNotAvailableException { String args = pWrite+" "+pRead; String script = REF.getFileAbsolutePath(serverFile); ! String executableStr = SimpleJythonRunner.makeExecutableCommandStr(script, ""); ! executableStr += " "+args; ! process = new SimplePythonRunner().createProcess(executableStr, serverFile.getParentFile()); ! return executableStr; } --- 20,34 ---- + /** + * Will create the jython shell and return a string to be shown to the user with the jython shell command line. + */ @Override protected synchronized String createServerProcess(int pWrite, int pRead) throws IOException, JDTNotAvailableException { String args = pWrite+" "+pRead; String script = REF.getFileAbsolutePath(serverFile); ! String[] executableStr = SimpleJythonRunner.makeExecutableCommandStr(script, "", args); ! process = SimpleRunner.createProcess(executableStr, serverFile.getParentFile()); ! return SimpleRunner.getArgumentsAsStr(executableStr); } Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/shell/PythonShell.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PythonShell.java 12 May 2008 11:39:06 -0000 1.3 --- PythonShell.java 21 May 2008 01:38:08 -0000 1.4 *************** *** 12,16 **** import org.python.pydev.core.REF; import org.python.pydev.plugin.PydevPlugin; ! import org.python.pydev.runners.SimplePythonRunner; /** --- 12,16 ---- import org.python.pydev.core.REF; import org.python.pydev.plugin.PydevPlugin; ! import org.python.pydev.runners.SimpleRunner; /** *************** *** 50,54 **** } String[] parameters = {interpreter, REF.getFileAbsolutePath(serverFile), ""+pWrite, ""+pRead}; ! process = new SimplePythonRunner().createProcess(parameters, serverFile.getParentFile()); return execMsg; --- 50,54 ---- } String[] parameters = {interpreter, REF.getFileAbsolutePath(serverFile), ""+pWrite, ""+pRead}; ! process = SimpleRunner.createProcess(parameters, serverFile.getParentFile()); return execMsg; |