mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
[java-refactoring] IDEA-369011 Refactor -> introduce constant added NotNull annotation
(cherry picked from commit 485a0861caad52b591044e221dec0e44729b4c1e) IJ-CR-158958 GitOrigin-RevId: a7555472e82a7a916c401a4e3eab30efee4279ac
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f70f3b4f3f
commit
623504d6db
@@ -22,6 +22,7 @@ import com.intellij.psi.search.PsiElementProcessor;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.FileTypeUtils;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer;
|
||||
@@ -159,7 +160,8 @@ public abstract class LocalToFieldHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static PsiField createField(PsiLocalVariable local, PsiType forcedType, String fieldName, boolean includeInitializer) {
|
||||
private static PsiField createField(PsiLocalVariable local, @NotNull PsiType forcedType, String fieldName, boolean includeInitializer) {
|
||||
forcedType = PsiTypesUtil.removeExternalAnnotations(forcedType);
|
||||
@NonNls StringBuilder pattern = new StringBuilder();
|
||||
pattern.append("private int ");
|
||||
pattern.append(fieldName);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
class X {
|
||||
void someMethod() {
|
||||
var <caret>mapOfLong = Map.of(1, 1L, 2, 2L); // refactor this line
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
class X {
|
||||
// refactor this line
|
||||
public static final Map<Integer, Long> xxx = Map.of(1, 1L, 2, 2L);
|
||||
|
||||
void someMethod() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,11 +4,14 @@ package com.intellij.java.refactoring;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightJavaCodeInsightTestCase;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -16,10 +19,17 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.JAVA_21_ANNOTATED;
|
||||
|
||||
@TestDataPath("$CONTENT_ROOT/testData")
|
||||
public class IntroduceConstantTest extends LightJavaCodeInsightTestCase {
|
||||
@NonNls private static final String BASE_PATH = "/refactoring/introduceConstant/";
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21_ANNOTATED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
@@ -49,7 +59,7 @@ public class IntroduceConstantTest extends LightJavaCodeInsightTestCase {
|
||||
|
||||
public void testNonStaticContainerForCompileTimeConstant2() { doTest(); }
|
||||
public void testStaticFieldInAnonymous() { doTest(); }
|
||||
public void testStaticFieldInAnonymousJava8() { doTest(); }
|
||||
public void testStaticFieldInAnonymousJava8() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_8, () -> doTest()); }
|
||||
|
||||
private void doTest(boolean makeEnumConstant) {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
@@ -89,6 +99,10 @@ public class IntroduceConstantTest extends LightJavaCodeInsightTestCase {
|
||||
public void testAnnotationDescription() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoExternalTypeAnnotations() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTailingErrorUnacceptableWholeLineSelection() {
|
||||
doTest();
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MockIntroduceConstantHandler extends IntroduceConstantHandler{
|
||||
protected Settings showRefactoringDialog(final Project project, final Editor editor, final PsiClass parentClass, final PsiExpression expr,
|
||||
final PsiType type, final PsiExpression[] occurrences, final PsiElement anchorElement,
|
||||
final PsiElement anchorElementIfAll) {
|
||||
return new Settings("xxx", expr, occurrences, true, true, true, InitializationPlace.IN_FIELD_DECLARATION, getVisibility(), null, null, false,
|
||||
return new Settings("xxx", expr, occurrences, true, true, true, InitializationPlace.IN_FIELD_DECLARATION, getVisibility(), null, type, false,
|
||||
myTargetClass != null ? myTargetClass : parentClass, false, false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user