10000 Fix issue when resolving a static method-call with only a generic variadic parameter by maartenc · Pull Request #3194 · javaparser/javaparser · GitHub
[go: up one dir, main page]

Skip to content

Fix issue when resolving a static method-call with only a generic variadic parameter #3194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Further improvements
  • Loading branch information
maartenc committed Mar 26, 2021
commit e060ef99a3d0535c19a5798c232b29d1ffbb14b9
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public boolean equals(Object o) {
if (!typeParameter.getName().equals(that.typeParameter.getName())) return false;
if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) return false;
if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) return false;
if (!typeParameter.getBounds().equals(that.typeParameter.getBounds())) return false;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.MethodCallExpr;
Expand All @@ -48,6 +49,7 @@
import com.github.javaparser.resolution.types.ResolvedWildcard;
import com.github.javaparser.symbolsolver.core.resolution.Context;
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
import com.github.javaparser.symbolsolver.logic.ConfilictingGenericTypesException;
import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
import com.github.javaparser.symbolsolver.model.resolution.Value;
Expand Down Expand Up @@ -102,6 +104,10 @@ public Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType>
if (ref.isSolved()) {
SymbolReference<ResolvedMethodDeclaration> m = MethodResolutionLogic.solveMethodInType(ref.getCorrespondingDeclaration(), name, argumentsTypes);
if (m.isSolved()) {
if (m.getCorrespondingDeclaration().getName().equals("mapAll")) {
System.out.println("m = " + m);
}

MethodUsage methodUsage = new MethodUsage(m.getCorrespondingDeclaration());
methodUsage = resolveMethodTypeParametersFromExplicitList(typeSolver, methodUsage);
methodUsage = resolveMethodTypeParameters(methodUsage, argumentsTypes);
Expand Down Expand Up @@ -235,12 +241,27 @@ private Optional<MethodUsage> solveMethodAsUsage(ResolvedReferenceType refType,
}

private void inferTypes(ResolvedType source, ResolvedType target, Map<ResolvedTypeParameterDeclaration, ResolvedType> mappings) {
if (source.equals(target)) {
return;
}
if (source.isReferenceType() && target.isReferenceType()) {
ResolvedReferenceType sourceRefType = source.asReferenceType();
ResolvedReferenceType targetRefType = target.asReferenceType();

if (!sourceRefType.getQualifiedName().equals(targetRefType.getQualifiedName())) {
List<ResolvedReferenceType> ancestors = sourceRefType.getAllAncestors();
final String formalParamTypeQName = targetRefType.getQualifiedName();
List<ResolvedType> correspondingFormalType = ancestors.stream().filter((a) -> a.getQualifiedName().equals(formalParamTypeQName)).collect(Collectors.toList());
if (correspondingFormalType.isEmpty()) {
ancestors = targetRefType.getAllAncestors();
final String actualParamTypeQname = sourceRefType.getQualifiedName();
List<ResolvedType> correspondingActualType = ancestors.stream().filter(a -> a.getQualifiedName().equals(actualParamTypeQname)).collect(Collectors.toList());
if (correspondingActualType.isEmpty()) {
throw new ConfilictingGenericTypesException(target, source);
}
correspondingFormalType = correspondingActualType;

}
sourceRefType = correspondingFormalType.get(0).asReferenceType();
}

if (sourceRefType.getQualifiedName().equals(targetRefType.getQualifiedName())) {
if (!sourceRefType.isRawType() && !targetRefType.isRawType()) {
for (int i = 0; i < sourceRefType.typeParametersValues().size(); i++) {
Expand All @@ -250,6 +271,9 @@ private void inferTypes(ResolvedType source, ResolvedType target, Map<ResolvedTy
}
return;
}
if (source.equals(target)) {
return;
}
if (source.isReferenceType() && target.isWildcard()) {
if (target.asWildcard().isBounded()) {
inferTypes(source, target.asWildcard().getBoundedType(), mappings);
Expand Down
0