From 876740dd0e9804ec2db08b13f06a5481efa959f6 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 2 Mar 2016 20:44:56 +0300 Subject: [PATCH] decompiler: fixed incorrect method references from single letter classes --- .../java/decompiler/main/ClassWriter.java | 4 +-- .../java/decompiler/SingleClassesTest.java | 1 + testData/classes/pkg/R.class | Bin 0 -> 250 bytes .../pkg/TestMethodReferenceLetterClass.class | Bin 0 -> 839 bytes .../TestMethodReferenceLetterClass.dec | 18 ++++++++++++ .../pkg/TestMethodReferenceLetterClass.java | 27 ++++++++++++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 testData/classes/pkg/R.class create mode 100644 testData/classes/pkg/TestMethodReferenceLetterClass.class create mode 100644 testData/results/TestMethodReferenceLetterClass.dec create mode 100644 testData/src/pkg/TestMethodReferenceLetterClass.java diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index b55f29d..dc0f3fc 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,7 +98,7 @@ public class ClassWriter { } else { // reference to a static method - buffer.append(ExprProcessor.getCastTypeName(new VarType(node.lambdaInformation.content_class_name, false))); + buffer.append(ExprProcessor.getCastTypeName(new VarType(node.lambdaInformation.content_class_name, true))); } buffer.append("::"); diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index 6ef71c0..e3a6f56 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -80,6 +80,7 @@ public class SingleClassesTest { @Test public void testStringConcat() { doTest("pkg/TestStringConcat"); } @Test public void testJava9StringConcat() { doTest("java9/TestJava9StringConcat"); } @Test public void testMethodReferenceSameName() { doTest("pkg/TestMethodReferenceSameName"); } + @Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); } protected void doTest(String testFile, String... companionFiles) { ConsoleDecompiler decompiler = fixture.getDecompiler(); diff --git a/testData/classes/pkg/R.class b/testData/classes/pkg/R.class new file mode 100644 index 0000000000000000000000000000000000000000..7c9c9e22c83c2a30917e4935a229eedcab9d1397 GIT binary patch literal 250 zcmZWjyGq1R5IvKp#$DZ3K@e=z!ZenPO<=3ILJamd$wU)kF5KMsUsl2vet;h(&b8Ra zftmA|Q=IRg-4}p694GK`6k`!%Nr=|n*x7r6e|7y#2r}I;;Uw=y-p+3on^IMSIDV@& zA$iiXsd>{m>$2p@KCpe&O~EZ29&66oS~l6Brs=j_L&JXr}s`UpE0B*F0J6Z9d35X+7J%u`_p`>0bc`Y(1S_MtpHB)>#BD&YVC literal 0 HcmV?d00001 diff --git a/testData/classes/pkg/TestMethodReferenceLetterClass.class b/testData/classes/pkg/TestMethodReferenceLetterClass.class new file mode 100644 index 0000000000000000000000000000000000000000..74bb32df8d438abca6a2b7ee6fc4e0a96342aef2 GIT binary patch literal 839 zcmbVKO>fgc5Pg$0ad8a^Eh(REY12}t2Ylfc#DPc%Bm+_s^}cZ?#jUd&+3QOES)7o1 z;0GXn6JlIPBz!0bEO}?<&6}B>+4=V4`YV7JIB~HCZ&UP52U`yA5$Z2v9otugs^2*! zto6*835_t;{2`x?I321{B1m;)48a|kJdOBGTtMw1XZAhYPiEZb38$`I4z*cVF_6-7L=ggw7g@^c#}!6es_jg1a^MrZky)2@R(4^MIE z;K;+X;{FGV^s&A)7aW9YIvOkKMom;?O?pMxm@X^_z7!0NxyWY(@1553sc=U4zI@$z zzH%;al^!RY9hQOJrLG1xjrG|w@>}5WYR3QPEK9DAosa8g@bj`gl_Z1Ma+g4TS&xY^ z4myORzb5ss&g89E^RSPq>}v54>!>l0?={zJNZ9LRgoxa06TN-}*&u3sw=t qxh_PwAiFnkONiT2#T7~g8)%DkC1fARIFN 5 +22 <-> 6 diff --git a/testData/src/pkg/TestMethodReferenceLetterClass.java b/testData/src/pkg/TestMethodReferenceLetterClass.java new file mode 100644 index 0000000..5f290d8 --- /dev/null +++ b/testData/src/pkg/TestMethodReferenceLetterClass.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.function.Consumer; + +public class TestMethodReferenceLetterClass { + void boo() { + Consumer foo = R::foo; + } +} + +class R { + void foo() {} +} \ No newline at end of file