Search in sources :

Example 1 with VarType

use of com.github.javaparser.ast.type.VarType 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);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) VarType(com.github.javaparser.ast.type.VarType) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Example 2 with VarType

use of com.github.javaparser.ast.type.VarType in project javaparser by javaparser.

the class VarTypeTest method failResolveNoInitializer.

@Test(expected = IllegalStateException.class)
public void failResolveNoInitializer() {
    CompilationUnit ast = javaParser.parse(ParseStart.COMPILATION_UNIT, provider("class X{void x(){var abc;}}")).getResult().get();
    VarType varType = ast.findFirst(VarType.class).get();
    varType.resolve();
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) VarType(com.github.javaparser.ast.type.VarType) Test(org.junit.Test)

Example 3 with VarType

use of com.github.javaparser.ast.type.VarType in project javaparser by javaparser.

the class VarTypeTest method failResolveWrongLocation.

@Test(expected = IllegalStateException.class)
public void failResolveWrongLocation() {
    CompilationUnit ast = javaParser.parse(ParseStart.COMPILATION_UNIT, provider("class X{void x(var x){};}")).getResult().get();
    VarType varType = ast.findFirst(VarType.class).get();
    varType.resolve();
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) VarType(com.github.javaparser.ast.type.VarType) Test(org.junit.Test)

Example 4 with VarType

use of com.github.javaparser.ast.type.VarType in project javaparser by javaparser.

the class VarTypeTest method resolveAPrimitive.

@Test
public void resolveAPrimitive() {
    CompilationUnit ast = javaParser.parse(ParseStart.COMPILATION_UNIT, provider("class X{void x(){var abc = 1;}}")).getResult().get();
    VarType varType = ast.findFirst(VarType.class).get();
    ResolvedType resolvedType = varType.resolve();
    assertEquals(ResolvedPrimitiveType.INT, resolvedType);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) VarType(com.github.javaparser.ast.type.VarType) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)4 VarType (com.github.javaparser.ast.type.VarType)4 Test (org.junit.Test)4 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)2 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)1 ReflectionClassDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration)1