Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5a58437 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Style improvements to LayoutLib create.

This change doesn't change the functionality but removes dead code and
simplifies various places to remove warnings.

Change-Id: I371e06bfbd587dbf0eeafc69787b9805f7008f62
parent 26e32ea5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -236,7 +236,7 @@ method as-is from the reader. This step is omitted if the method is native, sinc
implementation.
b- A brand new implementation of SomeClass.MethodName() which calls to a non-existing static method
named SomeClass_Delegate.MethodName(). The implementation of this 'delegate' method is done in
layoutlib_brigde.
layoutlib_bridge.

The delegate method is a static method. If the original method is non-static, the delegate method
receives the original 'this' as its first argument. If the original method is an inner non-static
+8 −10
Original line number Diff line number Diff line
@@ -216,21 +216,21 @@ public class AsmGenerator {
            String name = classToEntryPath(clazz);
            InputStream is = ClassLoader.getSystemResourceAsStream(name);
            ClassReader cr = new ClassReader(is);
            byte[] b = transform(cr, true /* stubNativesOnly */);
            byte[] b = transform(cr, true);
            name = classNameToEntryPath(transformName(cr.getClassName()));
            all.put(name, b);
        }

        for (Entry<String, ClassReader> entry : mDeps.entrySet()) {
            ClassReader cr = entry.getValue();
            byte[] b = transform(cr, true /* stubNativesOnly */);
            byte[] b = transform(cr, true);
            String name = classNameToEntryPath(transformName(cr.getClassName()));
            all.put(name, b);
        }

        for (Entry<String, ClassReader> entry : mKeep.entrySet()) {
            ClassReader cr = entry.getValue();
            byte[] b = transform(cr, true /* stubNativesOnly */);
            byte[] b = transform(cr, true);
            String name = classNameToEntryPath(transformName(cr.getClassName()));
            all.put(name, b);
        }
@@ -282,7 +282,7 @@ public class AsmGenerator {

    /**
     * Utility method to get the JAR entry path from a Class name.
     * e.g. it returns someting like "com/foo/OuterClass$InnerClass1$InnerClass2.class"
     * e.g. it returns something like "com/foo/OuterClass$InnerClass1$InnerClass2.class"
     */
    private String classToEntryPath(Class<?> clazz) {
        String name = "";
@@ -345,10 +345,8 @@ public class AsmGenerator {
            cv = new RenameClassAdapter(cv, className, newName);
        }

        cv = new TransformClassAdapter(mLog, mStubMethods,
                mDeleteReturns.get(className),
                newName, cv,
                stubNativesOnly, stubNativesOnly || hasNativeMethods);
        cv = new TransformClassAdapter(mLog, mStubMethods, mDeleteReturns.get(className),
                newName, cv, stubNativesOnly);

        Set<String> delegateMethods = mDelegateMethods.get(className);
        if (delegateMethods != null && !delegateMethods.isEmpty()) {
@@ -361,7 +359,7 @@ public class AsmGenerator {
            }
        }

        cr.accept(cv, 0 /* flags */);
        cr.accept(cv, 0);
        return cw.toByteArray();
    }

@@ -395,7 +393,7 @@ public class AsmGenerator {
     */
    boolean hasNativeMethods(ClassReader cr) {
        ClassHasNativeVisitor cv = new ClassHasNativeVisitor();
        cr.accept(cv, 0 /* flags */);
        cr.accept(cv, 0);
        return cv.hasNativeMethods();
    }

+14 −23
Original line number Diff line number Diff line
@@ -32,10 +32,10 @@ public class DelegateClassAdapter extends ClassVisitor {

    /** Suffix added to original methods. */
    private static final String ORIGINAL_SUFFIX = "_Original";
    private static String CONSTRUCTOR = "<init>";
    private static String CLASS_INIT = "<clinit>";
    private static final String CONSTRUCTOR = "<init>";
    private static final String CLASS_INIT = "<clinit>";

    public final static String ALL_NATIVES = "<<all_natives>>";
    public static final String ALL_NATIVES = "<<all_natives>>";

    private final String mClassName;
    private final Set<String> mDelegateMethods;
@@ -78,12 +78,10 @@ public class DelegateClassAdapter extends ClassVisitor {
                              mDelegateMethods.contains(name);

        if (!useDelegate) {
            // Not creating a delegate for this method, pass it as-is from the reader
            // to the writer.
            // Not creating a delegate for this method, pass it as-is from the reader to the writer.
            return super.visitMethod(access, name, desc, signature, exceptions);
        }

        if (useDelegate) {
        if (CONSTRUCTOR.equals(name) || CLASS_INIT.equals(name)) {
            // We don't currently support generating delegates for constructors.
            throw new UnsupportedOperationException(
@@ -91,15 +89,14 @@ public class DelegateClassAdapter extends ClassVisitor {
                    "Delegate doesn't support overriding constructor %1$s:%2$s(%3$s)",  //$NON-NLS-1$
                    mClassName, name, desc));
        }
        }

        if (isNative) {
            // Remove native flag
            access = access & ~Opcodes.ACC_NATIVE;
            MethodVisitor mwDelegate = super.visitMethod(access, name, desc, signature, exceptions);

            DelegateMethodAdapter2 a = new DelegateMethodAdapter2(
                    mLog, null /*mwOriginal*/, mwDelegate, mClassName, name, desc, isStatic);
            DelegateMethodAdapter a = new DelegateMethodAdapter(
                    mLog, null, mwDelegate, mClassName, name, desc, isStatic);

            // A native has no code to visit, so we need to generate it directly.
            a.generateDelegateCode();
@@ -112,22 +109,16 @@ public class DelegateClassAdapter extends ClassVisitor {
        //   The content is the original method as-is from the reader.
        // - A brand new implementation of SomeClass.MethodName() which calls to a
        //   non-existing method named SomeClass_Delegate.MethodName().
        //   The implementation of this 'delegate' method is done in layoutlib_brigde.
        //   The implementation of this 'delegate' method is done in layoutlib_bridge.

        int accessDelegate = access;
        // change access to public for the original one
        if (Main.sOptions.generatePublicAccess) {
            access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);
            access |= Opcodes.ACC_PUBLIC;
        }

        MethodVisitor mwOriginal = super.visitMethod(access, name + ORIGINAL_SUFFIX,
                                                     desc, signature, exceptions);
        MethodVisitor mwDelegate = super.visitMethod(accessDelegate, name,
                                                     desc, signature, exceptions);

        DelegateMethodAdapter2 a = new DelegateMethodAdapter2(
        return new DelegateMethodAdapter(
                mLog, mwOriginal, mwDelegate, mClassName, name, desc, isStatic);
        return a;
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ import java.util.ArrayList;
 * Instances of this class are not re-usable.
 * The class adapter creates a new instance for each method.
 */
class DelegateMethodAdapter2 extends MethodVisitor {
class DelegateMethodAdapter extends MethodVisitor {

    /** Suffix added to delegate classes. */
    public static final String DELEGATE_SUFFIX = "_Delegate";
@@ -97,10 +97,10 @@ class DelegateMethodAdapter2 extends MethodVisitor {
    private Object[] mDelegateLineNumber;

    /**
     * Creates a new {@link DelegateMethodAdapter2} that will transform this method
     * Creates a new {@link DelegateMethodAdapter} that will transform this method
     * into a delegate call.
     * <p/>
     * See {@link DelegateMethodAdapter2} for more details.
     * See {@link DelegateMethodAdapter} for more details.
     *
     * @param log The logger object. Must not be null.
     * @param mvOriginal The parent method writer to copy of the original method.
@@ -114,7 +114,7 @@ class DelegateMethodAdapter2 extends MethodVisitor {
     *          {@link Type#getArgumentTypes(String)})
     * @param isStatic True if the method is declared static.
     */
    public DelegateMethodAdapter2(Log log,
    public DelegateMethodAdapter(Log log,
            MethodVisitor mvOriginal,
            MethodVisitor mvDelegate,
            String className,
@@ -138,7 +138,7 @@ class DelegateMethodAdapter2 extends MethodVisitor {
     * (since they have no code to visit).
     * <p/>
     * Otherwise for non-native methods the {@link DelegateClassAdapter} simply needs to
     * return this instance of {@link DelegateMethodAdapter2} and let the normal visitor pattern
     * return this instance of {@link DelegateMethodAdapter} and let the normal visitor pattern
     * invoke it as part of the {@link ClassReader#accept(ClassVisitor, int)} workflow and then
     * this method will be invoked from {@link MethodVisitor#visitEnd()}.
     */
+0 −5
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import java.util.Set;
public class Main {

    public static class Options {
        public boolean generatePublicAccess = true;
        public boolean listAllDeps = false;
        public boolean listOnlyMissingDeps = false;
    }
@@ -196,8 +195,6 @@ public class Main {
        for (String s : args) {
            if (s.equals("-v")) {
                log.setVerbose(true);
            } else if (s.equals("-p")) {
                sOptions.generatePublicAccess = false;
            } else if (s.equals("--list-deps")) {
                sOptions.listAllDeps = true;
                needs_dest = false;
@@ -225,8 +222,6 @@ public class Main {
            return false;
        }

        sOptions.generatePublicAccess = false;

        return true;
    }
}
Loading