|
|
@ -17,6 +17,7 @@ package org.jetbrains.java.decompiler.struct.gen.generics; |
|
|
|
|
|
|
|
|
|
|
|
import org.jetbrains.java.decompiler.code.CodeConstants; |
|
|
|
import org.jetbrains.java.decompiler.code.CodeConstants; |
|
|
|
import org.jetbrains.java.decompiler.main.DecompilerContext; |
|
|
|
import org.jetbrains.java.decompiler.main.DecompilerContext; |
|
|
|
|
|
|
|
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; |
|
|
|
import org.jetbrains.java.decompiler.struct.StructClass; |
|
|
|
import org.jetbrains.java.decompiler.struct.StructClass; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
@ -24,7 +25,7 @@ import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
public class GenericMain { |
|
|
|
public class GenericMain { |
|
|
|
|
|
|
|
|
|
|
|
private static final String[] typeNames = new String[]{ |
|
|
|
private static final String[] typeNames = { |
|
|
|
"byte", |
|
|
|
"byte", |
|
|
|
"char", |
|
|
|
"char", |
|
|
|
"double", |
|
|
|
"double", |
|
|
@ -36,32 +37,45 @@ public class GenericMain { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static GenericClassDescriptor parseClassSignature(String signature) { |
|
|
|
public static GenericClassDescriptor parseClassSignature(String signature) { |
|
|
|
|
|
|
|
String original = signature; |
|
|
|
|
|
|
|
try { |
|
|
|
GenericClassDescriptor descriptor = new GenericClassDescriptor(); |
|
|
|
GenericClassDescriptor descriptor = new GenericClassDescriptor(); |
|
|
|
|
|
|
|
|
|
|
|
signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds); |
|
|
|
signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds); |
|
|
|
|
|
|
|
|
|
|
|
String supercl = GenericType.getNextType(signature); |
|
|
|
String superCl = GenericType.getNextType(signature); |
|
|
|
descriptor.superclass = new GenericType(supercl); |
|
|
|
descriptor.superclass = new GenericType(superCl); |
|
|
|
|
|
|
|
|
|
|
|
signature = signature.substring(supercl.length()); |
|
|
|
signature = signature.substring(superCl.length()); |
|
|
|
while (signature.length() > 0) { |
|
|
|
while (signature.length() > 0) { |
|
|
|
String superintr = GenericType.getNextType(signature); |
|
|
|
String superIf = GenericType.getNextType(signature); |
|
|
|
descriptor.superinterfaces.add(new GenericType(superintr)); |
|
|
|
descriptor.superinterfaces.add(new GenericType(superIf)); |
|
|
|
signature = signature.substring(superintr.length()); |
|
|
|
signature = signature.substring(superIf.length()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return descriptor; |
|
|
|
return descriptor; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (RuntimeException e) { |
|
|
|
|
|
|
|
DecompilerContext.getLogger().writeMessage("Invalid signature: " + original, IFernflowerLogger.Severity.WARN); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static GenericFieldDescriptor parseFieldSignature(String signature) { |
|
|
|
public static GenericFieldDescriptor parseFieldSignature(String signature) { |
|
|
|
|
|
|
|
try { |
|
|
|
GenericFieldDescriptor descriptor = new GenericFieldDescriptor(); |
|
|
|
GenericFieldDescriptor descriptor = new GenericFieldDescriptor(); |
|
|
|
descriptor.type = new GenericType(signature); |
|
|
|
descriptor.type = new GenericType(signature); |
|
|
|
return descriptor; |
|
|
|
return descriptor; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (RuntimeException e) { |
|
|
|
|
|
|
|
DecompilerContext.getLogger().writeMessage("Invalid signature: " + signature, IFernflowerLogger.Severity.WARN); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static GenericMethodDescriptor parseMethodSignature(String signature) { |
|
|
|
public static GenericMethodDescriptor parseMethodSignature(String signature) { |
|
|
|
|
|
|
|
String original = signature; |
|
|
|
|
|
|
|
try { |
|
|
|
GenericMethodDescriptor descriptor = new GenericMethodDescriptor(); |
|
|
|
GenericMethodDescriptor descriptor = new GenericMethodDescriptor(); |
|
|
|
|
|
|
|
|
|
|
|
signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds); |
|
|
|
signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds); |
|
|
@ -81,18 +95,22 @@ public class GenericMain { |
|
|
|
signature = signature.substring(par.length()); |
|
|
|
signature = signature.substring(par.length()); |
|
|
|
|
|
|
|
|
|
|
|
if (signature.length() > 0) { |
|
|
|
if (signature.length() > 0) { |
|
|
|
String[] excs = signature.split("\\^"); |
|
|
|
String[] exceptions = signature.split("\\^"); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < excs.length; i++) { |
|
|
|
for (int i = 1; i < exceptions.length; i++) { |
|
|
|
descriptor.exceptions.add(new GenericType(excs[i])); |
|
|
|
descriptor.exceptions.add(new GenericType(exceptions[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return descriptor; |
|
|
|
return descriptor; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (RuntimeException e) { |
|
|
|
|
|
|
|
DecompilerContext.getLogger().writeMessage("Invalid signature: " + original, IFernflowerLogger.Severity.WARN); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String parseFormalParameters(String signature, List<String> fparameters, List<List<GenericType>> fbounds) { |
|
|
|
private static String parseFormalParameters(String signature, List<String> parameters, List<List<GenericType>> bounds) { |
|
|
|
|
|
|
|
|
|
|
|
if (signature.charAt(0) != '<') { |
|
|
|
if (signature.charAt(0) != '<') { |
|
|
|
return signature; |
|
|
|
return signature; |
|
|
|
} |
|
|
|
} |
|
|
@ -120,10 +138,10 @@ public class GenericMain { |
|
|
|
signature = signature.substring(index + 1); |
|
|
|
signature = signature.substring(index + 1); |
|
|
|
|
|
|
|
|
|
|
|
while (value.length() > 0) { |
|
|
|
while (value.length() > 0) { |
|
|
|
int parto = value.indexOf(":"); |
|
|
|
int to = value.indexOf(":"); |
|
|
|
|
|
|
|
|
|
|
|
String param = value.substring(0, parto); |
|
|
|
String param = value.substring(0, to); |
|
|
|
value = value.substring(parto + 1); |
|
|
|
value = value.substring(to + 1); |
|
|
|
|
|
|
|
|
|
|
|
List<GenericType> lstBounds = new ArrayList<GenericType>(); |
|
|
|
List<GenericType> lstBounds = new ArrayList<GenericType>(); |
|
|
|
|
|
|
|
|
|
|
@ -146,8 +164,8 @@ public class GenericMain { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fparameters.add(param); |
|
|
|
parameters.add(param); |
|
|
|
fbounds.add(lstBounds); |
|
|
|
bounds.add(lstBounds); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return signature; |
|
|
|
return signature; |
|
|
@ -162,8 +180,7 @@ public class GenericMain { |
|
|
|
return s; |
|
|
|
return s; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String getTypeName(GenericType type) { |
|
|
|
private static String getTypeName(GenericType type) { |
|
|
|
|
|
|
|
|
|
|
|
int tp = type.type; |
|
|
|
int tp = type.type; |
|
|
|
if (tp <= CodeConstants.TYPE_BOOLEAN) { |
|
|
|
if (tp <= CodeConstants.TYPE_BOOLEAN) { |
|
|
|
return typeNames[tp]; |
|
|
|
return typeNames[tp]; |
|
|
@ -197,9 +214,9 @@ public class GenericMain { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GenericType genpar = type.getArguments().get(i); |
|
|
|
GenericType genPar = type.getArguments().get(i); |
|
|
|
if (genpar != null) { |
|
|
|
if (genPar != null) { |
|
|
|
buffer.append(getGenericCastTypeName(genpar)); |
|
|
|
buffer.append(getGenericCastTypeName(genPar)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
buffer.append(">"); |
|
|
|
buffer.append(">"); |
|
|
@ -208,11 +225,10 @@ public class GenericMain { |
|
|
|
return buffer.toString(); |
|
|
|
return buffer.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new RuntimeException("invalid type"); |
|
|
|
throw new RuntimeException("Invalid type: " + type); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String buildJavaClassName(GenericType type) { |
|
|
|
private static String buildJavaClassName(GenericType type) { |
|
|
|
|
|
|
|
|
|
|
|
String name = ""; |
|
|
|
String name = ""; |
|
|
|
for (GenericType tp : type.getEnclosingClasses()) { |
|
|
|
for (GenericType tp : type.getEnclosingClasses()) { |
|
|
|
name += tp.value + "$"; |
|
|
|
name += tp.value + "$"; |
|
|
|