natural enum formatting (injected constructor parameters omitted)

master
Roman Shevchenko 11 years ago
parent 290c3ae066
commit 495589a815
  1. 7
      src/de/fernflower/main/ClassWriter.java
  2. 3
      src/de/fernflower/main/EnumProcessor.java
  3. 19
      src/de/fernflower/modules/decompiler/exps/InvocationExprent.java
  4. 49
      src/de/fernflower/modules/decompiler/exps/NewExprent.java

@ -698,7 +698,7 @@ public class ClassWriter {
boolean isInterface = (cl.access_flags & CodeConstants.ACC_INTERFACE) != 0; boolean isInterface = (cl.access_flags & CodeConstants.ACC_INTERFACE) != 0;
boolean isAnnotation = (cl.access_flags & CodeConstants.ACC_ANNOTATION) != 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"); boolean isDeprecated = mt.getAttributes().containsKey("Deprecated");
String indstr = InterpreterUtil.getIndentString(indent); String indstr = InterpreterUtil.getIndentString(indent);
@ -863,8 +863,9 @@ public class ClassWriter {
} }
boolean firstpar = true; boolean firstpar = true;
int index = thisvar?1:0; int index = isEnum && init ? 3 : thisvar ? 1 : 0;
for(int i=0;i<md.params.length;i++) { int start = isEnum && init ? 2 : 0;
for(int i=start;i<md.params.length;i++) {
if(signFields == null || signFields.get(i) == null) { if(signFields == null || signFields.get(i) == null) {
if(!firstpar) { if(!firstpar) {

@ -86,7 +86,8 @@ public class EnumProcessor {
NewExprent nexpr = (NewExprent)initializer; NewExprent nexpr = (NewExprent)initializer;
if(nexpr.isAnonymous()) { if(nexpr.isAnonymous()) {
ClassNode child = DecompilerContext.getClassprocessor().getMapRootClasses().get(nexpr.getNewtype().value); ClassNode child = DecompilerContext.getClassprocessor().getMapRootClasses().get(nexpr.getNewtype().value);
hideDummyFieldInConstant(child.wrapper); } hideDummyFieldInConstant(child.wrapper);
}
} }
} }
} }

@ -14,19 +14,12 @@
package de.fernflower.modules.decompiler.exps; package de.fernflower.modules.decompiler.exps;
import java.io.BufferedWriter; import java.util.*;
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 de.fernflower.code.CodeConstants; 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.ClassesProcessor.ClassNode;
import de.fernflower.main.DecompilerContext;
import de.fernflower.main.extern.IFernflowerPreferences;
import de.fernflower.main.rels.MethodWrapper; import de.fernflower.main.rels.MethodWrapper;
import de.fernflower.modules.decompiler.ExprProcessor; import de.fernflower.modules.decompiler.ExprProcessor;
import de.fernflower.modules.decompiler.vars.CheckTypesResult; import de.fernflower.modules.decompiler.vars.CheckTypesResult;
@ -316,6 +309,7 @@ public class InvocationExprent extends Exprent {
} }
List<VarVersionPaar> sigFields = null; List<VarVersionPaar> sigFields = null;
boolean isEnum = false;
if(functype == TYP_INIT) { if(functype == TYP_INIT) {
ClassNode newnode = DecompilerContext.getClassprocessor().getMapRootClasses().get(classname); ClassNode newnode = DecompilerContext.getClassprocessor().getMapRootClasses().get(classname);
@ -328,13 +322,16 @@ public class InvocationExprent extends Exprent {
sigFields.set(0, new VarVersionPaar(-1, 0)); 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(); Set<Integer> setAmbiguousParameters = getAmbiguousParameters();
boolean firstpar = true; 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(sigFields == null || sigFields.get(i) == null) {
if(!firstpar) { if(!firstpar) {
buf.append(", "); buf.append(", ");

@ -163,7 +163,7 @@ public class NewExprent extends Exprent {
} }
public String toJava(int indent) { public String toJava(int indent) {
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
if(anonymous) { if(anonymous) {
@ -191,7 +191,11 @@ public class NewExprent extends Exprent {
} }
boolean firstpar = true; 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(sigFields == null || sigFields.get(i) == null) {
if(!firstpar) { if(!firstpar) {
buf.append(", "); buf.append(", ");
@ -240,6 +244,10 @@ public class NewExprent extends Exprent {
buf.append(")"); buf.append(")");
if(enumconst && buf.length() == 2) {
buf.setLength(0);
}
StringWriter strwriter = new StringWriter(); StringWriter strwriter = new StringWriter();
BufferedWriter bufstrwriter = new BufferedWriter(strwriter); BufferedWriter bufstrwriter = new BufferedWriter(strwriter);
@ -298,24 +306,27 @@ public class NewExprent extends Exprent {
} }
} }
buf.append("("); int start = enumconst ? 2 : 0;
if(start < lstParameters.size()) {
buf.append("(");
boolean firstpar = true; boolean firstpar = true;
for(int i=0;i<lstParameters.size();i++) { for(int i=start;i<lstParameters.size();i++) {
if(sigFields == null || sigFields.get(i) == null) { if(sigFields == null || sigFields.get(i) == null) {
if(!firstpar) { if(!firstpar) {
buf.append(", "); buf.append(", ");
} }
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
ExprProcessor.getCastedExprent(lstParameters.get(i), constructor.getDescriptor().params[i], buff, indent, true); ExprProcessor.getCastedExprent(lstParameters.get(i), constructor.getDescriptor().params[i], buff, indent, true);
buf.append(buff); buf.append(buff);
firstpar = false; firstpar = false;
} }
} }
buf.append(")"); buf.append(")");
} }
}
if(!enumconst) { if(!enumconst) {
String enclosing = null; String enclosing = null;
@ -341,11 +352,11 @@ public class NewExprent extends Exprent {
} }
} else { } else {
buf.append("new "+ExprProcessor.getTypeName(newtype)); buf.append("new ").append(ExprProcessor.getTypeName(newtype));
if(lstArrayElements.isEmpty()) { if(lstArrayElements.isEmpty()) {
for(int i=0;i<newtype.arraydim;i++) { 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 { } else {
for(int i=0;i<newtype.arraydim;i++) { for(int i=0;i<newtype.arraydim;i++) {

Loading…
Cancel
Save