Skip to content

Commit dd69f2a

Browse files
committed
Fix bug where only ClassTrees with kind CLASS are considered by TypeScanner, resulting in a broken generatesSources() for interfaces, enums, and annotation types.
------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=65448993
1 parent 1161551 commit dd69f2a

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/main/java/com/google/testing/compile/TypeScanner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
*/
1616
package com.google.testing.compile;
1717

18+
import static com.sun.source.tree.Tree.Kind.ANNOTATION_TYPE;
1819
import static com.sun.source.tree.Tree.Kind.CLASS;
20+
import static com.sun.source.tree.Tree.Kind.ENUM;
1921
import static com.sun.source.tree.Tree.Kind.COMPILATION_UNIT;
2022
import static com.sun.source.tree.Tree.Kind.EXPRESSION_STATEMENT;
2123
import static com.sun.source.tree.Tree.Kind.IDENTIFIER;
24+
import static com.sun.source.tree.Tree.Kind.INTERFACE;
2225
import static com.sun.source.tree.Tree.Kind.MEMBER_SELECT;
2326

2427
import com.google.common.base.Function;
@@ -59,7 +62,8 @@ static ImmutableSet<String> getTopLevelTypes(CompilationUnitTree t) {
5962
static final class NameVisitor extends TreeScanner<Set<String>, Void> {
6063

6164
private static final Set<Tree.Kind> RELEVANT_KINDS = Sets.immutableEnumSet(
62-
CLASS, COMPILATION_UNIT, EXPRESSION_STATEMENT, IDENTIFIER, MEMBER_SELECT);
65+
ANNOTATION_TYPE, CLASS, ENUM, COMPILATION_UNIT, EXPRESSION_STATEMENT, IDENTIFIER, INTERFACE,
66+
MEMBER_SELECT);
6367

6468
@Override
6569
public Set<String> scan(Tree node, Void v) {

src/test/java/com/google/testing/compile/TypeScannerTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,47 @@ public void getTopLevelTypes_manySimpleTypes() {
108108
"HelloWorld", "HelperWorld");
109109
}
110110

111+
@Test
112+
public void getTopLevelTypes_worksForAnnotationTypes() {
113+
CompilationUnitTree compilation = compileLines("test.HelloWorld",
114+
"package path.to.test;",
115+
"import java.util.List;",
116+
"",
117+
"public @interface HelloWorld {}");
118+
119+
ASSERT.that(TypeScanner.getTopLevelTypes(compilation)).has().exactly(
120+
"path.to.test.HelloWorld");
121+
}
122+
123+
@Test
124+
public void getTopLevelTypes_worksForEnums() {
125+
CompilationUnitTree compilation = compileLines("test.HelloWorld",
126+
"package path.to.test;",
127+
"import java.util.List;",
128+
"",
129+
"public enum HelloWorld {",
130+
" HELLO,",
131+
" WORLD;",
132+
"}");
133+
134+
ASSERT.that(TypeScanner.getTopLevelTypes(compilation)).has().exactly(
135+
"path.to.test.HelloWorld");
136+
}
137+
138+
@Test
139+
public void getTopLevelTypes_worksForInterfaces() {
140+
CompilationUnitTree compilation = compileLines("test.HelloWorld",
141+
"package path.to.test;",
142+
"import java.util.List;",
143+
"",
144+
"public interface HelloWorld {",
145+
" public String getSalutation();",
146+
"}");
147+
148+
ASSERT.that(TypeScanner.getTopLevelTypes(compilation)).has().exactly(
149+
"path.to.test.HelloWorld");
150+
}
151+
111152
@Test
112153
public void getTopLevelTypes_worksForNull() {
113154
ASSERT.that(TypeScanner.getTopLevelTypes(null)).isEmpty();

0 commit comments

Comments
 (0)