mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
explicit -> diamond: ignore invalid types (IDEA-155017)
This commit is contained in:
@@ -158,38 +158,38 @@ public class PsiDiamondTypeUtil {
|
||||
boolean constructorRef,
|
||||
@Nullable PsiMethod method,
|
||||
PsiTypeParameter[] typeParameters) {
|
||||
final PsiElement copy;
|
||||
final PsiType typeByParent = PsiTypesUtil.getExpectedTypeByParent(expression);
|
||||
if (typeByParent != null) {
|
||||
final String arrayInitializer = "new " + typeByParent.getCanonicalText() + "[]{0}";
|
||||
final PsiNewExpression newExpr =
|
||||
(PsiNewExpression)JavaPsiFacade.getInstance(expression.getProject()).getElementFactory().createExpressionFromText(arrayInitializer, expression);
|
||||
final PsiArrayInitializerExpression initializer = newExpr.getArrayInitializer();
|
||||
LOG.assertTrue(initializer != null);
|
||||
copy = initializer.getInitializers()[0].replace(expression);
|
||||
}
|
||||
else {
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
final int offset = (argumentList != null ? argumentList : expression).getTextRange().getStartOffset();
|
||||
final PsiCall call = LambdaUtil.treeWalkUp(expression);
|
||||
if (call != null) {
|
||||
final PsiCall callCopy = LambdaUtil.copyTopLevelCall(call);
|
||||
copy = callCopy != null ? callCopy.findElementAt(offset - call.getTextRange().getStartOffset()) : null;
|
||||
try {
|
||||
final PsiElement copy;
|
||||
final PsiType typeByParent = PsiTypesUtil.getExpectedTypeByParent(expression);
|
||||
if (typeByParent != null) {
|
||||
final String arrayInitializer = "new " + typeByParent.getCanonicalText() + "[]{0}";
|
||||
final PsiNewExpression newExpr =
|
||||
(PsiNewExpression)JavaPsiFacade.getInstance(expression.getProject()).getElementFactory().createExpressionFromText(arrayInitializer, expression);
|
||||
final PsiArrayInitializerExpression initializer = newExpr.getArrayInitializer();
|
||||
LOG.assertTrue(initializer != null);
|
||||
copy = initializer.getInitializers()[0].replace(expression);
|
||||
}
|
||||
else {
|
||||
final PsiFile containingFile = expression.getContainingFile();
|
||||
final PsiFile fileCopy = (PsiFile)containingFile.copy();
|
||||
copy = fileCopy.findElementAt(offset);
|
||||
if (method != null && method.getContainingFile() == containingFile) {
|
||||
final PsiElement startMethodElementInCopy = fileCopy.findElementAt(method.getTextOffset());
|
||||
method = PsiTreeUtil.getParentOfType(startMethodElementInCopy, PsiMethod.class);
|
||||
LOG.assertTrue(method != null, startMethodElementInCopy);
|
||||
else {
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
final int offset = (argumentList != null ? argumentList : expression).getTextRange().getStartOffset();
|
||||
final PsiCall call = LambdaUtil.treeWalkUp(expression);
|
||||
if (call != null) {
|
||||
final PsiCall callCopy = LambdaUtil.copyTopLevelCall(call);
|
||||
copy = callCopy != null ? callCopy.findElementAt(offset - call.getTextRange().getStartOffset()) : null;
|
||||
}
|
||||
else {
|
||||
final PsiFile containingFile = expression.getContainingFile();
|
||||
final PsiFile fileCopy = (PsiFile)containingFile.copy();
|
||||
copy = fileCopy.findElementAt(offset);
|
||||
if (method != null && method.getContainingFile() == containingFile) {
|
||||
final PsiElement startMethodElementInCopy = fileCopy.findElementAt(method.getTextOffset());
|
||||
method = PsiTreeUtil.getParentOfType(startMethodElementInCopy, PsiMethod.class);
|
||||
LOG.assertTrue(method != null, startMethodElementInCopy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
final PsiCallExpression exprCopy = PsiTreeUtil.getParentOfType(copy, PsiCallExpression.class, false);
|
||||
if (exprCopy != null) {
|
||||
try {
|
||||
final PsiCallExpression exprCopy = PsiTreeUtil.getParentOfType(copy, PsiCallExpression.class, false);
|
||||
if (exprCopy != null) {
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(exprCopy.getProject()).getElementFactory();
|
||||
if (constructorRef) {
|
||||
if (!(exprCopy instanceof PsiNewExpression) || !isInferenceEquivalent(typeArguments, elementFactory, (PsiNewExpression)exprCopy)) {
|
||||
@@ -203,10 +203,10 @@ public class PsiDiamondTypeUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.info(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with <>" "false"
|
||||
import java.util.ArrayList;
|
||||
class BaseClass {}
|
||||
|
||||
public class IllegalStringException {
|
||||
|
||||
void foo() {
|
||||
Map<StList<BaseClass> listBaseClass = new ArrayList<BaseC<caret>lass>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user