List of usage examples for org.objectweb.asm.signature SignatureWriter SignatureWriter
public SignatureWriter()
From source file:com.facebook.buck.jvm.java.abi.SignatureFactoryTest.java
License:Apache License
/** * We can't tell whether an inferred class is a class, interface, annotation, or enum. This is * problematic for expressing generic type bounds, because the bytecode is different depending on * whether it is a class or an interface. As it happens, it's safe (from the compiler's * perspective) to treat everything as an interface. This method is used to rework the "expected" * signature so that we can use the same test data for testing with and without deps. *//*from ww w. j a v a 2s .c o m*/ private String treatDependencyBoundsAsInterfaces(String signature) { if (signature == null) { return null; } if (isTestingWithDependencies() || !signature.contains(":Lcom/facebook/foo/Dep")) { return signature; } SignatureWriter writer = new SignatureWriter(); new SignatureReader(signature).accept(new SourceAbiCompatibleSignatureVisitor(writer)); return writer.toString(); }
From source file:com.google.code.jconts.instrument.context.MethodContext.java
License:Apache License
/** * This method assumes that return type of the method is * <code>com.google.code.jconts.Computation<T></code>. It extracts the type * argument <code>T</code> and returns it signature. *//*from ww w.j a va 2s .c o m*/ private String valueSignature() { final SignatureWriter sign = new SignatureWriter(); SignatureAdapter adaptor = new SignatureAdapter() { public SignatureVisitor visitReturnType() { return new SignatureAdapter() { @Override public SignatureVisitor visitTypeArgument(char wildcard) { return sign; } // FIXME: All other are error! }; }; }; new SignatureReader(signature).accept(adaptor); return sign.toString(); }
From source file:com.google.code.jconts.instrument.gen.ComputationClassGenerator.java
License:Apache License
public void accept(TransformationContext context) { ClassVisitor cv = context.writer();/*w ww . ja va 2 s. c om*/ // extends Object implements Computation<ValueType> SignatureWriter sign = new SignatureWriter(); SignatureVisitor supsign = sign.visitSuperclass(); supsign.visitClassType(OBJECT_NAME); supsign.visitEnd(); SignatureVisitor iface = sign.visitInterface(); iface.visitClassType(COMPUTATION_NAME); SignatureVisitor argsign = iface.visitTypeArgument('='); new SignatureReader(info.valueSignature).acceptType(argsign); argsign.visitEnd(); cv.visit(Opcodes.V1_6, Opcodes.ACC_FINAL, info.computationClassName, sign.toString(), OBJECT_NAME, new String[] { COMPUTATION_NAME }); cv.visitSource(info.ownerSource, null); cv.visitInnerClass(info.stateClassName, info.owner, info.stateSimpleName, 0); cv.visitInnerClass(info.computationClassName, info.owner, info.computationSimpleName, 0); cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "state", stateDesc, null, null); generateConstructor(cv); generateExecute(cv); cv.visitEnd(); }
From source file:com.google.code.jconts.instrument.gen.ComputationClassGenerator.java
License:Apache License
private void generateExecute(ClassVisitor cv) { final String name = info.computationClassName; final Type outerType = Type.getObjectType(info.owner); // Generate execute(Continuation<T> cont); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC, COMPUTATION_EXECUTE_NAME, COMPUTATION_EXECUTE_DESC, executeSignature(), null); mv.visitCode();/*from w ww . j av a 2 s. c o m*/ Label start = new Label(); Label end = new Label(); mv.visitLabel(start); // Load outer this if (!info.isStatic()) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "this$0", outerType.getDescriptor()); } // Load state field mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc); // state.continuation = continuation mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, info.stateClassName, CONTINUATION_FIELD, CONTINUATION_DESC); // Initial state (0) mv.visitIntInsn(Opcodes.BIPUSH, 0); mv.visitMethodInsn(info.isStatic() ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL, info.owner, info.name + "$async", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { info.stateType, Type.INT_TYPE })); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(end); mv.visitLocalVariable("this", 'L' + name + ';', signature, start, end, 0); if (!info.isStatic()) { mv.visitLocalVariable("this$0", outerType.getDescriptor(), null, start, end, 1); } SignatureWriter sign = new SignatureWriter(); contSignature(sign); mv.visitLocalVariable("continuation", CONTINUATION_DESC, sign.toString(), start, end, 1 + info.thisOffset); mv.visitMaxs(3 + info.thisOffset, 2 + info.thisOffset); mv.visitEnd(); }
From source file:com.google.code.jconts.instrument.gen.ComputationClassGenerator.java
License:Apache License
private String executeSignature() { SignatureWriter sw = new SignatureWriter(); contSignature(sw.visitParameterType()); sw.visitReturnType().visitBaseType('V'); return sw.toString(); }
From source file:com.google.code.jconts.instrument.gen.ContinuationClassGenerator.java
License:Apache License
public ContinuationClassGenerator(MethodContext info) { this.info = info; this.stateDesc = info.stateType.getDescriptor(); SignatureWriter sign = new SignatureWriter(); // Name<T> implements Continuation<T> sign.visitFormalTypeParameter("T"); SignatureVisitor v = sign.visitClassBound(); v.visitClassType(OBJECT_NAME);//from w w w . j a v a 2s . co m v.visitEnd(); v = sign.visitSuperclass(); v.visitClassType(OBJECT_NAME); v.visitEnd(); v = sign.visitInterface(); v.visitClassType(CONTINUATION_NAME); v.visitTypeArgument('=').visitTypeVariable("T"); v.visitEnd(); this.signature = sign.toString(); }
From source file:com.google.code.jconts.instrument.gen.ContinuationClassGenerator.java
License:Apache License
private void generateExecute(ClassVisitor cv, boolean execute) { final String name = info.continuationClassName; final Type outerType = Type.getObjectType(info.owner); // Generate invoke(T result); String signature = null;//from ww w.j ava2 s . c o m if (execute) { SignatureWriter sign = new SignatureWriter(); sign.visitParameterType().visitTypeVariable("T"); sign.visitReturnType().visitBaseType('V'); // void signature = sign.toString(); } MethodVisitor mv = cv.visitMethod(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC, execute ? CONTINUATION_INVOKE_NAME : CONTINUATION_SET_EXCEPTION_NAME, execute ? CONTINUATION_INVOKE_DESC : CONTINUATION_SET_EXCEPTION_DESC, signature, null); mv.visitCode(); Label start = new Label(); Label end = new Label(); mv.visitLabel(start); // Load outer this if (!info.isStatic()) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "this$0", outerType.getDescriptor()); } // state.result = result or state.exception = throwable mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, info.stateClassName, execute ? "result" : "exception", execute ? OBJECT_DESC : THROWABLE_DESC); // Load state field mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc); // Continue from this index or index+1 (for exception) mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, name, "index", "I"); if (!execute) { mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); } mv.visitMethodInsn(info.isStatic() ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL, info.owner, info.name + "$async", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { info.stateType, Type.INT_TYPE })); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(end); mv.visitLocalVariable("this", 'L' + name + ';', signature, start, end, 0); if (!info.isStatic()) { mv.visitLocalVariable("this$0", outerType.getDescriptor(), null, start, end, 1); } mv.visitLocalVariable("result", OBJECT_DESC, "TT;", start, end, 1 + info.thisOffset); mv.visitMaxs(3 + info.thisOffset + (execute ? 0 : 1), 2 + info.thisOffset); mv.visitEnd(); }
From source file:com.googlecode.d2j.map.DexMappingAdapter.java
License:Apache License
static String remapSignature(final Mapper mapper, String sig, boolean isType) { SignatureWriter w = new SignatureWriter() { String clzName;/* w w w . j a va 2 s . c om*/ @Override public void visitClassType(String name) { super.visitClassType(mapClassName(mapper, name)); clzName = name; } @Override public void visitInnerClassType(String simpleName) { String value = simpleName; if (simpleName != null) { if (clzName.endsWith("$" + simpleName + ";")) { String nNameDesc = mapClassName(mapper, clzName); String containd = mapClassName(mapper, clzName.substring(0, clzName.length() - 2 - simpleName.length()) + ";"); String internalNameWitherOwner = nNameDesc.substring(1, nNameDesc.length() - 1); String internalNameOwner = containd.substring(1, containd.length() - 1); if (internalNameWitherOwner.startsWith(internalNameOwner + "$")) { value = internalNameWitherOwner.substring(1 + internalNameOwner.length()); } else { value = null; } } else { value = null; } } super.visitInnerClassType(value); } }; if (isType) { new SignatureReader(sig).acceptType(w); } else { new SignatureReader(sig).accept(w); } return w.toString(); }
From source file:com.pongasoft.kiwidoc.builder.serializer.type.TypeEncoder.java
License:Apache License
/** * @return the signature for a type/*from ww w . j av a 2s .co m*/ */ public String encodeType(Type type) { SignatureWriter sw = new SignatureWriter(); buildType(sw, type); return sw.toString(); }
From source file:com.pongasoft.kiwidoc.builder.serializer.type.TypeEncoder.java
License:Apache License
/** * @return the signature for a given generic type variable *//*www . ja v a 2s . c o m*/ public String encodeGenericTypeVariables(GenericTypeVariables type) { SignatureWriter sw = new SignatureWriter(); for (GenericTypeVariable gtv : type.getGenericTypeVariables()) { sw.visitFormalTypeParameter(gtv.getName()); List<Type> bounds = gtv.getBounds(); if (bounds.isEmpty()) bounds = OBJECT_BOUNDS; int i = 0; for (Type bound : bounds) { SignatureVisitor sv; if (i > 0) { sv = sw.visitInterfaceBound(); } else { sv = sw.visitClassBound(); } buildType(sv, bound); i++; } } // the signature is not complete without visiting the superclass... so we visit it and then // we remove it from the signature SignatureVisitor sv = sw.visitSuperclass(); buildType(sv, OBJECT_TYPE); String signature = sw.toString(); signature = signature.substring(0, signature.length() - OBJECT_SIGNATURE_LENGTH); return signature; }