db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1574886 - in /db/torque/torque4/trunk/torque-generator/src: main/java/org/apache/torque/generator/processor/string/ test/java/org/apache/torque/generator/processor/string/ test/resources/org/apache/torque/generator/processor/string/
Date Thu, 06 Mar 2014 14:16:21 GMT
Author: tfischer
Date: Thu Mar  6 14:16:21 2014
New Revision: 1574886

URL: http://svn.apache.org/r1574886
Log:
TORQUE-310 better name for OrganizeImportsProcessor

Added:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessor.java
      - copied, changed from r1574712, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessor.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessorTest.java
      - copied, changed from r1574691, db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessorTest.java
    db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/processor/string/removeUnusedExpected.txt
      - copied unchanged from r1574885, db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/processor/string/organizeImportsExpected.txt
    db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/processor/string/removeUnusedImports.txt
      - copied unchanged from r1574885, db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/processor/string/organizeImports.txt
Removed:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessor.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessorTest.java
    db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/processor/string/organizeImports.txt
    db/torque/torque4/trunk/torque-generator/src/test/resources/org/apache/torque/generator/processor/string/organizeImportsExpected.txt

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessor.java
(from r1574712, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessor.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessor.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessor.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessor.java&r1=1574712&r2=1574886&rev=1574886&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessor.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessor.java
Thu Mar  6 14:16:21 2014
@@ -20,6 +20,7 @@ package org.apache.torque.generator.proc
  */
 
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -27,7 +28,7 @@ import java.util.regex.Pattern;
 /**
  * Tries to remove unused imports
  */
-public class OrganizeImportsProcessor implements StringProcessor
+public class RemoveUnusedImportsProcessor implements StringProcessor
 {
     /** Regex for import lines. */
     private static final Pattern IMPORT_PATTERN
@@ -70,13 +71,24 @@ public class OrganizeImportsProcessor im
             }
         }
         String result = toProcess;
-        for (Map.Entry<String, String> importForClassEntry
-                : importsForClasses.entrySet())
+        // do repeated runs to catch cases where e.g. a SimpleDateFormat
+        // and Date are both unused imports.
+        boolean doNextRun = true;
+        while (doNextRun)
         {
-            String className = importForClassEntry.getKey();
-            if (result.indexOf(className) == result.lastIndexOf(className))
+            doNextRun = false;
+            Iterator<Map.Entry<String, String>> entryIt
+                = importsForClasses.entrySet().iterator();
+            while (entryIt.hasNext())
             {
-                result = result.replace(importForClassEntry.getValue(), "");
+                Map.Entry<String, String> importForClassEntry = entryIt.next();
+                String className = importForClassEntry.getKey();
+                if (result.indexOf(className) == result.lastIndexOf(className))
+                {
+                    result = result.replace(importForClassEntry.getValue(), "");
+                    doNextRun = true;
+                    entryIt.remove();
+                }
             }
         }
         return result;

Copied: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessorTest.java
(from r1574691, db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessorTest.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessorTest.java?p2=db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessorTest.java&p1=db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessorTest.java&r1=1574691&r2=1574886&rev=1574886&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/OrganizeImportsProcessorTest.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/RemoveUnusedImportsProcessorTest.java
Thu Mar  6 14:16:21 2014
@@ -30,11 +30,11 @@ import org.junit.Test;
  *
  * @version $Id: $
  */
-public class OrganizeImportsProcessorTest extends BaseTest
+public class RemoveUnusedImportsProcessorTest extends BaseTest
 {
     /** System under test. */
-    private final OrganizeImportsProcessor organizeImportsProcessor
-            = new OrganizeImportsProcessor();
+    private final RemoveUnusedImportsProcessor organizeImportsProcessor
+            = new RemoveUnusedImportsProcessor();
 
     @Test
     public void testProcess()
@@ -57,9 +57,9 @@ public class OrganizeImportsProcessorTes
     @Test
     public void testProcessLong() throws Exception
     {
-        String source = IOUtils.toString(getClass().getResourceAsStream("organizeImports.txt"));
+        String source = IOUtils.toString(getClass().getResourceAsStream("removeUnusedImports.txt"));
         String result = organizeImportsProcessor.process(source);
-        String expected = IOUtils.toString(getClass().getResourceAsStream("organizeImportsExpected.txt"));
+        String expected = IOUtils.toString(getClass().getResourceAsStream("removeUnusedExpected.txt"));
         assertEquals(expected, result);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message