From 41b261afe530eb3e91d952bccc418585e9d06767 Mon Sep 17 00:00:00 2001 From: Marco Mosconi Date: Tue, 22 Jun 2010 22:04:13 +0000 Subject: Implementation for Bug 311081 - Extension point for a lifting participant --- .../otre/LiftingParticipantTransformation.java | 48 ++++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'othersrc') 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(); -- cgit v1.2.3