Skip to content

Commit

Permalink
move complexTypeSolving
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Aug 23, 2018
1 parent 87346d2 commit 7f8a284
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
Expand Up @@ -43,24 +43,11 @@


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;


/**
* Tests related to resolved Generics types.
*/
public class GenericsResolutionTest extends AbstractResolutionTest { public class GenericsResolutionTest extends AbstractResolutionTest {


@Test
public void complexTypeSolving() {
CompilationUnit cu = parseSample("ComplexTypeResolving");
ClassOrInterfaceDeclaration mainClass = Navigator.demandClass(cu, "Main");

ClassOrInterfaceDeclaration childDec = (ClassOrInterfaceDeclaration) mainClass.getMember(1);
ExpressionStmt stmt =
(ExpressionStmt) Navigator.demandMethod(childDec, "foo").getBody().get().getStatement(0);
ReferenceTypeImpl resolvedType =
(ReferenceTypeImpl) JavaParserFacade.get(new ReflectionTypeSolver()).getType(stmt.getExpression());
ClassOrInterfaceDeclaration resolvedTypeDeclaration
= ((JavaParserClassDeclaration) resolvedType.getTypeDeclaration()).getWrappedNode();

assertEquals(mainClass, resolvedTypeDeclaration.getParentNode().get());
}

@Test @Test
public void resolveFieldWithGenericTypeToString() { public void resolveFieldWithGenericTypeToString() {
CompilationUnit cu = parseSample("Generics"); CompilationUnit cu = parseSample("Generics");
Expand Down
Expand Up @@ -22,15 +22,18 @@
import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.ThisExpr; import com.github.javaparser.ast.expr.ThisExpr;
import com.github.javaparser.ast.stmt.ExpressionStmt;
import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.stmt.ReturnStmt;
import com.github.javaparser.resolution.MethodUsage; import com.github.javaparser.resolution.MethodUsage;
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.javaparser.Navigator; import com.github.javaparser.symbolsolver.javaparser.Navigator;
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration;
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration;
import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import org.junit.Test; import org.junit.Test;


Expand Down Expand Up @@ -378,4 +381,20 @@ public void resolveMethodCallWithScopeDeclarationInSwitchEntryStmt() {
assertTrue(reference.isSolved()); assertTrue(reference.isSolved());
assertEquals("java.io.File.delete()", reference.getCorrespondingDeclaration().getQualifiedSignature()); assertEquals("java.io.File.delete()", reference.getCorrespondingDeclaration().getQualifiedSignature());
} }

@Test
public void complexTypeSolving() {
CompilationUnit cu = parseSample("ComplexTypeResolving");
ClassOrInterfaceDeclaration mainClass = Navigator.demandClass(cu, "Main");

ClassOrInterfaceDeclaration childDec = (ClassOrInterfaceDeclaration) mainClass.getMember(1);
ExpressionStmt stmt =
(ExpressionStmt) Navigator.demandMethod(childDec, "foo").getBody().get().getStatement(0);
ReferenceTypeImpl resolvedType =
(ReferenceTypeImpl) JavaParserFacade.get(new ReflectionTypeSolver()).getType(stmt.getExpression());
ClassOrInterfaceDeclaration resolvedTypeDeclaration
= ((JavaParserClassDeclaration) resolvedType.getTypeDeclaration()).getWrappedNode();

assertEquals(mainClass, resolvedTypeDeclaration.getParentNode().get());
}
} }

0 comments on commit 7f8a284

Please sign in to comment.