mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diamond: replace wildcards with corresponding bound when inference (IDEA-66124)
This commit is contained in:
+7
-5
@@ -27,6 +27,8 @@ import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 1/28/11
|
||||
@@ -77,13 +79,13 @@ public class ExplicitTypeCanBeDiamondInspection extends BaseJavaLocalInspectionT
|
||||
if (typeElements.length == 1 && typeElements[0].getType() instanceof PsiDiamondType) return;
|
||||
final PsiDiamondType.DiamondInferenceResult inferenceResult = PsiDiamondType.resolveInferredTypes(expression);
|
||||
if (inferenceResult.getErrorMessage() == null) {
|
||||
final PsiType[] types = inferenceResult.getTypes();
|
||||
final List<PsiType> types = inferenceResult.getInferredTypes();
|
||||
final PsiType[] typeArguments = parameterList.getTypeArguments();
|
||||
if (types.length == typeArguments.length) {
|
||||
if (types.size() == typeArguments.length) {
|
||||
for (int i = 0, typeArgumentsLength = typeArguments.length; i < typeArgumentsLength; i++) {
|
||||
PsiType typeArgument = typeArguments[i];
|
||||
if (types[i] instanceof PsiWildcardType) {
|
||||
final PsiWildcardType wildcardType = (PsiWildcardType)types[i];
|
||||
if (types.get(i) instanceof PsiWildcardType) {
|
||||
final PsiWildcardType wildcardType = (PsiWildcardType)types.get(i);
|
||||
final PsiType bound = wildcardType.getBound();
|
||||
if (bound != null) {
|
||||
if (wildcardType.isExtends()) {
|
||||
@@ -93,7 +95,7 @@ public class ExplicitTypeCanBeDiamondInspection extends BaseJavaLocalInspectionT
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!typeArgument.equals(types[i])) {
|
||||
if (!typeArgument.equals(types.get(i))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +259,22 @@ public class PsiDiamondType extends PsiType {
|
||||
if (myErrorMessage != null) {
|
||||
return NULL_TYPES;
|
||||
}
|
||||
return myInferredTypes.toArray(new PsiType[myInferredTypes.size()]);
|
||||
final PsiType[] result = new PsiType[myInferredTypes.size()];
|
||||
for (int i = 0, myInferredTypesSize = myInferredTypes.size(); i < myInferredTypesSize; i++) {
|
||||
PsiType inferredType = myInferredTypes.get(i);
|
||||
if (inferredType instanceof PsiWildcardType) {
|
||||
final PsiType bound = ((PsiWildcardType)inferredType).getBound();
|
||||
result[i] = bound != null ? bound : PsiType.getJavaLangObject(PsiManager.getInstance(myProject), GlobalSearchScope.allScope(myProject));
|
||||
}
|
||||
else {
|
||||
result[i] = inferredType;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<PsiType> getInferredTypes() {
|
||||
return myInferredTypes;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
@@ -274,13 +289,7 @@ public class PsiDiamondType extends PsiType {
|
||||
myErrorMessage = "Cannot infer type arguments for " +
|
||||
myNewExpressionPresentableText + " because type " + psiType.getPresentableText() + " inferred is not allowed in current context";
|
||||
} else {
|
||||
if (psiType instanceof PsiWildcardType) {
|
||||
final PsiType bound = ((PsiWildcardType)psiType).getBound();
|
||||
myInferredTypes.add(bound != null ? bound : PsiType.getJavaLangObject(PsiManager.getInstance(myProject), GlobalSearchScope.allScope(myProject)));
|
||||
}
|
||||
else {
|
||||
myInferredTypes.add(psiType);
|
||||
}
|
||||
myInferredTypes.add(psiType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user