Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JavassistMethodDeclaration returns correct type of param if param has…
… raw type.
- Loading branch information
Kathrin Geilmann
committed
Feb 14, 2019
1 parent
ff33441
commit a7a5c9a
Showing
4 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ava/com/github/javaparser/symbolsolver/javassistmodel/JavassistMethodDeclarationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.github.javaparser.symbolsolver.javassistmodel; | ||
|
||
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; | ||
import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration; | ||
import com.github.javaparser.symbolsolver.AbstractSymbolResolutionTest; | ||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class JavassistMethodDeclarationTest extends AbstractSymbolResolutionTest { | ||
|
||
private TypeSolver typeSolver; | ||
|
||
@BeforeEach | ||
void setup() throws IOException { | ||
Path pathToJar = adaptPath("src/test/resources/javassistmethoddecl/javassistmethoddecl.jar"); | ||
typeSolver = new CombinedTypeSolver(new JarTypeSolver(pathToJar), new ReflectionTypeSolver()); | ||
} | ||
|
||
@Test | ||
void getParameterDeclaration_forMethodParameterWithRawType() { | ||
JavassistClassDeclaration classDecl = (JavassistClassDeclaration) typeSolver.solveType("C"); | ||
ResolvedMethodDeclaration methodWithRawParameter = findMethodWithNAme(classDecl, "methodWithRawParameter"); | ||
|
||
ResolvedParameterDeclaration rawParam = methodWithRawParameter.getParam(0); | ||
|
||
assertThat(rawParam.describeType(), is("java.util.List")); | ||
} | ||
|
||
@Test | ||
void getParameterDeclaration_forMethodParameterWithGenericType() { | ||
JavassistClassDeclaration classDecl = (JavassistClassDeclaration) typeSolver.solveType("C"); | ||
ResolvedMethodDeclaration methodWithRawParameter = findMethodWithNAme(classDecl, "methodWithGenericParameter"); | ||
|
||
ResolvedParameterDeclaration genericParam = methodWithRawParameter.getParam(0); | ||
|
||
assertThat(genericParam.describeType(), is("java.util.List<java.lang.String>")); | ||
} | ||
|
||
private ResolvedMethodDeclaration findMethodWithNAme(JavassistClassDeclaration classDecl, String name) { | ||
return classDecl.getDeclaredMethods().stream().filter(methodDecl -> methodDecl.getName().equals(name)).findAny().get(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
javaparser-symbol-solver-testing/src/test/resources/javassistmethoddecl/C.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import java.util.List; | ||
|
||
public class C { | ||
|
||
public void methodWithRawParameter(List l) { | ||
} | ||
|
||
public void methodWithGenericParameter(List<String> l) { | ||
} | ||
|
||
} |
Binary file added
BIN
+698 Bytes
...rser-symbol-solver-testing/src/test/resources/javassistmethoddecl/javassistmethoddecl.jar
Binary file not shown.