decompiler: for now disabled line numbers in inner classes

master
Egor.Ushakov 10 years ago
parent e0f22e6629
commit 7bb0f5ba7e
  1. 2
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 43
      src/org/jetbrains/java/decompiler/main/TextBuffer.java
  3. 3
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java

@ -805,7 +805,7 @@ public class ClassWriter {
}
//TODO: for now only start line set
buffer.setCurrentLine(startLine);
buffer.setCurrentLine(startLine-1);
buffer.append('{').appendLineSeparator();
RootStatement root = wrapper.getMethodWrapper(mt.getName(), mt.getDescriptor()).root;

@ -32,6 +32,7 @@ public class TextBuffer {
private final String myIndent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING);
private final StringBuilder myStringBuilder;
private Map<Integer, Integer> myLineToOffsetMapping = null;
private boolean myTrackLines = true;
public TextBuffer() {
myStringBuilder = new StringBuilder();
@ -41,8 +42,12 @@ public class TextBuffer {
myStringBuilder = new StringBuilder(size);
}
public void setTrackLines(boolean trackLines) {
myTrackLines = false;
}
public void setCurrentLine(int line) {
if (line >= 0) {
if (myTrackLines && line >= 0) {
checkMapCreated();
myLineToOffsetMapping.put(line, myStringBuilder.length()+1);
}
@ -70,16 +75,6 @@ public class TextBuffer {
return this;
}
public TextBuffer addBanner(String banner) {
myStringBuilder.insert(0, banner);
if (myLineToOffsetMapping != null) {
for (Integer line : myLineToOffsetMapping.keySet()) {
myLineToOffsetMapping.put(line, myLineToOffsetMapping.get(line) + banner.length());
}
}
return this;
}
@Override
public String toString() {
String original = myStringBuilder.toString();
@ -101,9 +96,10 @@ public class TextBuffer {
String line = srcLines[currentLine];
int lineEnd = currentLineStartOffset + line.length() + myLineSeparator.length();
if (markOffset >= currentLineStartOffset && markOffset <= lineEnd) {
int requiredLinesNumber = markLine - dumpedLines;
dumpedLines = markLine;
appendLines(res, srcLines, previousMarkLine, currentLine, requiredLinesNumber);
int requiredLine = markLine - 1;
int linesToAdd = requiredLine - dumpedLines;
dumpedLines = requiredLine;
appendLines(res, srcLines, previousMarkLine, currentLine, linesToAdd);
previousMarkLine = currentLine;
break;
}
@ -121,7 +117,7 @@ public class TextBuffer {
private void appendLines(StringBuilder res, String[] srcLines, int from, int to, int requiredLineNumber) {
if (to - from > requiredLineNumber) {
int separatorsRequired = to - from - requiredLineNumber - 1;
int separatorsRequired = requiredLineNumber - 1;
for (int i = from; i < to; i++) {
res.append(srcLines[i]);
if (separatorsRequired-- > 0) {
@ -163,17 +159,26 @@ public class TextBuffer {
return this;
}
private void shiftMapping(int startOffset, int shiftOffset) {
if (myLineToOffsetMapping != null) {
for (Map.Entry<Integer, Integer> entry : myLineToOffsetMapping.entrySet()) {
if (entry.getValue() >= startOffset) {
myLineToOffsetMapping.put(entry.getKey(), entry.getValue() + shiftOffset);
}
}
}
}
private void checkMapCreated() {
if (myLineToOffsetMapping == null) {
myLineToOffsetMapping = new HashMap<Integer, Integer>();
}
}
public void insert(int offset, String s) {
if (myLineToOffsetMapping != null) {
throw new IllegalStateException("insert not yet supported with Line mapping");
}
public TextBuffer insert(int offset, String s) {
myStringBuilder.insert(offset, s);
shiftMapping(offset, s.length());
return this;
}
public int count(String substring, int from) {

@ -268,7 +268,10 @@ public class NewExprent extends Exprent {
new ClassWriter().classLambdaToJava(child, buf, methodObject, indent);
}
else {
// do not track lines in sub classes for now
buf.setTrackLines(false);
new ClassWriter().classToJava(child, buf, indent);
buf.setTrackLines(true);
}
}
else if (directArrayInit) {

Loading…
Cancel
Save