protected void buildRemove( ClassWriter cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) {
String internalWrapper = BuildUtils.getInternalType( wrapperName );
MethodVisitor mv = cw.visitMethod( ACC_PUBLIC,
"remove",
"(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ),
null,
null );
mv.visitCode();
int stack = 0;
for ( FieldDefinition field : core.getFieldsDefinitions() ) {
stack = Math.max( stack, BuildUtils.sizeOf( field.getTypeName() ) );
invokeRemove( mv, wrapperName, core, field.getName(), field );
}
int j = 0;
for ( FieldDefinition field : trait.getFieldsDefinitions() ) {
boolean isSoftField = TraitRegistry.isSoftField( field, j++, mask );
if ( isSoftField ) {
stack = Math.max( stack, BuildUtils.sizeOf( field.getTypeName() ) );
mv.visitLdcInsn( field.getName() );
mv.visitVarInsn( ALOAD, 1 );
mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( String.class ), "equals", "(" + Type.getDescriptor( Object.class ) + ")Z" );
Label l2 = new Label();
mv.visitJumpInsn( IFEQ, l2 );
mv.visitVarInsn( ALOAD, 0 );
mv.visitFieldInsn( GETFIELD, internalWrapper, "store", Type.getDescriptor( TripleStore.class ) );
mv.visitVarInsn( ALOAD, 0);
mv.visitLdcInsn( field.getName() );
mv.visitMethodInsn( INVOKEVIRTUAL,
internalWrapper,
"propertyKey",
"(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Triple.class ) );
mv.visitMethodInsn( INVOKEVIRTUAL,
Type.getInternalName( TripleStore.class ),
"get",
"(" + Type.getDescriptor( Triple.class ) + ")" + Type.getDescriptor( Triple.class ) );
mv.visitVarInsn( ASTORE, 2 );
mv.visitVarInsn( ALOAD, 0 );
mv.visitLdcInsn( field.getName() );
mv.visitInsn( BuildUtils.zero( field.getTypeName() ) );
if ( BuildUtils.isPrimitive( field.getTypeName() ) ) {
TraitFactory.valueOf( mv, field.getTypeName() );
}
mv.visitMethodInsn( INVOKESPECIAL,
Type.getInternalName( TripleBasedStruct.class ),
"put",
"(" + Type.getDescriptor( String.class ) + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) );
mv.visitInsn( POP );
mv.visitVarInsn( ALOAD, 2 );
mv.visitInsn( ARETURN );
mv.visitLabel( l2 );
}
}
mv.visitVarInsn( ALOAD, 0 );
mv.visitVarInsn( ALOAD, 1 );
mv.visitMethodInsn( INVOKESPECIAL,
Type.getInternalName( TripleBasedStruct.class ),
"remove",
"(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) );
mv.visitVarInsn( ASTORE, 2 );
mv.visitVarInsn( ALOAD, 2 );
mv.visitInsn( ARETURN );
// mv.visitMaxs( 2 + stack, 3 );
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}