natural enum formatting (injected constructor parameters omitted)

This commit is contained in:
Roman Shevchenko 2014-05-24 14:00:22 +04:00
parent 290c3ae066
commit 495589a815
4 changed files with 52 additions and 42 deletions

View File

@ -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);
@ -863,8 +863,9 @@ public class ClassWriter {
}
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) {

View File

@ -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);
}
}
}
}

View File

@ -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(", ");

View File

@ -163,7 +163,7 @@ public class NewExprent extends Exprent {
}
public String toJava(int indent) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if(anonymous) {
@ -191,7 +191,11 @@ 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(", ");
@ -240,6 +244,10 @@ public class NewExprent extends Exprent {
buf.append(")");
if(enumconst && buf.length() == 2) {
buf.setLength(0);
}
StringWriter strwriter = new StringWriter();
BufferedWriter bufstrwriter = new BufferedWriter(strwriter);
@ -298,10 +306,12 @@ public class NewExprent extends Exprent {
}
}
int start = enumconst ? 2 : 0;
if(start < lstParameters.size()) {
buf.append("(");
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(!firstpar) {
buf.append(", ");
@ -315,6 +325,7 @@ public class NewExprent extends Exprent {
}
}
buf.append(")");
}
}
if(!enumconst) {
@ -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++) {