private MethodReference ConvertMethodReference(MethodReference methodRef, AssemblyCompiler compiler, DexTargetPackage targetPackage) { TypeEntry typeEntry; var owner = methodRef.Owner as ClassReference; if (owner == null) { return(methodRef); // this must be an internal method. return as-is. } MethodEntry methodEntry = _map.GetMethodByDexSignature(owner.Fullname, methodRef.Name, methodRef.Prototype.ToSignature()); string scopeId = null; if (methodEntry != null) { // important to do this indirection, to correctly resolve methods in // the "__generated" class typeEntry = _map.GetTypeByMethodId(methodEntry.Id); scopeId = methodEntry.ScopeId; } else { typeEntry = _map.GetTypeBySignature(methodRef.Owner.Descriptor); // special delegate handling if (IsDelegateInstance(typeEntry)) { var delInstanceType = GetDelegateInstanceType(typeEntry, owner, compiler, targetPackage); return(new MethodReference(delInstanceType.InstanceDefinition, methodRef.Name, methodRef.Prototype)); } } if (scopeId == null) { scopeId = methodRef.Name + methodRef.Prototype.ToSignature(); } if (scopeId == "(none)") { throw new CompilerCacheResolveException("unable to resolve method without scope: " + methodRef); } var xTypeDef = ResolveToType(typeEntry, owner, compiler); var methodDef = xTypeDef.GetMethodByScopeId(scopeId); if (methodDef == null) { throw new CompilerCacheResolveException("unable to resolve method by it's scope id: " + methodRef + " (" + scopeId + ")"); } return(methodDef.GetReference(targetPackage)); }
public MethodDisassembly GetFromLocation(DocumentLocation loc) { string className = null, methodName = null, methodSignature = null; if (loc == null) { return(null); } if (loc.Method != null) { var type = loc.Method.DeclaringType.GetSignatureAsync().Await(DalvikProcess.VmTimeout); var typeDef = Descriptors.ParseClassType(type); className = typeDef.ClassName.Replace("/", "."); methodName = loc.Method.Name; methodSignature = loc.Method.Signature; } if (className == null && loc.TypeEntry != null) { className = loc.TypeEntry.DexName; } if (methodName == null && loc.MethodEntry != null) { methodName = loc.MethodEntry.DexName; methodSignature = loc.MethodEntry.Signature; } if (methodName == null || className == null) { return(null); } var methodDef = _dex.Value.GetMethod(className, methodName, methodSignature); if (methodDef == null) { return(null); } var typeEntry = loc.TypeEntry ?? _mapFile.GetTypeByDexName(className); var methodEntry = loc.MethodEntry ?? _mapFile.GetMethodByDexSignature(className, methodName, methodSignature); return(new MethodDisassembly(methodDef, _mapFile, typeEntry, methodEntry)); }