List of usage examples for org.objectweb.asm.signature SignatureReader SignatureReader
public SignatureReader(final String signature)
From source file:com.android.build.gradle.shrinker.DependencyFinderVisitor.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from w ww . j a v a2 s. co m if (interfaces == null) { interfaces = new String[0]; } mKlass = mGraph.getClassReference(name); if (superName != null && !isSdkPackage(superName)) { // Don't create graph edges for obvious things. handleDependency(mKlass, mGraph.getClassReference(superName), DependencyType.REQUIRED_CLASS_STRUCTURE); } if (interfaces.length > 0) { handleInterfaceInheritance(mKlass); if (!Objects.equal(superName, "java/lang/Object")) { // It's possible the superclass is implementing a method from the interface, we may // need to add more edges to the graph to represent this. handleMultipleInheritance(mKlass); } } mClassName = name; mIsAnnotation = (access & Opcodes.ACC_ANNOTATION) != 0; if (signature != null) { SignatureReader reader = new SignatureReader(signature); SignatureVisitor visitor = new DependencyFinderSignatureVisitor(); reader.accept(visitor); } super.visit(version, access, name, signature, superName, interfaces); }
From source file:com.android.build.gradle.shrinker.DependencyFinderVisitor.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { T method = mGraph.getMemberReference(mClassName, name, desc); if ((access & Opcodes.ACC_STATIC) == 0 && !name.equals(ByteCodeUtils.CONSTRUCTOR)) { handleVirtualMethod(method);/* w ww . j av a 2 s .c o m*/ } // Keep class initializers, but also keep all default constructors. This is the ProGuard // behavior, if (name.equals(ByteCodeUtils.CLASS_INITIALIZER) || (name.equals(ByteCodeUtils.CONSTRUCTOR) && desc.equals("()V"))) { handleDependency(mKlass, method, DependencyType.REQUIRED_CLASS_STRUCTURE); } if (mIsAnnotation) { // TODO: Strip unused annotation classes members. handleDependency(mKlass, method, DependencyType.REQUIRED_CLASS_STRUCTURE); } if (signature != null) { SignatureReader reader = new SignatureReader(signature); SignatureVisitor visitor = new DependencyFinderSignatureVisitor(); reader.accept(visitor); } return new DependencyFinderMethodVisitor(method, desc, super.visitMethod(access, name, desc, signature, exceptions)); }
From source file:com.android.build.gradle.shrinker.DependencyFinderVisitor.java
License:Apache License
@Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { T field = mGraph.getMemberReference(mClassName, name, desc); Type fieldType = Type.getType(desc); handleDeclarationType(field, fieldType); if (signature != null) { SignatureReader reader = new SignatureReader(signature); SignatureVisitor visitor = new DependencyFinderSignatureVisitor(); reader.acceptType(visitor);//from w w w.ja v a 2 s . com } return super.visitField(access, name, desc, signature, value); }
From source file:com.android.builder.shrinker.DependencyFinderVisitor.java
License:Apache License
@Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { T field = mGraph.getMemberReference(mClassName, name, desc); Type fieldType = Type.getType(desc); handleDeclarationType(field, fieldType); if (signature != null) { SignatureReader reader = new SignatureReader(signature); SignatureVisitor visitor = new DependencyFinderSignatureVisitor(field); reader.acceptType(visitor);/*w w w .ja v a 2 s. c o m*/ } return super.visitField(access, name, desc, signature, value); }
From source file:com.android.builder.shrinker.DependencyFinderVisitor.java
License:Apache License
private void handleClassSignature(T source, String signature) { SignatureReader reader = new SignatureReader(signature); SignatureVisitor visitor = new DependencyFinderSignatureVisitor(source); reader.accept(visitor);//from w w w . j a va2s . c om }
From source file:com.android.mkstubs.sourcer.ClassSourcer.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {/*from w w w. ja v a2 s. c o m*/ String pkg = name.substring(0, name.lastIndexOf('/')).replace('/', '.'); mClassName = name.substring(name.lastIndexOf('/') + 1); mOutput.write("package %s;\n", pkg); // dump access keywords. Note: do not dump "super" here mAccessSourcer.write(access & ~Opcodes.ACC_SUPER, AccessSourcer.IS_CLASS); // write class name mOutput.write(" class %s", mClassName); if (signature != null) { // write template formal definition and super type SignatureReader sigReader = new SignatureReader(signature); SignatureSourcer sigSourcer = new SignatureSourcer(); sigReader.accept(sigSourcer); if (sigSourcer.hasFormalsContent()) { mOutput.write(sigSourcer.formalsToString()); } mOutput.write(" extends %s", sigSourcer.getSuperClass().toString()); } else { // write non-generic super type mOutput.write(" extends %s", superName.replace('/', '.')); } // write interfaces defined, if any if (interfaces != null && interfaces.length > 0) { mOutput.write(" implements "); boolean need_sep = false; for (String i : interfaces) { if (need_sep) { mOutput.write(", "); } mOutput.write(i.replace('/', '.')); need_sep = true; } } // open class body mOutput.write(" {\n"); }
From source file:com.android.mkstubs.sourcer.FieldSourcer.java
License:Apache License
@Override public void visitEnd() { // Need to write type and field name after the annotations and attributes. AccessSourcer as = new AccessSourcer(mOutput); as.write(mAccess, AccessSourcer.IS_FIELD); if (mSignature == null) { mOutput.write(" %s", Type.getType(mDesc).getClassName()); } else {/*from w w w . j ava2 s. co m*/ mOutput.write(" "); SignatureReader sigReader = new SignatureReader(mSignature); SignatureSourcer sigSourcer = new SignatureSourcer(); sigReader.acceptType(sigSourcer); mOutput.write(sigSourcer.toString()); } mOutput.write(" %s", mName); mOutput.write(";\n"); }
From source file:com.android.mkstubs.sourcer.MethodSourcer.java
License:Apache License
private void writeHeader() { if (!mNeedDeclaration) { return;// w ww . j a va2 s . c o m } AccessSourcer as = new AccessSourcer(mOutput); as.write(mAccess, AccessSourcer.IS_METHOD); // preprocess the signature to get the return type and the arguments SignatureSourcer sigSourcer = null; if (mSignature != null) { SignatureReader sigReader = new SignatureReader(mSignature); sigSourcer = new SignatureSourcer(); sigReader.accept(sigSourcer); if (sigSourcer.hasFormalsContent()) { // dump formal template parameter definitions mOutput.write(" %s", sigSourcer.formalsToString()); } } // output return type (constructor have no return type) if (!mIsConstructor) { // The signature overrides desc, if present if (sigSourcer == null || sigSourcer.getReturnType() == null) { mOutput.write(" %s", Type.getReturnType(mDesc).getClassName()); } else { mOutput.write(" %s", sigSourcer.getReturnType().toString()); } } // output name mOutput.write(" %s(", mIsConstructor ? mClassName : mName); // output arguments. The signature overrides desc, if present if (mSignature == null) { Type[] types = Type.getArgumentTypes(mDesc); for (int i = 0; i < types.length; i++) { if (i > 0) { mOutput.write(", "); } mOutput.write("%s arg%d", types[i].getClassName(), i); } } else { ArrayList<SignatureSourcer> params = sigSourcer.getParameters(); for (int i = 0; i < params.size(); i++) { if (i > 0) { mOutput.write(", "); } mOutput.write("%s arg%d", params.get(i).toString(), i); } } mOutput.write(")"); // output throwable exceptions if (mExceptions != null && mExceptions.length > 0) { mOutput.write(" throws "); for (int i = 0; i < mExceptions.length; i++) { if (i > 0) { mOutput.write(", "); } mOutput.write(mExceptions[i].replace('/', '.')); } } mOutput.write(" {\n"); mNeedDeclaration = false; }
From source file:com.android.mkstubs.sourcer.SignatureSourcerTest.java
License:Apache License
@Test public void testReturnMapNoArgs() { SignatureReader reader = new SignatureReader( "()Ljava/util/Map<Ljava/util/ArrayList<TT;>;Ljava/util/Map<Ljava/lang/String;Ljava/util/ArrayList<TU;>;>;>;"); reader.accept(mSourcer);// w ww .j a va 2 s.c om String result = mSourcer.getReturnType().toString(); Assert.assertEquals( "java.util.Map<java.util.ArrayList<T>, java.util.Map<java.lang.String, java.util.ArrayList<U>>>", result); }
From source file:com.android.mkstubs.sourcer.SignatureSourcerTest.java
License:Apache License
@Test public void testReturnVoid() { SignatureReader reader = new SignatureReader("(Ljava/util/List<+Lorg/w3c/dom/css/Rect;>;)V"); reader.accept(mSourcer);// w w w.j a va 2 s . c o m String result = mSourcer.getReturnType().toString(); Assert.assertEquals("void", result); }