use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl 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());
}
use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl 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());
}
use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl in project javaparser by javaparser.
the class JavaParserAPIIntegrationTest method setup.
@Before
public void setup() {
File src = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core"));
CombinedTypeSolver combinedTypeSolverNewCode = new CombinedTypeSolver();
combinedTypeSolverNewCode.add(new ReflectionTypeSolver());
combinedTypeSolverNewCode.add(new JavaParserTypeSolver(src));
combinedTypeSolverNewCode.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-generated-sources"))));
typeSolver = combinedTypeSolverNewCode;
TypeSolver ts = new ReflectionTypeSolver();
string = new ReferenceTypeImpl(ts.solveType(String.class.getCanonicalName()), ts);
ResolvedReferenceType booleanC = new ReferenceTypeImpl(ts.solveType(Boolean.class.getCanonicalName()), ts);
listOfBoolean = new ReferenceTypeImpl(ts.solveType(List.class.getCanonicalName()), ImmutableList.of(booleanC), ts);
}
use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl in project javaparser by javaparser.
the class TypeCompatibleWithType method reduce.
@Override
public ReductionResult reduce(BoundSet currentBoundSet) {
if (isProperType(s) && isProperType(t)) {
if (isCompatibleInALooseInvocationContext(s, t)) {
return ReductionResult.trueResult();
} else {
return ReductionResult.falseResult();
}
}
if (s.isPrimitive()) {
ReflectionTypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType sFirst = new ReferenceTypeImpl(typeSolver.solveType(s.asPrimitive().getBoxTypeQName()), typeSolver);
return ReductionResult.oneConstraint(new TypeCompatibleWithType(typeSolver, sFirst, t));
}
if (t.isPrimitive()) {
ReflectionTypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType tFirst = new ReferenceTypeImpl(typeSolver.solveType(t.asPrimitive().getBoxTypeQName()), typeSolver);
return ReductionResult.oneConstraint(new TypeSameAsType(s, tFirst));
}
if (t.isReferenceType() && !t.asReferenceType().getTypeDeclaration().getTypeParameters().isEmpty()) {
// FIXME I really cannot understand what the specification means...
// there exists a type of the form G<...> that is a supertype of S?
boolean condition1 = t.isAssignableBy(s);
// the raw type G is a supertype of S
ResolvedType G = t.asReferenceType().toRawType();
boolean condition2 = G.isAssignableBy(s);
if (!condition1 && condition2) {
return ReductionResult.trueResult();
}
// throw new UnsupportedOperationException();
}
if (t.isArray()) {
throw new UnsupportedOperationException();
}
return ReductionResult.empty().withConstraint(new TypeSubtypeOfType(typeSolver, s, t));
}
use of com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl in project javaparser by javaparser.
the class ReflectionMethodResolutionLogic method solveMethod.
static SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> parameterTypes, boolean staticOnly, TypeSolver typeSolver, ResolvedReferenceTypeDeclaration scopeType, Class clazz) {
List<ResolvedMethodDeclaration> methods = new ArrayList<>();
Predicate<Method> staticOnlyCheck = m -> !staticOnly || (staticOnly && Modifier.isStatic(m.getModifiers()));
for (Method method : clazz.getMethods()) {
if (method.isBridge() || method.isSynthetic() || !method.getName().equals(name) || !staticOnlyCheck.test(method))
continue;
ResolvedMethodDeclaration methodDeclaration = new ReflectionMethodDeclaration(method, typeSolver);
methods.add(methodDeclaration);
}
for (ResolvedReferenceType ancestor : scopeType.getAncestors()) {
SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(ancestor.getTypeDeclaration(), name, parameterTypes, staticOnly, typeSolver);
if (ref.isSolved()) {
methods.add(ref.getCorrespondingDeclaration());
}
}
if (scopeType.getAncestors().isEmpty()) {
ReferenceTypeImpl objectClass = new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, typeSolver), typeSolver);
SymbolReference<ResolvedMethodDeclaration> ref = MethodResolutionLogic.solveMethodInType(objectClass.getTypeDeclaration(), name, parameterTypes, staticOnly, typeSolver);
if (ref.isSolved()) {
methods.add(ref.getCorrespondingDeclaration());
}
}
return MethodResolutionLogic.findMostApplicable(methods, name, parameterTypes, typeSolver);
}
Aggregations