mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
override/implement: transform nullability annotations according to user settings (IDEA-233024)
annotation parameters may be removed GitOrigin-RevId: 6c959fcbbd04d84a72bd23a61734f731b5ce9332
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e01a95ccc1
commit
4536567535
+17
@@ -7,6 +7,7 @@ import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
@@ -26,6 +27,22 @@ public class OverrideImplementsAnnotationsHandlerImpl implements OverrideImpleme
|
||||
return ArrayUtilRt.toStringArray(annotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferToTarget(String annotation, PsiModifierListOwner source, PsiModifierListOwner target) {
|
||||
NullableNotNullManager manager = NullableNotNullManager.getInstance(source.getProject());
|
||||
String correctedAnnotation;
|
||||
if (manager.getNullables().contains(annotation) && !annotation.equals(manager.getDefaultNullable())) {
|
||||
correctedAnnotation = manager.getDefaultNullable();
|
||||
}
|
||||
else if (manager.getNotNulls().contains(annotation) && !annotation.equals(manager.getDefaultNotNull())) {
|
||||
correctedAnnotation = manager.getDefaultNotNull();
|
||||
}
|
||||
else {
|
||||
correctedAnnotation = annotation;
|
||||
}
|
||||
OverrideImplementsAnnotationsHandler.super.transferToTarget(correctedAnnotation, source, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAnnotations(@NotNull PsiFile file) {
|
||||
List<String> annotations = getCoreAnnotations(file.getProject());
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package p;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
class M implements Map {
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsKey(Object o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsValue(Object o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object get(Object o) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@N
|
||||
public Object put(Object o, Object o2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object remove(Object o) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void putAll(@NN Map map) {
|
||||
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
@NN
|
||||
public Set keySet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NN
|
||||
public Collection values() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NN
|
||||
public Set<Entry> entrySet() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@interface N {}
|
||||
@interface NN {}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p;
|
||||
import java.util.Map;
|
||||
class M implements Map {
|
||||
<caret>
|
||||
}
|
||||
|
||||
@interface N {}
|
||||
@interface NN {}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.java.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInsight.generation.JavaOverrideMethodsHandler;
|
||||
import com.intellij.codeInsight.generation.OverrideImplementExploreUtil;
|
||||
import com.intellij.codeInsight.generation.OverrideImplementUtil;
|
||||
@@ -33,6 +34,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.testFramework.LightJavaCodeInsightTestCase;
|
||||
import com.intellij.testFramework.MapDataContext;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.FunctionUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -54,6 +56,29 @@ public class OverrideImplement15Test extends LightJavaCodeInsightTestCase {
|
||||
|
||||
public void testSimple() { doTest(true); }
|
||||
public void testAnnotation() { doTest(true); }
|
||||
public void testTransformJBAnnotations() {
|
||||
NullableNotNullManager nullableNotNullManager = NullableNotNullManager.getInstance(getProject());
|
||||
String defaultNotNull = nullableNotNullManager.getDefaultNotNull();
|
||||
List<String> notNulls = nullableNotNullManager.getNotNulls();
|
||||
String defaultNullable = nullableNotNullManager.getDefaultNullable();
|
||||
List<String> nullables = nullableNotNullManager.getNullables();
|
||||
|
||||
try {
|
||||
nullableNotNullManager.setNotNulls(ArrayUtil.append(ArrayUtil.toStringArray(notNulls),"p.NN"));
|
||||
nullableNotNullManager.setDefaultNotNull("p.NN");
|
||||
|
||||
nullableNotNullManager.setNullables(ArrayUtil.append(ArrayUtil.toStringArray(nullables),"p.N"));
|
||||
nullableNotNullManager.setDefaultNullable("p.N");
|
||||
doTest(true, true);
|
||||
}
|
||||
finally {
|
||||
nullableNotNullManager.setDefaultNotNull(defaultNotNull);
|
||||
nullableNotNullManager.setNotNulls(ArrayUtil.toStringArray(notNulls));
|
||||
|
||||
nullableNotNullManager.setDefaultNullable(defaultNullable);
|
||||
nullableNotNullManager.setNullables(ArrayUtil.toStringArray(nullables));
|
||||
}
|
||||
}
|
||||
public void testJavadocForChangedParamName() { doTest(true); }
|
||||
public void testThrowsListFromMethodHierarchy() { doTest(true); }
|
||||
public void testThrowsListUnrelatedMethods() { doTest(true); }
|
||||
|
||||
Reference in New Issue
Block a user