IG: generate serialVersionUID correctly for generic parameters
authorBas Leijdekkers <basleijdekkers@gmail.com>
Mon, 22 Jun 2015 15:11:19 +0000 (17:11 +0200)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Tue, 23 Jun 2015 13:56:52 +0000 (15:56 +0200)
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MemberSignature.java
plugins/InspectionGadgets/test/com/siyeh/igfixes/serialization/serialVersionUID/GenericParameter.after.java [new file with mode: 0644]
plugins/InspectionGadgets/test/com/siyeh/igfixes/serialization/serialVersionUID/GenericParameter.java [new file with mode: 0644]
plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/serialization/AddSerialVersionUIDFixTest.java

index 36a111cdfc957e9a2fc59cf6d5f3b863bade1693..442bb79a3f779b2f684c0c0c8b9d84a04760dda7 100644 (file)
@@ -174,6 +174,14 @@ public class MemberSignature implements Comparable<MemberSignature> {
       if (internalType instanceof PsiClassType) {
         final PsiClassType classType = (PsiClassType)internalType;
         PsiClass psiClass = classType.resolve();
+        if (psiClass instanceof PsiTypeParameter) {
+          final PsiTypeParameter typeParameter = (PsiTypeParameter)psiClass;
+          final PsiReferenceList extendsList = typeParameter.getExtendsList();
+          final PsiClassType[] types = extendsList.getReferencedTypes();
+          if (types.length > 0) {
+            psiClass = types[0].resolve();
+          }
+        }
         if (psiClass != null) {
           final StringBuilder postFix = new StringBuilder("");
           PsiClass containingClass = psiClass.getContainingClass();
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/serialization/serialVersionUID/GenericParameter.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/serialization/serialVersionUID/GenericParameter.after.java
new file mode 100644 (file)
index 0000000..b344e9d
--- /dev/null
@@ -0,0 +1,8 @@
+import java.io.Serializable;
+
+public class GenericParameter implements Serializable {
+
+    private static final long serialVersionUID = 8306950084505752582L;
+
+    <T extends String> void s(T t) {}
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/serialization/serialVersionUID/GenericParameter.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/serialization/serialVersionUID/GenericParameter.java
new file mode 100644 (file)
index 0000000..7f6c4d9
--- /dev/null
@@ -0,0 +1,6 @@
+import java.io.Serializable;
+
+public class <caret>GenericParameter implements Serializable {
+
+    <T extends String> void s(T t) {}
+}
\ No newline at end of file
index e88bb7e2352944eb7313b30345114e746ed9f7cb..c2d340cf56a5c96e3c86fd2bd7c21503195dda35 100644 (file)
@@ -33,4 +33,5 @@ public class AddSerialVersionUIDFixTest extends IGQuickFixesTestCase {
   }
 
   public void testClassAccess() { doTest(); }
+  public void testGenericParameter() { doTest(); }
 }