Skip to content

Commit

Permalink
giving up processing all CUs looking for a type
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Jul 15, 2018
1 parent 98b30cb commit 300534a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
Expand Up @@ -213,8 +213,7 @@ private SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveTypeUncached
}

// If this is not possible we parse all files
// First we try just in the same package, for classes defined in a file not named as the class itself
// later we move to top directories until we get the root
// We try just in the same package, for classes defined in a file not named as the class itself
{
List<CompilationUnit> compilationUnits = parseDirectory(srcFile.getParent());
for (CompilationUnit compilationUnit : compilationUnits) {
Expand All @@ -224,22 +223,6 @@ private SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveTypeUncached
}
}
}

{
List<CompilationUnit> compilationUnits = parseDirectoryRecursively(srcDir);
for (CompilationUnit compilationUnit : compilationUnits) {
if (compilationUnit.getPackageDeclaration().isPresent()) {
String packageName = compilationUnit.getPackageDeclaration().get().getNameAsString();
if (name.startsWith(packageName)) {
String remainingName = name.substring(packageName.length() + 1);
Optional<com.github.javaparser.ast.body.TypeDeclaration<?>> astTypeDeclaration = Navigator.findType(compilationUnit, remainingName);
if (astTypeDeclaration.isPresent()) {
return SymbolReference.solved(JavaParserFacade.get(this).getTypeDeclaration(astTypeDeclaration.get()));
}
}
}
}
}
}

return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
Expand Down
Expand Up @@ -26,7 +26,8 @@ public class InternalClassInInterfaceTest {
@Test
public void resolveFieldOfEnumAsInternalClassOfInterfaceUnqualifiedSamePackage() throws FileNotFoundException {
File src = new File("src/test/resources/internalClassInInterface");
File aClass = new File(src.getPath() + File.separator + "AClass.java");
File aClass = new File(src.getPath() + File.separator + "foo" + File.separator+ "bar"
+ File.separator + "AClass.java");

CombinedTypeSolver localCts = new CombinedTypeSolver();
localCts.add(new ReflectionTypeSolver());
Expand All @@ -47,7 +48,8 @@ public void resolveFieldOfEnumAsInternalClassOfInterfaceUnqualifiedSamePackage()
@Test
public void resolveFieldOfEnumAsInternalClassOfInterfaceQualifiedSamePackage() throws FileNotFoundException {
File src = new File("src/test/resources/internalClassInInterface");
File aClass = new File(src.getPath() + File.separator + "AClass.java");
File aClass = new File(src.getPath() + File.separator + "foo" + File.separator+ "bar"
+ File.separator + "AClass.java");

CombinedTypeSolver localCts = new CombinedTypeSolver();
localCts.add(new ReflectionTypeSolver());
Expand All @@ -68,7 +70,8 @@ public void resolveFieldOfEnumAsInternalClassOfInterfaceQualifiedSamePackage() t
@Test
public void resolveFieldOfEnumAsInternalClassOfInterfaceUnqualifiedDifferentPackage() throws FileNotFoundException {
File src = new File("src/test/resources/internalClassInInterface");
File aClass = new File(src.getPath() + File.separator + "AClass2.java");
File aClass = new File(src.getPath() + File.separator + "foo" + File.separator+ "bar"
+ File.separator + "differentpackage" + File.separator + "AClass2.java");

CombinedTypeSolver localCts = new CombinedTypeSolver();
localCts.add(new ReflectionTypeSolver());
Expand All @@ -89,7 +92,8 @@ public void resolveFieldOfEnumAsInternalClassOfInterfaceUnqualifiedDifferentPack
@Test
public void resolveFieldOfEnumAsInternalClassOfInterfaceQualifiedDifferentPackage() throws FileNotFoundException {
File src = new File("src/test/resources/internalClassInInterface");
File aClass = new File(src.getPath() + File.separator + "AClass2.java");
File aClass = new File(src.getPath() + File.separator + "foo" + File.separator+ "bar"
+ File.separator + "differentpackage" + File.separator + "AClass2.java");

CombinedTypeSolver localCts = new CombinedTypeSolver();
localCts.add(new ReflectionTypeSolver());
Expand Down

0 comments on commit 300534a

Please sign in to comment.