IDEA-208443 Java decompiler not correctly decompiling string concatenation with recent Java
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
/*
|
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
package org.jetbrains.java.decompiler.code;
|
package org.jetbrains.java.decompiler.code;
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "SpellCheckingInspection"})
|
@SuppressWarnings({"unused", "SpellCheckingInspection"})
|
||||||
@@ -9,12 +7,16 @@ public interface CodeConstants {
|
|||||||
// BYTECODE VERSIONS
|
// BYTECODE VERSIONS
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
int BYTECODE_JAVA_LE_4 = 1;
|
int BYTECODE_JAVA_LE_4 = 48;
|
||||||
int BYTECODE_JAVA_5 = 2;
|
int BYTECODE_JAVA_5 = 49;
|
||||||
int BYTECODE_JAVA_6 = 3;
|
int BYTECODE_JAVA_6 = 50;
|
||||||
int BYTECODE_JAVA_7 = 4;
|
int BYTECODE_JAVA_7 = 51;
|
||||||
int BYTECODE_JAVA_8 = 5;
|
int BYTECODE_JAVA_8 = 52;
|
||||||
int BYTECODE_JAVA_9 = 6;
|
int BYTECODE_JAVA_9 = 53;
|
||||||
|
int BYTECODE_JAVA_10 = 54;
|
||||||
|
int BYTECODE_JAVA_11 = 55;
|
||||||
|
int BYTECODE_JAVA_12 = 56;
|
||||||
|
int BYTECODE_JAVA_13 = 57;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// VARIABLE TYPES
|
// VARIABLE TYPES
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
package org.jetbrains.java.decompiler.struct;
|
package org.jetbrains.java.decompiler.struct;
|
||||||
|
|
||||||
import org.jetbrains.java.decompiler.code.CodeConstants;
|
import org.jetbrains.java.decompiler.code.CodeConstants;
|
||||||
@@ -157,28 +157,16 @@ public class StructClass extends StructMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVersionGE_1_5() {
|
public boolean isVersionGE_1_5() {
|
||||||
return (majorVersion > 48 || (majorVersion == 48 && minorVersion > 0)); // FIXME: check second condition
|
return (majorVersion > CodeConstants.BYTECODE_JAVA_LE_4 ||
|
||||||
|
(majorVersion == CodeConstants.BYTECODE_JAVA_LE_4 && minorVersion > 0)); // FIXME: check second condition
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVersionGE_1_7() {
|
public boolean isVersionGE_1_7() {
|
||||||
return (majorVersion >= 51);
|
return (majorVersion >= CodeConstants.BYTECODE_JAVA_7);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBytecodeVersion() {
|
public int getBytecodeVersion() {
|
||||||
switch (majorVersion) {
|
return majorVersion < CodeConstants.BYTECODE_JAVA_LE_4 ? CodeConstants.BYTECODE_JAVA_LE_4 : majorVersion;
|
||||||
case 53:
|
|
||||||
return CodeConstants.BYTECODE_JAVA_9;
|
|
||||||
case 52:
|
|
||||||
return CodeConstants.BYTECODE_JAVA_8;
|
|
||||||
case 51:
|
|
||||||
return CodeConstants.BYTECODE_JAVA_7;
|
|
||||||
case 50:
|
|
||||||
return CodeConstants.BYTECODE_JAVA_6;
|
|
||||||
case 49:
|
|
||||||
return CodeConstants.BYTECODE_JAVA_5;
|
|
||||||
}
|
|
||||||
|
|
||||||
return CodeConstants.BYTECODE_JAVA_LE_4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
package org.jetbrains.java.decompiler;
|
package org.jetbrains.java.decompiler;
|
||||||
|
|
||||||
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
|
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
|
||||||
@@ -74,6 +74,7 @@ public class SingleClassesTest {
|
|||||||
"pkg/TestShadowingSuperClass"); }
|
"pkg/TestShadowingSuperClass"); }
|
||||||
@Test public void testStringConcat() { doTest("pkg/TestStringConcat"); }
|
@Test public void testStringConcat() { doTest("pkg/TestStringConcat"); }
|
||||||
@Test public void testJava9StringConcat() { doTest("java9/TestJava9StringConcat"); }
|
@Test public void testJava9StringConcat() { doTest("java9/TestJava9StringConcat"); }
|
||||||
|
@Test public void testJava11StringConcat() { doTest("java11/TestJava11StringConcat"); }
|
||||||
@Test public void testMethodReferenceSameName() { doTest("pkg/TestMethodReferenceSameName"); }
|
@Test public void testMethodReferenceSameName() { doTest("pkg/TestMethodReferenceSameName"); }
|
||||||
@Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); }
|
@Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); }
|
||||||
@Test public void testConstructorReference() { doTest("pkg/TestConstructorReference"); }
|
@Test public void testConstructorReference() { doTest("pkg/TestConstructorReference"); }
|
||||||
|
|||||||
BIN
testData/classes/java11/TestJava11StringConcat.class
Normal file
BIN
testData/classes/java11/TestJava11StringConcat.class
Normal file
Binary file not shown.
27
testData/results/TestJava11StringConcat.dec
Normal file
27
testData/results/TestJava11StringConcat.dec
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package java11;
|
||||||
|
|
||||||
|
public class TestJava11StringConcat {
|
||||||
|
public String test1(String var1, int var2) {
|
||||||
|
return var1 + var2;// 20
|
||||||
|
}
|
||||||
|
|
||||||
|
public String test2(String var1, int var2, Object var3) {
|
||||||
|
return "(" + var1 + "-" + var2 + "---" + var3 + ")";// 24
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class 'java11/TestJava11StringConcat' {
|
||||||
|
method 'test1 (Ljava/lang/String;I)Ljava/lang/String;' {
|
||||||
|
2 4
|
||||||
|
7 4
|
||||||
|
}
|
||||||
|
|
||||||
|
method 'test2 (Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;' {
|
||||||
|
3 8
|
||||||
|
8 8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Lines mapping:
|
||||||
|
20 <-> 5
|
||||||
|
24 <-> 9
|
||||||
26
testData/src/java11/TestJava11StringConcat.java
Normal file
26
testData/src/java11/TestJava11StringConcat.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2014 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.
|
||||||
|
*/
|
||||||
|
package java11;
|
||||||
|
|
||||||
|
public class TestJava11StringConcat {
|
||||||
|
public String test1(String prefix, int a) {
|
||||||
|
return prefix + a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String test2(String var, int b, Object c) {
|
||||||
|
return "(" + var + "-" + b + "---" + c + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user