Mail Archive Home | fractal-commits List | May 2006 Index
| <-- Date Index --> | <-- Thread Index --> |
Date: Thursday, May 25, 2006 @ 14:18:12
Author: seintur
Path: .../aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue
Modified: SpoonHelper.java processor/CtrlItfInjectorProcessor.java
processor/LifeCycleInterceptorProcessor.java
Factorizing code.
----------------------------------------------+
SpoonHelper.java | 34 +++++++
processor/CtrlItfInjectorProcessor.java | 113 +++----------------------
processor/LifeCycleInterceptorProcessor.java | 11 --
3 files changed, 56 insertions(+), 102 deletions(-)
Index:
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/SpoonHelper.java
diff -u
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/SpoonHelper.java:1.2
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/SpoonHelper.java:1.3
---
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/SpoonHelper.java:1.2
Sat Apr 1 10:36:01 2006
+++
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/SpoonHelper.java
Thu May 25 14:18:12 2006
@@ -27,6 +27,8 @@
import spoon.reflect.declaration.CtClass;
import spoon.reflect.reference.CtTypeReference;
+import spoon.template.Substitution;
+import spoon.template.Template;
/**
* Helper class for working with Spoon.
@@ -40,6 +42,10 @@
*/
public static boolean impls( CtClass ct, Class<?> itf ) {
+ if( itf.getName().equals("java.lang.Object") ) {
+ return true;
+ }
+
// TODO should recurse in extended classes and interfaces
Set<CtTypeReference<?>> supers = ct.getSuperinterfaces();
CtTypeReference itfctr = ct.getFactory().Type().createReference(itf);
@@ -57,4 +63,32 @@
return false;
}
+ /**
+ * Insert in a CtClass a template if the CtClass implements the given
type.
+ *
+ * @param ct the CtClass where the insertion must be performed
+ * @param typeToClass the type to match (a class or an interface)
+ * @param template the Spoon template containing the code to insert
+ */
+ public static void insert( CtClass<?> ct, Class<?> typeToMatch, Template
template ) {
+
+ if( ! impls(ct,typeToMatch) ) {
+ return;
+ }
+
+ // Insert the template
+ Substitution.insertAll(ct,template);
+
+ // Add implemented interfaces (except Template)
+ CtTypeReference<?> templtr =
ct.getFactory().Type().createReference(Template.class);
+ Class<? extends Template> c = template.getClass();
+ CtClass<?> t = ct.getFactory().Template().getTemplate(c);
+ Set<CtTypeReference<?>> supers = t.getSuperinterfaces();
+ for (CtTypeReference<?> sup : supers) {
+ if( ! templtr.isAssignableFrom(sup) ) {
+ ct.getSuperinterfaces().add(sup);
+ }
+ }
+ }
+
}
Index:
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/CtrlItfInjectorProcessor.java
diff -u
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/CtrlItfInjectorProcessor.java:1.4
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/CtrlItfInjectorProcessor.java:1.5
---
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/CtrlItfInjectorProcessor.java:1.4
Fri May 5 11:33:52 2006
+++
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/CtrlItfInjectorProcessor.java
Thu May 25 14:18:12 2006
@@ -23,7 +23,6 @@
package org.objectweb.fractal.aokell.glue.processor;
-import java.util.Set;
import org.objectweb.fractal.aokell.glue.SpoonHelper;
import org.objectweb.fractal.aokell.glue.template.BindingControllerTemplate;
@@ -33,8 +32,6 @@
import org.objectweb.fractal.aokell.glue.template.NameControllerTemplate;
import org.objectweb.fractal.aokell.glue.template.SuperControllerTemplate;
import org.objectweb.fractal.aokell.glue.template.TemplateControllerTemplate;
-import org.objectweb.fractal.aokell.lib.control.component.ComponentSetterItf;
-import
org.objectweb.fractal.aokell.lib.control.lifecycle.LifeCycleControllerItf;
import org.objectweb.fractal.aokell.lib.membrane.marker.BaseType;
import org.objectweb.fractal.aokell.lib.membrane.marker.BindingType;
import org.objectweb.fractal.aokell.lib.membrane.marker.ContentType;
@@ -42,18 +39,9 @@
import org.objectweb.fractal.aokell.lib.membrane.marker.NameType;
import org.objectweb.fractal.aokell.lib.membrane.marker.SuperType;
import org.objectweb.fractal.aokell.lib.membrane.marker.TemplateType;
-import org.objectweb.fractal.api.Component;
-import org.objectweb.fractal.api.control.BindingController;
-import org.objectweb.fractal.api.control.ContentController;
-import org.objectweb.fractal.api.control.NameController;
-import org.objectweb.fractal.api.control.SuperController;
-import org.objectweb.fractal.api.factory.Factory;
import spoon.processing.AbstractProcessor;
import spoon.reflect.declaration.CtClass;
-import spoon.reflect.factory.TypeFactory;
-import spoon.reflect.reference.CtTypeReference;
-import spoon.template.Substitution;
import spoon.template.Template;
/**
@@ -64,89 +52,24 @@
*/
public class CtrlItfInjectorProcessor extends AbstractProcessor<CtClass<?>> {
- public CtrlItfInjectorProcessor() {
- }
-
- public void process(CtClass<?> ct) {
-
- // ----------------------------------------
- // Lifecycle Controller
- // ----------------------------------------
- if( SpoonHelper.impls(ct,LifeCycleType.class)) {
- Template t = new LifeCycleControllerTemplate();
- Substitution.insertAll(ct,t);
-
- ct.getSuperinterfaces().add(
-
getFactory().Type().createReference(LifeCycleControllerItf.class) );
- }
-
- // ----------------------------------------
- // Component Controller
- // ----------------------------------------
- if( SpoonHelper.impls(ct,BaseType.class)) {
- Template t = new ComponentControllerTemplate();
- Substitution.insertAll(ct,t);
-
- TypeFactory tf = getFactory().Type();
- Set<CtTypeReference<?>> supers = ct.getSuperinterfaces();
- supers.add( tf.createReference(Component.class) );
- supers.add( tf.createReference(ComponentSetterItf.class) );
- }
-
- // ----------------------------------------
- // Binding Controller
- // ----------------------------------------
- if( SpoonHelper.impls(ct,BindingType.class)) {
- Template t = new BindingControllerTemplate();
- Substitution.insertAll(ct,t);
-
- ct.getSuperinterfaces().add(
-
getFactory().Type().createReference(BindingController.class) );
- }
-
- // ----------------------------------------
- // Content Controller
- // ----------------------------------------
- if( SpoonHelper.impls(ct,ContentType.class)) {
- Template t = new ContentControllerTemplate();
- Substitution.insertAll(ct,t);
-
- ct.getSuperinterfaces().add(
-
getFactory().Type().createReference(ContentController.class) );
- }
-
- // ----------------------------------------
- // Name Controller
- // ----------------------------------------
- if( SpoonHelper.impls(ct,NameType.class)) {
- Template t = new NameControllerTemplate();
- Substitution.insertAll(ct,t);
-
- ct.getSuperinterfaces().add(
-
getFactory().Type().createReference(NameController.class) );
- }
-
- // ----------------------------------------
- // Super Controller
- // ----------------------------------------
- if( SpoonHelper.impls(ct,SuperType.class)) {
- Template t = new SuperControllerTemplate();
- Substitution.insertAll(ct,t);
-
- ct.getSuperinterfaces().add(
-
getFactory().Type().createReference(SuperController.class) );
- }
-
- // ----------------------------------------
- // Template Controller
- // ----------------------------------------
- if( SpoonHelper.impls(ct,TemplateType.class)) {
- Template t = new TemplateControllerTemplate();
- Substitution.insertAll(ct,t);
-
- ct.getSuperinterfaces().add(
- getFactory().Type().createReference(Factory.class) );
- }
+ public CtrlItfInjectorProcessor() {}
+
+ final private static Template lifecycleControllerTemplate = new
LifeCycleControllerTemplate();
+ final private static Template componentControllerTemplate = new
ComponentControllerTemplate();
+ final private static Template bindingControllerTemplate = new
BindingControllerTemplate();
+ final private static Template contentControllerTemplate = new
ContentControllerTemplate();
+ final private static Template nameControllerTemplate = new
NameControllerTemplate();
+ final private static Template superControllerTemplate = new
SuperControllerTemplate();
+ final private static Template templateControllerTemplate = new
TemplateControllerTemplate();
+
+ public void process(CtClass<?> ct) {
+
SpoonHelper.insert(ct,LifeCycleType.class,lifecycleControllerTemplate);
+ SpoonHelper.insert(ct,BaseType.class,componentControllerTemplate);
+ SpoonHelper.insert(ct,BindingType.class,bindingControllerTemplate);
+ SpoonHelper.insert(ct,ContentType.class,contentControllerTemplate);
+ SpoonHelper.insert(ct,NameType.class,nameControllerTemplate);
+ SpoonHelper.insert(ct,SuperType.class,superControllerTemplate);
+ SpoonHelper.insert(ct,TemplateType.class,templateControllerTemplate);
}
}
Index:
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/LifeCycleInterceptorProcessor.java
diff -u
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/LifeCycleInterceptorProcessor.java:1.3
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/LifeCycleInterceptorProcessor.java:1.4
---
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/LifeCycleInterceptorProcessor.java:1.3
Fri May 5 11:33:52 2006
+++
aokell/features/glue/spoon/src/org/objectweb/fractal/aokell/glue/processor/LifeCycleInterceptorProcessor.java
Thu May 25 14:18:12 2006
@@ -28,14 +28,13 @@
import org.objectweb.fractal.aokell.glue.SpoonHelper;
import
org.objectweb.fractal.aokell.glue.template.LifeCycleInterceptorBeforeTemplate;
import
org.objectweb.fractal.aokell.glue.template.LifeCycleInterceptorTemplate;
-import
org.objectweb.fractal.aokell.lib.control.lifecycle.LifeCycleInterceptorItf;
import
org.objectweb.fractal.aokell.lib.membrane.marker.LifeCycleInterceptorType;
import org.objectweb.fractal.aokell.lib.util.FractalHelper;
import spoon.processing.AbstractProcessor;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtMethod;
-import spoon.template.Substitution;
+import spoon.template.Template;
/**
* This processor introduces the features releted to the interception
performed
@@ -50,17 +49,15 @@
public boolean isToBeProcessed(CtClass<?> ct) {
return SpoonHelper.impls(ct,LifeCycleInterceptorType.class);
}
+
+ private static Template lifecycleInterceptorTemplate = new
LifeCycleInterceptorTemplate();
public void process(CtClass<?> ct) {
/*
* Insert the implementation of the LifeCycleInterceptorItf
interface.
*/
- LifeCycleInterceptorTemplate t = new LifeCycleInterceptorTemplate();
- Substitution.insertAll(ct,t);
-
- ct.getSuperinterfaces().add(
-
getFactory().Type().createReference(LifeCycleInterceptorItf.class) );
+ SpoonHelper.insert(ct,Object.class,lifecycleInterceptorTemplate);
/*
* Insert before each method of the processed class, a if statement
to
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 2006-2007, OW2 Consortium | contact | webmaster.