mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
reformat on replace type args with <> (IDEA-138079)
This commit is contained in:
@@ -22,8 +22,9 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.PsiDiamondTypeUtil;
|
||||
import com.intellij.psi.impl.source.tree.ChildRole;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -97,7 +98,11 @@ public class ExplicitTypeCanBeDiamondInspection extends BaseJavaBatchLocalInspec
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return;
|
||||
PsiDiamondTypeUtil.replaceExplicitWithDiamond(element);
|
||||
final PsiNewExpression newExpression =
|
||||
PsiTreeUtil.getParentOfType(PsiDiamondTypeUtil.replaceExplicitWithDiamond(element), PsiNewExpression.class);
|
||||
if (newExpression != null) {
|
||||
CodeStyleManager.getInstance(project).reformat(newExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace with <>" "true"
|
||||
class Test<T> {
|
||||
public Test(String s1, String s2) {}
|
||||
|
||||
Test<String> s = new Test<>("s1",
|
||||
"s2");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace with <>" "true"
|
||||
class Test<T> {
|
||||
public Test(String s1, String s2) {}
|
||||
|
||||
Test<String> s = new Test<Str<caret>ing>("s1",
|
||||
"s2");
|
||||
|
||||
}
|
||||
@@ -17,12 +17,17 @@ package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInspection.ExplicitTypeCanBeDiamondInspection;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
//todo test3 should be checked if it compiles - as now javac infers Object instead of String?!
|
||||
public class Simplify2DiamondInspectionsTest extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
@@ -31,6 +36,26 @@ public class Simplify2DiamondInspectionsTest extends LightQuickFixParameterizedT
|
||||
};
|
||||
}
|
||||
|
||||
private boolean myAlignment;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CommonCodeStyleSettings settings = getSettings();
|
||||
myAlignment = settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS;
|
||||
settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = myAlignment;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private CommonCodeStyleSettings getSettings() {
|
||||
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user