Bug 397182 - Prepare OTDT for new (dynamic) weaver
- calculate nesting depth when using 'this$n'
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java
index e79817c..a64cd4d 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java
@@ -150,18 +150,16 @@
// already loaded by a class loader or not
private boolean isLoaded;
- // Does this AbstractBoundClass represent a team
- private boolean isTeam;
- private boolean isInterface;
+ private int modifiers;
private int otClassFlags;
- private int visibilityFlags;
private boolean implicitTeamActivationEnabled = false;
private Set<String> methodsForImplicitActivation;
protected ClassLoader loader;
+
/**
* No public constructor, beacause only the ClassRepository should
* create AbstractBoundClasses
@@ -238,15 +236,7 @@
*/
public boolean isInterface() {
parseBytecode();
- return isInterface;
- }
-
- /**
- * Mark as interface
- * @param isInterface
- */
- public void setInterface(boolean isInterface) {
- this.isInterface = isInterface;
+ return (this.modifiers & Opcodes.ACC_INTERFACE) != 0;
}
/**
@@ -256,30 +246,38 @@
*/
public boolean isTeam() {
parseBytecode();
- return isTeam;
+ return (this.modifiers & Types.TEAM) != 0;
+ }
+
+ /**
+ * Number of outer instances required in an instance of this class.
+ */
+ public int nestingDepth() {
+ parseBytecode();
+ if ((this.modifiers & Opcodes.ACC_STATIC) != 0)
+ return 0;
+ if (this.enclosingClass != null)
+ return this.enclosingClass.nestingDepth()+1;
+ return 0;
}
/**
- * Mark as team
- * @param isTeam
+ * Store class modifiers (incl. visibility, AccStatic, AccInterface, AccStatic
*/
- public void setTeam(boolean isTeam) {
- this.isTeam = isTeam;
+ public void setModifiers(int modifiers) {
+ this.modifiers = modifiers;
}
public void setOTClassFlags(int flags) {
this.otClassFlags = flags;
}
- public void setVisibility(int flags) {
- this.visibilityFlags = flags;
- }
public boolean isRole() {
return (this.otClassFlags & Types.ROLE_FLAG) != 0;
}
public boolean isProtected() {
- return (this.visibilityFlags & Opcodes.ACC_PROTECTED) != 0;
+ return (this.modifiers & Opcodes.ACC_PROTECTED) != 0;
}
public void enableImplicitActivation() {
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddImplicitActivationAdapter.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddImplicitActivationAdapter.java
index 8afbb66..acf72b0 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddImplicitActivationAdapter.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddImplicitActivationAdapter.java
@@ -15,15 +15,14 @@
**********************************************************************/
package org.eclipse.objectteams.otredyn.bytecode.asm;
+import static org.eclipse.objectteams.otredyn.bytecode.asm.AsmBoundClass.ASM_API;
+
import org.eclipse.objectteams.otredyn.transformer.names.ClassNames;
import org.eclipse.objectteams.otredyn.transformer.names.ConstantMembers;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.commons.AdviceAdapter;
-
import org.objectweb.asm.Opcodes;
-
-import static org.eclipse.objectteams.otredyn.bytecode.asm.AsmBoundClass.ASM_API;
+import org.objectweb.asm.commons.AdviceAdapter;
/**
* This visitor adds calls to _OT$implicitlyActivate and _OT$implicitlyDeactivate
@@ -71,6 +70,7 @@
if (isCandidateForImplicitActivation(name, desc, access)) {
final MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, null, null);
final String enclTeamDesc = clazz.isRole() ? 'L'+clazz.getEnclosingClass().getName().replace('.', '/')+';' : null;
+ final int nesting = clazz.nestingDepth()-1;
return new AdviceAdapter(this.api, methodVisitor, access, name, desc) {
@Override
protected void onMethodEnter() {
@@ -81,7 +81,7 @@
if (clazz.isRole()) {
// TODO(SH): respect nesting depth (this$n)
methodVisitor.visitIntInsn(Opcodes.ALOAD, 0);
- methodVisitor.visitFieldInsn(Opcodes.GETFIELD, clazz.getName().replace('.', '/'), "this$0", enclTeamDesc);
+ methodVisitor.visitFieldInsn(Opcodes.GETFIELD, clazz.getName().replace('.', '/'), "this$"+nesting, enclTeamDesc);
methodVisitor.visitMethodInsn(INVOKEINTERFACE, TARGET_CLASS_NAME, IMPLICIT_ACTIVATE_METHOD_NAME, METHOD_DESC, true);
}
}
@@ -94,7 +94,7 @@
if (clazz.isRole()) {
// TODO(SH): respect nesting depth (this$n)
methodVisitor.visitIntInsn(Opcodes.ALOAD, 0);
- methodVisitor.visitFieldInsn(Opcodes.GETFIELD, clazz.getName().replace('.', '/'), "this$0", enclTeamDesc);
+ methodVisitor.visitFieldInsn(Opcodes.GETFIELD, clazz.getName().replace('.', '/'), "this$"+nesting, enclTeamDesc);
methodVisitor.visitMethodInsn(INVOKEINTERFACE, TARGET_CLASS_NAME, IMPLICIT_DEACTIVATE_METHOD_NAME, METHOD_DESC, true);
}
}
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmClassVisitor.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmClassVisitor.java
index a89a2b0..15ac4c6 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmClassVisitor.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmClassVisitor.java
@@ -51,10 +51,8 @@
*/
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
- clazz.setSuperClassName(superName);
- clazz.setTeam((access & Types.TEAM) != 0);
- clazz.setInterface((access & Opcodes.ACC_INTERFACE) != 0);
- clazz.setVisibility((access & (Opcodes.ACC_PRIVATE|Opcodes.ACC_PROTECTED|Opcodes.ACC_PUBLIC)));
+ clazz.setSuperClassName(superName);
+ clazz.setModifiers(access);
}
/**