From 7310e9e989eb6b0e8828e5cfd4da525713dd5fd8 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Fri, 16 Feb 2018 20:00:30 +0300 Subject: [PATCH] fixed line numbers when replacing nested access --- .../main/rels/NestedMemberAccess.java | 11 +++++++++- testData/results/TestAccessReplace.dec | 18 +++++++-------- testData/results/TestClassFields.dec | 10 ++++----- testData/results/TestSyntheticAccess.dec | 22 +++++++++---------- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java b/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java index bbd027c..692a8b9 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java +++ b/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java @@ -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-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.main.rels; import org.jetbrains.java.decompiler.code.CodeConstants; @@ -394,6 +394,11 @@ public class NestedMemberAccess { ret.replaceExprent(ret.getRight(), invexpr.getLstParameters().get(1)); fexpr.replaceExprent(fexpr.getInstance(), invexpr.getLstParameters().get(0)); } + + // do not use copied bytecodes + ret.getLeft().bytecode = null; + ret.getRight().bytecode = null; + retexprent = ret; break; case FUNCTION: @@ -421,6 +426,10 @@ public class NestedMemberAccess { if (retexprent != null) { + // preserve original bytecodes + retexprent.bytecode = null; + retexprent.addBytecodeOffsets(invexpr.bytecode); + // hide synthetic access method boolean hide = true; diff --git a/testData/results/TestAccessReplace.dec b/testData/results/TestAccessReplace.dec index 1177aa2..f365126 100644 --- a/testData/results/TestAccessReplace.dec +++ b/testData/results/TestAccessReplace.dec @@ -15,8 +15,8 @@ public class TestAccessReplace { public class Inner { public Inner(String b) { - TestAccessReplace.fooS();// 25 - TestAccessReplace.this.foo(); + TestAccessReplace.fooS();// 26 + TestAccessReplace.this.foo();// 27 TestAccessReplace.fooSParams(1L, 2L);// 28 TestAccessReplace.this.fooParams(1L, 2L);// 29 }// 30 @@ -43,14 +43,14 @@ class 'pkg/TestAccessReplace' { class 'pkg/TestAccessReplace$Inner' { method ' (Lpkg/TestAccessReplace;Ljava/lang/String;)V' { - 0 17 - 1 18 - 2 19 - 3 20 + 9 17 + d 18 10 19 11 19 + 14 19 18 20 19 20 + 1c 20 1f 21 } } @@ -60,10 +60,10 @@ Lines mapping: 20 <-> 8 21 <-> 11 22 <-> 14 -25 <-> 18 +26 <-> 18 +27 <-> 19 28 <-> 20 29 <-> 21 30 <-> 22 Not mapped: -26 -27 +25 diff --git a/testData/results/TestClassFields.dec b/testData/results/TestClassFields.dec index 6917171..ea272ea 100644 --- a/testData/results/TestClassFields.dec +++ b/testData/results/TestClassFields.dec @@ -8,7 +8,7 @@ public class TestClassFields { static { sizes = new int[names.length];// 15 TestClassFields.Inner.staticMutable = 3;// 17 - SIZE = TestClassFields.Inner.staticMutable;// 14 18 + SIZE = TestClassFields.Inner.staticMutable;// 18 }// 19 private static class Inner { @@ -18,20 +18,20 @@ public class TestClassFields { class 'pkg/TestClassFields' { method ' ()V' { - 0 10 - 2 9 11 8 14 8 17 8 - 1a 9 + 1b 9 + 1f 10 22 10 25 11 } } Lines mapping: -14 <-> 11 15 <-> 9 17 <-> 10 18 <-> 11 19 <-> 12 +Not mapped: +14 diff --git a/testData/results/TestSyntheticAccess.dec b/testData/results/TestSyntheticAccess.dec index 9f1c0ee..d5016a2 100644 --- a/testData/results/TestSyntheticAccess.dec +++ b/testData/results/TestSyntheticAccess.dec @@ -28,8 +28,8 @@ class TestSyntheticAccess { }// 19 void incrementS() { - ++TestSyntheticAccess.s;// 22 23 - } + ++TestSyntheticAccess.s;// 22 + }// 23 void decrementS() { TestSyntheticAccess.s--;// 26 @@ -39,46 +39,44 @@ class TestSyntheticAccess { class 'pkg/TestSyntheticAccess$Assigner' { method 'assignI (I)V' { - 3 8 + 5 8 9 9 } method 'assignS (I)V' { - 2 12 + 1 12 5 13 } } class 'pkg/TestSyntheticAccess$Incrementer' { method 'orI ()V' { - 1 18 - 3 18 + 8 18 b 18 - c 18 + d 18 11 19 } method 'incrementI ()V' { 2 22 - 7 22 + 4 22 8 23 } method 'decrementI ()V' { 2 26 - 6 26 + 4 26 8 27 } method 'incrementS ()V' { 0 30 - 4 30 + 4 31 } method 'decrementS ()V' { 0 34 4 35 - 5 34 } } @@ -90,7 +88,7 @@ Lines mapping: 18 <-> 27 19 <-> 28 22 <-> 31 -23 <-> 31 +23 <-> 32 26 <-> 35 27 <-> 36 32 <-> 9