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

Commit 23e47f56 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Java 8 in layoutlib-create

Upgrade to ASM 5 and diamond operators.

Also minor fixes here and there.

Bug: 26442940
Change-Id: I5611ed0889aa94cca8655fec47799e1ddccb0150
parent a5fcd502
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -21,7 +21,5 @@
        <processorPath useClasspath="true" />
        <processorPath useClasspath="true" />
      </profile>
      </profile>
    </annotationProcessing>
    </annotationProcessing>
    <bytecodeTargetLevel target="1.6" />
  </component>
  </component>
</project>
</project>
 No newline at end of file
+1 −1
Original line number Original line Diff line number Diff line
@@ -20,7 +20,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src)


LOCAL_JAR_MANIFEST := manifest.txt
LOCAL_JAR_MANIFEST := manifest.txt
LOCAL_STATIC_JAVA_LIBRARIES := \
LOCAL_STATIC_JAVA_LIBRARIES := \
	asm-4.0
	asm-5.0


LOCAL_MODULE := layoutlib_create
LOCAL_MODULE := layoutlib_create


+4 −4
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
    <exclude-output />
    <exclude-output />
    <content url="file://$MODULE_DIR$">
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
@@ -9,12 +9,12 @@
      <sourceFolder url="file://$MODULE_DIR$/tests/mock_data" type="java-test-resource" />
      <sourceFolder url="file://$MODULE_DIR$/tests/mock_data" type="java-test-resource" />
      <excludeFolder url="file://$MODULE_DIR$/.settings" />
      <excludeFolder url="file://$MODULE_DIR$/.settings" />
    </content>
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="module-library">
    <orderEntry type="module-library">
      <library name="asm-4.0">
      <library name="asm-5.0">
        <CLASSES>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../../../../../prebuilts/misc/common/asm/asm-4.0.jar!/" />
          <root url="jar://$MODULE_DIR$/../../../../../prebuilts/misc/common/asm/asm-5.0.jar!/" />
        </CLASSES>
        </CLASSES>
        <JAVADOC />
        <JAVADOC />
        <SOURCES>
        <SOURCES>
+6 −6
Original line number Original line Diff line number Diff line
@@ -21,7 +21,6 @@ import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.Type;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
import org.objectweb.asm.signature.SignatureVisitor;
@@ -44,7 +43,7 @@ public abstract class AbstractClassAdapter extends ClassVisitor {
    abstract String renameInternalType(String name);
    abstract String renameInternalType(String name);


    public AbstractClassAdapter(ClassVisitor cv) {
    public AbstractClassAdapter(ClassVisitor cv) {
        super(Opcodes.ASM4, cv);
        super(Main.ASM_VERSION, cv);
    }
    }


    /**
    /**
@@ -239,7 +238,7 @@ public abstract class AbstractClassAdapter extends ClassVisitor {
         * The names must be full qualified internal ASM names (e.g. com/blah/MyClass$InnerClass).
         * The names must be full qualified internal ASM names (e.g. com/blah/MyClass$InnerClass).
         */
         */
        public RenameMethodAdapter(MethodVisitor mv) {
        public RenameMethodAdapter(MethodVisitor mv) {
            super(Opcodes.ASM4, mv);
            super(Main.ASM_VERSION, mv);
        }
        }


        @Override
        @Override
@@ -276,7 +275,8 @@ public abstract class AbstractClassAdapter extends ClassVisitor {
        }
        }


        @Override
        @Override
        public void visitMethodInsn(int opcode, String owner, String name, String desc) {
        public void visitMethodInsn(int opcode, String owner, String name, String desc,
                boolean itf) {
            // The owner sometimes turns out to be a type descriptor. We try to detect it and fix.
            // The owner sometimes turns out to be a type descriptor. We try to detect it and fix.
            if (owner.indexOf(';') > 0) {
            if (owner.indexOf(';') > 0) {
                owner = renameTypeDesc(owner);
                owner = renameTypeDesc(owner);
@@ -285,7 +285,7 @@ public abstract class AbstractClassAdapter extends ClassVisitor {
            }
            }
            desc = renameMethodDesc(desc);
            desc = renameMethodDesc(desc);


            super.visitMethodInsn(opcode, owner, name, desc);
            super.visitMethodInsn(opcode, owner, name, desc, itf);
        }
        }


        @Override
        @Override
@@ -330,7 +330,7 @@ public abstract class AbstractClassAdapter extends ClassVisitor {
        private final SignatureVisitor mSv;
        private final SignatureVisitor mSv;


        public RenameSignatureAdapter(SignatureVisitor sv) {
        public RenameSignatureAdapter(SignatureVisitor sv) {
            super(Opcodes.ASM4);
            super(Main.ASM_VERSION);
            mSv = sv;
            mSv = sv;
        }
        }


+15 −15
Original line number Original line Diff line number Diff line
@@ -23,7 +23,6 @@ import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.Type;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
import org.objectweb.asm.signature.SignatureVisitor;
@@ -65,7 +64,7 @@ public class AsmAnalyzer {
    /** Glob patterns of files to keep as is. */
    /** Glob patterns of files to keep as is. */
    private final String[] mIncludeFileGlobs;
    private final String[] mIncludeFileGlobs;
    /** Internal names of classes that contain method calls that need to be rewritten. */
    /** Internal names of classes that contain method calls that need to be rewritten. */
    private final Set<String> mReplaceMethodCallClasses = new HashSet<String>();
    private final Set<String> mReplaceMethodCallClasses = new HashSet<>();


    /**
    /**
     * Creates a new analyzer.
     * Creates a new analyzer.
@@ -97,8 +96,8 @@ public class AsmAnalyzer {
     */
     */
    public void analyze() throws IOException, LogAbortException {
    public void analyze() throws IOException, LogAbortException {


        TreeMap<String, ClassReader> zipClasses = new TreeMap<String, ClassReader>();
        TreeMap<String, ClassReader> zipClasses = new TreeMap<>();
        Map<String, InputStream> filesFound = new TreeMap<String, InputStream>();
        Map<String, InputStream> filesFound = new TreeMap<>();


        parseZip(mOsSourceJar, zipClasses, filesFound);
        parseZip(mOsSourceJar, zipClasses, filesFound);
        mLog.info("Found %d classes in input JAR%s.", zipClasses.size(),
        mLog.info("Found %d classes in input JAR%s.", zipClasses.size(),
@@ -189,7 +188,7 @@ public class AsmAnalyzer {
     */
     */
    Map<String, ClassReader> findIncludes(Map<String, ClassReader> zipClasses)
    Map<String, ClassReader> findIncludes(Map<String, ClassReader> zipClasses)
            throws LogAbortException {
            throws LogAbortException {
        TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>();
        TreeMap<String, ClassReader> found = new TreeMap<>();


        mLog.debug("Find classes to include.");
        mLog.debug("Find classes to include.");


@@ -318,10 +317,10 @@ public class AsmAnalyzer {
    Map<String, ClassReader> findDeps(Map<String, ClassReader> zipClasses,
    Map<String, ClassReader> findDeps(Map<String, ClassReader> zipClasses,
            Map<String, ClassReader> inOutKeepClasses) {
            Map<String, ClassReader> inOutKeepClasses) {


        TreeMap<String, ClassReader> deps = new TreeMap<String, ClassReader>();
        TreeMap<String, ClassReader> deps = new TreeMap<>();
        TreeMap<String, ClassReader> new_deps = new TreeMap<String, ClassReader>();
        TreeMap<String, ClassReader> new_deps = new TreeMap<>();
        TreeMap<String, ClassReader> new_keep = new TreeMap<String, ClassReader>();
        TreeMap<String, ClassReader> new_keep = new TreeMap<>();
        TreeMap<String, ClassReader> temp = new TreeMap<String, ClassReader>();
        TreeMap<String, ClassReader> temp = new TreeMap<>();


        DependencyVisitor visitor = getVisitor(zipClasses,
        DependencyVisitor visitor = getVisitor(zipClasses,
                inOutKeepClasses, new_keep,
                inOutKeepClasses, new_keep,
@@ -399,7 +398,7 @@ public class AsmAnalyzer {
                Map<String, ClassReader> outKeep,
                Map<String, ClassReader> outKeep,
                Map<String,ClassReader> inDeps,
                Map<String,ClassReader> inDeps,
                Map<String,ClassReader> outDeps) {
                Map<String,ClassReader> outDeps) {
            super(Opcodes.ASM4);
            super(Main.ASM_VERSION);
            mZipClasses = zipClasses;
            mZipClasses = zipClasses;
            mInKeep = inKeep;
            mInKeep = inKeep;
            mOutKeep = outKeep;
            mOutKeep = outKeep;
@@ -557,7 +556,7 @@ public class AsmAnalyzer {
        private class MyFieldVisitor extends FieldVisitor {
        private class MyFieldVisitor extends FieldVisitor {


            public MyFieldVisitor() {
            public MyFieldVisitor() {
                super(Opcodes.ASM4);
                super(Main.ASM_VERSION);
            }
            }


            @Override
            @Override
@@ -630,7 +629,7 @@ public class AsmAnalyzer {
            private String mOwnerClass;
            private String mOwnerClass;


            public MyMethodVisitor(String ownerClass) {
            public MyMethodVisitor(String ownerClass) {
                super(Opcodes.ASM4);
                super(Main.ASM_VERSION);
                mOwnerClass = ownerClass;
                mOwnerClass = ownerClass;
            }
            }


@@ -719,7 +718,8 @@ public class AsmAnalyzer {


            // instruction that invokes a method
            // instruction that invokes a method
            @Override
            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc) {
            public void visitMethodInsn(int opcode, String owner, String name, String desc,
                    boolean itf) {


                // owner is the internal name of the method's owner class
                // owner is the internal name of the method's owner class
                considerName(owner);
                considerName(owner);
@@ -779,7 +779,7 @@ public class AsmAnalyzer {
        private class MySignatureVisitor extends SignatureVisitor {
        private class MySignatureVisitor extends SignatureVisitor {


            public MySignatureVisitor() {
            public MySignatureVisitor() {
                super(Opcodes.ASM4);
                super(Main.ASM_VERSION);
            }
            }


            // ---------------------------------------------------
            // ---------------------------------------------------
@@ -878,7 +878,7 @@ public class AsmAnalyzer {
        private class MyAnnotationVisitor extends AnnotationVisitor {
        private class MyAnnotationVisitor extends AnnotationVisitor {


            public MyAnnotationVisitor() {
            public MyAnnotationVisitor() {
                super(Opcodes.ASM4);
                super(Main.ASM_VERSION);
            }
            }


            // Visits a primitive value of an annotation
            // Visits a primitive value of an annotation
Loading