]> source.dussan.org Git - aspectj.git/commitdiff
refactored generic type handling
authoraclement <aclement>
Mon, 5 Apr 2010 19:36:57 +0000 (19:36 +0000)
committeraclement <aclement>
Mon, 5 Apr 2010 19:36:57 +0000 (19:36 +0000)
tests/src/org/aspectj/systemtest/ajc150/GenericITDsDesign.java
tests/src/org/aspectj/systemtest/ajc169/Ajc169Tests.java
tests/src/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java
tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java

index 0ef98b99de93a951354910bc842d5f3419ef1b6e..542c47554f7895879f4c881a9939318df3b53e89 100644 (file)
@@ -34,6 +34,7 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                return XMLBasedAjcTestCase.loadSuite(GenericITDsDesign.class);
        }
 
+       @Override
        protected File getSpecFile() {
                return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
        }
@@ -59,8 +60,9 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                Attribute[] attrs = clazz.getAttributes();
                for (int i = 0; i < attrs.length; i++) {
                        Attribute attribute = attrs[i];
-                       if (attribute.getName().equals("Signature"))
+                       if (attribute.getName().equals("Signature")) {
                                sigAttr = (Signature) attribute;
+                       }
                }
                return sigAttr;
        }
@@ -86,8 +88,9 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                List allMungers = getTypeMunger(classname);
                for (Iterator iter = allMungers.iterator(); iter.hasNext();) {
                        BcelTypeMunger element = (BcelTypeMunger) iter.next();
-                       if (element.getMunger().getSourceLocation().getLine() == linenumber)
+                       if (element.getMunger().getSourceLocation().getLine() == linenumber) {
                                return element;
+                       }
                }
                for (Iterator iter = allMungers.iterator(); iter.hasNext();) {
                        BcelTypeMunger element = (BcelTypeMunger) iter.next();
@@ -169,7 +172,7 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                verifyDebugString(theBcelMunger.getMunger().getSignature(), "<T extends java.lang.Number,Q extends I> void C.m0(T, Q)");
 
                theBcelMunger = getMungerFromLine("X", 11);
-               System.err.println(theBcelMunger.getMunger().getSignature().toDebugString());
+               // System.err.println(theBcelMunger.getMunger().getSignature().toDebugString());
                verifyDebugString(theBcelMunger.getMunger().getSignature(), "<A,B,C> java.util.List<A> C.m1(B, java.util.Collection<C>)");
        }
 
index 80d992169b495c7646c7f11ea5ca5e28918221c9..110eb0f283e72a76c7e01c4621a1de508525bf12 100644 (file)
@@ -18,14 +18,18 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc169Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
-//     public void testAmbiguousMethod_298665() {
-//             runTest("ambiguous method");
-//     }
-       
+       // public void testAmbiguousMethod_298665() {
+       // runTest("ambiguous method");
+       // }
+
        // public void testStaticallyAnalyzableIf_292262_1() {
        // runTest("if with statically recognizable code");
        // }
 
+       // public void testAdvisingPrivilegedAccessMethod_307147() {
+       // runTest("advising privileged access method");
+       // }
+
        public void testAdvisingPrivilegedAccessMember_307120() {
                runTest("advising privileged access member");
        }
@@ -33,7 +37,7 @@ public class Ajc169Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
        public void testAdvisingPrivilegedAccessMember_307120_2() {
                runTest("advising privileged access member - 2");
        }
-       
+
        public void testTypePatternCategories_44365_Class() {
                runTest("type category type patterns - class");
        }
@@ -82,7 +86,6 @@ public class Ajc169Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
                runTest("type category type patterns - e2");
        }
 
-
        public void testChecker() {
                runTest("inserts in messages");
        }
index f1d9af6c95ea08f8371487c351dd2ba62a5c74d8..2976e5f190a6496271c7a7c5810c6e830a1a863d 100644 (file)
@@ -20,12 +20,14 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.aspectj.ajdt.internal.core.builder.AjState;
+import org.aspectj.asm.IRelationship;
+import org.aspectj.asm.IRelationshipMap;
 import org.aspectj.testing.util.FileUtil;
 
-public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends
-               AjdeInteractionTestbed {
+public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeInteractionTestbed {
 
        public static boolean VERBOSE = false;
 
@@ -41,29 +43,50 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends
        }
 
        public void build(String projectName) {
-               constructUpToDateLstFile(projectName,"build.lst");
+               constructUpToDateLstFile(projectName, "build.lst");
                doBuild(projectName);
-               if (AjdeInteractionTestbed.VERBOSE) printBuildReport(projectName);
+               if (AjdeInteractionTestbed.VERBOSE)
+                       printBuildReport(projectName);
+       }
+
+       public int getRelationshipCount(String project) {
+               IRelationshipMap relmap = getModelFor(project).getRelationshipMap();
+               int ctr = 0;
+               Set entries = relmap.getEntries();
+               for (Iterator iter = entries.iterator(); iter.hasNext();) {
+                       String hid = (String) iter.next();
+                       List rels = relmap.get(hid);
+                       for (Iterator iterator = rels.iterator(); iterator.hasNext();) {
+                               IRelationship ir = (IRelationship) iterator.next();
+                               List targets = ir.getTargets();
+                               for (Iterator iterator2 = targets.iterator(); iterator2.hasNext();) {
+                                       String thid = (String) iterator2.next();
+                                       ctr++;
+                               }
+                       }
+               }
+               return ctr;
        }
 
        public void fullBuild(String projectName) {
-               constructUpToDateLstFile(projectName,"build.lst");
+               constructUpToDateLstFile(projectName, "build.lst");
                doFullBuild(projectName);
-               if (AjdeInteractionTestbed.VERBOSE) printBuildReport(projectName);
+               if (AjdeInteractionTestbed.VERBOSE)
+                       printBuildReport(projectName);
        }
 
        private void constructUpToDateLstFile(String pname, String configname) {
-               File projectBase = new File(sandboxDir,pname);
-               File toConstruct = new File(projectBase,configname);
+               File projectBase = new File(sandboxDir, pname);
+               File toConstruct = new File(projectBase, configname);
                List filesForCompilation = new ArrayList();
-               collectUpFiles(projectBase,projectBase,filesForCompilation);
-       
+               collectUpFiles(projectBase, projectBase, filesForCompilation);
+
                try {
                        FileOutputStream fos = new FileOutputStream(toConstruct);
                        DataOutputStream dos = new DataOutputStream(fos);
                        for (Iterator iter = filesForCompilation.iterator(); iter.hasNext();) {
                                String file = (String) iter.next();
-                               dos.writeBytes(file+"\n");
+                               dos.writeBytes(file + "\n");
                        }
                        dos.close();
                } catch (IOException ioe) {
@@ -73,19 +96,21 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends
 
        private void collectUpFiles(File location, File base, List collectionPoint) {
                String contents[] = location.list();
-               if (contents==null) return;
+               if (contents == null)
+                       return;
                for (int i = 0; i < contents.length; i++) {
                        String string = contents[i];
-                       File f = new File(location,string);
+                       File f = new File(location, string);
                        if (f.isDirectory()) {
-                               collectUpFiles(f,base,collectionPoint);
+                               collectUpFiles(f, base, collectionPoint);
                        } else if (f.isFile() && (f.getName().endsWith(".aj") || f.getName().endsWith(".java"))) {
                                String fileFound;
                                try {
                                        fileFound = f.getCanonicalPath();
-                                       String toRemove  = base.getCanonicalPath();
-                                       if (!fileFound.startsWith(toRemove)) throw new RuntimeException("eh? "+fileFound+"   "+toRemove);
-                                       collectionPoint.add(fileFound.substring(toRemove.length()+1));//+1 captures extra separator
+                                       String toRemove = base.getCanonicalPath();
+                                       if (!fileFound.startsWith(toRemove))
+                                               throw new RuntimeException("eh? " + fileFound + "   " + toRemove);
+                                       collectionPoint.add(fileFound.substring(toRemove.length() + 1));// +1 captures extra separator
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
@@ -94,89 +119,88 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends
        }
 
        /**
-        * Fill in the working directory with the project base files,
-        * from the 'base' folder.
+        * Fill in the working directory with the project base files, from the 'base' folder.
         */
        protected void initialiseProject(String p) {
-               File projectSrc=new File(testdataSrcDir+File.separatorChar+p+File.separatorChar+"base");
-               File destination=new File(getWorkingDir(),p);
-               if (!destination.exists()) {destination.mkdir();}
-               copy(projectSrc,destination);//,false);
+               File projectSrc = new File(testdataSrcDir + File.separatorChar + p + File.separatorChar + "base");
+               File destination = new File(getWorkingDir(), p);
+               if (!destination.exists()) {
+                       destination.mkdir();
+               }
+               copy(projectSrc, destination);// ,false);
                // create the AjCompiler instance associated with this project
                // (has id of the form c:\temp\ajcSandbox\<workspace_name>\<project_name>)
                CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + p);
        }
 
        /**
-        * Applies an overlay onto the project being tested - copying
-        * the contents of the specified overlay directory.
+        * Applies an overlay onto the project being tested - copying the contents of the specified overlay directory.
         */
-       public void alter(String projectName,String overlayDirectory) {
-               File projectSrc =new File(testdataSrcDir+File.separatorChar+projectName+
-                                                 File.separatorChar+overlayDirectory);
-               File destination=new File(getWorkingDir(),projectName);
+       public void alter(String projectName, String overlayDirectory) {
+               File projectSrc = new File(testdataSrcDir + File.separatorChar + projectName + File.separatorChar + overlayDirectory);
+               File destination = new File(getWorkingDir(), projectName);
 
-               if (AjdeInteractionTestbed.VERBOSE) System.out.println("Altering project "+projectName);
-               copy(projectSrc,destination);
+               if (AjdeInteractionTestbed.VERBOSE)
+                       System.out.println("Altering project " + projectName);
+               copy(projectSrc, destination);
        }
-       
+
        /**
-        * Copy the contents of some directory to another location - the
-        * copy is recursive.
+        * Copy the contents of some directory to another location - the copy is recursive.
         */
        protected void copy(File from, File to) {
                String contents[] = from.list();
-               if (contents==null) return;
+               if (contents == null)
+                       return;
                for (int i = 0; i < contents.length; i++) {
                        String string = contents[i];
-                       File f = new File(from,string);
-                       File t = new File(to,string);
-                       
+                       File f = new File(from, string);
+                       File t = new File(to, string);
+
                        if (f.isDirectory() && !f.getName().startsWith("inc")) {
                                t.mkdir();
-                               copy(f,t);
+                               copy(f, t);
                        } else if (f.isFile()) {
                                StringBuffer sb = new StringBuffer();
-                               //if (VERBOSE) System.err.println("Copying "+f+" to "+t);
-                               FileUtil.copyFile(f,t,sb);
-                               if (sb.length()!=0) { System.err.println(sb.toString());}
-                       } 
+                               // if (VERBOSE) System.err.println("Copying "+f+" to "+t);
+                               FileUtil.copyFile(f, t, sb);
+                               if (sb.length() != 0) {
+                                       System.err.println(sb.toString());
+                               }
+                       }
                }
        }
 
        /**
-        * Count the number of times a specified aspectName appears in the default
-        * aop.xml file and compare with the expected number of occurrences. If just 
-        * want to count the number of aspects mentioned within the file then 
-        * pass "" for the aspectName, otherwise, specify the name of the 
-        * aspect interested in.
+        * Count the number of times a specified aspectName appears in the default aop.xml file and compare with the expected number of
+        * occurrences. If just want to count the number of aspects mentioned within the file then pass "" for the aspectName,
+        * otherwise, specify the name of the aspect interested in.
         */
-       protected void checkXMLAspectCount(String projectName, String aspectName,
-                       int expectedOccurrences, String outputDir) {
-                               int aspectCount = 0;
-                               File aopXML = new File(outputDir + File.separatorChar + "META-INF" + File.separatorChar + "aop-ajc.xml");
-                       
-                               if (!aopXML.exists()) {
-                                       fail("Expected file " + aopXML.getAbsolutePath() + " to exist but it doesn't");
-                               }
-                               try {
-                                       BufferedReader reader = new BufferedReader(new FileReader(aopXML));
-                                       String line = reader.readLine();
-                                       while (line != null) {
-                                               if (aspectName.equals("") && line.indexOf("aspect name=\"") != -1) {
-                                                       aspectCount++;
-                                               } else if (line.indexOf("aspect name=\""+aspectName+"\"") != -1) {
-                                                       aspectCount++;
-                                               }
-                                               line = reader.readLine();
-                                       }
-                                       reader.close();
-                               } catch (IOException ie) {
-                                       ie.printStackTrace();
-                               }
-                               if (aspectCount != expectedOccurrences) {
-                                       fail("Expected aspect " + aspectName + " to appear " + expectedOccurrences + " times" +
-                                                       " in the aop.xml file but found " + aspectCount + " occurrences");
+       protected void checkXMLAspectCount(String projectName, String aspectName, int expectedOccurrences, String outputDir) {
+               int aspectCount = 0;
+               File aopXML = new File(outputDir + File.separatorChar + "META-INF" + File.separatorChar + "aop-ajc.xml");
+
+               if (!aopXML.exists()) {
+                       fail("Expected file " + aopXML.getAbsolutePath() + " to exist but it doesn't");
+               }
+               try {
+                       BufferedReader reader = new BufferedReader(new FileReader(aopXML));
+                       String line = reader.readLine();
+                       while (line != null) {
+                               if (aspectName.equals("") && line.indexOf("aspect name=\"") != -1) {
+                                       aspectCount++;
+                               } else if (line.indexOf("aspect name=\"" + aspectName + "\"") != -1) {
+                                       aspectCount++;
                                }
+                               line = reader.readLine();
                        }
+                       reader.close();
+               } catch (IOException ie) {
+                       ie.printStackTrace();
+               }
+               if (aspectCount != expectedOccurrences) {
+                       fail("Expected aspect " + aspectName + " to appear " + expectedOccurrences + " times"
+                                       + " in the aop.xml file but found " + aspectCount + " occurrences");
+               }
+       }
 }
index 4793e1d3b72b7ae35de3b765c6639e56b311d938..c77188fe6ae258750e393686c64baf6d00723a75 100644 (file)
@@ -224,6 +224,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa
 
        // just simple incremental build - no code change, just the aspect touched
        public void testIncrementalFqItds_280380() throws Exception {
+
                String p = "pr280380";
                initialiseProject(p);
                build(p);
@@ -235,6 +236,26 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa
                // printModel(p);
        }
 
+       public void testIncrementalAdvisingItdJoinpointsAccessingPrivFields_307120() throws Exception {
+               String p = "pr307120";
+               initialiseProject(p);
+               build(p);
+               // Hid:1:(targets=1) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo) (advised by) =pr307120<{Test.java}Test&before
+               // Hid:2:(targets=1) =pr307120<{A.java[A (aspect declarations) =pr307120<{Test.java}Test)A.getFoo
+               // Hid:3:(targets=1) =pr307120<{Test.java}Test&before (advises) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo)
+               // Hid:4:(targets=1) =pr307120<{Test.java}Test)A.getFoo (declared on) =pr307120<{A.java[A
+               alter(p, "inc1");
+               assertEquals(4, getRelationshipCount(p));
+               build(p);
+               // Hid:1:(targets=1) =pr307120<{A.java[A (aspect declarations) =pr307120<{Test.java}Test)A.getFoo
+               // Hid:2:(targets=1) =pr307120<{Test.java}Test)A.getFoo (declared on) =pr307120<{A.java[A
+               // These two are missing without the fix:
+               // Hid:1:(targets=1) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo) (advised by) =pr307120<{Test.java}Test&before
+               // Hid:7:(targets=1) =pr307120<{Test.java}Test&before (advises) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo)
+               assertNoErrors(p);
+               assertEquals(4, getRelationshipCount(p));
+       }
+
        // modified aspect so target is fully qualified on the incremental change
        public void testIncrementalFqItds_280380_2() throws Exception {
                String p = "pr280380";
@@ -405,7 +426,6 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa
        }
 
        public void testOutputLocationCallbacksFileAdd() {
-               AjdeInteractionTestbed.VERBOSE = true;
                String p = "pr268827_ol2";
                initialiseProject(p);
                CustomOLM olm = new CustomOLM(getProjectRelativePath(p, ".").toString());
@@ -1431,6 +1451,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa
                // assertEquals("=AspectPathTwo/binaries<(Asp2.class}Asp2&before", findElementAtLine(root, 16).getHandleIdentifier());
        }
 
+       /** @return the number of relationship pairs */
        private void printModel(String projectName) throws Exception {
                dumptree(getModelFor(projectName).getHierarchy().getRoot(), 0);
                PrintWriter pw = new PrintWriter(System.out);