public static GenericClassDescriptor ParseClassSignature(string signature) { string original = signature; try { GenericClassDescriptor descriptor = new GenericClassDescriptor(); signature = ParseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds ); string superCl = GenericType.GetNextType(signature); descriptor.superclass = new GenericType(superCl); signature = Sharpen.Runtime.Substring(signature, superCl.Length); while (signature.Length > 0) { string superIf = GenericType.GetNextType(signature); descriptor.superinterfaces.Add(new GenericType(superIf)); signature = Sharpen.Runtime.Substring(signature, superIf.Length); } return(descriptor); } catch (Exception) { DecompilerContext.GetLogger().WriteMessage("Invalid signature: " + original, IFernflowerLogger.Severity .Warn); return(null); } }
public static GenericMethodDescriptor ParseMethodSignature(string signature) { string original = signature; try { List <string> typeParameters = new List <string>(); List <List <GenericType> > typeParameterBounds = new List <List <GenericType> >(); signature = ParseFormalParameters(signature, typeParameters, typeParameterBounds); int to = signature.IndexOf(")"); string parameters = Sharpen.Runtime.Substring(signature, 1, to); signature = Sharpen.Runtime.Substring(signature, to + 1); List <GenericType> parameterTypes = new List <GenericType>(); while (parameters.Length > 0) { string par = GenericType.GetNextType(parameters); parameterTypes.Add(new GenericType(par)); parameters = Sharpen.Runtime.Substring(parameters, par.Length); } string ret = GenericType.GetNextType(signature); GenericType returnType = new GenericType(ret); signature = Sharpen.Runtime.Substring(signature, ret.Length); List <GenericType> exceptionTypes = new List <GenericType>(); if (signature.Length > 0) { string[] exceptions = signature.Split("\\^"); for (int i = 1; i < exceptions.Length; i++) { exceptionTypes.Add(new GenericType(exceptions[i])); } } return(new GenericMethodDescriptor(typeParameters, typeParameterBounds, parameterTypes , returnType, exceptionTypes)); } catch (Exception) { DecompilerContext.GetLogger().WriteMessage("Invalid signature: " + original, IFernflowerLogger.Severity .Warn); return(null); } }
private static string ParseFormalParameters(string signature, List <string > parameters, List <List <GenericType> > bounds) { if (signature[0] != '<') { return(signature); } int counter = 1; int index = 1; while (index < signature.Length) { switch (signature[index]) { case '<': { counter++; break; } case '>': { counter--; if (counter == 0) { goto loop_break; } break; } } index++; loop_continue :; } loop_break :; string value = Sharpen.Runtime.Substring(signature, 1, index); signature = Sharpen.Runtime.Substring(signature, index + 1); while (value.Length > 0) { int to = value.IndexOf(":"); string param = Sharpen.Runtime.Substring(value, 0, to); value = Sharpen.Runtime.Substring(value, to + 1); List <GenericType> lstBounds = new List <GenericType>(); while (true) { if (value[0] == ':') { // empty superclass, skip value = Sharpen.Runtime.Substring(value, 1); } string bound = GenericType.GetNextType(value); lstBounds.Add(new GenericType(bound)); value = Sharpen.Runtime.Substring(value, bound.Length); if (value.Length == 0 || value[0] != ':') { break; } else { value = Sharpen.Runtime.Substring(value, 1); } } parameters.Add(param); bounds.Add(lstBounds); } return(signature); }