diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index dc3b829..50bd994 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.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 { diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java index 9b85579..a651817 100644 --- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java +++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java @@ -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; + } +} \ No newline at end of file diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java index d531fe4..45ca557 100644 --- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java +++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java @@ -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 typeParameters = new ArrayList<>(); + List> 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 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 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); diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java index 7fce57a..eb80491 100644 --- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java +++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java @@ -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 typeParameters; + public final List> typeParameterBounds; + public final List parameterTypes; + public final GenericType returnType; + public final List exceptionTypes; - public final List fparameters = new ArrayList<>(); + public GenericMethodDescriptor(List typeParameters, + List> typeParameterBounds, + List parameterTypes, + GenericType returnType, + List exceptionTypes) { + this.typeParameters = substitute(typeParameters); + this.typeParameterBounds = substitute(typeParameterBounds); + this.parameterTypes = substitute(parameterTypes); + this.returnType = returnType; + this.exceptionTypes = substitute(exceptionTypes); + } - public final List> fbounds = new ArrayList<>(); - - public final List params = new ArrayList<>(); - - public GenericType ret; - - public final List exceptions = new ArrayList<>(); -} + private static List substitute(List list) { + return list.isEmpty() ? Collections.emptyList() : list; + } +} \ No newline at end of file