mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-05 08:06:56 +07:00
IDEA-189985 SerializableCtorInspection: cleanups
GitOrigin-RevId: 6704189a3e5c60c13665539abfae403648513d54
This commit is contained in:
committed by
intellij-monorepo-bot
parent
35c4d3c933
commit
7334c80250
@@ -49,7 +49,7 @@ public class SerializableCtorInspection extends DevKitUastInspectionBase {
|
||||
if (!hasFieldWithName(aClass, CommonClassNames.SERIAL_VERSION_UID_FIELD_NAME)) return null;
|
||||
ProblemsHolder holder = createProblemsHolder(aClass, manager, isOnTheFly);
|
||||
for (UMethod constructor : getConstructors(aClass)) {
|
||||
if (!isAnnotated(constructor, PROPERTY_MAPPING_ANNOTATION)) {
|
||||
if (!isAnnotatedWithPropertyMapping(constructor)) {
|
||||
PsiElement constructorAnchor = UElementKt.getSourcePsiElement(constructor.getUastAnchor());
|
||||
if (constructorAnchor != null) {
|
||||
holder.registerProblem(constructorAnchor, DevKitBundle.message("inspection.serializable.constructor.message"),
|
||||
@@ -77,12 +77,11 @@ public class SerializableCtorInspection extends DevKitUastInspectionBase {
|
||||
return ContainerUtil.filter(aClass.getMethods(), method -> method.isConstructor());
|
||||
}
|
||||
|
||||
private static boolean isAnnotated(UMethod constructor, String annotationFqn) {
|
||||
private static boolean isAnnotatedWithPropertyMapping(UMethod constructor) {
|
||||
return ContainerUtil.exists(constructor.getUAnnotations(),
|
||||
annotation -> annotationFqn.equals(annotation.getQualifiedName()));
|
||||
annotation -> PROPERTY_MAPPING_ANNOTATION.equals(annotation.getQualifiedName()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static LocalQuickFix[] createFixes(@NotNull UClass aClass, ProblemsHolder holder, UMethod constructor) {
|
||||
return JavaLanguage.INSTANCE.is(aClass.getLang()) ?
|
||||
new LocalQuickFix[]{
|
||||
|
||||
@@ -19,42 +19,34 @@ public class SerializableCtorInspectionTest extends SerializableCtorInspectionTe
|
||||
}
|
||||
|
||||
public void testCorrectAnnotatedConstructor() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testSerializableClassButPropertyMappingAnnotationNotAvailable() {
|
||||
// no @PropertyMapping in the project
|
||||
doTest();
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testNotSerializableClass() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSerializableClassButDoesNotContainSerialVersionUidField() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassContainingSerialVersionUidFieldButIsNotSerializable() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotAnnotatedConstructor() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotAnnotatedMultipleConstructors() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotAnnotatedAndAnnotatedConstructorsInSingleClass() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,42 +20,34 @@ public class KtSerializableCtorInspectionTest extends SerializableCtorInspection
|
||||
}
|
||||
|
||||
public void testCorrectAnnotatedConstructor() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSerializableClassButPropertyMappingAnnotationNotAvailable() {
|
||||
// no @PropertyMapping in the project
|
||||
doTest();
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testNotSerializableClass() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSerializableClassButDoesNotContainSerialVersionUidField() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassContainingSerialVersionUidFieldButIsNotSerializable() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotAnnotatedConstructor() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotAnnotatedMultipleConstructors() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotAnnotatedAndAnnotatedConstructorsInSingleClass() {
|
||||
addPropertyMappingClass();
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,15 +14,22 @@ public abstract class SerializableCtorInspectionTestBase extends LightJavaCodeIn
|
||||
myFixture.enableInspections(new SerializableCtorInspection());
|
||||
}
|
||||
|
||||
protected void addPropertyMappingClass() {
|
||||
myFixture.addClass("package com.intellij.serialization;\n" +
|
||||
"public @interface PropertyMapping { String[] value(); }");
|
||||
protected void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
protected void doTest() {
|
||||
protected void doTest(boolean disablePropertyMappingClass) {
|
||||
if (!disablePropertyMappingClass) {
|
||||
addPropertyMappingClass();
|
||||
}
|
||||
myFixture.testHighlighting(getTestName(false) + '.' + getFileExtension());
|
||||
}
|
||||
|
||||
private void addPropertyMappingClass() {
|
||||
myFixture.addClass("package com.intellij.serialization;\n" +
|
||||
"public @interface PropertyMapping { String[] value(); }");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract String getFileExtension();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user