Merge changes from topic 'asm5'

* changes:
  Update mkstubs to Java 8.
  Upgrade to ASM 5
This commit is contained in:
Deepanshu Gupta
2016-01-08 17:37:57 +00:00
committed by Android (Google) Code Review
29 changed files with 216 additions and 59 deletions

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="var" path="ANDROID_SRC/prebuilt/common/asm/asm-4.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -1,2 +1,3 @@
bin
out

1
tools/mkstubs/.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
mstubs

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="FIELD_NAME_PREFIX" value="m" />
<option name="STATIC_FIELD_NAME_PREFIX" value="s" />
<option name="INSERT_INNER_CLASS_IMPORTS" value="true" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="com.android" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="android" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
</value>
</option>
<option name="RIGHT_MARGIN" value="100" />
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
<option name="JD_ALIGN_PARAM_COMMENTS" value="false" />
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
<option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" />
<option name="WRAP_COMMENTS" value="true" />
<JavaCodeStyleSettings>
<option name="CLASS_NAMES_IN_JAVADOC" value="3" />
</JavaCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="JAVA">
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="CALL_PARAMETERS_WRAP" value="1" />
<option name="METHOD_PARAMETERS_WRAP" value="1" />
<option name="THROWS_LIST_WRAP" value="1" />
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
<option name="THROWS_KEYWORD_WRAP" value="1" />
<option name="BINARY_OPERATION_WRAP" value="1" />
<option name="TERNARY_OPERATION_WRAP" value="1" />
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
<option name="ASSIGNMENT_WRAP" value="1" />
<option name="ASSERT_STATEMENT_WRAP" value="1" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
<arrangement>
<groups>
<group>
<type>GETTERS_AND_SETTERS</type>
<order>KEEP</order>
</group>
<group>
<type>OVERRIDDEN_METHODS</type>
<order>KEEP</order>
</group>
</groups>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
</value>
</option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</component>
</project>

22
tools/mkstubs/.idea/compiler.xml generated Normal file
View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@@ -0,0 +1,9 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="Copyright (C) &amp;#36;today.year The Android Open Source Project&#10;&#10;Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);&#10;you may not use this file except in compliance with the License.&#10;You may obtain a copy of the License at&#10;&#10; http://www.apache.org/licenses/LICENSE-2.0&#10;&#10;Unless required by applicable law or agreed to in writing, software&#10;distributed under the License is distributed on an &quot;AS IS&quot; BASIS,&#10;WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&#10;See the License for the specific language governing permissions and&#10;limitations under the License." />
<option name="keyword" value="Copyright" />
<option name="allowReplaceKeyword" value="" />
<option name="myName" value="Android" />
<option name="myLocal" value="true" />
</copyright>
</component>

View File

@@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="Android" />
</component>

6
tools/mkstubs/.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

View File

@@ -0,0 +1,14 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
<inspection_tool class="WeakerAccess" enabled="false" level="WARNING" enabled_by_default="false">
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="true" />
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="true" />
<option name="SUGGEST_PRIVATE_FOR_INNERS" value="false" />
</inspection_tool>
</profile>
</component>

View File

@@ -0,0 +1,7 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>

19
tools/mkstubs/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
tools/mkstubs/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/mkstubs.iml" filepath="$PROJECT_DIR$/mkstubs.iml" />
</modules>
</component>
</project>

6
tools/mkstubs/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MkStubs</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -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 := mkstubs

View File

@@ -33,7 +33,7 @@ import java.util.zip.ZipFile;
* Analyzes an input Jar to get all the relevant classes according to the given filter.
* <p/>
* This is mostly a helper extracted for convenience. Callers will want to use
* {@link #parseInputJar(String)} followed by {@link #filter(Map, Filter)}.
* {@link #parseInputJar(String)} followed by {@link #filter(Map, Filter, Logger)}.
*/
class AsmAnalyzer {
@@ -42,7 +42,7 @@ class AsmAnalyzer {
* class name => ASM ClassReader. Class names are in the form "android.view.View".
*/
Map<String,ClassReader> parseInputJar(String inputJarPath) throws IOException {
TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();
TreeMap<String, ClassReader> classes = new TreeMap<>();
ZipFile zip = new ZipFile(inputJarPath);
Enumeration<? extends ZipEntry> entries = zip.entries();

View File

@@ -30,10 +30,10 @@ import java.util.TreeSet;
* pattern to decide if it should be included.
*/
class Filter {
private TreeSet<String> mIncludePrefix = new TreeSet<String>();
private TreeSet<String> mIncludeFull = new TreeSet<String>();
private TreeSet<String> mExcludePrefix = new TreeSet<String>();
private TreeSet<String> mExcludeFull = new TreeSet<String>();
private TreeSet<String> mIncludePrefix = new TreeSet<>();
private TreeSet<String> mIncludeFull = new TreeSet<>();
private TreeSet<String> mExcludePrefix = new TreeSet<>();
private TreeSet<String> mExcludeFull = new TreeSet<>();
/**
* Returns the set of all full patterns to be included.

View File

@@ -36,7 +36,7 @@ class FilterClassAdapter extends ClassVisitor {
private String mClassName;
public FilterClassAdapter(ClassVisitor writer, Filter filter, Logger log) {
super(Opcodes.ASM4, writer);
super(Main.ASM_VERSION, writer);
mFilter = filter;
mLog = log;
}

View File

@@ -16,9 +16,8 @@
package com.android.mkstubs;
import com.android.mkstubs.Main.Params;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import java.io.BufferedReader;
import java.io.File;
@@ -34,6 +33,8 @@ import java.util.Map;
*/
public class Main {
public static final int ASM_VERSION = Opcodes.ASM5;
/**
* A struct-like class to hold the various input values (e.g. command-line args)
*/

View File

@@ -58,12 +58,8 @@ class SourceGenerator {
String name = classNameToJavaPath(cr.getClassName());
FileWriter fw = null;
try {
fw = createWriter(baseDir, name);
try (FileWriter fw = createWriter(baseDir, name)) {
visitClassSource(fw, cr, filter);
} finally {
fw.close();
}
}
}

View File

@@ -55,7 +55,7 @@ class StubGenerator {
Map<String, ClassReader> classes,
Filter filter) throws IOException {
TreeMap<String, byte[]> all = new TreeMap<String, byte[]>();
TreeMap<String, byte[]> all = new TreeMap<>();
for (Entry<String, ClassReader> entry : classes.entrySet()) {
ClassReader cr = entry.getValue();

View File

@@ -58,7 +58,7 @@ class AccessSourcer {
private final int mValue;
private final int mFilter;
private Flag(int value, int filter) {
Flag(int value, int filter) {
mValue = value;
mFilter = filter;
}

View File

@@ -16,8 +16,9 @@
package com.android.mkstubs.sourcer;
import com.android.mkstubs.Main;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Opcodes;
/**
* An annotation visitor that generates Java source for an annotation.
@@ -34,7 +35,7 @@ class AnnotationSourcer extends AnnotationVisitor {
}
public AnnotationSourcer(Output output, boolean isArray) {
super(Opcodes.ASM4);
super(Main.ASM_VERSION);
mOutput = output;
mOpenChar = isArray ? "[" : "(";
mCloseChar = isArray ? "]" : ")";

View File

@@ -16,6 +16,8 @@
package com.android.mkstubs.sourcer;
import com.android.mkstubs.Main;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassVisitor;
@@ -34,7 +36,7 @@ public class ClassSourcer extends ClassVisitor {
private String mClassName;
public ClassSourcer(Output output) {
super(Opcodes.ASM4);
super(Main.ASM_VERSION);
mOutput = output;
mAccessSourcer = new AccessSourcer(mOutput);
}

View File

@@ -16,10 +16,11 @@
package com.android.mkstubs.sourcer;
import com.android.mkstubs.Main;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.signature.SignatureReader;
@@ -35,7 +36,7 @@ class FieldSourcer extends FieldVisitor {
private final String mSignature;
public FieldSourcer(Output output, int access, String name, String desc, String signature) {
super(Opcodes.ASM4);
super(Main.ASM_VERSION);
mOutput = output;
mAccess = access;
mName = name;

View File

@@ -16,11 +16,12 @@
package com.android.mkstubs.sourcer;
import com.android.mkstubs.Main;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
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;
@@ -43,7 +44,7 @@ class MethodSourcer extends MethodVisitor {
public MethodSourcer(Output output, String className, int access, String name,
String desc, String signature, String[] exceptions) {
super(Opcodes.ASM4);
super(Main.ASM_VERSION);
mOutput = output;
mClassName = className;
mAccess = access;
@@ -223,7 +224,7 @@ class MethodSourcer 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) {
// pass
}

View File

@@ -16,7 +16,8 @@
package com.android.mkstubs.sourcer;
import org.objectweb.asm.Opcodes;
import com.android.mkstubs.Main;
import org.objectweb.asm.Type;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
@@ -83,7 +84,7 @@ class SignatureSourcer extends SignatureVisitor {
* {@link SignatureSourcer}s for each parameters generated when parsing the method parameters
* of <em>this</em> signature. Initially empty but not null.
*/
private ArrayList<SignatureSourcer> mParameters = new ArrayList<SignatureSourcer>();
private ArrayList<SignatureSourcer> mParameters = new ArrayList<>();
@@ -91,7 +92,7 @@ class SignatureSourcer extends SignatureVisitor {
* Constructs a new {@link SignatureWriter} object.
*/
public SignatureSourcer() {
super(Opcodes.ASM4);
super(Main.ASM_VERSION);
}
private StringBuilder getBuf() {

View File

@@ -16,12 +16,13 @@
package com.android.mkstubs.stubber;
import com.android.mkstubs.Main;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
/**
* A class visitor that generates stubs for all methods of the visited class.
@@ -30,7 +31,7 @@ import org.objectweb.asm.Opcodes;
public class ClassStubber extends ClassVisitor {
public ClassStubber(ClassVisitor cv) {
super(Opcodes.ASM4, cv);
super(Main.ASM_VERSION, cv);
}
@Override

View File

@@ -16,6 +16,8 @@
package com.android.mkstubs.stubber;
import com.android.mkstubs.Main;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.Label;
@@ -35,7 +37,7 @@ public class MethodStubber extends MethodVisitor {
public MethodStubber(MethodVisitor mw,
int access, String name, String desc, String signature, String[] exceptions) {
super(Opcodes.ASM4, mw);
super(Main.ASM_VERSION, mw);
}
@Override
@@ -50,7 +52,8 @@ public class MethodStubber extends MethodVisitor {
Opcodes.INVOKESPECIAL, // opcode
"java/lang/RuntimeException", // owner
"<init>", // name
"(Ljava/lang/String;)V"); // desc
"(Ljava/lang/String;)V", // desc
false);
mv.visitInsn(Opcodes.ATHROW);
Label l1 = new Label();
mv.visitLabel(l1);
@@ -153,7 +156,7 @@ public class MethodStubber 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) {
// skip
}