diff options
| author | 2016-02-10 03:29:28 +0000 | |
|---|---|---|
| committer | 2016-02-10 03:29:28 +0000 | |
| commit | 205bf7a1044742c0f18064293dce0ce256b0901c (patch) | |
| tree | ca47a8039e73adcbb572dc1018dd77d274360019 | |
| parent | 9653790de25dfa77076701c3c2932ea93b7f9968 (diff) | |
| parent | e96ffcfd50d2ed3d12f6d9677711bcb5c4092c60 (diff) | |
Merge "Java 8 in layoutlib-create"
26 files changed, 189 insertions, 192 deletions
diff --git a/tools/layoutlib/.idea/compiler.xml b/tools/layoutlib/.idea/compiler.xml index 5aaaf18f9d94..35961a2896ac 100644 --- a/tools/layoutlib/.idea/compiler.xml +++ b/tools/layoutlib/.idea/compiler.xml @@ -21,7 +21,5 @@ <processorPath useClasspath="true" /> </profile> </annotationProcessing> - <bytecodeTargetLevel target="1.6" /> </component> -</project> - +</project>
\ No newline at end of file diff --git a/tools/layoutlib/create/Android.mk b/tools/layoutlib/create/Android.mk index e6f0bc306b07..c7f2c4137687 100644 --- a/tools/layoutlib/create/Android.mk +++ b/tools/layoutlib/create/Android.mk @@ -20,7 +20,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src) LOCAL_JAR_MANIFEST := manifest.txt LOCAL_STATIC_JAVA_LIBRARIES := \ - asm-4.0 + asm-5.0 LOCAL_MODULE := layoutlib_create diff --git a/tools/layoutlib/create/create.iml b/tools/layoutlib/create/create.iml index 9b18e73aae90..b2b14b4e8a91 100644 --- a/tools/layoutlib/create/create.iml +++ b/tools/layoutlib/create/create.iml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <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 /> <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> @@ -9,12 +9,12 @@ <sourceFolder url="file://$MODULE_DIR$/tests/mock_data" type="java-test-resource" /> <excludeFolder url="file://$MODULE_DIR$/.settings" /> </content> - <orderEntry type="inheritedJdk" /> + <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" /> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="module-library"> - <library name="asm-4.0"> + <library name="asm-5.0"> <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> <JAVADOC /> <SOURCES> diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AbstractClassAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AbstractClassAdapter.java index a6902a40b1a3..758bd48e6067 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AbstractClassAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AbstractClassAdapter.java @@ -21,7 +21,6 @@ import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.signature.SignatureReader; import org.objectweb.asm.signature.SignatureVisitor; @@ -44,7 +43,7 @@ public abstract class AbstractClassAdapter extends ClassVisitor { abstract String renameInternalType(String name); 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). */ public RenameMethodAdapter(MethodVisitor mv) { - super(Opcodes.ASM4, mv); + super(Main.ASM_VERSION, mv); } @Override @@ -276,7 +275,8 @@ public abstract class AbstractClassAdapter extends ClassVisitor { } @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. if (owner.indexOf(';') > 0) { owner = renameTypeDesc(owner); @@ -285,7 +285,7 @@ public abstract class AbstractClassAdapter extends ClassVisitor { } desc = renameMethodDesc(desc); - super.visitMethodInsn(opcode, owner, name, desc); + super.visitMethodInsn(opcode, owner, name, desc, itf); } @Override @@ -330,7 +330,7 @@ public abstract class AbstractClassAdapter extends ClassVisitor { private final SignatureVisitor mSv; public RenameSignatureAdapter(SignatureVisitor sv) { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); mSv = sv; } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java index c8b2b8448e21..48544cac16ab 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java @@ -23,7 +23,6 @@ import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.signature.SignatureReader; import org.objectweb.asm.signature.SignatureVisitor; @@ -65,7 +64,7 @@ public class AsmAnalyzer { /** Glob patterns of files to keep as is. */ private final String[] mIncludeFileGlobs; /** 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. @@ -97,8 +96,8 @@ public class AsmAnalyzer { */ public void analyze() throws IOException, LogAbortException { - TreeMap<String, ClassReader> zipClasses = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + TreeMap<String, ClassReader> zipClasses = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); parseZip(mOsSourceJar, zipClasses, filesFound); 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) throws LogAbortException { - TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>(); + TreeMap<String, ClassReader> found = new TreeMap<>(); mLog.debug("Find classes to include."); @@ -318,10 +317,10 @@ public class AsmAnalyzer { Map<String, ClassReader> findDeps(Map<String, ClassReader> zipClasses, Map<String, ClassReader> inOutKeepClasses) { - TreeMap<String, ClassReader> deps = new TreeMap<String, ClassReader>(); - TreeMap<String, ClassReader> new_deps = new TreeMap<String, ClassReader>(); - TreeMap<String, ClassReader> new_keep = new TreeMap<String, ClassReader>(); - TreeMap<String, ClassReader> temp = new TreeMap<String, ClassReader>(); + TreeMap<String, ClassReader> deps = new TreeMap<>(); + TreeMap<String, ClassReader> new_deps = new TreeMap<>(); + TreeMap<String, ClassReader> new_keep = new TreeMap<>(); + TreeMap<String, ClassReader> temp = new TreeMap<>(); DependencyVisitor visitor = getVisitor(zipClasses, inOutKeepClasses, new_keep, @@ -399,7 +398,7 @@ public class AsmAnalyzer { Map<String, ClassReader> outKeep, Map<String,ClassReader> inDeps, Map<String,ClassReader> outDeps) { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); mZipClasses = zipClasses; mInKeep = inKeep; mOutKeep = outKeep; @@ -557,7 +556,7 @@ public class AsmAnalyzer { private class MyFieldVisitor extends FieldVisitor { public MyFieldVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } @Override @@ -630,7 +629,7 @@ public class AsmAnalyzer { private String mOwnerClass; public MyMethodVisitor(String ownerClass) { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); mOwnerClass = ownerClass; } @@ -719,7 +718,8 @@ public class AsmAnalyzer { // instruction that invokes a method @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 considerName(owner); @@ -779,7 +779,7 @@ public class AsmAnalyzer { private class MySignatureVisitor extends SignatureVisitor { public MySignatureVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } // --------------------------------------------------- @@ -878,7 +878,7 @@ public class AsmAnalyzer { private class MyAnnotationVisitor extends AnnotationVisitor { public MyAnnotationVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } // Visits a primitive value of an annotation diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java index 8f0ad01c6dc3..5b99a6bae195 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java @@ -91,7 +91,7 @@ public class AsmGenerator { mLog = log; mOsDestJar = osDestJar; ArrayList<Class<?>> injectedClasses = - new ArrayList<Class<?>>(Arrays.asList(createInfo.getInjectedClasses())); + new ArrayList<>(Arrays.asList(createInfo.getInjectedClasses())); // Search for and add anonymous inner classes also. ListIterator<Class<?>> iter = injectedClasses.listIterator(); while (iter.hasNext()) { @@ -107,25 +107,25 @@ public class AsmGenerator { } } mInjectClasses = injectedClasses.toArray(new Class<?>[0]); - mStubMethods = new HashSet<String>(Arrays.asList(createInfo.getOverriddenMethods())); + mStubMethods = new HashSet<>(Arrays.asList(createInfo.getOverriddenMethods())); // Create the map/set of methods to change to delegates - mDelegateMethods = new HashMap<String, Set<String>>(); + mDelegateMethods = new HashMap<>(); addToMap(createInfo.getDelegateMethods(), mDelegateMethods); for (String className : createInfo.getDelegateClassNatives()) { className = binaryToInternalClassName(className); Set<String> methods = mDelegateMethods.get(className); if (methods == null) { - methods = new HashSet<String>(); + methods = new HashSet<>(); mDelegateMethods.put(className, methods); } methods.add(DelegateClassAdapter.ALL_NATIVES); } // Create the map of classes to rename. - mRenameClasses = new HashMap<String, String>(); - mClassesNotRenamed = new HashSet<String>(); + mRenameClasses = new HashMap<>(); + mClassesNotRenamed = new HashSet<>(); String[] renameClasses = createInfo.getRenamedClasses(); int n = renameClasses.length; for (int i = 0; i < n; i += 2) { @@ -138,7 +138,7 @@ public class AsmGenerator { } // Create a map of classes to be refactored. - mRefactorClasses = new HashMap<String, String>(); + mRefactorClasses = new HashMap<>(); String[] refactorClasses = createInfo.getJavaPkgClasses(); n = refactorClasses.length; for (int i = 0; i < n; i += 2) { @@ -149,7 +149,7 @@ public class AsmGenerator { } // create the map of renamed class -> return type of method to delete. - mDeleteReturns = new HashMap<String, Set<String>>(); + mDeleteReturns = new HashMap<>(); String[] deleteReturns = createInfo.getDeleteReturns(); Set<String> returnTypes = null; String renamedClass = null; @@ -172,12 +172,12 @@ public class AsmGenerator { // just a standard return type, we add it to the list. if (returnTypes == null) { - returnTypes = new HashSet<String>(); + returnTypes = new HashSet<>(); } returnTypes.add(binaryToInternalClassName(className)); } - mPromotedFields = new HashMap<String, Set<String>>(); + mPromotedFields = new HashMap<>(); addToMap(createInfo.getPromotedFields(), mPromotedFields); mInjectedMethodsMap = createInfo.getInjectedMethodsMap(); @@ -197,7 +197,7 @@ public class AsmGenerator { String methodOrFieldName = entry.substring(pos + 1); Set<String> set = map.get(className); if (set == null) { - set = new HashSet<String>(); + set = new HashSet<>(); map.put(className, set); } set.add(methodOrFieldName); @@ -247,7 +247,7 @@ public class AsmGenerator { /** Generates the final JAR */ public void generate() throws IOException { - TreeMap<String, byte[]> all = new TreeMap<String, byte[]>(); + TreeMap<String, byte[]> all = new TreeMap<>(); for (Class<?> clazz : mInjectClasses) { String name = classToEntryPath(clazz); @@ -314,7 +314,7 @@ public class AsmGenerator { * e.g. for the input "android.view.View" it returns "android/view/View.class" */ String classNameToEntryPath(String className) { - return className.replaceAll("\\.", "/").concat(".class"); + return className.replace('.', '/').concat(".class"); } /** diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ClassHasNativeVisitor.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ClassHasNativeVisitor.java index 2c955fd9d9bb..4748a7c7b2f1 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ClassHasNativeVisitor.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ClassHasNativeVisitor.java @@ -31,7 +31,7 @@ import org.objectweb.asm.Opcodes; */ public class ClassHasNativeVisitor extends ClassVisitor { public ClassHasNativeVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } private boolean mHasNativeMethods = false; diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java index 7c838e97cd63..c063b529cb7d 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java @@ -111,7 +111,7 @@ public final class CreateInfo implements ICreateInfo { public Set<String> getExcludedClasses() { String[] refactoredClasses = getJavaPkgClasses(); int count = refactoredClasses.length / 2 + EXCLUDED_CLASSES.length; - Set<String> excludedClasses = new HashSet<String>(count); + Set<String> excludedClasses = new HashSet<>(count); for (int i = 0; i < refactoredClasses.length; i+=2) { excludedClasses.add(refactoredClasses[i]); } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java index ae4a57d8eea4..cb3de4e6efac 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java @@ -58,7 +58,7 @@ public class DelegateClassAdapter extends ClassVisitor { ClassVisitor cv, String className, Set<String> delegateMethods) { - super(Opcodes.ASM4, cv); + super(Main.ASM_VERSION, cv); mLog = log; mClassName = className; mDelegateMethods = delegateMethods; diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter.java index 12690db547a9..a1b1d944cf6d 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter.java @@ -121,7 +121,7 @@ class DelegateMethodAdapter extends MethodVisitor { String methodName, String desc, boolean isStatic) { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); mLog = log; mOrgWriter = mvOriginal; mDelWriter = mvDelegate; @@ -184,7 +184,7 @@ class DelegateMethodAdapter extends MethodVisitor { mDelWriter.visitLineNumber((Integer) p[0], (Label) p[1]); } - ArrayList<Type> paramTypes = new ArrayList<Type>(); + ArrayList<Type> paramTypes = new ArrayList<>(); String delegateClassName = mClassName + DELEGATE_SUFFIX; boolean pushedArg0 = false; int maxStack = 0; @@ -249,7 +249,8 @@ class DelegateMethodAdapter extends MethodVisitor { mDelWriter.visitMethodInsn(Opcodes.INVOKESTATIC, delegateClassName, mMethodName, - desc); + desc, + false); Type returnType = Type.getReturnType(mDesc); mDelWriter.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); @@ -367,9 +368,9 @@ class DelegateMethodAdapter extends MethodVisitor { } @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) { if (mOrgWriter != null) { - mOrgWriter.visitMethodInsn(opcode, owner, name, desc); + mOrgWriter.visitMethodInsn(opcode, owner, name, desc, itf); } } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DependencyFinder.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DependencyFinder.java index 61b64a2e8e38..aa68ea099844 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DependencyFinder.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DependencyFinder.java @@ -26,7 +26,6 @@ import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.signature.SignatureReader; import org.objectweb.asm.signature.SignatureVisitor; @@ -82,7 +81,7 @@ public class DependencyFinder { Map<String, Set<String>> missing = findMissingClasses(deps, zipClasses.keySet()); - List<Map<String, Set<String>>> result = new ArrayList<Map<String,Set<String>>>(2); + List<Map<String, Set<String>>> result = new ArrayList<>(2); result.add(deps); result.add(missing); return result; @@ -151,7 +150,7 @@ public class DependencyFinder { * class name => ASM ClassReader. Class names are in the form "android.view.View". */ Map<String,ClassReader> parseZip(List<String> jarPathList) throws IOException { - TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>(); + TreeMap<String, ClassReader> classes = new TreeMap<>(); for (String jarPath : jarPathList) { ZipFile zip = new ZipFile(jarPath); @@ -202,7 +201,7 @@ public class DependencyFinder { // The dependencies that we'll collect. // It's a map Class name => uses class names. - Map<String, Set<String>> dependencyMap = new TreeMap<String, Set<String>>(); + Map<String, Set<String>> dependencyMap = new TreeMap<>(); DependencyVisitor visitor = getVisitor(); @@ -211,7 +210,7 @@ public class DependencyFinder { for (Entry<String, ClassReader> entry : zipClasses.entrySet()) { String name = entry.getKey(); - TreeSet<String> set = new TreeSet<String>(); + TreeSet<String> set = new TreeSet<>(); dependencyMap.put(name, set); visitor.setDependencySet(set); @@ -240,7 +239,7 @@ public class DependencyFinder { private Map<String, Set<String>> findMissingClasses( Map<String, Set<String>> deps, Set<String> zipClasses) { - Map<String, Set<String>> missing = new TreeMap<String, Set<String>>(); + Map<String, Set<String>> missing = new TreeMap<>(); for (Entry<String, Set<String>> entry : deps.entrySet()) { String name = entry.getKey(); @@ -250,7 +249,7 @@ public class DependencyFinder { // This dependency doesn't exist in the zip classes. Set<String> set = missing.get(dep); if (set == null) { - set = new TreeSet<String>(); + set = new TreeSet<>(); missing.put(dep, set); } set.add(name); @@ -284,7 +283,7 @@ public class DependencyFinder { * Creates a new visitor that will find all the dependencies for the visited class. */ public DependencyVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } /** @@ -435,7 +434,7 @@ public class DependencyFinder { private class MyFieldVisitor extends FieldVisitor { public MyFieldVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } @Override @@ -510,7 +509,7 @@ public class DependencyFinder { private class MyMethodVisitor extends MethodVisitor { public MyMethodVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } @@ -598,7 +597,8 @@ public class DependencyFinder { // instruction that invokes a method @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 if (!considerDesc(owner) && owner.indexOf('/') != -1) { @@ -654,7 +654,7 @@ public class DependencyFinder { private class MySignatureVisitor extends SignatureVisitor { public MySignatureVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } // --------------------------------------------------- @@ -753,7 +753,7 @@ public class DependencyFinder { private class MyAnnotationVisitor extends AnnotationVisitor { public MyAnnotationVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } // Visits a primitive value of an annotation diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/InjectMethodRunnables.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/InjectMethodRunnables.java index 37fc096acb04..1941ab4e78d8 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/InjectMethodRunnables.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/InjectMethodRunnables.java @@ -42,9 +42,9 @@ public class InjectMethodRunnables { mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", - "()Ljava/lang/Class;"); + "()Ljava/lang/Class;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getClassLoader", - "()Ljava/lang/ClassLoader;"); + "()Ljava/lang/ClassLoader;", false); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/InjectMethodsAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/InjectMethodsAdapter.java index ea2b9c900ad0..c834808d950d 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/InjectMethodsAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/InjectMethodsAdapter.java @@ -19,7 +19,6 @@ package com.android.tools.layoutlib.create; import com.android.tools.layoutlib.create.ICreateInfo.InjectMethodRunnable; import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.Opcodes; /** * Injects methods into some classes. @@ -29,7 +28,7 @@ public class InjectMethodsAdapter extends ClassVisitor { private final ICreateInfo.InjectMethodRunnable mRunnable; public InjectMethodsAdapter(ClassVisitor cv, InjectMethodRunnable runnable) { - super(Opcodes.ASM4, cv); + super(Main.ASM_VERSION, cv); mRunnable = runnable; } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java index 383168face86..9bb91e599d77 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java @@ -16,6 +16,8 @@ package com.android.tools.layoutlib.create; +import org.objectweb.asm.Opcodes; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -52,13 +54,15 @@ public class Main { public boolean listOnlyMissingDeps = false; } + public static final int ASM_VERSION = Opcodes.ASM5; + public static final Options sOptions = new Options(); public static void main(String[] args) { Log log = new Log(); - ArrayList<String> osJarPath = new ArrayList<String>(); + ArrayList<String> osJarPath = new ArrayList<>(); String[] osDestJar = { null }; if (!processArgs(log, args, osJarPath, osDestJar)) { diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/MethodListener.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/MethodListener.java index 6fc2b240b84f..faba4d727a06 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/MethodListener.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/MethodListener.java @@ -36,41 +36,40 @@ public interface MethodListener { * @param isNative True if the method was a native method. * @param caller The calling object. Null for static methods, "this" for instance methods. */ - public void onInvokeV(String signature, boolean isNative, Object caller); + void onInvokeV(String signature, boolean isNative, Object caller); /** * Same as {@link #onInvokeV(String, boolean, Object)} but returns an integer or similar. * @see #onInvokeV(String, boolean, Object) * @return an integer, or a boolean, or a short or a byte. */ - public int onInvokeI(String signature, boolean isNative, Object caller); + int onInvokeI(String signature, boolean isNative, Object caller); /** * Same as {@link #onInvokeV(String, boolean, Object)} but returns a long. * @see #onInvokeV(String, boolean, Object) * @return a long. */ - public long onInvokeL(String signature, boolean isNative, Object caller); + long onInvokeL(String signature, boolean isNative, Object caller); /** * Same as {@link #onInvokeV(String, boolean, Object)} but returns a float. * @see #onInvokeV(String, boolean, Object) * @return a float. */ - public float onInvokeF(String signature, boolean isNative, Object caller); + float onInvokeF(String signature, boolean isNative, Object caller); /** * Same as {@link #onInvokeV(String, boolean, Object)} but returns a double. * @see #onInvokeV(String, boolean, Object) * @return a double. */ - public double onInvokeD(String signature, boolean isNative, Object caller); + double onInvokeD(String signature, boolean isNative, Object caller); /** * Same as {@link #onInvokeV(String, boolean, Object)} but returns an object. * @see #onInvokeV(String, boolean, Object) * @return an object. */ - public Object onInvokeA(String signature, boolean isNative, Object caller); + Object onInvokeA(String signature, boolean isNative, Object caller); } - diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/OverrideMethod.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/OverrideMethod.java index 4c87b3c3562d..7ccafc3867e7 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/OverrideMethod.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/OverrideMethod.java @@ -28,7 +28,7 @@ import java.util.HashMap; public final class OverrideMethod { /** Map of method overridden. */ - private static HashMap<String, MethodListener> sMethods = new HashMap<String, MethodListener>(); + private static HashMap<String, MethodListener> sMethods = new HashMap<>(); /** Default listener for all method not listed in sMethods. Nothing if null. */ private static MethodListener sDefaultListener = null; diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/PromoteFieldClassAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/PromoteFieldClassAdapter.java index e4b70da2504f..05af0337a397 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/PromoteFieldClassAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/PromoteFieldClassAdapter.java @@ -24,7 +24,6 @@ import java.util.Set; import static org.objectweb.asm.Opcodes.ACC_PRIVATE; import static org.objectweb.asm.Opcodes.ACC_PROTECTED; import static org.objectweb.asm.Opcodes.ACC_PUBLIC; -import static org.objectweb.asm.Opcodes.ASM4; /** * Promotes given fields to public visibility. @@ -35,7 +34,7 @@ public class PromoteFieldClassAdapter extends ClassVisitor { private static final int ACC_NOT_PUBLIC = ~(ACC_PRIVATE | ACC_PROTECTED); public PromoteFieldClassAdapter(ClassVisitor cv, Set<String> fieldNames) { - super(ASM4, cv); + super(Main.ASM_VERSION, cv); mFieldNames = fieldNames; } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java index 0b85c48b4e68..4bc6508b75c3 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java @@ -43,11 +43,11 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { * Descriptors for specialized versions {@link System#arraycopy} that are not present on the * Desktop VM. */ - private static Set<String> ARRAYCOPY_DESCRIPTORS = new HashSet<String>(Arrays.asList( + private static Set<String> ARRAYCOPY_DESCRIPTORS = new HashSet<>(Arrays.asList( "([CI[CII)V", "([BI[BII)V", "([SI[SII)V", "([II[III)V", "([JI[JII)V", "([FI[FII)V", "([DI[DII)V", "([ZI[ZII)V")); - private static final List<MethodReplacer> METHOD_REPLACERS = new ArrayList<MethodReplacer>(5); + private static final List<MethodReplacer> METHOD_REPLACERS = new ArrayList<>(5); private static final String ANDROID_LOCALE_CLASS = "com/android/layoutlib/bridge/android/AndroidLocale"; @@ -206,7 +206,7 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { private final String mOriginalClassName; public ReplaceMethodCallsAdapter(ClassVisitor cv, String originalClassName) { - super(Opcodes.ASM4, cv); + super(Main.ASM_VERSION, cv); mOriginalClassName = originalClassName; } @@ -219,11 +219,12 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { private class MyMethodVisitor extends MethodVisitor { public MyMethodVisitor(MethodVisitor mv) { - super(Opcodes.ASM4, mv); + super(Main.ASM_VERSION, mv); } @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) { for (MethodReplacer replacer : METHOD_REPLACERS) { if (replacer.isNeeded(owner, name, desc, mOriginalClassName)) { MethodInformation mi = new MethodInformation(opcode, owner, name, desc); @@ -235,7 +236,7 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { break; } } - super.visitMethodInsn(opcode, owner, name, desc); + super.visitMethodInsn(opcode, owner, name, desc, itf); } } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/StubMethodAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/StubMethodAdapter.java index 416b73a43c11..b5ab73855189 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/StubMethodAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/StubMethodAdapter.java @@ -50,7 +50,7 @@ class StubMethodAdapter extends MethodVisitor { public StubMethodAdapter(MethodVisitor mv, String methodName, Type returnType, String invokeSignature, boolean isStatic, boolean isNative) { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); mParentVisitor = mv; mReturnType = returnType; mInvokeSignature = invokeSignature; @@ -82,7 +82,8 @@ class StubMethodAdapter extends MethodVisitor { mParentVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/android/tools/layoutlib/create/OverrideMethod", "invokeV", - "(Ljava/lang/String;ZLjava/lang/Object;)V"); + "(Ljava/lang/String;ZLjava/lang/Object;)V", + false); mParentVisitor.visitInsn(Opcodes.RETURN); break; case Type.BOOLEAN: @@ -93,7 +94,8 @@ class StubMethodAdapter extends MethodVisitor { mParentVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/android/tools/layoutlib/create/OverrideMethod", "invokeI", - "(Ljava/lang/String;ZLjava/lang/Object;)I"); + "(Ljava/lang/String;ZLjava/lang/Object;)I", + false); switch(sort) { case Type.BOOLEAN: Label l1 = new Label(); @@ -119,21 +121,24 @@ class StubMethodAdapter extends MethodVisitor { mParentVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/android/tools/layoutlib/create/OverrideMethod", "invokeL", - "(Ljava/lang/String;ZLjava/lang/Object;)J"); + "(Ljava/lang/String;ZLjava/lang/Object;)J", + false); mParentVisitor.visitInsn(Opcodes.LRETURN); break; case Type.FLOAT: mParentVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/android/tools/layoutlib/create/OverrideMethod", "invokeF", - "(Ljava/lang/String;ZLjava/lang/Object;)F"); + "(Ljava/lang/String;ZLjava/lang/Object;)F", + false); mParentVisitor.visitInsn(Opcodes.FRETURN); break; case Type.DOUBLE: mParentVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/android/tools/layoutlib/create/OverrideMethod", "invokeD", - "(Ljava/lang/String;ZLjava/lang/Object;)D"); + "(Ljava/lang/String;ZLjava/lang/Object;)D", + false); mParentVisitor.visitInsn(Opcodes.DRETURN); break; case Type.ARRAY: @@ -141,7 +146,8 @@ class StubMethodAdapter extends MethodVisitor { mParentVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/android/tools/layoutlib/create/OverrideMethod", "invokeA", - "(Ljava/lang/String;ZLjava/lang/Object;)Ljava/lang/Object;"); + "(Ljava/lang/String;ZLjava/lang/Object;)Ljava/lang/Object;", + false); mParentVisitor.visitTypeInsn(Opcodes.CHECKCAST, mReturnType.getInternalName()); mParentVisitor.visitInsn(Opcodes.ARETURN); break; @@ -282,9 +288,9 @@ class StubMethodAdapter extends MethodVisitor { } @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) { if (mIsInitMethod) { - mParentVisitor.visitMethodInsn(opcode, owner, name, desc); + mParentVisitor.visitMethodInsn(opcode, owner, name, desc, itf); } } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java index d9ecf980658c..a28ae694246d 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java @@ -49,7 +49,7 @@ class TransformClassAdapter extends ClassVisitor { public TransformClassAdapter(Log logger, Set<String> stubMethods, Set<String> deleteReturns, String className, ClassVisitor cv, boolean stubNativesOnly) { - super(Opcodes.ASM4, cv); + super(Main.ASM_VERSION, cv); mLog = logger; mStubMethods = stubMethods; mClassName = className; diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/java/AutoCloseable.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/AutoCloseable.java index ed2c128e1900..7d6c4ec1ad9e 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/java/AutoCloseable.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/AutoCloseable.java @@ -28,4 +28,5 @@ public interface AutoCloseable { /** * Closes the object and release any system resources it holds. */ - void close() throws Exception; } + void close() throws Exception; +} diff --git a/tools/layoutlib/create/tests/Android.mk b/tools/layoutlib/create/tests/Android.mk index c197d5733658..dafb9c6f9402 100644 --- a/tools/layoutlib/create/tests/Android.mk +++ b/tools/layoutlib/create/tests/Android.mk @@ -24,7 +24,7 @@ LOCAL_MODULE := layoutlib-create-tests LOCAL_MODULE_TAGS := optional LOCAL_JAVA_LIBRARIES := layoutlib_create junit -LOCAL_STATIC_JAVA_LIBRARIES := asm-4.0 +LOCAL_STATIC_JAVA_LIBRARIES := asm-5.0 include $(BUILD_HOST_JAVA_LIBRARY) diff --git a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmAnalyzerTest.java b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmAnalyzerTest.java index 78e2c4899c1b..f86917a8139c 100644 --- a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmAnalyzerTest.java +++ b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmAnalyzerTest.java @@ -17,13 +17,8 @@ package com.android.tools.layoutlib.create; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - import com.android.tools.layoutlib.create.AsmAnalyzer.DependencyVisitor; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.objectweb.asm.ClassReader; @@ -32,11 +27,15 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; -import java.util.HashSet; +import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.TreeMap; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + /** * Unit tests for some methods of {@link AsmAnalyzer}. */ @@ -51,26 +50,22 @@ public class AsmAnalyzerTest { mLog = new MockLog(); URL url = this.getClass().getClassLoader().getResource("data/mock_android.jar"); - mOsJarPath = new ArrayList<String>(); + mOsJarPath = new ArrayList<>(); + //noinspection ConstantConditions mOsJarPath.add(url.getFile()); - Set<String> excludeClasses = new HashSet<String>(1); - excludeClasses.add("java.lang.JavaClass"); + Set<String> excludeClasses = Collections.singleton("java.lang.JavaClass"); String[] includeFiles = new String[]{"mock_android/data/data*"}; mAa = new AsmAnalyzer(mLog, mOsJarPath, null /* gen */, null /* deriveFrom */, null /* includeGlobs */, excludeClasses, includeFiles); } - @After - public void tearDown() throws Exception { - } - @Test public void testParseZip() throws IOException { - Map<String, ClassReader> map = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + Map<String, ClassReader> map = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); mAa.parseZip(mOsJarPath, map, filesFound); @@ -101,11 +96,11 @@ public class AsmAnalyzerTest { @Test public void testFindClass() throws IOException, LogAbortException { - Map<String, ClassReader> zipClasses = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + Map<String, ClassReader> zipClasses = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); mAa.parseZip(mOsJarPath, zipClasses, filesFound); - TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>(); + TreeMap<String, ClassReader> found = new TreeMap<>(); ClassReader cr = mAa.findClass("mock_android.view.ViewGroup$LayoutParams", zipClasses, found); @@ -120,11 +115,11 @@ public class AsmAnalyzerTest { @Test public void testFindGlobs() throws IOException, LogAbortException { - Map<String, ClassReader> zipClasses = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + Map<String, ClassReader> zipClasses = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); mAa.parseZip(mOsJarPath, zipClasses, filesFound); - TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>(); + TreeMap<String, ClassReader> found = new TreeMap<>(); // this matches classes, a package match returns nothing found.clear(); @@ -183,11 +178,11 @@ public class AsmAnalyzerTest { @Test public void testFindClassesDerivingFrom() throws LogAbortException, IOException { - Map<String, ClassReader> zipClasses = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + Map<String, ClassReader> zipClasses = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); mAa.parseZip(mOsJarPath, zipClasses, filesFound); - TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>(); + TreeMap<String, ClassReader> found = new TreeMap<>(); mAa.findClassesDerivingFrom("mock_android.view.View", zipClasses, found); @@ -209,14 +204,14 @@ public class AsmAnalyzerTest { @Test public void testDependencyVisitor() throws IOException, LogAbortException { - Map<String, ClassReader> zipClasses = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + Map<String, ClassReader> zipClasses = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); mAa.parseZip(mOsJarPath, zipClasses, filesFound); - TreeMap<String, ClassReader> keep = new TreeMap<String, ClassReader>(); - TreeMap<String, ClassReader> new_keep = new TreeMap<String, ClassReader>(); - TreeMap<String, ClassReader> in_deps = new TreeMap<String, ClassReader>(); - TreeMap<String, ClassReader> out_deps = new TreeMap<String, ClassReader>(); + TreeMap<String, ClassReader> keep = new TreeMap<>(); + TreeMap<String, ClassReader> new_keep = new TreeMap<>(); + TreeMap<String, ClassReader> in_deps = new TreeMap<>(); + TreeMap<String, ClassReader> out_deps = new TreeMap<>(); ClassReader cr = mAa.findClass("mock_android.widget.LinearLayout", zipClasses, keep); DependencyVisitor visitor = mAa.getVisitor(zipClasses, keep, new_keep, in_deps, out_deps); diff --git a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmGeneratorTest.java b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmGeneratorTest.java index 8a2235b8526c..c4dd7eeafbba 100644 --- a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmGeneratorTest.java +++ b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmGeneratorTest.java @@ -18,12 +18,6 @@ package com.android.tools.layoutlib.create; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -31,7 +25,6 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import java.io.ByteArrayOutputStream; @@ -44,7 +37,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -52,11 +44,18 @@ import java.util.TreeMap; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * Unit tests for some methods of {@link AsmGenerator}. */ public class AsmGeneratorTest { + private static final String[] EMPTY_STRING_ARRAY = new String[0]; private MockLog mLog; private ArrayList<String> mOsJarPath; private String mOsDestJar; @@ -70,7 +69,8 @@ public class AsmGeneratorTest { mLog = new MockLog(); URL url = this.getClass().getClassLoader().getResource("data/mock_android.jar"); - mOsJarPath = new ArrayList<String>(); + mOsJarPath = new ArrayList<>(); + //noinspection ConstantConditions mOsJarPath.add(url.getFile()); mTempFile = File.createTempFile("mock", ".jar"); @@ -98,18 +98,18 @@ public class AsmGeneratorTest { @Override public String[] getDelegateMethods() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getDelegateClassNatives() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getOverriddenMethods() { // methods to force override - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override @@ -123,7 +123,7 @@ public class AsmGeneratorTest { @Override public String[] getJavaPkgClasses() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override @@ -134,17 +134,17 @@ public class AsmGeneratorTest { @Override public String[] getDeleteReturns() { // methods deleted from their return type. - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getPromotedFields() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public Map<String, InjectMethodRunnable> getInjectedMethodsMap() { - return new HashMap<String, InjectMethodRunnable>(0); + return Collections.emptyMap(); } }; @@ -155,7 +155,7 @@ public class AsmGeneratorTest { new String[] { // include classes "**" }, - new HashSet<String>(0) /* excluded classes */, + Collections.<String>emptySet() /* excluded classes */, new String[]{} /* include files */); aa.analyze(); agen.generate(); @@ -178,24 +178,24 @@ public class AsmGeneratorTest { @Override public String[] getDelegateMethods() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getDelegateClassNatives() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getOverriddenMethods() { // methods to force override - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getRenamedClasses() { // classes to rename (so that we can replace them) - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override @@ -214,17 +214,17 @@ public class AsmGeneratorTest { @Override public String[] getDeleteReturns() { // methods deleted from their return type. - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getPromotedFields() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public Map<String, InjectMethodRunnable> getInjectedMethodsMap() { - return new HashMap<String, InjectMethodRunnable>(0); + return Collections.emptyMap(); } }; @@ -235,14 +235,14 @@ public class AsmGeneratorTest { new String[] { // include classes "**" }, - new HashSet<String>(1), + Collections.<String>emptySet(), new String[] { /* include files */ "mock_android/data/data*" }); aa.analyze(); agen.generate(); - Map<String, ClassReader> output = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + Map<String, ClassReader> output = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); parseZip(mOsDestJar, output, filesFound); boolean injectedClassFound = false; for (ClassReader cr: output.values()) { @@ -265,35 +265,35 @@ public class AsmGeneratorTest { @Override public String[] getDelegateMethods() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getDelegateClassNatives() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getOverriddenMethods() { // methods to force override - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getRenamedClasses() { // classes to rename (so that we can replace them) - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getJavaPkgClasses() { // classes to refactor (so that we can replace them) - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public Set<String> getExcludedClasses() { - Set<String> set = new HashSet<String>(2); + Set<String> set = new HashSet<>(2); set.add("mock_android.dummy.InnerTest"); set.add("java.lang.JavaClass"); return set; @@ -302,17 +302,17 @@ public class AsmGeneratorTest { @Override public String[] getDeleteReturns() { // methods deleted from their return type. - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getPromotedFields() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public Map<String, InjectMethodRunnable> getInjectedMethodsMap() { - return new HashMap<String, InjectMethodRunnable>(0); + return Collections.emptyMap(); } }; @@ -329,8 +329,8 @@ public class AsmGeneratorTest { }); aa.analyze(); agen.generate(); - Map<String, ClassReader> output = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + Map<String, ClassReader> output = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); parseZip(mOsDestJar, output, filesFound); for (String s : output.keySet()) { assertFalse(excludedClasses.contains(s)); @@ -351,55 +351,52 @@ public class AsmGeneratorTest { @Override public String[] getDelegateMethods() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getDelegateClassNatives() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getOverriddenMethods() { // methods to force override - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getRenamedClasses() { // classes to rename (so that we can replace them) - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getJavaPkgClasses() { // classes to refactor (so that we can replace them) - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public Set<String> getExcludedClasses() { - return new HashSet<String>(0); + return Collections.emptySet(); } @Override public String[] getDeleteReturns() { // methods deleted from their return type. - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public String[] getPromotedFields() { - return new String[0]; + return EMPTY_STRING_ARRAY; } @Override public Map<String, InjectMethodRunnable> getInjectedMethodsMap() { - HashMap<String, InjectMethodRunnable> map = - new HashMap<String, InjectMethodRunnable>(1); - map.put("mock_android.util.EmptyArray", + return Collections.singletonMap("mock_android.util.EmptyArray", InjectMethodRunnables.CONTEXT_GET_FRAMEWORK_CLASS_LOADER); - return map; } }; @@ -415,8 +412,8 @@ public class AsmGeneratorTest { }); aa.analyze(); agen.generate(); - Map<String, ClassReader> output = new TreeMap<String, ClassReader>(); - Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + Map<String, ClassReader> output = new TreeMap<>(); + Map<String, InputStream> filesFound = new TreeMap<>(); parseZip(mOsDestJar, output, filesFound); final String modifiedClass = "mock_android.util.EmptyArray"; final String modifiedClassPath = modifiedClass.replace('.', '/').concat(".class"); @@ -424,11 +421,8 @@ public class AsmGeneratorTest { ZipEntry entry = zipFile.getEntry(modifiedClassPath); assertNotNull(entry); final byte[] bytes; - final InputStream inputStream = zipFile.getInputStream(entry); - try { + try (InputStream inputStream = zipFile.getInputStream(entry)) { bytes = getByteArray(inputStream); - } finally { - inputStream.close(); } ClassLoader classLoader = new ClassLoader(getClass().getClassLoader()) { @Override @@ -489,7 +483,7 @@ public class AsmGeneratorTest { boolean mInjectedClassFound = false; TestClassVisitor() { - super(Opcodes.ASM4); + super(Main.ASM_VERSION); } @Override @@ -514,7 +508,7 @@ public class AsmGeneratorTest { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); - return new MethodVisitor(Opcodes.ASM4, mv) { + return new MethodVisitor(Main.ASM_VERSION, mv) { @Override public void visitFieldInsn(int opcode, String owner, String name, @@ -540,10 +534,10 @@ public class AsmGeneratorTest { @Override public void visitMethodInsn(int opcode, String owner, String name, - String desc) { + String desc, boolean itf) { assertTrue(!getBase(owner).equals(JAVA_CLASS_NAME)); assertTrue(testType(Type.getType(desc))); - super.visitMethodInsn(opcode, owner, name, desc); + super.visitMethodInsn(opcode, owner, name, desc, itf); } }; diff --git a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/ClassHasNativeVisitorTest.java b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/ClassHasNativeVisitorTest.java index 0135c40e71ab..0cdcdc0c1235 100644 --- a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/ClassHasNativeVisitorTest.java +++ b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/ClassHasNativeVisitorTest.java @@ -60,7 +60,7 @@ public class ClassHasNativeVisitorTest { * Overrides {@link ClassHasNativeVisitor} to collec the name of the native methods found. */ private static class MockClassHasNativeVisitor extends ClassHasNativeVisitor { - private ArrayList<String> mMethodsFound = new ArrayList<String>(); + private ArrayList<String> mMethodsFound = new ArrayList<>(); public String[] getMethodsFound() { return mMethodsFound.toArray(new String[mMethodsFound.size()]); diff --git a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/DelegateClassAdapterTest.java b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/DelegateClassAdapterTest.java index 648cea430de2..b5cfaa801b9c 100644 --- a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/DelegateClassAdapterTest.java +++ b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/DelegateClassAdapterTest.java @@ -85,7 +85,7 @@ public class DelegateClassAdapterTest { // Now process it but tell the delegate to not modify any method ClassWriter cw = new ClassWriter(0 /*flags*/); - HashSet<String> delegateMethods = new HashSet<String>(); + HashSet<String> delegateMethods = new HashSet<>(); String internalClassName = NATIVE_CLASS_NAME.replace('.', '/'); DelegateClassAdapter cv = new DelegateClassAdapter( mLog, cw, internalClassName, delegateMethods); @@ -149,7 +149,7 @@ public class DelegateClassAdapterTest { String internalClassName = NATIVE_CLASS_NAME.replace('.', '/'); - HashSet<String> delegateMethods = new HashSet<String>(); + HashSet<String> delegateMethods = new HashSet<>(); delegateMethods.add("<init>"); DelegateClassAdapter cv = new DelegateClassAdapter( mLog, cw, internalClassName, delegateMethods); @@ -163,7 +163,7 @@ public class DelegateClassAdapterTest { ClassWriter cw = new ClassWriter(0 /*flags*/); String internalClassName = NATIVE_CLASS_NAME.replace('.', '/'); - HashSet<String> delegateMethods = new HashSet<String>(); + HashSet<String> delegateMethods = new HashSet<>(); delegateMethods.add(DelegateClassAdapter.ALL_NATIVES); DelegateClassAdapter cv = new DelegateClassAdapter( mLog, cw, internalClassName, delegateMethods); @@ -214,7 +214,7 @@ public class DelegateClassAdapterTest { @Test public void testDelegateInner() throws Throwable { // We'll delegate the "get" method of both the inner and outer class. - HashSet<String> delegateMethods = new HashSet<String>(); + HashSet<String> delegateMethods = new HashSet<>(); delegateMethods.add("get"); delegateMethods.add("privateMethod"); @@ -309,7 +309,7 @@ public class DelegateClassAdapterTest { */ private abstract class ClassLoader2 extends ClassLoader { - private final Map<String, byte[]> mClassDefs = new HashMap<String, byte[]>(); + private final Map<String, byte[]> mClassDefs = new HashMap<>(); public ClassLoader2() { super(null); |