Search in sources :

Example 1 with ResolvedType

use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.

the class TypeExtractor method visit.

@Override
public ResolvedType visit(ClassExpr node, Boolean solveLambdas) {
    // This implementation does not regard the actual type argument of the ClassExpr.
    com.github.javaparser.ast.type.Type astType = node.getType();
    ResolvedType jssType = facade.convertToUsage(astType, node.getType());
    return new ReferenceTypeImpl(new ReflectionClassDeclaration(Class.class, typeSolver), ImmutableList.of(jssType), typeSolver);
}
Also used : ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) ResolvedType(com.github.javaparser.resolution.types.ResolvedType)

Example 2 with ResolvedType

use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.

the class FunctionInterfaceLogicTest method testGetFunctionalMethodPositiveCasesOnInterfaces.

@Test
public void testGetFunctionalMethodPositiveCasesOnInterfaces() {
    TypeSolver typeSolver = new ReflectionTypeSolver();
    ResolvedType function = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Function.class, typeSolver), typeSolver);
    assertEquals(true, FunctionalInterfaceLogic.getFunctionalMethod(function).isPresent());
    assertEquals("apply", FunctionalInterfaceLogic.getFunctionalMethod(function).get().getName());
    ResolvedType consumer = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Consumer.class, typeSolver), typeSolver);
    assertEquals(true, FunctionalInterfaceLogic.getFunctionalMethod(consumer).isPresent());
    assertEquals("accept", FunctionalInterfaceLogic.getFunctionalMethod(consumer).get().getName());
}
Also used : Function(java.util.function.Function) Consumer(java.util.function.Consumer) TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) ReflectionInterfaceDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionInterfaceDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Example 3 with ResolvedType

use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.

the class FunctionInterfaceLogicTest method testGetFunctionalMethodNegativeCaseOnClass.

@Test
public void testGetFunctionalMethodNegativeCaseOnClass() {
    TypeSolver typeSolver = new ReflectionTypeSolver();
    ResolvedType string = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver);
    assertEquals(false, FunctionalInterfaceLogic.getFunctionalMethod(string).isPresent());
}
Also used : TypeSolver(com.github.javaparser.symbolsolver.model.resolution.TypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) ReflectionClassDeclaration(com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Example 4 with ResolvedType

use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.

the class InferenceContextTest method placingASingleVariableTopLevel.

@Test
public void placingASingleVariableTopLevel() {
    ResolvedType result = new InferenceContext(MyObjectProvider.INSTANCE).addPair(new ResolvedTypeVariable(tpE), listOfString);
    assertEquals(new InferenceVariableType(0, MyObjectProvider.INSTANCE), result);
}
Also used : ResolvedTypeVariable(com.github.javaparser.resolution.types.ResolvedTypeVariable) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Example 5 with ResolvedType

use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.

the class InferenceContextTest method noVariablesArePlacedWhenNotNeeded.

@Test
public void noVariablesArePlacedWhenNotNeeded() {
    ResolvedType result = new InferenceContext(MyObjectProvider.INSTANCE).addPair(object, string);
    assertEquals(object, result);
}
Also used : ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Aggregations

ResolvedType (com.github.javaparser.resolution.types.ResolvedType)119 Test (org.junit.Test)78 CompilationUnit (com.github.javaparser.ast.CompilationUnit)68 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)58 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)41 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)39 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)32 Expression (com.github.javaparser.ast.expr.Expression)27 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)22 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)21 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)20 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)18 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)18 MethodUsage (com.github.javaparser.resolution.MethodUsage)17 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)15 Context (com.github.javaparser.symbolsolver.core.resolution.Context)15 ResolvedReferenceType (com.github.javaparser.resolution.types.ResolvedReferenceType)14 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)10 ResolvedTypeParameterDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration)10 Collectors (java.util.stream.Collectors)10