natural enum formatting (injected constructor parameters omitted)

master
Roman Shevchenko 11 years ago
parent 290c3ae066
commit 495589a815
  1. 9
      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. 63
      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 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) {

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

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

@ -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++) {

Loading…
Cancel
Save