/** * Creates a new {@link Method}. * * @param name * the method's name. * @param returnType * the method's return type. * @param argumentTypes * the method's argument types. */ public Method(final String name, final Type returnType, final Type[] argumentTypes) { this(name, Type.getMethodDescriptor(returnType, argumentTypes)); }
/** * Returns the Java method type corresponding to the given method. * * @param m * a {@link Method Method} object. * @return the Java method type corresponding to the given method. */ public static Type getType(final Method m) { return getType(getMethodDescriptor(m)); }
/** * Creates a new {@link Method}. * * @param m * a java.lang.reflect method descriptor * @return a {@link Method} corresponding to the given Java method * declaration. */ public static Method getMethod(java.lang.reflect.Method m) { return new Method(m.getName(), Type.getMethodDescriptor(m)); }
/** * Returns the method {@link Type} corresponding to the given method. * * @param method a {@link Method} object. * @return the method {@link Type} corresponding to the given method. */ public static Type getType(final Method method) { return getType(getMethodDescriptor(method)); }
/** * Returns the method {@link Type} corresponding to the given argument and return types. * * @param returnType the return type of the method. * @param argumentTypes the argument types of the method. * @return the method {@link Type} corresponding to the given argument and return types. */ public static Type getMethodType(final Type returnType, final Type... argumentTypes) { return getType(getMethodDescriptor(returnType, argumentTypes)); }
/** * Returns the Java method type corresponding to the given argument and * return types. * * @param returnType * the return type of the method. * @param argumentTypes * the argument types of the method. * @return the Java type corresponding to the given argument and return * types. */ public static Type getMethodType(final Type returnType, final Type... argumentTypes) { return getType(getMethodDescriptor(returnType, argumentTypes)); }
protected void initFields( MethodVisitor mv, String internalProxy ) { mv.visitVarInsn( ALOAD, 0 ); mv.visitVarInsn( ILOAD, 6 ); mv.visitMethodInsn( INVOKESPECIAL, internalProxy, "synchFields", Type.getMethodDescriptor( Type.VOID_TYPE, new Type[] { Type.BOOLEAN_TYPE } ) ); }
protected void buildSynchFields( ClassWriter cw, String proxyName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { { MethodVisitor mv = cw.visitMethod( ACC_PRIVATE, "synchFields", Type.getMethodDescriptor( Type.VOID_TYPE, new Type[] { Type.BOOLEAN_TYPE } ), null, null ); mv.visitCode(); if ( core.isFullTraiting() ) { Iterator<FieldDefinition> iter = trait.getFieldsDefinitions().iterator(); for ( int j = 0; j < trait.getFieldsDefinitions().size(); j++ ) { FieldDefinition fld = iter.next(); boolean hardField = ! TraitRegistry.isSoftField( fld, j, mask ); synchFieldLogical( mv, fld, proxyName, trait, core, hardField, j + 3 ); } } else { for ( FieldDefinition fld : trait.getFieldsDefinitions() ) { if ( fld.getInitExpr() != null ) { synchField( mv, fld, proxyName ); } } } mv.visitInsn( RETURN ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); } }
protected void buildSynchFields( ClassWriter cw, String proxyName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { { MethodVisitor mv = cw.visitMethod( ACC_PRIVATE, "synchFields", Type.getMethodDescriptor( Type.VOID_TYPE, new Type[] { Type.BOOLEAN_TYPE } ), null, null ); mv.visitCode(); if ( core.isFullTraiting() ) { Iterator<FieldDefinition> iter = trait.getFieldsDefinitions().iterator(); for ( int j = 0; j < trait.getFieldsDefinitions().size(); j++ ) { FieldDefinition fld = iter.next(); boolean hardField = ! TraitRegistry.isSoftField( fld, j, mask ); synchFieldLogical( mv, fld, proxyName, trait, core, hardField, j + 3 ); } } else { for ( FieldDefinition fld : trait.getFieldsDefinitions() ) { if ( fld.getInitExpr() != null ) { synchField( mv, fld, proxyName ); } } } mv.visitInsn( RETURN ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); } }
protected boolean defaultConstructorStart( MethodVisitor mv, ClassDefinition classDef ) { // Building default constructor mv.visitVarInsn( Opcodes.ALOAD, 0 ); String sup = ""; try { sup = Type.getInternalName(Class.forName(classDef.getSuperClass())); } catch (ClassNotFoundException e) { sup = BuildUtils.getInternalType( classDef.getSuperClass() ); } mv.visitMethodInsn( Opcodes.INVOKESPECIAL, sup, "<init>", Type.getMethodDescriptor( Type.VOID_TYPE, new Type[]{} ) ); boolean hasObjects = false; for (FieldDefinition field : classDef.getFieldsDefinitions()) { hasObjects = hasObjects || initFieldWithDefaultValue( mv, classDef, field ); } if ( classDef.isTraitable() ) { initializeDynamicTypeStructures( mv, classDef ); } return hasObjects; }
protected void visitFieldOrGetter(MethodVisitor mv, ClassDefinition classDef, FieldDefinition field) { if (! field.isInherited()) { mv.visitFieldInsn( Opcodes.GETFIELD, BuildUtils.getInternalType( classDef.getClassName() ), field.getName(), BuildUtils.getTypeDescriptor( field.getTypeName() ) ); } else { mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL, BuildUtils.getInternalType( classDef.getClassName()), field.getReadMethod(), Type.getMethodDescriptor(Type.getType(BuildUtils.getTypeDescriptor(field.getTypeName())), new Type[]{}) ); } }
public static void invokeExtractor( MethodVisitor mv, String masterName, ClassDefinition trait, ClassDefinition core, FieldDefinition field ) { FieldDefinition tgtField = core.getFieldByAlias( field.resolveAlias() ); String fieldType = tgtField.getTypeName(); String fieldName = tgtField.getName(); String returnType = BuildUtils.getTypeDescriptor( fieldType ); mv.visitVarInsn( ALOAD, 0 ); mv.visitFieldInsn( GETFIELD, BuildUtils.getInternalType( masterName ), "object", BuildUtils.getTypeDescriptor( core.getClassName() ) ); mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( core.getDefinedClass() ), BuildUtils.getterName( fieldName, fieldType ), Type.getMethodDescriptor( Type.getType( returnType ), new Type[] {} ) ); }
Type.getInternalName( StringBuilder.class ), "append", Type.getMethodDescriptor( Type.getType( StringBuilder.class ), new Type[]{Type.getType( BuildUtils.getTypeDescriptor( type ) )} ) ); } else if ( BuildUtils.isArray( field.getTypeName() ) && BuildUtils.arrayDimSize( field.getTypeName() ) == 1 ) { Type.getInternalName( StringBuilder.class ), "append", Type.getMethodDescriptor( Type.getType( StringBuilder.class ), new Type[]{Type.getType( Object.class )} ) );
Type.getMethodDescriptor( Type.VOID_TYPE, new Type[]{} ), null,
Type.getMethodDescriptor( Type.getType( TraitFieldTMS.class ), new Type[] {} ), null, null); Type.getMethodDescriptor( Type.VOID_TYPE, new Type[] { Type.getType( TraitFieldTMS.class ) } ), null, null);
public static void invokeInjector( MethodVisitor mv, String masterName, ClassDefinition trait, ClassDefinition core, FieldDefinition field, boolean toNull, int pointer ) { FieldDefinition tgtField = core.getFieldByAlias( field.resolveAlias() ); String fieldType = tgtField.getTypeName(); String fieldName = tgtField.getName(); String returnType = BuildUtils.getTypeDescriptor( fieldType ); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn( GETFIELD, BuildUtils.getInternalType( masterName ), "object", BuildUtils.getTypeDescriptor( core.getName() ) ); if ( toNull ) { mv.visitInsn( BuildUtils.zero( field.getTypeName() ) ); } else { mv.visitVarInsn( BuildUtils.varType( fieldType ), pointer ); } if ( ! BuildUtils.isPrimitive( fieldType ) ) { mv.visitTypeInsn( CHECKCAST, BuildUtils.getInternalType( fieldType ) ); } mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( core.getDefinedClass() ), BuildUtils.setterName( fieldName, fieldType ), Type.getMethodDescriptor( Type.getType( void.class ), new Type[] { Type.getType( returnType ) } ) ); }
Type.getInternalName( TraitFieldTMS.class ), "set", Type.getMethodDescriptor( Type.getType( Object.class ), new Type[] { Type.getType( String.class ), Type.getType( Object.class ), Type.getType( Class.class ) } ) );
Type.getInternalName( MVEL.class ), "eval", Type.getMethodDescriptor( Type.getType( Object.class ), new Type[] { Type.getType( String.class ), Type.getType( Class.class ) } ) ); if ( BuildUtils.isPrimitive( fld.getTypeName() ) ) { mv.visitTypeInsn( CHECKCAST, BuildUtils.getInternalType( BuildUtils.box( fld.getTypeName() ) ) );
Type.getInternalName( MVEL.class ), "eval", Type.getMethodDescriptor( Type.getType( Object.class ), new Type[] { Type.getType( String.class ), Type.getType( Class.class ) } ) ); if ( BuildUtils.isPrimitive( fld.getTypeName() ) ) { mv.visitTypeInsn( CHECKCAST, BuildUtils.getInternalType( BuildUtils.box( fld.getTypeName() ) ) );
Type.getInternalName( TraitFieldTMS.class ), "registerField", Type.getMethodDescriptor( Type.VOID_TYPE, new Type[] { Type.getType( Class.class ), Type.getType( String.class ), Type.getType( Class.class ), Type.getType( Object.class ), Type.getType( String.class ) } ) );