EA-91047 - IOE: PsiJavaParserFacadeImpl.createExpressionFromText

This commit is contained in:
Anna.Kozlova
2016-11-02 16:02:39 +01:00
parent 15ca425f25
commit 8067101fcf
3 changed files with 23 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.util.PsiTypesUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -61,7 +63,7 @@ public class AddNewArrayExpressionFix implements IntentionAction {
PsiManager manager = file.getManager();
PsiType type = getType();
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
@NonNls String text = "new " + type.getPresentableText() + "[]{}";
@NonNls String text = "new " + type.getCanonicalText() + "[]{}";
PsiNewExpression newExpr = (PsiNewExpression) factory.createExpressionFromText(text, null);
newExpr.getArrayInitializer().replace(myInitializer);
newExpr = (PsiNewExpression) CodeStyleManager.getInstance(manager.getProject()).reformat(newExpr);
@@ -85,7 +87,9 @@ public class AddNewArrayExpressionFix implements IntentionAction {
}
private static PsiType validateType(PsiType type) {
return LambdaUtil.notInferredType(type) ? null : type;
if (PsiType.NULL.equals(type)) return null;
return LambdaUtil.notInferredType(type) || !PsiTypesUtil.isDenotableType(type) ? null
: TypeConversionUtil.erasure(type);
}
@Override

View File

@@ -0,0 +1,8 @@
// "Add 'new List[]'" "true"
import java.util.List;
class c {
void f(List<String> l) {
List<String>[] a;
a = new List[]{l};
}
}

View File

@@ -0,0 +1,8 @@
// "Add 'new List[]'" "true"
import java.util.List;
class c {
void f(List<String> l) {
List<String>[] a;
a = <caret>{l};
}
}