Cleanup (duplicates; final fields; typos)

master
Roman Shevchenko 7 years ago
parent 741f9945a8
commit e449aeb6fa
  1. 46
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 5
      src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java
  3. 33
      src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java
  4. 29
      src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java

@ -654,7 +654,7 @@ public class ClassWriter {
else if (isEnum && init) { else if (isEnum && init) {
actualParams -= 2; actualParams -= 2;
} }
if (actualParams != descriptor.params.size()) { if (actualParams != descriptor.parameterTypes.size()) {
String message = "Inconsistent generic signature in method " + mt.getName() + " " + mt.getDescriptor() + " in " + cl.qualifiedName; String message = "Inconsistent generic signature in method " + mt.getName() + " " + mt.getDescriptor() + " in " + cl.qualifiedName;
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN); DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
descriptor = null; descriptor = null;
@ -669,14 +669,14 @@ public class ClassWriter {
if (!clinit && !dinit) { if (!clinit && !dinit) {
boolean thisVar = !mt.hasModifier(CodeConstants.ACC_STATIC); boolean thisVar = !mt.hasModifier(CodeConstants.ACC_STATIC);
if (descriptor != null && !descriptor.fparameters.isEmpty()) { if (descriptor != null && !descriptor.typeParameters.isEmpty()) {
appendTypeParameters(buffer, descriptor.fparameters, descriptor.fbounds); appendTypeParameters(buffer, descriptor.typeParameters, descriptor.typeParameterBounds);
buffer.append(' '); buffer.append(' ');
} }
if (!init) { if (!init) {
if (descriptor != null) { if (descriptor != null) {
buffer.append(GenericMain.getGenericCastTypeName(descriptor.ret)); buffer.append(GenericMain.getGenericCastTypeName(descriptor.returnType));
} }
else { else {
buffer.append(ExprProcessor.getCastTypeName(md.ret)); buffer.append(ExprProcessor.getCastTypeName(md.ret));
@ -700,7 +700,7 @@ public class ClassWriter {
int index = isEnum && init ? 3 : thisVar ? 1 : 0; int index = isEnum && init ? 3 : thisVar ? 1 : 0;
boolean hasDescriptor = descriptor != null; boolean hasDescriptor = descriptor != null;
int start = isEnum && init && !hasDescriptor ? 2 : 0; int start = isEnum && init && !hasDescriptor ? 2 : 0;
int params = hasDescriptor ? descriptor.params.size() : md.params.length; int params = hasDescriptor ? descriptor.parameterTypes.size() : md.params.length;
for (int i = start; i < params; i++) { for (int i = start; i < params; i++) {
if (hasDescriptor || mask == null || mask.get(i) == null) { if (hasDescriptor || mask == null || mask.get(i) == null) {
if (!firstParameter) { if (!firstParameter) {
@ -713,46 +713,34 @@ public class ClassWriter {
buffer.append("final "); buffer.append("final ");
} }
if (descriptor != null) { String typeName;
GenericType parameterType = descriptor.params.get(i); boolean isVarArg = i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS);
boolean isVarArg = (i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0); if (descriptor != null) {
GenericType parameterType = descriptor.parameterTypes.get(i);
isVarArg &= parameterType.arrayDim > 0;
if (isVarArg) { if (isVarArg) {
parameterType = parameterType.decreaseArrayDim(); parameterType = parameterType.decreaseArrayDim();
} }
typeName = GenericMain.getGenericCastTypeName(parameterType);
String typeName = GenericMain.getGenericCastTypeName(parameterType);
if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) &&
DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
}
buffer.append(typeName);
if (isVarArg) {
buffer.append("...");
}
} }
else { else {
VarType parameterType = md.params[i]; VarType parameterType = md.params[i];
isVarArg &= parameterType.arrayDim > 0;
boolean isVarArg = (i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0);
if (isVarArg) { if (isVarArg) {
parameterType = parameterType.decreaseArrayDim(); parameterType = parameterType.decreaseArrayDim();
} }
typeName = ExprProcessor.getCastTypeName(parameterType);
}
String typeName = ExprProcessor.getCastTypeName(parameterType);
if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) && if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) &&
DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) { DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT); typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
} }
buffer.append(typeName); buffer.append(typeName);
if (isVarArg) { if (isVarArg) {
buffer.append("..."); buffer.append("...");
} }
}
buffer.append(' '); buffer.append(' ');
String parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0)); String parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0));
@ -768,7 +756,7 @@ public class ClassWriter {
buffer.append(')'); buffer.append(')');
StructExceptionsAttribute attr = (StructExceptionsAttribute)mt.getAttribute("Exceptions"); StructExceptionsAttribute attr = (StructExceptionsAttribute)mt.getAttribute("Exceptions");
if ((descriptor != null && !descriptor.exceptions.isEmpty()) || attr != null) { if ((descriptor != null && !descriptor.exceptionTypes.isEmpty()) || attr != null) {
throwsExceptions = true; throwsExceptions = true;
buffer.append(" throws "); buffer.append(" throws ");
@ -776,8 +764,8 @@ public class ClassWriter {
if (i > 0) { if (i > 0) {
buffer.append(", "); buffer.append(", ");
} }
if (descriptor != null && !descriptor.exceptions.isEmpty()) { if (descriptor != null && !descriptor.exceptionTypes.isEmpty()) {
GenericType type = descriptor.exceptions.get(i); GenericType type = descriptor.exceptionTypes.get(i);
buffer.append(GenericMain.getGenericCastTypeName(type)); buffer.append(GenericMain.getGenericCastTypeName(type));
} }
else { else {

@ -2,6 +2,9 @@
package org.jetbrains.java.decompiler.struct.gen.generics; package org.jetbrains.java.decompiler.struct.gen.generics;
public class GenericFieldDescriptor { public class GenericFieldDescriptor {
public final GenericType type;
public GenericType type; public GenericFieldDescriptor(GenericType type) {
this.type = type;
}
} }

@ -49,9 +49,7 @@ public class GenericMain {
public static GenericFieldDescriptor parseFieldSignature(String signature) { public static GenericFieldDescriptor parseFieldSignature(String signature) {
try { try {
GenericFieldDescriptor descriptor = new GenericFieldDescriptor(); return new GenericFieldDescriptor(new GenericType(signature));
descriptor.type = new GenericType(signature);
return descriptor;
} }
catch (RuntimeException e) { catch (RuntimeException e) {
DecompilerContext.getLogger().writeMessage("Invalid signature: " + signature, IFernflowerLogger.Severity.WARN); DecompilerContext.getLogger().writeMessage("Invalid signature: " + signature, IFernflowerLogger.Severity.WARN);
@ -62,33 +60,34 @@ public class GenericMain {
public static GenericMethodDescriptor parseMethodSignature(String signature) { public static GenericMethodDescriptor parseMethodSignature(String signature) {
String original = signature; String original = signature;
try { try {
GenericMethodDescriptor descriptor = new GenericMethodDescriptor(); List<String> typeParameters = new ArrayList<>();
List<List<GenericType>> typeParameterBounds = new ArrayList<>();
signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds); signature = parseFormalParameters(signature, typeParameters, typeParameterBounds);
int to = signature.indexOf(")"); int to = signature.indexOf(")");
String pars = signature.substring(1, to); String parameters = signature.substring(1, to);
signature = signature.substring(to + 1); signature = signature.substring(to + 1);
while (pars.length() > 0) { List<GenericType> parameterTypes = new ArrayList<>();
String par = GenericType.getNextType(pars); while (parameters.length() > 0) {
descriptor.params.add(new GenericType(par)); String par = GenericType.getNextType(parameters);
pars = pars.substring(par.length()); parameterTypes.add(new GenericType(par));
parameters = parameters.substring(par.length());
} }
String par = GenericType.getNextType(signature); String ret = GenericType.getNextType(signature);
descriptor.ret = new GenericType(par); GenericType returnType = new GenericType(ret);
signature = signature.substring(par.length()); signature = signature.substring(ret.length());
List<GenericType> exceptionTypes = new ArrayList<>();
if (signature.length() > 0) { if (signature.length() > 0) {
String[] exceptions = signature.split("\\^"); String[] exceptions = signature.split("\\^");
for (int i = 1; i < exceptions.length; i++) { for (int i = 1; i < exceptions.length; i++) {
descriptor.exceptions.add(new GenericType(exceptions[i])); exceptionTypes.add(new GenericType(exceptions[i]));
} }
} }
return descriptor; return new GenericMethodDescriptor(typeParameters, typeParameterBounds, parameterTypes, returnType, exceptionTypes);
} }
catch (RuntimeException e) { catch (RuntimeException e) {
DecompilerContext.getLogger().writeMessage("Invalid signature: " + original, IFernflowerLogger.Severity.WARN); DecompilerContext.getLogger().writeMessage("Invalid signature: " + original, IFernflowerLogger.Severity.WARN);

@ -1,18 +1,29 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.struct.gen.generics; package org.jetbrains.java.decompiler.struct.gen.generics;
import java.util.ArrayList; import java.util.Collections;
import java.util.List; import java.util.List;
public class GenericMethodDescriptor { public class GenericMethodDescriptor {
public final List<String> typeParameters;
public final List<List<GenericType>> typeParameterBounds;
public final List<GenericType> parameterTypes;
public final GenericType returnType;
public final List<GenericType> exceptionTypes;
public final List<String> fparameters = new ArrayList<>(); public GenericMethodDescriptor(List<String> typeParameters,
List<List<GenericType>> typeParameterBounds,
List<GenericType> parameterTypes,
GenericType returnType,
List<GenericType> exceptionTypes) {
this.typeParameters = substitute(typeParameters);
this.typeParameterBounds = substitute(typeParameterBounds);
this.parameterTypes = substitute(parameterTypes);
this.returnType = returnType;
this.exceptionTypes = substitute(exceptionTypes);
}
public final List<List<GenericType>> fbounds = new ArrayList<>(); private static <T> List<T> substitute(List<T> list) {
return list.isEmpty() ? Collections.emptyList() : list;
public final List<GenericType> params = new ArrayList<>(); }
public GenericType ret;
public final List<GenericType> exceptions = new ArrayList<>();
} }
Loading…
Cancel
Save