summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-05-24 14:00:22 +0400
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-05-24 14:00:22 +0400
commit495589a81532a9a5ee32bea8f1a2a6ac7420d3e2 (patch)
tree261db1a0ede5d59c0d0f69391ce4b58f273596fb /src
parent290c3ae0663e018c796c5874a2145ddcc9df0bba (diff)
downloadfernflower-495589a81532a9a5ee32bea8f1a2a6ac7420d3e2.tar
fernflower-495589a81532a9a5ee32bea8f1a2a6ac7420d3e2.tar.gz
fernflower-495589a81532a9a5ee32bea8f1a2a6ac7420d3e2.tar.lz
fernflower-495589a81532a9a5ee32bea8f1a2a6ac7420d3e2.tar.xz
fernflower-495589a81532a9a5ee32bea8f1a2a6ac7420d3e2.zip
natural enum formatting (injected constructor parameters omitted)
Diffstat (limited to 'src')
-rw-r--r--src/de/fernflower/main/ClassWriter.java9
-rw-r--r--src/de/fernflower/main/EnumProcessor.java3
-rw-r--r--src/de/fernflower/modules/decompiler/exps/InvocationExprent.java19
-rw-r--r--src/de/fernflower/modules/decompiler/exps/NewExprent.java63
4 files changed, 52 insertions, 42 deletions
diff --git a/src/de/fernflower/main/ClassWriter.java b/src/de/fernflower/main/ClassWriter.java
index 68b4689..54a490e 100644
--- a/src/de/fernflower/main/ClassWriter.java
+++ b/src/de/fernflower/main/ClassWriter.java
@@ -698,7 +698,7 @@ public class ClassWriter {
boolean isInterface = (cl.access_flags & CodeConstants.ACC_INTERFACE) != 0;
boolean isAnnotation = (cl.access_flags & CodeConstants.ACC_ANNOTATION) != 0;
-
+ boolean isEnum = (cl.access_flags & CodeConstants.ACC_ENUM) != 0 && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM);
boolean isDeprecated = mt.getAttributes().containsKey("Deprecated");
String indstr = InterpreterUtil.getIndentString(indent);
@@ -861,10 +861,11 @@ public class ClassWriter {
lastparam_index = i;
}
}
-
+
boolean firstpar = true;
- int index = thisvar?1:0;
- for(int i=0;i<md.params.length;i++) {
+ int index = isEnum && init ? 3 : thisvar ? 1 : 0;
+ int start = isEnum && init ? 2 : 0;
+ for(int i=start;i<md.params.length;i++) {
if(signFields == null || signFields.get(i) == null) {
if(!firstpar) {
diff --git a/src/de/fernflower/main/EnumProcessor.java b/src/de/fernflower/main/EnumProcessor.java
index 036b6b7..f5bede8 100644
--- a/src/de/fernflower/main/EnumProcessor.java
+++ b/src/de/fernflower/main/EnumProcessor.java
@@ -86,7 +86,8 @@ public class EnumProcessor {
NewExprent nexpr = (NewExprent)initializer;
if(nexpr.isAnonymous()) {
ClassNode child = DecompilerContext.getClassprocessor().getMapRootClasses().get(nexpr.getNewtype().value);
- hideDummyFieldInConstant(child.wrapper); }
+ hideDummyFieldInConstant(child.wrapper);
+ }
}
}
}
diff --git a/src/de/fernflower/modules/decompiler/exps/InvocationExprent.java b/src/de/fernflower/modules/decompiler/exps/InvocationExprent.java
index 8427cbf..7d312a5 100644
--- a/src/de/fernflower/modules/decompiler/exps/InvocationExprent.java
+++ b/src/de/fernflower/modules/decompiler/exps/InvocationExprent.java
@@ -14,19 +14,12 @@
package de.fernflower.modules.decompiler.exps;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import de.fernflower.code.CodeConstants;
-import de.fernflower.main.ClassWriter;
-import de.fernflower.main.DecompilerContext;
import de.fernflower.main.ClassesProcessor.ClassNode;
+import de.fernflower.main.DecompilerContext;
+import de.fernflower.main.extern.IFernflowerPreferences;
import de.fernflower.main.rels.MethodWrapper;
import de.fernflower.modules.decompiler.ExprProcessor;
import de.fernflower.modules.decompiler.vars.CheckTypesResult;
@@ -316,6 +309,7 @@ public class InvocationExprent extends Exprent {
}
List<VarVersionPaar> sigFields = null;
+ boolean isEnum = false;
if(functype == TYP_INIT) {
ClassNode newnode = DecompilerContext.getClassprocessor().getMapRootClasses().get(classname);
@@ -328,13 +322,16 @@ public class InvocationExprent extends Exprent {
sigFields.set(0, new VarVersionPaar(-1, 0));
}
}
+ isEnum = (newnode.classStruct.access_flags & CodeConstants.ACC_ENUM) != 0 &&
+ DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM);
}
}
Set<Integer> setAmbiguousParameters = getAmbiguousParameters();
boolean firstpar = true;
- for(int i=0;i<lstParameters.size();i++) {
+ int start = isEnum ? 2 : 0;
+ for(int i=start;i<lstParameters.size();i++) {
if(sigFields == null || sigFields.get(i) == null) {
if(!firstpar) {
buf.append(", ");
diff --git a/src/de/fernflower/modules/decompiler/exps/NewExprent.java b/src/de/fernflower/modules/decompiler/exps/NewExprent.java
index 3e636d7..8db9f89 100644
--- a/src/de/fernflower/modules/decompiler/exps/NewExprent.java
+++ b/src/de/fernflower/modules/decompiler/exps/NewExprent.java
@@ -163,7 +163,7 @@ public class NewExprent extends Exprent {
}
public String toJava(int indent) {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
if(anonymous) {
@@ -189,9 +189,13 @@ public class NewExprent extends Exprent {
}
}
}
-
+
boolean firstpar = true;
- for(int i=0;i<invsuper.getLstParameters().size();i++) {
+ int start = 0, end = invsuper.getLstParameters().size();
+ if(enumconst) {
+ start += 2; end -= 1;
+ }
+ for(int i=start;i<end;i++) {
if(sigFields == null || sigFields.get(i) == null) {
if(!firstpar) {
buf.append(", ");
@@ -239,7 +243,11 @@ public class NewExprent extends Exprent {
}
buf.append(")");
-
+
+ if(enumconst && buf.length() == 2) {
+ buf.setLength(0);
+ }
+
StringWriter strwriter = new StringWriter();
BufferedWriter bufstrwriter = new BufferedWriter(strwriter);
@@ -297,26 +305,29 @@ public class NewExprent extends Exprent {
}
}
}
-
- buf.append("(");
-
- boolean firstpar = true;
- for(int i=0;i<lstParameters.size();i++) {
- if(sigFields == null || sigFields.get(i) == null) {
- if(!firstpar) {
- buf.append(", ");
- }
-
- StringBuilder buff = new StringBuilder();
- ExprProcessor.getCastedExprent(lstParameters.get(i), constructor.getDescriptor().params[i], buff, indent, true);
-
- buf.append(buff);
- firstpar = false;
- }
- }
- buf.append(")");
- }
-
+
+ int start = enumconst ? 2 : 0;
+ if(start < lstParameters.size()) {
+ buf.append("(");
+
+ boolean firstpar = true;
+ for(int i=start;i<lstParameters.size();i++) {
+ if(sigFields == null || sigFields.get(i) == null) {
+ if(!firstpar) {
+ buf.append(", ");
+ }
+
+ StringBuilder buff = new StringBuilder();
+ ExprProcessor.getCastedExprent(lstParameters.get(i), constructor.getDescriptor().params[i], buff, indent, true);
+
+ buf.append(buff);
+ firstpar = false;
+ }
+ }
+ buf.append(")");
+ }
+ }
+
if(!enumconst) {
String enclosing = null;
if(constructor != null) {
@@ -341,11 +352,11 @@ public class NewExprent extends Exprent {
}
} else {
- buf.append("new "+ExprProcessor.getTypeName(newtype));
+ buf.append("new ").append(ExprProcessor.getTypeName(newtype));
if(lstArrayElements.isEmpty()) {
for(int i=0;i<newtype.arraydim;i++) {
- buf.append("["+(i<lstDims.size()?lstDims.get(i).toJava(indent):"")+"]");
+ buf.append("[").append(i < lstDims.size() ? lstDims.get(i).toJava(indent) : "").append("]");
}
} else {
for(int i=0;i<newtype.arraydim;i++) {