[java-decompiler] cleanup (text rearranging mode dropped)

master
Roman Shevchenko 9 years ago
parent 810818e2c3
commit 26ab681d56
  1. 39
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 2
      src/org/jetbrains/java/decompiler/main/DecompilerContext.java
  3. 16
      src/org/jetbrains/java/decompiler/main/TextBuffer.java
  4. 6
      src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java
  5. 33
      test/org/jetbrains/java/decompiler/LineNumbersMatchTest.java
  6. BIN
      testData/classes/pkg/TestLineNumbersMatch.class
  7. 22
      testData/results/TestLineNumbersMatch.dec
  8. 22
      testData/src/pkg/TestLineNumbersMatch.java

@ -835,9 +835,6 @@ public class ClassWriter {
// We do not have line information for method start, lets have it here for now
StructLineNumberTableAttribute lineNumberTable =
(StructLineNumberTableAttribute)mt.getAttributes().getWithKey(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE);
if (lineNumberTable != null && DecompilerContext.getOption(IFernflowerPreferences.USE_DEBUG_LINE_NUMBERS)) {
buffer.setCurrentLine(lineNumberTable.getFirstLine() - 1);
}
buffer.append('{').appendLineSeparator();
tracer.incrementCurrentSourceLine();
@ -851,10 +848,6 @@ public class ClassWriter {
hideMethod = (clinit || dinit || hideConstructor(wrapper, init, throwsExceptions, paramCount)) && code.length() == 0;
if (!hideMethod && lineNumberTable != null && DecompilerContext.getOption(IFernflowerPreferences.USE_DEBUG_LINE_NUMBERS)) {
mapLines(code, lineNumberTable, tracer, startLine);
}
buffer.append(code);
}
catch (Throwable ex) {
@ -888,38 +881,6 @@ public class ClassWriter {
return !hideMethod;
}
private static void mapLines(TextBuffer code, StructLineNumberTableAttribute table, BytecodeMappingTracer tracer, int startLine) {
// build line start offsets map
HashMap<Integer, Set<Integer>> lineStartOffsets = new HashMap<Integer, Set<Integer>>();
for (Map.Entry<Integer, Integer> entry : tracer.getMapping().entrySet()) {
Integer lineNumber = entry.getValue() - startLine;
Set<Integer> curr = lineStartOffsets.get(lineNumber);
if (curr == null) {
curr = new TreeSet<Integer>(); // requires natural sorting!
}
curr.add(entry.getKey());
lineStartOffsets.put(lineNumber, curr);
}
String lineSeparator = DecompilerContext.getNewLineSeparator();
StringBuilder text = code.getOriginalText();
int pos = text.indexOf(lineSeparator);
int lineNumber = 0;
while (pos != -1) {
Set<Integer> startOffsets = lineStartOffsets.get(lineNumber);
if (startOffsets != null) {
for (Integer offset : startOffsets) {
int number = table.findLineNumber(offset);
if (number >= 0) {
code.setLineMapping(number, pos);
break;
}
}
}
pos = text.indexOf(lineSeparator, pos+1);
lineNumber++;
}
}
private static boolean hideConstructor(ClassWrapper wrapper, boolean init, boolean throwsExceptions, int paramCount) {
if (!init || throwsExceptions || paramCount > 0 || !DecompilerContext.getOption(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR)) {
return false;

@ -156,6 +156,6 @@ public class DecompilerContext {
public static String getNewLineSeparator() {
return getOption(IFernflowerPreferences.NEW_LINE_SEPARATOR) ?
IFernflowerPreferences.LINE_SEPARATOR_LIN : IFernflowerPreferences.LINE_SEPARATOR_WIN;
IFernflowerPreferences.LINE_SEPARATOR_UNX : IFernflowerPreferences.LINE_SEPARATOR_WIN;
}
}

@ -42,17 +42,6 @@ public class TextBuffer {
myStringBuilder = new StringBuilder(text);
}
public void setCurrentLine(int line) {
setLineMapping(line, myStringBuilder.length()+1);
}
public void setLineMapping(int line, int offset) {
if (line >= 0) {
checkMapCreated();
myLineToOffsetMapping.put(line, offset);
}
}
public TextBuffer append(String str) {
myStringBuilder.append(str);
return this;
@ -301,11 +290,8 @@ public class TextBuffer {
return res;
}
public StringBuilder getOriginalText() {
return myStringBuilder;
}
private Map<Integer, Set<Integer>> myLineMapping = null; // new to original
public void dumpOriginalLineNumbers(int[] lineMapping) {
if (lineMapping.length > 0) {
myLineMapping = new HashMap<Integer, Set<Integer>>();

@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@ -44,7 +44,6 @@ public interface IFernflowerPreferences {
String IDEA_NOT_NULL_ANNOTATION = "inn";
String LAMBDA_TO_ANONYMOUS_CLASS = "lac";
String BYTECODE_SOURCE_MAPPING = "bsm";
String USE_DEBUG_LINE_NUMBERS = "udl";
String LOG_LEVEL = "log";
String MAX_PROCESSING_METHOD = "mpm";
@ -58,7 +57,7 @@ public interface IFernflowerPreferences {
String UNIT_TEST_MODE = "__unit_test_mode__";
String LINE_SEPARATOR_WIN = "\r\n";
String LINE_SEPARATOR_LIN = "\n";
String LINE_SEPARATOR_UNX = "\n";
Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>() {{
put(REMOVE_BRIDGE, "1");
@ -83,7 +82,6 @@ public interface IFernflowerPreferences {
put(IDEA_NOT_NULL_ANNOTATION, "1");
put(LAMBDA_TO_ANONYMOUS_CLASS, "0");
put(BYTECODE_SOURCE_MAPPING, "0");
put(USE_DEBUG_LINE_NUMBERS, "0");
put(LOG_LEVEL, IFernflowerLogger.Severity.INFO.name());
put(MAX_PROCESSING_METHOD, "0");

@ -1,33 +0,0 @@
/*
* 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 org.jetbrains.java.decompiler;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
public class LineNumbersMatchTest extends SingleClassesTestBase {
@Override
protected Map<String, Object> getDecompilerOptions() {
return new HashMap<String, Object>() {{
put(IFernflowerPreferences.USE_DEBUG_LINE_NUMBERS, "1");
}};
}
@Test public void testMatch1() { doTest("pkg/TestLineNumbersMatch"); }
}

@ -1,22 +0,0 @@
package pkg;
class TestLineNumbersMatch {
void m1(boolean b) {
if(b) {
System.out.println("a");
} else {
System.out.println("b");
} }
void m2() {
(new Runnable() {
public void run() {
System.out.println("run with me");
}
}).run();
}
}

@ -1,22 +0,0 @@
/*
* Weird comment here.
*/
package pkg;
class TestLineNumbersMatch {
void m1(boolean b) {
if (b)
System.out.println("a");
else
System.out.println("b");
}
void m2() {
new Runnable() {
@Override
public void run() {
System.out.println("run with me");
}
}.run();
}
}
Loading…
Cancel
Save