use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class VarTypeTest method resolveAReferenceType.
@Test
public void resolveAReferenceType() {
CompilationUnit ast = javaParser.parse(ParseStart.COMPILATION_UNIT, provider("class X{void x(){var abc = \"\";}}")).getResult().get();
VarType varType = ast.findFirst(VarType.class).get();
ResolvedType resolvedType = varType.resolve();
assertEquals(new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver), resolvedType);
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class SymbolResolutionResolutionTest method conditionalExpressionExample.
@Test
public void conditionalExpressionExample() {
CompilationUnit cu = parseSample("JreConditionalExpression");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo1");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
Expression expression = returnStmt.getExpression().get();
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class SymbolResolutionResolutionTest method getTypeOfFieldAccess.
@Test
public void getTypeOfFieldAccess() {
CompilationUnit cu = parseSample("ReflectionFieldOfItself");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
VariableDeclarator field = Navigator.demandField(clazz, "PUBLIC");
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(field.getInitializer().get());
assertEquals("int", ref.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class SymbolResolutionResolutionTest method getTypeOfField.
@Test
public void getTypeOfField() {
CompilationUnit cu = parseSample("ReflectionFieldOfItself");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
VariableDeclarator field = Navigator.demandField(clazz, "PUBLIC");
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(field);
assertEquals("int", ref.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class SubtypeOfBoundTest method recognizeProperUpperBound2.
@Test
public void recognizeProperUpperBound2() {
ResolvedTypeParameterDeclaration typeParameterDeclaration1 = mock(ResolvedTypeParameterDeclaration.class);
ResolvedTypeParameterDeclaration typeParameterDeclaration2 = mock(ResolvedTypeParameterDeclaration.class);
// { α <: Iterable<?>, β <: Object, α <: List<β> } describes a proper upper bound for each of α and β, along with a dependency between them.
InferenceVariable alpha = new InferenceVariable("α", typeParameterDeclaration1);
InferenceVariable beta = new InferenceVariable("β", typeParameterDeclaration2);
ResolvedType iterableOfWildcard = new ReferenceTypeImpl(iterableType.getTypeDeclaration(), Arrays.asList(ResolvedWildcard.UNBOUNDED), typeSolver);
ResolvedType listOfBeta = new ReferenceTypeImpl(listType.getTypeDeclaration(), Arrays.asList(beta), typeSolver);
Bound bound1 = new SubtypeOfBound(alpha, iterableOfWildcard);
Bound bound2 = new SubtypeOfBound(beta, objectType);
Bound bound3 = new SubtypeOfBound(alpha, listOfBeta);
assertEquals(false, isProperType(listOfBeta));
assertEquals(Optional.of(new ProperUpperBound(alpha, iterableOfWildcard)), bound1.isProperUpperBound());
assertEquals(Optional.of(new ProperUpperBound(beta, objectType)), bound2.isProperUpperBound());
assertEquals(true, bound3.isADependency());
}
Aggregations