ResolvedType T = bound.getType(); Substitution substitution = Substitution.empty(); for (int j=0;j<typeParameterDeclarations.size();j++) {
@Override public List<Bound> getBounds() { return Arrays.stream(typeVariable.getBounds()).map((refB) -> Bound.extendsBound(ReflectionFactory.typeUsageFor(refB, typeSolver))).collect(Collectors.toList()); }
} else if (tp.getBounds().size() == 1) { ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0); if (bound.isExtends()) { expectedType = expectedType.replaceTypeVariables(tp, ResolvedWildcard.extendsBound(bound.getType())); } else { expectedType = expectedType.replaceTypeVariables(tp, ResolvedWildcard.superBound(bound.getType())); } else if (tp.getBounds().size() == 1) { ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0); if (bound.isExtends()) { expectedType2 = expectedType2.replaceTypeVariables(tp, bound.getType()); } else { expectedType2 = expectedType2.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver));
} else if (tp.getBounds().size() == 1) { ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0); if (bound.isExtends()) { expectedType = expectedType.replaceTypeVariables(tp, ResolvedWildcard.extendsBound(bound.getType())); } else { expectedType = expectedType.replaceTypeVariables(tp, ResolvedWildcard.superBound(bound.getType())); } else if (tp.getBounds().size() == 1) { ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0); if (bound.isExtends()) { expectedType2 = expectedType2.replaceTypeVariables(tp, bound.getType()); } else { expectedType2 = expectedType2.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver));
} else if (tp.getBounds().size() == 1) { ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0); if (bound.isExtends()) { expectedType = expectedType.replaceTypeVariables(tp, ResolvedWildcard.extendsBound(bound.getType())); } else { expectedType = expectedType.replaceTypeVariables(tp, ResolvedWildcard.superBound(bound.getType())); } else if (tp.getBounds().size() == 1) { ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0); if (bound.isExtends()) { expectedType2 = expectedType2.replaceTypeVariables(tp, bound.getType()); } else { expectedType2 = expectedType2.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver));
} else if (typeOfScope.isTypeVariable()) { for (ResolvedTypeParameterDeclaration.Bound bound : typeOfScope.asTypeParameter().getBounds()) { SymbolReference<ResolvedMethodDeclaration> res = MethodResolutionLogic.solveMethodInType(bound.getType().asReferenceType().getTypeDeclaration(), name, argumentsTypes, false, typeSolver); if (res.isSolved()) { return res;
Collection<ResolvedReferenceTypeDeclaration> result = new ArrayList<>(); for (ResolvedTypeParameterDeclaration.Bound bound : typeOfScope.asTypeParameter().getBounds()) { result.add(bound.getType().asReferenceType().getTypeDeclaration());
ResolvedType T = bound.getType(); Substitution substitution = Substitution.empty(); for (int j=0;j<typeParameterDeclarations.size();j++) {
Collection<ResolvedReferenceTypeDeclaration> result = new ArrayList<>(); for (ResolvedTypeParameterDeclaration.Bound bound : typeOfScope.asTypeParameter().getBounds()) { result.add(bound.getType().asReferenceType().getTypeDeclaration());
throw new UnsupportedOperationException(); } else if (bounds.size() == 1) { return bounds.get(0).getType(); } else { return new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver); throw new UnsupportedOperationException(); } else if (bounds.size() == 1) { return bounds.get(0).getType(); } else { return new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver);
ResolvedType T = bound.getType(); Substitution substitution = Substitution.empty(); for (int j=0;j<typeParameterDeclarations.size();j++) {
throw new UnsupportedOperationException(); } else if (bounds.size() == 1) { return bounds.get(0).getType(); } else { return new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver); throw new UnsupportedOperationException(); } else if (bounds.size() == 1) { return bounds.get(0).getType(); } else { return new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver);
public static ResolvedType replaceTypeParam(ResolvedType type, ResolvedTypeParameterDeclaration tp, TypeSolver typeSolver) { if (type.isTypeVariable() || type.isWildcard()) { if (type.describe().equals(tp.getName())) { List<ResolvedTypeParameterDeclaration.Bound> bounds = tp.getBounds(); if (bounds.size() > 1) { throw new UnsupportedOperationException(); } else if (bounds.size() == 1) { return bounds.get(0).getType(); } else { return new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver); } } return type; } else if (type.isPrimitive()) { return type; } else if (type.isArray()) { return new ResolvedArrayType(replaceTypeParam(type.asArrayType().getComponentType(), tp, typeSolver)); } else if (type.isReferenceType()) { ResolvedReferenceType result = type.asReferenceType(); result = result.transformTypeParameters(typeParam -> replaceTypeParam(typeParam, tp, typeSolver)).asReferenceType(); return result; } else { throw new UnsupportedOperationException("Replacing " + type + ", param " + tp + " with " + type.getClass().getCanonicalName()); } }
@Test public void nodesTypeIsCorrect() throws IOException, ParseException { CompilationUnit cu = parse("com/github/javaparser/utils/PositionUtils"); NameExpr nodes = Navigator.findAllNodesOfGivenClass(cu, NameExpr.class).stream().filter(it -> it.getName() != null && it.getName().getId().equals("nodes")).findFirst().get(); ResolvedType type = JavaParserFacade.get(TYPESOLVER).solve(nodes).getCorrespondingDeclaration().getType(); assertEquals("java.util.List<T>", type.describe()); assertEquals(1, type.asReferenceType().typeParametersValues().size()); assertEquals(true, type.asReferenceType().typeParametersValues().get(0).isTypeVariable()); assertEquals("T", type.asReferenceType().typeParametersValues().get(0).asTypeParameter().getName()); assertEquals("com.github.javaparser.utils.PositionUtils.sortByBeginPosition(java.util.List<T>).T", type.asReferenceType().typeParametersValues().get(0).asTypeParameter().getQualifiedName()); assertEquals(1, type.asReferenceType().typeParametersValues().get(0).asTypeParameter().getBounds().size()); ResolvedTypeParameterDeclaration.Bound bound = type.asReferenceType().typeParametersValues().get(0).asTypeParameter().getBounds().get(0); assertEquals(true, bound.isExtends()); assertEquals("com.github.javaparser.ast.Node", bound.getType().describe()); }
@Override public List<Bound> getBounds() { return Arrays.stream(typeVariable.getBounds()).map((refB) -> Bound.extendsBound(ReflectionFactory.typeUsageFor(refB, typeSolver))).collect(Collectors.toList()); }
private Bound toBound(ClassOrInterfaceType classOrInterfaceType, TypeSolver typeSolver) { ResolvedType type = JavaParserFacade.get(typeSolver).convertToUsage(classOrInterfaceType, classOrInterfaceType); return Bound.extendsBound(type); }
@Override public List<Bound> getBounds() { return Arrays.stream(typeVariable.getBounds()).map((refB) -> Bound.extendsBound(ReflectionFactory.typeUsageFor(refB, typeSolver))).collect(Collectors.toList()); }