Skip to content

Commit

Permalink
Fix HasImportTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Aug 22, 2020
1 parent 97b141e commit 37b7447
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,17 @@ public List<J.CompilationUnit> parseInputs(Iterable<Input> sourceFiles, @Nullabl
.tag("file.type", "Java")
.tag("step", "JDK parsing")
.register(meterRegistry)
.record(() -> compiler.parse(new ParserInputFileObject(input))),
.record(() -> {
try {
return compiler.parse(new ParserInputFileObject(input));
} catch (IllegalStateException e) {
if (e.getMessage().equals("endPosTable already set")) {
throw new IllegalStateException("Call reset() on JavaParser before parsing another" +
"set of source files that have some of the same fully qualified names", e);
}
throw e;
}
}),
(e2, e1) -> e1, LinkedHashMap::new));

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import org.junit.jupiter.api.Test
import org.openrewrite.java.JavaParser

interface HasImportTest {

@Test
fun hasImport(jp: JavaParser) {
val a = jp.parse("""
import java.util.List;
class A {}
""")[0]

assertTrue(a.hasImport("java.util.List"))
assertFalse(a.hasImport("java.util.Set"))
}
Expand All @@ -51,7 +51,7 @@ interface HasImportTest {
public static class B { }
}
"""

val c = """
import a.*;
public class C {
Expand All @@ -60,6 +60,6 @@ interface HasImportTest {
"""

assertTrue(jp.parse(c, a)[0].hasImport("a.A.B"))
assertTrue(jp.parse(c, a)[0].hasImport("a.A"))
assertTrue(jp.reset().parse(c, a)[0].hasImport("a.A"))
}
}

0 comments on commit 37b7447

Please sign in to comment.