All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datanucleus.enhancer.asm.method.JdoGetNormal Maven / Gradle / Ivy

Go to download

DataNucleus Enhancer is a Java byte-code enhancer for use with DataNucleus.

There is a newer version: 3.1.1
Show newest version
/**********************************************************************
Copyright (c) 2007 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors:
    ...
**********************************************************************/
package org.datanucleus.enhancer.asm.method;

import org.datanucleus.enhancer.ClassEnhancer;
import org.datanucleus.enhancer.asm.ASMClassMethod;
import org.datanucleus.enhancer.asm.ASMUtils;
import org.datanucleus.metadata.AbstractMemberMetaData;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

/**
 * Method to generate the method "jdoGetZZZ" using ASM for NORMAL_GET fields.
 * 
 * static YYY jdoGetZZZ(MyClass objPC)
 * {
 *     return objPC.ZZZ;
 * }
 * 
*/ public class JdoGetNormal extends ASMClassMethod { /** Field that this jdoGetXXX is for. */ protected AbstractMemberMetaData fmd; /** * Constructor. * @param enhancer ClassEnhancer * @param fmd MetaData for the field we are generating for */ public JdoGetNormal(ClassEnhancer enhancer, AbstractMemberMetaData fmd) { super(enhancer, enhancer.getGetMethodPrefixMethodName() + fmd.getName(), (fmd.isPublic() ? Opcodes.ACC_PUBLIC : 0) | (fmd.isProtected() ? Opcodes.ACC_PROTECTED : 0) | (fmd.isPrivate() ? Opcodes.ACC_PRIVATE : 0) | Opcodes.ACC_STATIC, fmd.getType(), null, null); // Set the arg type/name argTypes = new Class[] {getClassEnhancer().getClassEnhanced()}; argNames = new String[] {"objPC"}; this.fmd = fmd; } /** * Method to add the contents of the class method. */ public void execute() { visitor.visitCode(); String fieldTypeDesc = Type.getDescriptor(fmd.getType()); Label startLabel = new Label(); visitor.visitLabel(startLabel); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc); ASMUtils.addReturnForType(visitor, (Class)returnType); Label endLabel = new Label(); visitor.visitLabel(endLabel); visitor.visitLocalVariable(argNames[0], getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0); visitor.visitMaxs(1, 1); visitor.visitEnd(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy