[java-refactoring] Diagnostics for EA-248598

GitOrigin-RevId: 3665e542fe08a255cd9c0b4091718edb042518ec
This commit is contained in:
Tagir Valeev
2020-12-14 05:11:02 +00:00
committed by intellij-monorepo-bot
parent 8ecc63ba0e
commit 5bb5d6cf85
@@ -23,6 +23,8 @@ import com.intellij.openapi.actionSystem.Shortcut;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
@@ -369,6 +371,12 @@ public class JavaVariableInplaceIntroducer extends AbstractJavaInplaceIntroducer
LOG.assertTrue(initializer != null);
final PsiType type = initializer.getType();
if (((PsiReferenceExpression)parent).resolve() == null && type != null && !type.equals(psiVariable.getType())) {
if (LambdaUtil.notInferredType(type)) {
throw new RuntimeExceptionWithAttachments(
"Unexpected initializer type: " + type,
new Attachment("variable.txt", psiVariable.getText()), new Attachment("reference.txt", parent.getText()),
new Attachment("file.txt", file.getText()));
}
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
final PsiExpression castedExpr =
elementFactory.createExpressionFromText("((" + type.getCanonicalText() + ")" + referenceExpression.getText() + ")", parent);