Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Mosconi2010-06-22 22:04:13 +0000
committerMarco Mosconi2010-06-22 22:04:13 +0000
commit41b261afe530eb3e91d952bccc418585e9d06767 (patch)
tree5ffda96c64868e5959e133f4829468e0bd98ee62 /othersrc
parent31a90a50a93f55b4ea4475dd3961d737ffc1eba7 (diff)
downloadorg.eclipse.objectteams-41b261afe530eb3e91d952bccc418585e9d06767.tar.gz
org.eclipse.objectteams-41b261afe530eb3e91d952bccc418585e9d06767.tar.xz
org.eclipse.objectteams-41b261afe530eb3e91d952bccc418585e9d06767.zip
Implementation for Bug 311081 - Extension point for a lifting participant
Diffstat (limited to 'othersrc')
-rw-r--r--othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java48
1 files changed, 35 insertions, 13 deletions
diff --git a/othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java b/othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java
index 1adcaeffa..e43204c57 100644
--- a/othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java
+++ b/othersrc/OTRE/src/org/eclipse/objectteams/otre/LiftingParticipantTransformation.java
@@ -17,6 +17,8 @@
package org.eclipse.objectteams.otre;
+import java.lang.reflect.Field;
+
import org.objectteams.Team;
import org.apache.bcel.Constants;
@@ -70,22 +72,17 @@ public class LiftingParticipantTransformation extends ObjectTeamsTransformation
public void doTransformCode(ClassGen cg)
{
- if (PARTICIPANT_NAME == null) return;
-
if (!classNeedsTeamExtensions(cg)) return;
-
+
synchronized (LiftingParticipantTransformation.class) {
- if (!checked) {
- try {
- // install a shared instance into class Team:
- Class<?> participantClass = loader.loadClass(PARTICIPANT_NAME);
- Team.class.getField(LIFTING_PARTICIPANT_FIELD).set(null, participantClass.newInstance());
- } catch (Exception e) {
- new IllegalArgumentException("Lifting participant "+PARTICIPANT_NAME+" is invalid.", e).printStackTrace();
- PARTICIPANT_NAME = null;
- }
- checked = true;
+ try {
+ checkInitParticipant();
+ } catch (Exception e) {
+ new IllegalArgumentException("Lifting participant "+PARTICIPANT_NAME+" is invalid.", e).printStackTrace();
+ PARTICIPANT_NAME = null;
}
+ if (PARTICIPANT_NAME == null)
+ return;
}
factory = new InstructionFactory(cg);
@@ -104,6 +101,31 @@ public class LiftingParticipantTransformation extends ObjectTeamsTransformation
}
}
+ private void checkInitParticipant() throws Exception {
+ if (checked) return;
+ checked = true;
+
+ Field participantField = Team.class.getField(LIFTING_PARTICIPANT_FIELD);
+ Object participant = participantField.get(null);
+
+ if (PARTICIPANT_NAME != null)
+ {
+ // initialize from property "ot.lifting.participant"
+ if (participant != null)
+ throw new IllegalStateException("liftingParticipant already installed.");
+ // install a shared instance into class Team:
+ Class<?> participantClass = loader.loadClass(PARTICIPANT_NAME);
+ participantField.set(null, participantClass.newInstance());
+ }
+ else if (participant != null)
+ {
+ // field was already initialized by a third party
+
+ // fetch the class name to signal that transformations are needed.
+ PARTICIPANT_NAME = participant.getClass().getName();
+ }
+ }
+
private Method weaveLiftingParticipant(Method m, String className, ConstantPoolGen cpg) {
MethodGen mg = newMethodGen(m, className, cpg);
InstructionList il = mg.getInstructionList();

Back to the top