Fixes CompilationUnitProvider and all implementors such that CompilationUnitProvider.getMainTypeName never returns null. Patch by: tobyr Review by: scottb Issue: 2031 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1737 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/CompilationUnitProvider.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/CompilationUnitProvider.java index d727965..4d2aa8a 100644 --- a/dev/core/src/com/google/gwt/core/ext/typeinfo/CompilationUnitProvider.java +++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/CompilationUnitProvider.java
@@ -1,5 +1,5 @@ /* - * Copyright 2007 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 @@ -37,6 +37,10 @@ String getLocation(); + /** + * Returns the, not <code>null</code>, name of the top level public type. + * + */ String getMainTypeName(); String getPackageName();
diff --git a/dev/core/src/com/google/gwt/dev/jdt/ICompilationUnitAdapter.java b/dev/core/src/com/google/gwt/dev/jdt/ICompilationUnitAdapter.java index 03c078c..e483c59 100644 --- a/dev/core/src/com/google/gwt/dev/jdt/ICompilationUnitAdapter.java +++ b/dev/core/src/com/google/gwt/dev/jdt/ICompilationUnitAdapter.java
@@ -1,5 +1,5 @@ /* - * Copyright 2007 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 @@ -53,15 +53,16 @@ /** * This method is supposed to return the simple class name for this * compilation unit. Examples of simple class names would be "String", or - * "ArrayList". JDT allows this method to return null in the cases where this - * compilation unit is not a package-info class. + * "ArrayList". + * + * <p>Although JDT allows this method to return null in the cases + * where this compilation unit is not a package-info class, JDT never + * constructs a CUP with a null main type, and we should never do so + * either.</p> */ public char[] getMainTypeName() { String typeName = cup.getMainTypeName(); - if (typeName != null) { - return typeName.toCharArray(); - } - return null; + return typeName.toCharArray(); } public char[][] getPackageName() {
diff --git a/dev/core/test/com/google/gwt/dev/jdt/test/ByteCodeCompilerTest.java b/dev/core/test/com/google/gwt/dev/jdt/test/ByteCodeCompilerTest.java index d17cb5c..4d51f30 100644 --- a/dev/core/test/com/google/gwt/dev/jdt/test/ByteCodeCompilerTest.java +++ b/dev/core/test/com/google/gwt/dev/jdt/test/ByteCodeCompilerTest.java
@@ -1,5 +1,5 @@ /* - * Copyright 2007 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 @@ -42,11 +42,16 @@ private abstract class TestCup implements CompilationUnitProvider { - public TestCup(String packageName, String onlyTypeName) { - this(packageName, new String[] {onlyTypeName}); - } - - public TestCup(String packageName, String[] typeNames) { + /** + * Creates a new {@code TestCup} with several types. The first type in + * {@code typeNames} is considered to be the main type. + * + * @param packageName the package for the types in this {@code TestCup} + * @param typeNames the types for this {@code TestCup}. Must have + * at least one type. The first type is considered to be the main type + * for this {@code TestCup}. + */ + public TestCup(String packageName, String... typeNames) { this.packageName = packageName; registerPackage(packageName); for (int i = 0; i < typeNames.length; i++) { @@ -70,7 +75,7 @@ } public String getMainTypeName() { - return null; + return firstTypeName; } public String getPackageName() { @@ -130,8 +135,7 @@ cupsByTypeName = new HashMap<String, CompilationUnitProvider>(); } - final CompilationUnitProvider CU_AB = new TestCup("test", new String[] { - "A", "A.B"}) { + final CompilationUnitProvider CU_AB = new TestCup("test", "A", "A.B") { public char[] getSource() { StringBuffer sb = new StringBuffer(); sb.append("package test;\n"); @@ -142,8 +146,7 @@ } }; - final CompilationUnitProvider CU_C = new TestCup("test", new String[] { - "C", "C.Message"}) { + final CompilationUnitProvider CU_C = new TestCup("test", "C", "C.Message") { public char[] getSource() { StringBuffer sb = new StringBuffer(); sb.append("package test;\n"); @@ -176,8 +179,7 @@ * This one is different because D is not public and it lives in the default * package. */ - final CompilationUnitProvider CU_DE = new TestCup("", new String[] { - "D", "D.E"}) { + final CompilationUnitProvider CU_DE = new TestCup("", "D", "D.E") { public char[] getSource() { StringBuffer sb = new StringBuffer(); sb.append("class D extends test.C.Message {\n");
diff --git a/dev/core/test/com/google/gwt/dev/typeinfo/test/TypeOracleBuilderTest.java b/dev/core/test/com/google/gwt/dev/typeinfo/test/TypeOracleBuilderTest.java index 9bf5e19..65d709e 100644 --- a/dev/core/test/com/google/gwt/dev/typeinfo/test/TypeOracleBuilderTest.java +++ b/dev/core/test/com/google/gwt/dev/typeinfo/test/TypeOracleBuilderTest.java
@@ -1,5 +1,5 @@ /* - * Copyright 2007 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 @@ -43,13 +43,19 @@ private final String[] typeNames; - public TestCup(String packageName, String onlyTypeName) { - this(packageName, new String[] {onlyTypeName}); - } - - public TestCup(String packageName, String[] typeNames) { + /** + * Creates a new {@code TestCup} with several types. The first type in + * {@code typeNames} is considered to be the main type. + * + * @param packageName the package for the types in this {@code TestCup} + * @param typeNames the types for this {@code TestCup}. Must have + * at least one type. The first type is considered to be the main type + * for this {@code TestCup}. + */ + public TestCup(String packageName, String... typeNames) { this.packageName = packageName; this.typeNames = typeNames; + assert typeNames != null && typeNames.length > 0; for (int i = 0; i < typeNames.length; i++) { String typeName = typeNames[i]; register(typeName, this); @@ -68,7 +74,7 @@ } public String getMainTypeName() { - return null; + return typeNames[0]; } public String getPackageName() { @@ -113,7 +119,7 @@ } protected TestCup CU_AfterAssimilate = new TestCup("test.assim", - new String[] {"AfterAssimilate"}) { + "AfterAssimilate") { public void check(JClassType type) { // Don't need to check the type itself. } @@ -126,8 +132,8 @@ } }; - protected TestCup CU_Assignable = new TestCup("test.sub", new String[] { - "BaseInterface", "DerivedInterface", "Derived", "Derived.Nested"}) { + protected TestCup CU_Assignable = new TestCup("test.sub", "Derived", + "BaseInterface", "DerivedInterface", "Derived.Nested") { public void check(JClassType type) { if ("Derived".equals(type.getSimpleSourceName())) checkDerived(type); @@ -158,7 +164,7 @@ }; protected TestCup CU_BeforeAssimilate = new TestCup("test.assim", - new String[] {"BeforeAssimilate"}) { + "BeforeAssimilate") { public void check(JClassType type) { // Don't need to check the type itself. } @@ -171,9 +177,8 @@ } }; - protected TestCup CU_BindToTypeScope = new TestCup("test", new String[] { - "BindToTypeScope", "BindToTypeScope.Object", - "BindToTypeScope.DerivedObject"}) { + protected TestCup CU_BindToTypeScope = new TestCup("test", "BindToTypeScope", + "BindToTypeScope.Object", "BindToTypeScope.DerivedObject") { public void check(JClassType type) throws NotFoundException { if ("BindToTypeScope".equals(type.getSimpleSourceName())) @@ -242,8 +247,8 @@ } }; - protected TestCup CU_FieldsAndTypes = new TestCup("test", new String[] { - "Fields", "SomeType"}) { + protected TestCup CU_FieldsAndTypes = new TestCup("test", "Fields", + "SomeType") { public void check(JClassType type) throws NotFoundException { if ("Fields".equals(type.getSimpleSourceName())) { assertEquals("test.Fields", type.getQualifiedSourceName()); @@ -354,8 +359,8 @@ } }; - protected TestCup CU_HasSyntaxErrors = new TestCup("test", new String[] { - "HasSyntaxErrors", "NoSyntaxErrors"}) { + protected TestCup CU_HasSyntaxErrors = new TestCup("test", "HasSyntaxErrors", + "NoSyntaxErrors") { public void check(JClassType classInfo) { fail("This class should have been removed"); } @@ -363,14 +368,14 @@ public char[] getSource() { StringBuffer sb = new StringBuffer(); sb.append("package test;\n"); - sb.append("public class NoSyntaxErrors { }\n"); + sb.append("class NoSyntaxErrors { }\n"); sb.append("public class HasSyntaxErrors { a syntax error }\n"); return sb.toString().toCharArray(); } }; - protected TestCup CU_HasUnresolvedSymbols = new TestCup("test", new String[] { - "Invalid", "Valid"}) { + protected TestCup CU_HasUnresolvedSymbols = new TestCup("test", "Invalid", + "Valid") { public void check(JClassType classInfo) { fail("Both classes should have been removed"); } @@ -379,7 +384,7 @@ StringBuffer sb = new StringBuffer(); sb.append("package test;\n"); sb.append("public class Invalid extends NoSuchClass { }\n"); - sb.append("public class Valid extends Object { }\n"); + sb.append("class Valid extends Object { }\n"); return sb.toString().toCharArray(); } }; @@ -552,8 +557,8 @@ } }; - protected TestCup CU_OuterInner = new TestCup("test", new String[] { - "Outer", "Outer.Inner"}) { + protected TestCup CU_OuterInner = new TestCup("test", "Outer", + "Outer.Inner") { public void check(JClassType type) { final String name = type.getSimpleSourceName(); @@ -590,7 +595,7 @@ }; protected TestCup CU_RefsInfectedCompilationUnit = new TestCup("test", - new String[] {"RefsInfectedCompilationUnit"}) { + "RefsInfectedCompilationUnit") { public void check(JClassType classInfo) { fail("This class should should have been removed because it refers to a class in another compilation unit that had problems"); }