Cleanup (duplicates; final fields; typos)

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

@ -654,7 +654,7 @@ public class ClassWriter {
else if (isEnum && init) {
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;
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
descriptor = null;
@ -669,14 +669,14 @@ public class ClassWriter {
if (!clinit && !dinit) {
boolean thisVar = !mt.hasModifier(CodeConstants.ACC_STATIC);
if (descriptor != null && !descriptor.fparameters.isEmpty()) {
appendTypeParameters(buffer, descriptor.fparameters, descriptor.fbounds);
if (descriptor != null && !descriptor.typeParameters.isEmpty()) {
appendTypeParameters(buffer, descriptor.typeParameters, descriptor.typeParameterBounds);
buffer.append(' ');
}
if (!init) {
if (descriptor != null) {
buffer.append(GenericMain.getGenericCastTypeName(descriptor.ret));
buffer.append(GenericMain.getGenericCastTypeName(descriptor.returnType));
}
else {
buffer.append(ExprProcessor.getCastTypeName(md.ret));
@ -700,7 +700,7 @@ public class ClassWriter {
int index = isEnum && init ? 3 : thisVar ? 1 : 0;
boolean hasDescriptor = descriptor != null;
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++) {
if (hasDescriptor || mask == null || mask.get(i) == null) {
if (!firstParameter) {
@ -713,45 +713,33 @@ public class ClassWriter {
buffer.append("final ");
}
if (descriptor != null) {
GenericType parameterType = descriptor.params.get(i);
String typeName;
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) {
parameterType = parameterType.decreaseArrayDim();
}
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("...");
}
typeName = GenericMain.getGenericCastTypeName(parameterType);
}
else {
VarType parameterType = md.params[i];
boolean isVarArg = (i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0);
isVarArg &= parameterType.arrayDim > 0;
if (isVarArg) {
parameterType = parameterType.decreaseArrayDim();
}
typeName = ExprProcessor.getCastTypeName(parameterType);
}
String typeName = ExprProcessor.getCastTypeName(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("...");
}
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("...");
}
buffer.append(' ');
@ -768,7 +756,7 @@ public class ClassWriter {
buffer.append(')');
StructExceptionsAttribute attr = (StructExceptionsAttribute)mt.getAttribute("Exceptions");
if ((descriptor != null && !descriptor.exceptions.isEmpty()) || attr != null) {
if ((descriptor != null && !descriptor.exceptionTypes.isEmpty()) || attr != null) {
throwsExceptions = true;
buffer.append(" throws ");
@ -776,8 +764,8 @@ public class ClassWriter {
if (i > 0) {
buffer.append(", ");
}
if (descriptor != null && !descriptor.exceptions.isEmpty()) {
GenericType type = descriptor.exceptions.get(i);
if (descriptor != null && !descriptor.exceptionTypes.isEmpty()) {
GenericType type = descriptor.exceptionTypes.get(i);
buffer.append(GenericMain.getGenericCastTypeName(type));
}
else {

@ -2,6 +2,9 @@
package org.jetbrains.java.decompiler.struct.gen.generics;
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) {
try {
GenericFieldDescriptor descriptor = new GenericFieldDescriptor();
descriptor.type = new GenericType(signature);
return descriptor;
return new GenericFieldDescriptor(new GenericType(signature));
}
catch (RuntimeException e) {
DecompilerContext.getLogger().writeMessage("Invalid signature: " + signature, IFernflowerLogger.Severity.WARN);
@ -62,33 +60,34 @@ public class GenericMain {
public static GenericMethodDescriptor parseMethodSignature(String signature) {
String original = signature;
try {
GenericMethodDescriptor descriptor = new GenericMethodDescriptor();
signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds);
List<String> typeParameters = new ArrayList<>();
List<List<GenericType>> typeParameterBounds = new ArrayList<>();
signature = parseFormalParameters(signature, typeParameters, typeParameterBounds);
int to = signature.indexOf(")");
String pars = signature.substring(1, to);
String parameters = signature.substring(1, to);
signature = signature.substring(to + 1);
while (pars.length() > 0) {
String par = GenericType.getNextType(pars);
descriptor.params.add(new GenericType(par));
pars = pars.substring(par.length());
List<GenericType> parameterTypes = new ArrayList<>();
while (parameters.length() > 0) {
String par = GenericType.getNextType(parameters);
parameterTypes.add(new GenericType(par));
parameters = parameters.substring(par.length());
}
String par = GenericType.getNextType(signature);
descriptor.ret = new GenericType(par);
signature = signature.substring(par.length());
String ret = GenericType.getNextType(signature);
GenericType returnType = new GenericType(ret);
signature = signature.substring(ret.length());
List<GenericType> exceptionTypes = new ArrayList<>();
if (signature.length() > 0) {
String[] exceptions = signature.split("\\^");
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) {
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.
package org.jetbrains.java.decompiler.struct.gen.generics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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<>();
public final List<GenericType> params = new ArrayList<>();
public GenericType ret;
public final List<GenericType> exceptions = new ArrayList<>();
}
private static <T> List<T> substitute(List<T> list) {
return list.isEmpty() ? Collections.emptyList() : list;
}
}
Loading…
Cancel
Save