Refactored JDT error recording into Shared.  Split the error recording test in BinaryTypeReferenceRestrictionsCheckerTest out to a new SharedTest

Patch by: scottb, spoon (pair prog)


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2213 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsChecker.java b/dev/core/src/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsChecker.java
index eed88f9..b80127a 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsChecker.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsChecker.java
@@ -15,9 +15,6 @@
  */
 package com.google.gwt.dev.jdt;
 
-import org.eclipse.jdt.core.compiler.IProblem;
-import org.eclipse.jdt.internal.compiler.CompilationResult;
-import org.eclipse.jdt.internal.compiler.ast.ASTNode;
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.Expression;
 import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
@@ -26,9 +23,6 @@
 import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
-import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
-import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
-import org.eclipse.jdt.internal.compiler.util.Util;
 
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -127,7 +121,7 @@
       String qualifiedTypeName = binaryTypeBinding.debugName();
       String error = formatBinaryTypeRefErrorMessage(qualifiedTypeName);
 
-      recordError(cud, binaryTypeReferenceSite.getExpression(), error);
+      Shared.recordError(binaryTypeReferenceSite.getExpression(), cud, error);
     }
   }
 
@@ -145,20 +139,6 @@
         + "; did you forget to inherit a required module?";
   }
 
-  static void recordError(CompilationUnitDeclaration cud, ASTNode node,
-      String error) {
-    CompilationResult compResult = cud.compilationResult();
-    int[] lineEnds = compResult.getLineSeparatorPositions();
-    int startLine = Util.getLineNumber(node.sourceStart(), lineEnds, 0,
-        lineEnds.length - 1);
-    int startColumn = Util.searchColumnNumber(lineEnds, startLine,
-        node.sourceStart());
-    DefaultProblem problem = new DefaultProblem(compResult.fileName, error,
-        IProblem.ExternalProblemNotFixable, null, ProblemSeverities.Error,
-        node.sourceStart(), node.sourceEnd(), startLine, startColumn);
-    compResult.record(problem, cud);
-  }
-
   private BinaryTypeReferenceRestrictionsChecker() {
     // Not instantiable
   }
diff --git a/dev/core/src/com/google/gwt/dev/jdt/Shared.java b/dev/core/src/com/google/gwt/dev/jdt/Shared.java
index b7de772..dc6187e 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/Shared.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/Shared.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006 Google Inc.
+ * Copyright 2008 Google Inc.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -23,9 +23,16 @@
 import com.google.gwt.core.ext.typeinfo.JParameter;
 import com.google.gwt.core.ext.typeinfo.JType;
 
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.ast.ASTNode;
+import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
+import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
+import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
+import org.eclipse.jdt.internal.compiler.util.Util;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -89,7 +96,7 @@
   }
 
   static String[] modifierBitsToNames(int bits) {
-    List strings = new ArrayList();
+    List<String> strings = new ArrayList<String>();
 
     // The order is based on the order in which we want them to appear.
     //
@@ -129,7 +136,20 @@
       strings.add("volatile");
     }
 
-    return (String[]) strings.toArray(NO_STRINGS);
+    return strings.toArray(NO_STRINGS);
   }
 
+  static void recordError(ASTNode node, CompilationUnitDeclaration cud,
+      String error) {
+    CompilationResult compResult = cud.compilationResult();
+    int[] lineEnds = compResult.getLineSeparatorPositions();
+    int startLine = Util.getLineNumber(node.sourceStart(), lineEnds, 0,
+        lineEnds.length - 1);
+    int startColumn = Util.searchColumnNumber(lineEnds, startLine,
+        node.sourceStart());
+    DefaultProblem problem = new DefaultProblem(compResult.fileName, error,
+        IProblem.ExternalProblemNotFixable, null, ProblemSeverities.Error,
+        node.sourceStart(), node.sourceEnd(), startLine, startColumn);
+    compResult.record(problem, cud);
+  }
 }
diff --git a/dev/core/test/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsCheckerTest.java b/dev/core/test/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsCheckerTest.java
index bfca795..5d60966 100644
--- a/dev/core/test/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsCheckerTest.java
+++ b/dev/core/test/com/google/gwt/dev/jdt/BinaryTypeReferenceRestrictionsCheckerTest.java
@@ -19,7 +19,6 @@
 
 import junit.framework.TestCase;
 
-import org.eclipse.jdt.core.compiler.CategorizedProblem;
 import org.eclipse.jdt.internal.compiler.CompilationResult;
 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -32,7 +31,6 @@
 import org.eclipse.jdt.internal.compiler.ast.Statement;
 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.TypeReference;
-import org.eclipse.jdt.internal.compiler.ast.Wildcard;
 import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
 import org.eclipse.jdt.internal.compiler.env.IBinaryField;
 import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
@@ -217,24 +215,4 @@
     String actualMessage = BinaryTypeReferenceRestrictionsChecker.formatBinaryTypeRefErrorMessage("MyClass");
     assertEquals(expectedMessage, actualMessage);
   }
-
-  public void testRecordError() {
-    String fileName = "TestCompilationUnit.java";
-    String errorMessage = "Unit has errors";
-    CompilationResult compilationResult = new CompilationResult(
-        fileName.toCharArray(), 0, 0, 0);
-    CompilationUnitDeclaration cud = new CompilationUnitDeclaration(null,
-        compilationResult, 0);
-
-    // Pick an Expression subtype to pass in
-    BinaryTypeReferenceRestrictionsChecker.recordError(cud, new Wildcard(
-        Wildcard.EXTENDS), errorMessage);
-
-    CategorizedProblem[] errors = compilationResult.getErrors();
-    assertEquals(1, errors.length);
-    CategorizedProblem problem = errors[0];
-    assertTrue(problem.isError());
-    assertEquals(1, problem.getSourceLineNumber());
-    assertEquals(errorMessage, problem.getMessage());
-  }
 }
diff --git a/dev/core/test/com/google/gwt/dev/jdt/SharedTest.java b/dev/core/test/com/google/gwt/dev/jdt/SharedTest.java
new file mode 100644
index 0000000..1e64bda
--- /dev/null
+++ b/dev/core/test/com/google/gwt/dev/jdt/SharedTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2008 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.dev.jdt;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jdt.core.compiler.CategorizedProblem;
+import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.Wildcard;
+
+/**
+ * 
+ */
+public class SharedTest extends TestCase {
+  public void testRecordError() {
+    String fileName = "TestCompilationUnit.java";
+    String errorMessage = "Unit has errors";
+    CompilationResult compilationResult = new CompilationResult(
+        fileName.toCharArray(), 0, 0, 0);
+    CompilationUnitDeclaration cud = new CompilationUnitDeclaration(null,
+        compilationResult, 0);
+
+    // Pick an Expression subtype to pass in
+    Shared.recordError(new Wildcard(Wildcard.EXTENDS), cud, errorMessage);
+
+    CategorizedProblem[] errors = compilationResult.getErrors();
+    assertEquals(1, errors.length);
+    CategorizedProblem problem = errors[0];
+    assertTrue(problem.isError());
+    assertEquals(1, problem.getSourceLineNumber());
+    assertEquals(errorMessage, problem.getMessage());
+  }
+}