]> source.dussan.org Git - aspectj.git/commitdiff
251277: making asmmanager non-singleton
authoraclement <aclement>
Mon, 20 Oct 2008 04:40:56 +0000 (04:40 +0000)
committeraclement <aclement>
Mon, 20 Oct 2008 04:40:56 +0000 (04:40 +0000)
testing/src/org/aspectj/testing/util/StructureModelUtil.java
testing/testsrc/org/aspectj/testing/util/StructureModelUtilTest.java

index d08098a2955a34787015f8be1cebcf1eff9e044c..10e03dd225b45f3d3a7b3c9e3f24a22ebe65bf8a 100644 (file)
@@ -11,7 +11,6 @@
  *     Xerox/PARC     initial implementation 
  * ******************************************************************/
 
-
 package org.aspectj.testing.util;
 
 import java.util.ArrayList;
@@ -31,9 +30,9 @@ import org.aspectj.asm.IProgramElement;
 
 /**
  * Prototype functionality for package view clients.
- */  
+ */
 public class StructureModelUtil {
-       
+
        public static class ModelIncorrectException extends Exception {
 
                private static final long serialVersionUID = 8920868549577870993L;
@@ -42,44 +41,42 @@ public class StructureModelUtil {
                        super(s);
                }
        }
-       
+
        /**
-        * Check the properties of the current model.  The parameter string lists properties of the model
-        * that should be correct.  If any of the properties are incorrect, a ModelIncorrectException is
-        * thrown.
+        * Check the properties of the current model. The parameter string lists properties of the model that should be correct. If any
+        * of the properties are incorrect, a ModelIncorrectException is thrown.
         * 
         * @param toCheck comma separated list of name=value pairs that should be found in the ModelInfo object
         * @throws ModelIncorrectException thrown if any of the name=value pairs in toCheck are not found
         */
        public static void checkModel(String toCheck) throws ModelIncorrectException {
-               Properties modelProperties = AsmManager.ModelInfo.summarizeModel().getProperties();
-               
+               Properties modelProperties = AsmManager.lastActiveStructureModel.summarizeModel().getProperties();
+
                // Break toCheck into pieces and check each exists
-               StringTokenizer st = new StringTokenizer(toCheck,",=");
+               StringTokenizer st = new StringTokenizer(toCheck, ",=");
                while (st.hasMoreTokens()) {
                        String key = st.nextToken();
                        String expValue = st.nextToken();
                        boolean expectingZero = false;
                        try {
-                               expectingZero = (Integer.parseInt(expValue)==0);
+                               expectingZero = (Integer.parseInt(expValue) == 0);
                        } catch (NumberFormatException nfe) {
                                // this is ok as expectingZero will be false
                        }
-                   String value = modelProperties.getProperty(key);
-                   if (value == null) {
-                       if (!expectingZero)
-                         throw new ModelIncorrectException("Couldn't find '"+key+"' property for the model");  
-                   } else if (!value.equals(expValue)) {
-                       throw new ModelIncorrectException("Model property '"+key+"' incorrect:  Expected "+expValue+" but found "+value);
-                   }
-               }       
+                       String value = modelProperties.getProperty(key);
+                       if (value == null) {
+                               if (!expectingZero)
+                                       throw new ModelIncorrectException("Couldn't find '" + key + "' property for the model");
+                       } else if (!value.equals(expValue)) {
+                               throw new ModelIncorrectException("Model property '" + key + "' incorrect:  Expected " + expValue + " but found "
+                                               + value);
+                       }
+               }
        }
-       
+
        /**
-        * This method returns a map from affected source lines in a class to
-        * a List of aspects affecting that line.
-        * Based on method of same name by mik kirsten. To be replaced when StructureModelUtil
-        * corrects its implementation
+        * This method returns a map from affected source lines in a class to a List of aspects affecting that line. Based on method of
+        * same name by mik kirsten. To be replaced when StructureModelUtil corrects its implementation
         * 
         * @param the full path of the source file to get a map for
         * 
@@ -87,74 +84,71 @@ public class StructureModelUtil {
         */
        public static Map getLinesToAspectMap(String sourceFilePath) {
 
-//             Map annotationsMap =
-//                     AsmManager.getDefault().getInlineAnnotations(
-//                             sourceFilePath,
-//                             true,
-//                             true);
+               // Map annotationsMap =
+               // AsmManager.getDefault().getInlineAnnotations(
+               // sourceFilePath,
+               // true,
+               // true);
 
                Map aspectMap = new HashMap();
-//             Set keys = annotationsMap.keySet();
-//             for (Iterator it = keys.iterator(); it.hasNext();) {
-//                     Object key = it.next();
-//                     List annotations = (List) annotationsMap.get(key);
-//                     for (Iterator it2 = annotations.iterator(); it2.hasNext();) {
-//                             IProgramElement node = (IProgramElement) it2.next();
+               // Set keys = annotationsMap.keySet();
+               // for (Iterator it = keys.iterator(); it.hasNext();) {
+               // Object key = it.next();
+               // List annotations = (List) annotationsMap.get(key);
+               // for (Iterator it2 = annotations.iterator(); it2.hasNext();) {
+               // IProgramElement node = (IProgramElement) it2.next();
 
-//                             List relations = node.getRelations();
-//
-//                             for (Iterator it3 = relations.iterator(); it3.hasNext();) {
-//                                     IRelationship relationNode = (IRelationship) it3.next();
+               // List relations = node.getRelations();
+               //
+               // for (Iterator it3 = relations.iterator(); it3.hasNext();) {
+               // IRelationship relationNode = (IRelationship) it3.next();
 
-//                                     if (relationNode.getKind().equals("Advice")) {
-//                                             List children = relationNode.getTargets();
-//
-//                                             List aspects = new Vector();
-//
-//                                             for (Iterator it4 = children.iterator();
-//                                                     it4.hasNext();
-//                                                     ) {
-//                                                     Object object = it4.next();
-//
-////                                                   if (object instanceof LinkNode) {
-////                                                           IProgramElement pNode =
-////                                                                   ((LinkNode) object).getProgramElementNode();
-////
-////                                                           if (pNode.getProgramElementKind()
-////                                                                   == IProgramElement.Kind.ADVICE) {
-////
-////                                                                   IProgramElement theAspect = pNode.getParent();
-////
-////                                                                   aspects.add(theAspect);
-////
-////                                                           }
-////                                                   }
-//                                             }
-//                                             if (!aspects.isEmpty()) {
-//                                                     aspectMap.put(key, aspects);
-//                                             }
-//                                     }
-//
-//                             }
-//                     }
-//             }
+               // if (relationNode.getKind().equals("Advice")) {
+               // List children = relationNode.getTargets();
+               //
+               // List aspects = new Vector();
+               //
+               // for (Iterator it4 = children.iterator();
+               // it4.hasNext();
+               // ) {
+               // Object object = it4.next();
+               //
+               // // if (object instanceof LinkNode) {
+               // // IProgramElement pNode =
+               // // ((LinkNode) object).getProgramElementNode();
+               // //
+               // // if (pNode.getProgramElementKind()
+               // // == IProgramElement.Kind.ADVICE) {
+               // //
+               // // IProgramElement theAspect = pNode.getParent();
+               // //
+               // // aspects.add(theAspect);
+               // //
+               // // }
+               // // }
+               // }
+               // if (!aspects.isEmpty()) {
+               // aspectMap.put(key, aspects);
+               // }
+               // }
+               //
+               // }
+               // }
+               // }
                return aspectMap;
        }
 
        /**
-        * This method is copied from StructureModelUtil inoder for it to use the working
-        * version of getLineToAspectMap()
+        * This method is copied from StructureModelUtil inoder for it to use the working version of getLineToAspectMap()
         * 
-        * @return              the set of aspects with advice that affects the specified package
+        * @return the set of aspects with advice that affects the specified package
         */
        public static Set getAspectsAffectingPackage(IProgramElement packageNode) {
                List files = StructureModelUtil.getFilesInPackage(packageNode);
                Set aspects = new HashSet();
                for (Iterator it = files.iterator(); it.hasNext();) {
                        IProgramElement fileNode = (IProgramElement) it.next();
-                       Map adviceMap =
-                               getLinesToAspectMap(
-                                       fileNode.getSourceLocation().getSourceFile().getAbsolutePath());
+                       Map adviceMap = getLinesToAspectMap(fileNode.getSourceLocation().getSourceFile().getAbsolutePath());
                        Collection values = adviceMap.values();
                        for (Iterator it2 = values.iterator(); it2.hasNext();) {
                                aspects.add(it2.next());
@@ -163,25 +157,17 @@ public class StructureModelUtil {
                return aspects;
        }
 
-       public static List getPackagesInModel() {
+       public static List getPackagesInModel(AsmManager modl) {
                List packages = new ArrayList();
-               IHierarchy model = AsmManager.getDefault().getHierarchy();
+               IHierarchy model = modl.getHierarchy();
                if (model.getRoot().equals(IHierarchy.NO_STRUCTURE)) {
                        return null;
                } else {
-                       return getPackagesHelper(
-                               (IProgramElement) model.getRoot(),
-                               IProgramElement.Kind.PACKAGE,
-                               null,
-                               packages);
+                       return getPackagesHelper(model.getRoot(), IProgramElement.Kind.PACKAGE, null, packages);
                }
        }
 
-       private static List getPackagesHelper(
-               IProgramElement node,
-               IProgramElement.Kind kind,
-               String prename,
-               List matches) {
+       private static List getPackagesHelper(IProgramElement node, IProgramElement.Kind kind, String prename, List matches) {
 
                if (kind == null || node.getKind().equals(kind)) {
                        if (prename == null) {
@@ -207,75 +193,71 @@ public class StructureModelUtil {
        /**
         * Helper function sorts a list of resources into alphabetical order
         */
-//     private List sortElements(List oldElements) {
-//             Object[] temp = oldElements.toArray();
-//             SortingComparator comparator = new SortingComparator();
-//
-//             Arrays.sort(temp, comparator);
-//
-//             List newResources = Arrays.asList(temp);
-//
-//             return newResources;
-//     }
-//
-//     private static List sortArray(List oldElements) {
-//             Object[] temp = oldElements.toArray();
-//             SortArrayComparator comparator = new SortArrayComparator();
-//
-//             Arrays.sort(temp, comparator);
-//             
-//             List newElements = Arrays.asList(temp);
-//
-//             return newElements;
-//     }
-
-//     private class SortingComparator implements Comparator {
-//             public int compare(Object o1, Object o2) {
-//                     IProgramElement p1 = (IProgramElement) o1;
-//                     IProgramElement p2 = (IProgramElement) o2;
-//
-//                     String name1 = p1.getName();
-//                     String name2 = p2.getName();
-//
-//                     return name1.compareTo(name2);
-//             }
-//     }
-//
-//     private static class SortArrayComparator implements Comparator {
-//             public int compare(Object o1, Object o2) {
-//                     Object[] array1 = (Object[]) o1;
-//                     Object[] array2 = (Object[]) o2;
-//
-//                     IProgramElement p1 = (IProgramElement) array1[1];
-//                     IProgramElement p2 = (IProgramElement) array2[1];
-//
-//                     String name1 = p1.getName();
-//                     String name2 = p2.getName();
-//
-//                     return name1.compareTo(name2);
-//             }
-//     }
-
+       // private List sortElements(List oldElements) {
+       // Object[] temp = oldElements.toArray();
+       // SortingComparator comparator = new SortingComparator();
+       //
+       // Arrays.sort(temp, comparator);
+       //
+       // List newResources = Arrays.asList(temp);
+       //
+       // return newResources;
+       // }
+       //
+       // private static List sortArray(List oldElements) {
+       // Object[] temp = oldElements.toArray();
+       // SortArrayComparator comparator = new SortArrayComparator();
+       //
+       // Arrays.sort(temp, comparator);
+       //              
+       // List newElements = Arrays.asList(temp);
+       //
+       // return newElements;
+       // }
+       // private class SortingComparator implements Comparator {
+       // public int compare(Object o1, Object o2) {
+       // IProgramElement p1 = (IProgramElement) o1;
+       // IProgramElement p2 = (IProgramElement) o2;
+       //
+       // String name1 = p1.getName();
+       // String name2 = p2.getName();
+       //
+       // return name1.compareTo(name2);
+       // }
+       // }
+       //
+       // private static class SortArrayComparator implements Comparator {
+       // public int compare(Object o1, Object o2) {
+       // Object[] array1 = (Object[]) o1;
+       // Object[] array2 = (Object[]) o2;
+       //
+       // IProgramElement p1 = (IProgramElement) array1[1];
+       // IProgramElement p2 = (IProgramElement) array2[1];
+       //
+       // String name1 = p1.getName();
+       // String name2 = p2.getName();
+       //
+       // return name1.compareTo(name2);
+       // }
+       // }
        /**
-        * @return              all of the AspectJ and Java source files in a package
-        */ 
+        * @return all of the AspectJ and Java source files in a package
+        */
        public static List getFilesInPackage(IProgramElement packageNode) {
                List packageContents;
                if (packageNode == null) {
                        return null;
                } else {
-                       packageContents = packageNode.getChildren();    
+                       packageContents = packageNode.getChildren();
                }
                List files = new ArrayList();
-               for (Iterator it = packageContents.iterator(); it.hasNext(); ) {
-                       IProgramElement packageItem = (IProgramElement)it.next();
-                       if (packageItem.getKind() == IProgramElement.Kind.FILE_JAVA 
-                               || packageItem.getKind() == IProgramElement.Kind.FILE_ASPECTJ) {
+               for (Iterator it = packageContents.iterator(); it.hasNext();) {
+                       IProgramElement packageItem = (IProgramElement) it.next();
+                       if (packageItem.getKind() == IProgramElement.Kind.FILE_JAVA
+                                       || packageItem.getKind() == IProgramElement.Kind.FILE_ASPECTJ) {
                                files.add(packageItem);
                        }
-               } 
+               }
                return files;
-       }       
+       }
 }
-
-
index e766c95d3341deca609ccfb373d85002bafbcb13..e3f91decc6f58ecda501a4cf7edee570951dc453 100644 (file)
@@ -11,7 +11,6 @@
  *     Helen Hawkins    Converted to new interface (bug 148190) 
  * ******************************************************************/
 
-
 package org.aspectj.testing.util;
 
 import java.io.File;
@@ -26,18 +25,14 @@ import org.aspectj.asm.IProgramElement;
 /**
  * @author Mik Kersten
  */
-public class StructureModelUtilTest extends AjdeCoreTestCase{
-       
-       private String[] files = new String[]{
-                       "figures" + File.separator + "Debug.java",
-                       "figures" + File.separator + "Figure.java",
-                       "figures" + File.separator + "FigureElement.java",
-                       "figures" + File.separator + "Main.java",
-                       "figures" + File.separator + "composites" + File.separator + "Line.java",
+public class StructureModelUtilTest extends AjdeCoreTestCase {
+
+       private final String[] files = new String[] { "figures" + File.separator + "Debug.java",
+                       "figures" + File.separator + "Figure.java", "figures" + File.separator + "FigureElement.java",
+                       "figures" + File.separator + "Main.java", "figures" + File.separator + "composites" + File.separator + "Line.java",
                        "figures" + File.separator + "composites" + File.separator + "Square.java",
                        "figures" + File.separator + "primitives" + File.separator + "planar" + File.separator + "Point.java",
-                       "figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java"
-       };
+                       "figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java" };
 
        public static void main(String[] args) {
                junit.swingui.TestRunner.run(StructureModelUtilTest.class);
@@ -45,37 +40,35 @@ public class StructureModelUtilTest extends AjdeCoreTestCase{
 
        public static TestSuite suite() {
                TestSuite result = new TestSuite();
-               result.addTestSuite(StructureModelUtilTest.class);      
+               result.addTestSuite(StructureModelUtilTest.class);
                return result;
        }
 
        public void testPackageViewUtil() {
-               List packages = StructureModelUtil.getPackagesInModel(); 
+               List packages = StructureModelUtil.getPackagesInModel(getCompiler().getModel());
                assertTrue("packages list not null", packages != null);
-        assertTrue("packages list not empty", !packages.isEmpty());
-       
-               IProgramElement packageNode = (IProgramElement)((Object[])packages.get(0))[0];
+               assertTrue("packages list not empty", !packages.isEmpty());
+
+               IProgramElement packageNode = (IProgramElement) ((Object[]) packages.get(0))[0];
                assertTrue("package node not null", packageNode != null);
-               
+
                List files = StructureModelUtil.getFilesInPackage(packageNode);
                assertTrue("fle list not null", files != null);
-               
+
                // TODO: re-enable
-//             Map lineAdviceMap = StructureModelUtil.getLinesToAspectMap(
-//                     ((IProgramElement)files.get(0)).getSourceLocation().getSourceFile().getAbsolutePath()
-//             );
-//             
-//             assertTrue("line->advice map not null", lineAdviceMap != null);                 
-//             
-//             Set aspects = StructureModelUtil.getAspectsAffectingPackage(packageNode);
-//             assertTrue("aspect list not null", aspects != null);                    
+               // Map lineAdviceMap = StructureModelUtil.getLinesToAspectMap(
+               // ((IProgramElement)files.get(0)).getSourceLocation().getSourceFile().getAbsolutePath()
+               // );
+               //              
+               // assertTrue("line->advice map not null", lineAdviceMap != null);
+               //              
+               // Set aspects = StructureModelUtil.getAspectsAffectingPackage(packageNode);
+               // assertTrue("aspect list not null", aspects != null);
        }
 
-  
        protected void setUp() throws Exception {
                initialiseProject("figures-coverage");
-               TestCompilerConfiguration compilerConfig = (TestCompilerConfiguration) getCompiler()
-                               .getCompilerConfiguration();
+               TestCompilerConfiguration compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
                compilerConfig.setProjectSourceFiles(getSourceFileList(files));
                doBuild();
        }
@@ -84,4 +77,3 @@ public class StructureModelUtilTest extends AjdeCoreTestCase{
                super.tearDown();
        }
 }
-