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 void AppendTypeArguments(GenericType type, StringBuilder buffer) { if (!(type.GetArguments().Count == 0)) { buffer.Append('<'); for (int i = 0; i < type.GetArguments().Count; i++) { if (i > 0) { buffer.Append(", "); } int wildcard = type.GetWildcards()[i]; switch (wildcard) { case GenericType.Wildcard_Unbound: { buffer.Append('?'); break; } case GenericType.Wildcard_Extends: { buffer.Append("? extends "); break; } case GenericType.Wildcard_Super: { buffer.Append("? super "); break; } } GenericType genPar = type.GetArguments()[i]; if (genPar != null) { buffer.Append(GetGenericCastTypeName(genPar)); } } buffer.Append(">"); } }
private static void ParseArgumentsList(string value, GenericType type) { if (value == null) { return; } while (value.Length > 0) { string typeStr = GetNextType(value); int len = typeStr.Length; int wildcard = Wildcard_No; switch (typeStr[0]) { case '*': { wildcard = Wildcard_Unbound; break; } case '+': { wildcard = Wildcard_Extends; break; } case '-': { wildcard = Wildcard_Super; break; } } type.GetWildcards().Add(wildcard); if (wildcard != Wildcard_No) { typeStr = Sharpen.Runtime.Substring(typeStr, 1); } type.GetArguments().Add(typeStr.Length == 0 ? null : new GenericType(typeStr)); value = Sharpen.Runtime.Substring(value, len); } }
private static string GetTypeName(GenericType type) { int tp = type.type; if (tp <= ICodeConstants.Type_Boolean) { return(typeNames[tp]); } else if (tp == ICodeConstants.Type_Void) { return("void"); } else if (tp == ICodeConstants.Type_Genvar) { return(type.value); } else if (tp == ICodeConstants.Type_Object) { StringBuilder buffer = new StringBuilder(); AppendClassName(type, buffer); return(buffer.ToString()); } throw new Exception("Invalid type: " + type); }
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 GenericType(string signature) { int type = 0; int arrayDim = 0; string value = null; int index = 0; while (index < signature.Length) { switch (signature[index]) { case '[': { arrayDim++; break; } case 'T': { type = ICodeConstants.Type_Genvar; value = Sharpen.Runtime.Substring(signature, index + 1, signature.Length - 1); goto loop_break; } case 'L': { type = ICodeConstants.Type_Object; signature = Sharpen.Runtime.Substring(signature, index + 1, signature.Length - 1); while (true) { string cl = GetNextClassSignature(signature); string name = cl; string args = null; int argStart = cl.IndexOf("<"); if (argStart >= 0) { name = Sharpen.Runtime.Substring(cl, 0, argStart); args = Sharpen.Runtime.Substring(cl, argStart + 1, cl.Length - 1); } if (cl.Length < signature.Length) { signature = Sharpen.Runtime.Substring(signature, cl.Length + 1); // skip '.' GenericType type11 = new GenericType(ICodeConstants.Type_Object, 0, name); ParseArgumentsList(args, type11); enclosingClasses.Add(type11); } else { value = name; ParseArgumentsList(args, this); break; } } goto loop_break; } default: { value = Sharpen.Runtime.Substring(signature, index, index + 1); type = VarType.GetType(value[0]); break; } } index++; loop_continue :; } loop_break :; this.type = type; this.arrayDim = arrayDim; this.value = value; }
public GenericFieldDescriptor(GenericType type) { this.type = type; }
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); }