Skip to content

Commit

Permalink
commenting and refining #1806
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Aug 30, 2018
1 parent d867d8d commit 007acfa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Expand Up @@ -17,6 +17,8 @@
import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;

import java.util.function.Supplier;

/**
* This implementation of the SymbolResolver wraps the functionality of the library to make them easily usable
* from JavaParser nodes.
Expand Down Expand Up @@ -91,7 +93,11 @@ public <T> T resolveDeclaration(Node node, Class<T> resultClass) {
ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) node;
TypeDeclaration<?> typeDeclaration = (TypeDeclaration<?>) node.getParentNode().get();
ResolvedReferenceTypeDeclaration resolvedTypeDeclaration = resolveDeclaration(typeDeclaration, ResolvedReferenceTypeDeclaration.class);
ResolvedConstructorDeclaration resolved = resolvedTypeDeclaration.getConstructors().stream().filter(c -> ((JavaParserConstructorDeclaration) c).getWrappedNode() == constructorDeclaration).findFirst().get();
ResolvedConstructorDeclaration resolved = resolvedTypeDeclaration.getConstructors().stream()
.filter(c -> c instanceof JavaParserConstructorDeclaration)
.filter(c -> ((JavaParserConstructorDeclaration) c).getWrappedNode() == constructorDeclaration)
.findFirst()
.orElseThrow(() -> new RuntimeException("This constructor cannot be found in its parent. This seems wrong"));
if (resultClass.isInstance(resolved)) {
return resultClass.cast(resolved);
}
Expand Down
Expand Up @@ -264,6 +264,6 @@ public List<ResolvedEnumConstantDeclaration> getEnumConstants() {

@Override
public List<ResolvedConstructorDeclaration> getConstructors() {
throw new UnsupportedOperationException("To be implemented");
return javassistTypeDeclarationAdapter.getConstructors();
}
}
Expand Up @@ -98,7 +98,7 @@ public void solveInnerInnerClassConstructor() {
}

@Test
public void solveEnumConstructor() {
public void solveEnumConstructorForJavaParserClass() {
// configure symbol solver before parsing
JavaParser.getStaticConfiguration().setSymbolResolver(new JavaSymbolSolver(new ReflectionTypeSolver()));

Expand Down

0 comments on commit 007acfa

Please sign in to comment.