use of org.eclipse.persistence.internal.libraries.asm.MethodVisitor in project eclipselink by eclipse-ee4j.
the class MetadataDynamicClassWriter method addMethods.
/**
* Add get methods for all virtual attributes
*/
@Override
protected void addMethods(ClassWriter cw, String parentClassType) {
for (MappingAccessor accessor : getDescriptor().getMappingAccessors()) {
String propertyName = propertyName(accessor.getAttributeName());
Type returnType = getAsmType(accessor);
// Add getter
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, GET + propertyName, "()" + returnType.getDescriptor(), null, new String[] { DYNAMIC_EXCEPTION });
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitLdcInsn(accessor.getAttributeName());
mv.visitMethodInsn(INVOKESPECIAL, parentClassType, "get", "(" + LJAVA_LANG_STRING + ")" + LJAVA_LANG_OBJECT, false);
mv.visitTypeInsn(CHECKCAST, returnType.getInternalName());
mv.visitInsn(ARETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
// Add setter
mv = cw.visitMethod(ACC_PUBLIC, SET + propertyName, "(" + returnType.getDescriptor() + ")V", null, new String[] { DYNAMIC_EXCEPTION });
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitLdcInsn("id");
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKESPECIAL, parentClassType, SET, "(" + LJAVA_LANG_STRING + LJAVA_LANG_OBJECT + ")" + LDYNAMIC_ENTITY, false);
mv.visitInsn(POP);
mv.visitInsn(RETURN);
mv.visitMaxs(3, 2);
mv.visitEnd();
}
}
use of org.eclipse.persistence.internal.libraries.asm.MethodVisitor in project eclipselink by eclipse-ee4j.
the class ClassWeaver method addPropertyChange.
/**
* Add a method to track property changes. The method will look as follows:
*
* public void _toplink_propertyChange(String s, Object obj, Object obj1){
* if(_persistence_listener != null {@literal &&} obj != obj1){
* _persistence_listener.propertyChange(new PropertyChangeEvent(this, s,
* obj, obj1)); } }
*/
public void addPropertyChange(ClassDetails classDetails) {
// create the _toplink_propertyChange() method
MethodVisitor cv_addPC = cv.visitMethod(ACC_PUBLIC, "_persistence_propertyChange", "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", null, null);
// if (_toplink_Listener != null)
cv_addPC.visitVarInsn(ALOAD, 0);
cv_addPC.visitFieldInsn(GETFIELD, classDetails.getClassName(), "_persistence_listener", PCL_SIGNATURE);
Label l0 = new Label();
cv_addPC.visitJumpInsn(IFNULL, l0);
// if (obj != obj1)
cv_addPC.visitVarInsn(ALOAD, 2);
cv_addPC.visitVarInsn(ALOAD, 3);
cv_addPC.visitJumpInsn(IF_ACMPEQ, l0);
// _toplink_listener.propertyChange(...);
cv_addPC.visitVarInsn(ALOAD, 0);
cv_addPC.visitFieldInsn(GETFIELD, classDetails.getClassName(), "_persistence_listener", PCL_SIGNATURE);
cv_addPC.visitTypeInsn(NEW, PCE_SHORT_SIGNATURE);
cv_addPC.visitInsn(DUP);
// new PropertyChangeEvent(this, s, obj, obj1)
cv_addPC.visitVarInsn(ALOAD, 0);
cv_addPC.visitVarInsn(ALOAD, 1);
cv_addPC.visitVarInsn(ALOAD, 2);
cv_addPC.visitVarInsn(ALOAD, 3);
cv_addPC.visitMethodInsn(INVOKESPECIAL, PCE_SHORT_SIGNATURE, "<init>", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", false);
cv_addPC.visitMethodInsn(INVOKEINTERFACE, PCL_SHORT_SIGNATURE, "propertyChange", "(" + PCE_SIGNATURE + ")V", true);
// }
cv_addPC.visitLabel(l0);
cv_addPC.visitInsn(RETURN);
cv_addPC.visitMaxs(0, 0);
}
use of org.eclipse.persistence.internal.libraries.asm.MethodVisitor in project eclipselink by eclipse-ee4j.
the class ClassWeaver method addFetchGroupMethods.
/**
* Adds get/set method for FetchGroupTracker interface. This adds the
* following methods:
*
* public Session _persistence_getSession() { return _persistence_session; }
* public void _persistence_setSession(Session session) {
* this._persistence_session = session; }
*
* public FetchGroup _persistence_getFetchGroup() { return
* _persistence_fetchGroup; } public void
* _persistence_setFetchGroup(FetchGroup fetchGroup) {
* this._persistence_fetchGroup = fetchGroup; }
*
* public boolean _persistence_shouldRefreshFetchGroup() { return
* _persistence_shouldRefreshFetchGroup; } public void
* _persistence_setShouldRefreshFetchGroup(boolean shouldRefreshFetchGroup)
* { this._persistence_shouldRefreshFetchGroup = shouldRefreshFetchGroup; }
*
* public void _persistence_resetFetchGroup() { }
*
* public void _persistence_isAttributeFetched(String attribute) { return
* this._persistence_fetchGroup == null ||
* _persistence_fetchGroup.containsAttribute(attribute); }
*
* public void _persistence_checkFetched(String attribute) { if
* (this._persistence_fetchGroup != null) {
* EntityManagerImpl.processUnfetchedAttribute(this, attribute); } }
*
* public void _persistence_checkSetFetched(String attribute) { if
* (this._persistence_fetchGroup != null) {
* EntityManagerImpl.processUnfetchedAttributeForSet(this, attribute); } }
*/
public void addFetchGroupMethods(ClassDetails classDetails) {
MethodVisitor cv_getSession = cv.visitMethod(ACC_PUBLIC, "_persistence_getSession", "()" + SESSION_SIGNATURE, null, null);
cv_getSession.visitVarInsn(ALOAD, 0);
cv_getSession.visitFieldInsn(GETFIELD, classDetails.getClassName(), "_persistence_session", SESSION_SIGNATURE);
cv_getSession.visitInsn(ARETURN);
cv_getSession.visitMaxs(0, 0);
MethodVisitor cv_setSession = cv.visitMethod(ACC_PUBLIC, "_persistence_setSession", "(" + SESSION_SIGNATURE + ")V", null, null);
cv_setSession.visitVarInsn(ALOAD, 0);
cv_setSession.visitVarInsn(ALOAD, 1);
cv_setSession.visitFieldInsn(PUTFIELD, classDetails.getClassName(), "_persistence_session", SESSION_SIGNATURE);
cv_setSession.visitInsn(RETURN);
cv_setSession.visitMaxs(0, 0);
MethodVisitor cv_getFetchGroup = cv.visitMethod(ACC_PUBLIC, "_persistence_getFetchGroup", "()" + FETCHGROUP_SIGNATURE, null, null);
cv_getFetchGroup.visitVarInsn(ALOAD, 0);
cv_getFetchGroup.visitFieldInsn(GETFIELD, classDetails.getClassName(), "_persistence_fetchGroup", FETCHGROUP_SIGNATURE);
cv_getFetchGroup.visitInsn(ARETURN);
cv_getFetchGroup.visitMaxs(0, 0);
MethodVisitor cv_setFetchGroup = cv.visitMethod(ACC_PUBLIC, "_persistence_setFetchGroup", "(" + FETCHGROUP_SIGNATURE + ")V", null, null);
cv_setFetchGroup.visitVarInsn(ALOAD, 0);
cv_setFetchGroup.visitVarInsn(ALOAD, 1);
cv_setFetchGroup.visitFieldInsn(PUTFIELD, classDetails.getClassName(), "_persistence_fetchGroup", FETCHGROUP_SIGNATURE);
cv_setFetchGroup.visitInsn(RETURN);
cv_setFetchGroup.visitMaxs(0, 0);
MethodVisitor cv_shouldRefreshFetchGroup = cv.visitMethod(ACC_PUBLIC, "_persistence_shouldRefreshFetchGroup", "()" + PBOOLEAN_SIGNATURE, null, null);
cv_shouldRefreshFetchGroup.visitVarInsn(ALOAD, 0);
cv_shouldRefreshFetchGroup.visitFieldInsn(GETFIELD, classDetails.getClassName(), "_persistence_shouldRefreshFetchGroup", PBOOLEAN_SIGNATURE);
cv_shouldRefreshFetchGroup.visitInsn(IRETURN);
cv_shouldRefreshFetchGroup.visitMaxs(0, 0);
MethodVisitor cv_setShouldRefreshFetchGroup = cv.visitMethod(ACC_PUBLIC, "_persistence_setShouldRefreshFetchGroup", "(" + PBOOLEAN_SIGNATURE + ")V", null, null);
cv_setShouldRefreshFetchGroup.visitVarInsn(ALOAD, 0);
cv_setShouldRefreshFetchGroup.visitVarInsn(ILOAD, 1);
cv_setShouldRefreshFetchGroup.visitFieldInsn(PUTFIELD, classDetails.getClassName(), "_persistence_shouldRefreshFetchGroup", PBOOLEAN_SIGNATURE);
cv_setShouldRefreshFetchGroup.visitInsn(RETURN);
cv_setShouldRefreshFetchGroup.visitMaxs(0, 0);
MethodVisitor cv_resetFetchGroup = cv.visitMethod(ACC_PUBLIC, "_persistence_resetFetchGroup", "()V", null, null);
cv_resetFetchGroup.visitInsn(RETURN);
cv_resetFetchGroup.visitMaxs(0, 0);
MethodVisitor cv_isAttributeFetched = cv.visitMethod(ACC_PUBLIC, "_persistence_isAttributeFetched", "(Ljava/lang/String;)Z", null, null);
cv_isAttributeFetched.visitVarInsn(ALOAD, 0);
cv_isAttributeFetched.visitFieldInsn(GETFIELD, classDetails.getClassName(), "_persistence_fetchGroup", FETCHGROUP_SIGNATURE);
Label gotoTrue = new Label();
cv_isAttributeFetched.visitJumpInsn(IFNULL, gotoTrue);
cv_isAttributeFetched.visitVarInsn(ALOAD, 0);
cv_isAttributeFetched.visitFieldInsn(GETFIELD, classDetails.getClassName(), "_persistence_fetchGroup", FETCHGROUP_SIGNATURE);
cv_isAttributeFetched.visitVarInsn(ALOAD, 1);
cv_isAttributeFetched.visitMethodInsn(INVOKEVIRTUAL, FETCHGROUP_SHORT_SIGNATURE, "containsAttributeInternal", "(Ljava/lang/String;)Z", false);
Label gotoFalse = new Label();
cv_isAttributeFetched.visitJumpInsn(IFEQ, gotoFalse);
cv_isAttributeFetched.visitLabel(gotoTrue);
cv_isAttributeFetched.visitInsn(ICONST_1);
Label gotoReturn = new Label();
cv_isAttributeFetched.visitJumpInsn(GOTO, gotoReturn);
cv_isAttributeFetched.visitLabel(gotoFalse);
cv_isAttributeFetched.visitInsn(ICONST_0);
cv_isAttributeFetched.visitLabel(gotoReturn);
cv_isAttributeFetched.visitInsn(IRETURN);
cv_isAttributeFetched.visitMaxs(0, 0);
MethodVisitor cv_checkFetched = cv.visitMethod(ACC_PUBLIC, "_persistence_checkFetched", "(Ljava/lang/String;)V", null, null);
cv_checkFetched.visitVarInsn(ALOAD, 0);
cv_checkFetched.visitVarInsn(ALOAD, 1);
cv_checkFetched.visitMethodInsn(INVOKEVIRTUAL, classDetails.getClassName(), "_persistence_isAttributeFetched", "(Ljava/lang/String;)Z", false);
gotoReturn = new Label();
cv_checkFetched.visitJumpInsn(IFNE, gotoReturn);
cv_checkFetched.visitVarInsn(ALOAD, 0);
cv_checkFetched.visitTypeInsn(CHECKCAST, FETCHGROUP_TRACKER_SHORT_SIGNATURE);
cv_checkFetched.visitVarInsn(ALOAD, 1);
cv_checkFetched.visitMethodInsn(INVOKESTATIC, ENTITY_MANAGER_IMPL_SHORT_SIGNATURE, "processUnfetchedAttribute", "(" + FETCHGROUP_TRACKER_SIGNATURE + "Ljava/lang/String;)V", false);
cv_checkFetched.visitLabel(gotoReturn);
cv_checkFetched.visitInsn(RETURN);
cv_checkFetched.visitMaxs(0, 0);
MethodVisitor cv_checkFetchedForSet = cv.visitMethod(ACC_PUBLIC, "_persistence_checkFetchedForSet", "(Ljava/lang/String;)V", null, null);
cv_checkFetchedForSet.visitVarInsn(ALOAD, 0);
cv_checkFetchedForSet.visitVarInsn(ALOAD, 1);
cv_checkFetchedForSet.visitMethodInsn(INVOKEVIRTUAL, classDetails.getClassName(), "_persistence_isAttributeFetched", "(Ljava/lang/String;)Z", false);
gotoReturn = new Label();
cv_checkFetchedForSet.visitJumpInsn(IFNE, gotoReturn);
cv_checkFetchedForSet.visitVarInsn(ALOAD, 0);
cv_checkFetchedForSet.visitTypeInsn(CHECKCAST, FETCHGROUP_TRACKER_SHORT_SIGNATURE);
cv_checkFetchedForSet.visitVarInsn(ALOAD, 1);
cv_checkFetchedForSet.visitMethodInsn(INVOKESTATIC, ENTITY_MANAGER_IMPL_SHORT_SIGNATURE, "processUnfetchedAttributeForSet", "(" + FETCHGROUP_TRACKER_SIGNATURE + "Ljava/lang/String;)V", false);
cv_checkFetchedForSet.visitLabel(gotoReturn);
cv_checkFetchedForSet.visitInsn(RETURN);
cv_checkFetchedForSet.visitMaxs(0, 0);
}
use of org.eclipse.persistence.internal.libraries.asm.MethodVisitor in project eclipselink by eclipse-ee4j.
the class ClassWeaver method addGetterMethodForFieldAccess.
/**
* Adds a convenience method used to replace a GETFIELD when field access is
* used. The method follows the following form:
*
* public (VariableClass) _persistence_get_variableName() {
* _persistence_checkFetched("variableName");
* _persistence_initialize_variableName_vh(); this.variableName =
* ((VariableClass))_persistence_variableName_vh.getValue(); return
* this.variableName; }
*/
public void addGetterMethodForFieldAccess(ClassDetails classDetails, AttributeDetails attributeDetails) {
String attribute = attributeDetails.getAttributeName();
// create the _persistenc_getvariableName method
MethodVisitor cv_get = cv.visitMethod(ACC_PUBLIC, PERSISTENCE_GET + attribute, "()" + attributeDetails.getReferenceClassType().getDescriptor(), null, null);
if (classDetails.shouldWeaveFetchGroups()) {
cv_get.visitVarInsn(ALOAD, 0);
cv_get.visitLdcInsn(attribute);
// _persistence_checkFetched("variableName");
cv_get.visitMethodInsn(INVOKEVIRTUAL, classDetails.getClassName(), "_persistence_checkFetched", "(Ljava/lang/String;)V", false);
}
if (attributeDetails.weaveValueHolders()) {
// _persistence_initialize_variableName_vh();
cv_get.visitVarInsn(ALOAD, 0);
cv_get.visitMethodInsn(INVOKEVIRTUAL, classDetails.getClassName(), "_persistence_initialize_" + attributeDetails.getAttributeName() + PERSISTENCE_FIELDNAME_POSTFIX, "()V", false);
// _persistenc_variableName_vh.getValue();
cv_get.visitVarInsn(ALOAD, 0);
cv_get.visitVarInsn(ALOAD, 0);
cv_get.visitFieldInsn(GETFIELD, classDetails.getClassName(), PERSISTENCE_FIELDNAME_PREFIX + attribute + PERSISTENCE_FIELDNAME_POSTFIX, ClassWeaver.VHI_SIGNATURE);
cv_get.visitMethodInsn(INVOKEINTERFACE, ClassWeaver.VHI_SHORT_SIGNATURE, "getValue", "()Ljava/lang/Object;", true);
// Add the cast:
// (<VariableClass>)_persistenc_variableName_vh.getValue()
cv_get.visitTypeInsn(CHECKCAST, attributeDetails.getReferenceClassName().replace('.', '/'));
// add the assignment: this.variableName =
// (<VariableClass>)_persistenc_variableName_vh.getValue();
cv_get.visitFieldInsn(PUTFIELD, classDetails.getClassName(), attribute, attributeDetails.getReferenceClassType().getDescriptor());
}
// return this.variableName;
cv_get.visitVarInsn(ALOAD, 0);
cv_get.visitFieldInsn(GETFIELD, classDetails.getClassName(), attribute, attributeDetails.getReferenceClassType().getDescriptor());
// Get the opcode for the return insturction. This may be different
// depending on the type.
int opcode = attributeDetails.getReferenceClassType().getOpcode(IRETURN);
cv_get.visitInsn(opcode);
cv_get.visitMaxs(0, 0);
}
use of org.eclipse.persistence.internal.libraries.asm.MethodVisitor in project eclipselink by eclipse-ee4j.
the class ClassWeaver method addGetPropertyChangeListener.
/**
* Add the implementation of the changeTracker_getPropertyChangeListener
* method to the class. The result is a method that looks as follows:
*
* public PropertyChangeListener _persistence_getPropertyChangeListener() {
* return _persistence_listener; }
*/
public void addGetPropertyChangeListener(ClassDetails classDetails) {
MethodVisitor cv_getPCL = cv.visitMethod(ACC_PUBLIC, "_persistence_getPropertyChangeListener", "()" + PCL_SIGNATURE, null, null);
cv_getPCL.visitVarInsn(ALOAD, 0);
cv_getPCL.visitFieldInsn(GETFIELD, classDetails.getClassName(), "_persistence_listener", PCL_SIGNATURE);
cv_getPCL.visitInsn(ARETURN);
cv_getPCL.visitMaxs(0, 0);
}
Aggregations