/// <summary> /// Create the current type as class definition. /// </summary> public void Create(ClassDefinition declaringClass, DexTargetPackage targetPackage) { // Find xMethod xMethod = XBuilder.AsMethodDefinition(compiler.Module, method); // Create method definition dmethod = new DexLib.MethodDefinition(); dmethod.Name = GetMethodName(method, targetPackage); dmethod.MapFileId = compiler.GetNextMapFileId(); AddMethodToDeclaringClass(declaringClass, dmethod, targetPackage); targetPackage.Record(xMethod, dmethod); // Set access flags SetAccessFlags(dmethod, method); // Create prototype dmethod.Prototype = PrototypeBuilder.BuildPrototype(compiler, targetPackage, declaringClass, method); }
/// <summary> /// Add the given method to its declaring class. /// </summary> protected virtual void SetAccessFlags(DexLib.MethodDefinition dmethod, MethodDefinition method) { if (method.IsPrivate) { dmethod.IsPrivate = true; } if (method.IsProtected) { dmethod.IsProtected = true; } if (method.IsPublic) { dmethod.IsPublic = true; } if (method.DeclaringClass.IsInterface) { dmethod.IsAbstract = true; } else { if (method.IsConstructor) { dmethod.IsConstructor = true; } if (method.IsAbstract) { dmethod.IsAbstract = true; } if (method.IsStatic) { dmethod.IsStatic = true; } if (!method.IsStatic && !method.IsFinal && !method.IsConstructor && !method.IsPrivate) { dmethod.IsVirtual = true; } if (method.IsFinal || method.IsPrivate && !method.IsConstructor) { dmethod.IsFinal = true; } } }
/// <summary> /// Add the given method to its declaring class. /// </summary> protected virtual void AddMethodToDeclaringClass(ClassDefinition declaringClass, DexLib.MethodDefinition dmethod, DexTargetPackage targetPackage) { dmethod.Owner = declaringClass; declaringClass.Methods.Add(dmethod); }