From 766fc1390d833f1694f67dccc40c99033b88e452 Mon Sep 17 00:00:00 2001 From: Alexandru-Constantin Bledea Date: Mon, 7 Sep 2015 20:44:51 +0300 Subject: [PATCH] Decompiler name shadowing resolution https://github.com/JetBrains/intellij-community/pull/295 --- .../main/collectors/ImportCollector.java | 3 ++- .../java/decompiler/SingleClassesTest.java | 1 + testData/classes/ext/Shadow$B.class | Bin 0 -> 243 bytes testData/classes/ext/Shadow.class | Bin 0 -> 243 bytes testData/classes/pkg/Shadow.class | Bin 0 -> 190 bytes testData/classes/pkg/TestShadowing.class | Bin 0 -> 342 bytes testData/results/TestShadowing.dec | 6 ++++++ testData/src/ext/Shadow.java | 6 ++++++ testData/src/pkg/Shadow.java | 4 ++++ testData/src/pkg/TestShadowing.java | 5 +++++ 10 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 testData/classes/ext/Shadow$B.class create mode 100644 testData/classes/ext/Shadow.class create mode 100644 testData/classes/pkg/Shadow.class create mode 100644 testData/classes/pkg/TestShadowing.class create mode 100644 testData/results/TestShadowing.dec create mode 100644 testData/src/ext/Shadow.java create mode 100644 testData/src/pkg/Shadow.java create mode 100644 testData/src/pkg/TestShadowing.java diff --git a/src/org/jetbrains/java/decompiler/main/collectors/ImportCollector.java b/src/org/jetbrains/java/decompiler/main/collectors/ImportCollector.java index 05dc835..ada6abc 100644 --- a/src/org/jetbrains/java/decompiler/main/collectors/ImportCollector.java +++ b/src/org/jetbrains/java/decompiler/main/collectors/ImportCollector.java @@ -99,7 +99,8 @@ public class ImportCollector { if (existsDefaultClass || (mapSimpleNames.containsKey(nshort) && !npackage.equals(mapSimpleNames.get(nshort)))) { - return fullname; + // don't return full name because if the class is a inner class, full name refers to the parent full name, not the child full name + return retname == null ? fullname : (npackage + "." + retname); } else if (!mapSimpleNames.containsKey(nshort)) { mapSimpleNames.put(nshort, npackage); diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index e85cd67..0da0d3b 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -61,4 +61,5 @@ public class SingleClassesTest extends SingleClassesTestBase { @Test public void testInnerLocalPkg() { doTest("pkg/TestInnerLocalPkg"); } @Test public void testInnerSignature() { doTest("pkg/TestInnerSignature"); } @Test public void testParameterizedTypes() { doTest("pkg/TestParameterizedTypes"); } + @Test public void testShadowing() { doTest("pkg/TestShadowing", "pkg/Shadow", "ext/Shadow"); } } diff --git a/testData/classes/ext/Shadow$B.class b/testData/classes/ext/Shadow$B.class new file mode 100644 index 0000000000000000000000000000000000000000..eeb9d384874454df5be278d03747e9da23ae6fa6 GIT binary patch literal 243 zcmYLD%?`m}5S%S-siGdhLE?aeUL3`NL?RIm75A@vp;BLy{@}HoBn}?HLy2u2Y_dC< znapJ0pXUp}2rUaGSSD-}O@c8FRFF;xrCxtaD9@t3Bs7i(SWlt8@pLMa)~LXjjgAvk%!4TU#ZKQ9~6CMvGMqHPli40_$KbJOBUy literal 0 HcmV?d00001 diff --git a/testData/classes/ext/Shadow.class b/testData/classes/ext/Shadow.class new file mode 100644 index 0000000000000000000000000000000000000000..e576dfd9b0fdfd1b1feffd31f52d1a42bb23e849 GIT binary patch literal 243 zcmYL@%?`m(5QWcZDOGiHVuu$e)UUT<{2~8ciu~0jA6&z%k^Vxsi s_0U0qU(>};=>@D6cI~eRii11o_Kj`U5@W#Rp(^(R943IxRI?%~AJWb&K>z>% literal 0 HcmV?d00001 diff --git a/testData/classes/pkg/Shadow.class b/testData/classes/pkg/Shadow.class new file mode 100644 index 0000000000000000000000000000000000000000..61ed27b36a1d424dc1237961c416e6f9a4490b12 GIT binary patch literal 190 zcmX^0Z`VEs1_l!bUM>b^1}=66ZgvJ9Mg}&U%)HDJJ4Oa(4b3n{1{UZ1lvG9rexJ;| zRKL>Pq|~C2#H1Xc2v=}^X;E^jTPBFZ9h{Mvl3%Wul~|U@!@$D83Y0I%PS=MBGcpK( zB=mC<^V0SGld@8iOBfUxn1Hr|03#3rbpS~=AWs&|XJBB}+RnhZ5iHFPB-wz%3_xX! L3>-k3iGdRUsiz`b literal 0 HcmV?d00001 diff --git a/testData/classes/pkg/TestShadowing.class b/testData/classes/pkg/TestShadowing.class new file mode 100644 index 0000000000000000000000000000000000000000..228fd8f7571f13eb43fd7fd3d86211b334142ec8 GIT binary patch literal 342 zcmY*V%Syvg5IvK`#H6uJ>T~JBg%&XzcZ!P^1fkePi{SDmy~bPPO-WMqw_Hd;!4L4G z#7Pv?#SCX2=Nx7}K40Gf9An3WjnKim2Lqvt6>K=zbg)HeDP2}VCvtStClH5!p|vaq znJ7zH652!gR7K-kG0h+M`X>bYRB2V65zPIAD}pu1r;^YaDlIP;_pvM{BF?zujq^p3 z$a7T}-H9x#ZxN-_qnUURK3eb{Y_sEE2OkbRLO8!mqkkkqP}8DJ=rkI|GnrIu@=L`o z-(~Z?#K9Urh)uY&#?>LrW)}38pxzsd>m|$=SkKL7n{)jh@Rr3&20Dxl1aO-PG45g& F?iW35LgoMf literal 0 HcmV?d00001 diff --git a/testData/results/TestShadowing.dec b/testData/results/TestShadowing.dec new file mode 100644 index 0000000..45adbea --- /dev/null +++ b/testData/results/TestShadowing.dec @@ -0,0 +1,6 @@ +package pkg; + +class TestShadowing { + ext.Shadow.B instanceOfB = new ext.Shadow.B(); +} + diff --git a/testData/src/ext/Shadow.java b/testData/src/ext/Shadow.java new file mode 100644 index 0000000..02869ca --- /dev/null +++ b/testData/src/ext/Shadow.java @@ -0,0 +1,6 @@ +package ext; + +// companion class for pkg/TestShadowing.java +public class Shadow { + public static class B { } +} \ No newline at end of file diff --git a/testData/src/pkg/Shadow.java b/testData/src/pkg/Shadow.java new file mode 100644 index 0000000..d76fb78 --- /dev/null +++ b/testData/src/pkg/Shadow.java @@ -0,0 +1,4 @@ +package pkg; + +// companion class for pkg/TestShadowing.java +public class Shadow { } \ No newline at end of file diff --git a/testData/src/pkg/TestShadowing.java b/testData/src/pkg/TestShadowing.java new file mode 100644 index 0000000..c8792b2 --- /dev/null +++ b/testData/src/pkg/TestShadowing.java @@ -0,0 +1,5 @@ +package pkg; + +class TestShadowing { + ext.Shadow.B instanceOfB = new ext.Shadow.B(); +} \ No newline at end of file