OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | fractal-commits List | August 2006 Index

<--  Date Index  --> <--  Thread Index  -->

CVS update of AOKELL_2_1 aokell/src/org/objectweb/fractal/aokell/mixin (2 files)


    Date: Thursday, August 31, 2006 @ 15:59:51
  Author: seintur
    Path: /cvsroot/fractal/aokell/src/org/objectweb/fractal/aokell/mixin
     Tag: AOKELL_2_1

Modified: MixinClassProcessor.java
 Removed: MixinFieldProcessor.java

Field and class mixin integrated in the same Spoon processor.


--------------------------+
 MixinClassProcessor.java |   90 ++++++++++++++++++++++++++++++++++++---------
 MixinFieldProcessor.java |   76 --------------------------------------
 2 files changed, 72 insertions(+), 94 deletions(-)


Index: aokell/src/org/objectweb/fractal/aokell/mixin/MixinClassProcessor.java
diff -u 
aokell/src/org/objectweb/fractal/aokell/mixin/MixinClassProcessor.java:1.1.2.1
 
aokell/src/org/objectweb/fractal/aokell/mixin/MixinClassProcessor.java:1.1.2.2
--- 
aokell/src/org/objectweb/fractal/aokell/mixin/MixinClassProcessor.java:1.1.2.1
      Tue Aug 29 08:49:53 2006
+++ aokell/src/org/objectweb/fractal/aokell/mixin/MixinClassProcessor.java    
  Thu Aug 31 15:59:50 2006
@@ -23,6 +23,7 @@
 
 package org.objectweb.fractal.aokell.mixin;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -32,6 +33,7 @@
 import spoon.processing.AbstractProcessor;
 import spoon.reflect.Factory;
 import spoon.reflect.code.CtBlock;
+import spoon.reflect.code.CtFieldAccess;
 import spoon.reflect.code.CtInvocation;
 import spoon.reflect.code.CtLiteral;
 import spoon.reflect.code.CtReturn;
@@ -44,6 +46,7 @@
 import spoon.reflect.declaration.ModifierKind;
 import spoon.reflect.factory.CodeFactory;
 import spoon.reflect.reference.CtExecutableReference;
+import spoon.reflect.reference.CtFieldReference;
 import spoon.reflect.reference.CtPackageReference;
 import spoon.reflect.reference.CtTypeReference;
 import spoon.reflect.visitor.Query;
@@ -106,24 +109,31 @@
     }
     
     public void processingDone() {
-        /*
-         * Remove the temporary class.
-         * processingDone is called several times (??) (to be investigates).
-         * Do not remove the test (foo == null) else a null pointer 
exception is
-         * thrown.
-         */
-        CtClass<?> foo =
-            getFactory().Class().get(TMP_CLASS_NAME);
-        
-        if( foo == null ) {
-            return;
+
+        // Retrieve the list of mixin target classes
+        MixinLayersDef[] layers = AOKellMixinLayers.getMixinLayers();
+        List<String> targets = new ArrayList<String>();
+        for (int i = 0; i < layers.length; i++) {
+            String targetClassName = layers[i].getClassName();
+            targets.add(targetClassName);
         }
         
-        if( foo.isTopLevel() ) {
-            foo.getParent(CtPackage.class).getTypes().remove(foo);
-        }
-        else {
-            foo.getParent(CtSimpleType.class).getNestedTypes().remove(foo);
+        /*
+         * Prevent spoon from generating all classes contained in the source 
set.
+         * Keep only classes which have been generated.
+         */
+        List<CtSimpleType> types = getFactory().Type().getAll();
+        for (CtSimpleType type : types) {
+            String name = type.getQualifiedName();
+            if( ! targets.contains(name) ) {
+                if( type.isTopLevel() ) {
+                    type.getParent(CtPackage.class).getTypes().remove(type);
+                }
+                else {
+                    type.getParent(CtSimpleType.class).getNestedTypes().
+                        remove(type);
+                }
+            }
         }
     }
 
@@ -133,16 +143,60 @@
     // ---------------------------------------------------
     
     public void process( CtClass<?> _ ) {
+        
+        /*
+         * The class on which this processor is run does not matter.
+         * We just need to run this processor.
+         */
+        
         MixinLayersDef[] layers = AOKellMixinLayers.getMixinLayers();
         for (int i = 0; i < layers.length; i++) {
             String targetClassName = layers[i].getClassName();
             Class<?>[] srcClasses = layers[i].getLayers();
             CtClass<?> target = getFactory().Class().create(targetClassName);
-            process(target,srcClasses);
+            target.setVisibility(ModifierKind.PUBLIC);
+            processMethods(target,srcClasses);
+            processFields(target);
+        }
+    }
+    
+    /**
+     * Remove the _this_ prefix in all field accesses defined in the given
+     * class.
+     */
+    private void processFields( CtClass<?> target ) {
+        
+        // Get all the field accesses contained in target
+        List<CtFieldAccess<?>> fas =
+            Query.getElements(
+                target,
+                new AbstractFilter<CtFieldAccess<?>>(CtFieldAccess.class) {
+                    public boolean matches( CtFieldAccess<?> fa) {
+                        return true;
+                    }
+                }
+        );
+        
+        // Remove the _this_ prefix
+        for (CtFieldAccess<?> fa : fas) {
+            CtFieldReference<?> cfr = fa.getVariable();
+            String fieldName = cfr.getSimpleName();
+            if( fieldName.startsWith(METH_CALL_PREFIX) ) {
+                String newFieldName =
+                    fieldName.substring(METH_CALL_PREFIX.length());
+                cfr.setSimpleName(newFieldName);
+            }
         }
     }
     
-    private void process( CtClass<?> target, Class<?>[] srcClasses ) {
+    /**
+     * Mix the methods defined in the given classes and insert the result in 
the
+     * given target class.
+     * 
+     * @param target      the target class
+     * @param srcClasses  the source classes containing the methods to be 
mixed
+     */
+    private void processMethods( CtClass<?> target, Class<?>[] srcClasses ) {
         
         Factory f = getFactory();
         
Index: aokell/src/org/objectweb/fractal/aokell/mixin/MixinFieldProcessor.java
diff -u 
aokell/src/org/objectweb/fractal/aokell/mixin/MixinFieldProcessor.java:1.1.2.1
 
aokell/src/org/objectweb/fractal/aokell/mixin/MixinFieldProcessor.java:removed
--- 
aokell/src/org/objectweb/fractal/aokell/mixin/MixinFieldProcessor.java:1.1.2.1
      Tue Aug 29 08:49:53 2006
+++ aokell/src/org/objectweb/fractal/aokell/mixin/MixinFieldProcessor.java    
  Thu Aug 31 15:59:51 2006
@@ -1,76 +0,0 @@
-/***
- * AOKell
- * Copyright (C) 2006 INRIA, France Telecom
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Contact: Lionel.Seinturier@xxxxxxx
- *
- * Author: Lionel Seinturier
- */
-
-package org.objectweb.fractal.aokell.mixin;
-
-import spoon.processing.AbstractProcessor;
-import spoon.reflect.code.CtFieldAccess;
-import spoon.reflect.declaration.CtClass;
-import spoon.reflect.reference.CtFieldReference;
-
-/**
- * A Spoon processor for replacing accesses to fields with a name which 
starts
- * with _this_ by their effective value in the mixed class.
- * 
- * Only classes with the JuliaMixin annotation are processed.
- * 
- * @author Lionel Seinturier <Lionel.Seinturier@xxxxxxx>
- */
-public class MixinFieldProcessor
-    extends AbstractProcessor<CtFieldAccess<?>> {
-
-    public boolean isToBeProcessed( CtFieldAccess<?> fa ) {
-        
-        /*
-         * Check whether the class declaring the field access is annotated by
-         * the JuliaMixin annotation.
-         */
-        CtClass<?> declCl = fa.getParent(CtClass.class);
-        if( declCl.getAnnotation((Class)null /*Mixin.class*/ ) == null ) {
-            return false;
-        }
-        
-        /*
-         * Check whether the name of the accessed fields starts with _this_.
-         */
-        CtFieldReference<?> cfr = fa.getVariable();
-        String fieldName = cfr.getSimpleName();
-        
-        return
-            fieldName.startsWith(MixinClassProcessor.METH_CALL_PREFIX);
-    }
-    
-    public void process( CtFieldAccess<?> fa ) {
-        
-        CtFieldReference<?> cfr = fa.getVariable();
-        String fieldName = cfr.getSimpleName();
-        
-        if( fieldName.startsWith(MixinClassProcessor.METH_CALL_PREFIX) ) {
-            String newFieldName =
-                fieldName.substring(
-                        MixinClassProcessor.METH_CALL_PREFIX.length());
-            cfr.setSimpleName(newFieldName);
-        }
-
-    }
-}



<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.