]> source.dussan.org Git - aspectj.git/commitdiff
some code for 141730 - store type signatures in program elements rather than processe...
authoraclement <aclement>
Tue, 6 Jun 2006 08:38:28 +0000 (08:38 +0000)
committeraclement <aclement>
Tue, 6 Jun 2006 08:38:28 +0000 (08:38 +0000)
15 files changed:
asm/.classpath
asm/src/org/aspectj/asm/AsmManager.java
asm/src/org/aspectj/asm/IHierarchy.java
asm/src/org/aspectj/asm/INameConvertor.java [new file with mode: 0644]
asm/src/org/aspectj/asm/IProgramElement.java
asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
asm/src/org/aspectj/asm/internal/ProgramElement.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/IncrementalStateManager.java
tests/bugs152/pr141730.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
util/src/org/aspectj/util/CharOperation.java [new file with mode: 0644]

index 5781c41aec39ca568cbdaa4028adcc18acd02153..a96910321396ae5ad231e435b5c27c4acf766ec8 100644 (file)
@@ -1,9 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-    <classpathentry kind="src" path="src"/>
-    <classpathentry kind="src" path="testsrc"/>
-    <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
-    <classpathentry kind="src" path="/bridge"/>
-    <classpathentry kind="lib" path="/lib/junit/junit.jar" sourcepath="/lib/junit/junit-src.jar"/>
-    <classpathentry kind="output" path="bin"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="testsrc"/>
+       <classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB"/>
+       <classpathentry kind="src" path="/bridge"/>
+       <classpathentry sourcepath="/lib/junit/junit-src.jar" kind="lib" path="/lib/junit/junit.jar"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/util"/>
+       <classpathentry kind="output" path="bin"/>
 </classpath>
index e9b8c4bc163de23615f34bb707c72b5ac8ed4815..f7d0c677eb74ddb937972b57d3b6fa74e07ee8e6 100644 (file)
@@ -77,8 +77,9 @@ public class AsmManager {
         handleProvider = new OptimizedFullPathHandleProvider(); 
     }
        
-       public void createNewASM() {
+       public void createNewASM(INameConvertor convertor) {
                hierarchy = new AspectJElementHierarchy();
+               hierarchy.setNameConvertor(convertor);
                mapper = new RelationshipMap(hierarchy);
        }
        
index d458da3389582f7f972636c7e7c1d792d53d0551..82428481b8f291892f4118ce1861b747eb4882fc 100644 (file)
@@ -102,4 +102,7 @@ public interface IHierarchy extends Serializable {
        public void flushHandleMap();
 
        public void updateHandleMap(Set deletedFiles);
+       
+       public void setNameConvertor(INameConvertor convertor);
+       public INameConvertor getNameConvertor();
 }
\ No newline at end of file
diff --git a/asm/src/org/aspectj/asm/INameConvertor.java b/asm/src/org/aspectj/asm/INameConvertor.java
new file mode 100644 (file)
index 0000000..58197bb
--- /dev/null
@@ -0,0 +1,17 @@
+/********************************************************************
+ * Copyright (c) 2006 Contributors. All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: IBM Corporation - initial API and implementation 
+ *                              Helen Hawkins   - initial version
+ *******************************************************************/
+package org.aspectj.asm;
+
+public interface INameConvertor {
+
+       public char[] convertName(char[] name);
+       
+}
index d0024aac832c2577aa1875c406c0377edaaedec9..f88c2dbbad7ae7ffc8d203ebd9a538bc039321f9 100644 (file)
@@ -116,12 +116,13 @@ public interface IProgramElement extends Serializable {
        public String toLabelString();
        public String toLabelString(boolean getFullyQualifiedArgTypes);
 
-       public List getParameterTypes();
-       public void setParameterTypes(List list);
-
        public List getParameterNames();
        public void setParameterNames(List list);
        
+       public List getParameterSignatures();
+       public void setParameterSignatures(List list);
+       public List getParameterTypes();
+       
        /**
         * The format of the string handle is not specified, but is stable across 
         * compilation sessions.
index 42c60a203a123154fc958eaf2a0922b853506c01..62a1a31a8b23b067d9a18a49fe2e8f2854a58a62 100644 (file)
@@ -29,6 +29,7 @@ public class AspectJElementHierarchy implements IHierarchy {
        
        protected  IProgramElement root = null;
     protected String configFile = null;
+    private transient INameConvertor convertor = null;
 
     private Map fileMap = null;
     private Map handleMap = null;
@@ -449,5 +450,13 @@ public class AspectJElementHierarchy implements IHierarchy {
                return hid.substring(0,hid.indexOf("|"));
        }
 
+       public void setNameConvertor(INameConvertor convertor) {
+               this.convertor = convertor;
+       }
+
+       public INameConvertor getNameConvertor() {
+               return convertor;
+       }
+
 }
 
index 35b6a60becb32e5726b5fd25561142f9e6dfe184..0e8826fc16d310f4cf4cb4d0372a3dddea4ec7cb 100644 (file)
@@ -22,9 +22,11 @@ import java.util.Map;
 
 import org.aspectj.asm.AsmManager;
 import org.aspectj.asm.HierarchyWalker;
+import org.aspectj.asm.INameConvertor;
 import org.aspectj.asm.IProgramElement;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.util.CharOperation;
 
 
 /**
@@ -408,16 +410,22 @@ public class ProgramElement implements IProgramElement {
                sb.append(name);
                
                List ptypes = getParameterTypes();
-               if (ptypes != null) {
+               if (ptypes != null && (!ptypes.isEmpty() 
+                               || this.kind.equals(IProgramElement.Kind.METHOD))
+                               || this.kind.equals(IProgramElement.Kind.CONSTRUCTOR)
+                               || this.kind.equals(IProgramElement.Kind.ADVICE)
+                               || this.kind.equals(IProgramElement.Kind.POINTCUT)
+                               || this.kind.equals(IProgramElement.Kind.INTER_TYPE_METHOD)
+                               || this.kind.equals(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR)) {
                        sb.append('('); 
                        for (Iterator it = ptypes.iterator(); it.hasNext(); ) {
-                               String arg = (String)it.next();
+                               char[] arg = (char[])it.next();
                                if (getFullyQualifiedArgTypes) {
                                        sb.append(arg);
                                } else {
-                                       int index = arg.lastIndexOf(".");
+                                       int index = CharOperation.lastIndexOf('.',arg);
                                        if (index != -1) {
-                                               sb.append(arg.substring(index + 1));
+                                               sb.append(CharOperation.subarray(arg,index+1,arg.length));
                                        } else {
                                                sb.append(arg);
                                        }
@@ -503,17 +511,35 @@ public class ProgramElement implements IProgramElement {
                //parameterNames = list; 
        }
 
-       public List getParameterTypes() { 
-               List parameterTypes = (List)kvpairs.get("parameterTypes");
-               return parameterTypes; 
+       public List getParameterTypes() {
+               List l = getParameterSignatures();
+               if (l == null || l.isEmpty()) {
+                       return Collections.EMPTY_LIST;
+               }
+               List params = new ArrayList();
+               for (Iterator iter = l.iterator(); iter.hasNext();) {
+                       char[] param = (char[])iter.next();
+                       INameConvertor convertor = AsmManager.getDefault().getHierarchy().getNameConvertor();
+                       if (convertor != null) {
+                               params.add(convertor.convertName(param));                               
+                       } else {
+                               params.add(param);
+                       }
+               }
+               return params;
        }
-       public void setParameterTypes(List list) { 
-               if (kvpairs==Collections.EMPTY_MAP) kvpairs = new HashMap();
-               if (list==null || list.size()==0) kvpairs.put("parameterTypes",Collections.EMPTY_LIST);
-               else                               kvpairs.put("parameterTypes",list);
-//             parameterTypes = list; 
+       
+       public List getParameterSignatures() {
+               List parameters = (List)kvpairs.get("parameterSigs");
+               return parameters;
        }
 
+       public void setParameterSignatures(List list) {
+               if (kvpairs==Collections.EMPTY_MAP) kvpairs = new HashMap();
+               if (list==null || list.size()==0) kvpairs.put("parameterSigs",Collections.EMPTY_LIST);
+               else kvpairs.put("parameterSigs",list);
+       }
+       
        public String getDetails() {
                String details = (String)kvpairs.get("details");
                return details; 
index d2b09def22fdd5a8c772ca53430d874141425a1d..ac3f04b53cdebd9ef2dcc1d0f3a0887ea3941556 100644 (file)
@@ -49,6 +49,7 @@ import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
 import org.aspectj.ajdt.internal.compiler.problem.AjProblemReporter;
 import org.aspectj.asm.AsmManager;
 import org.aspectj.asm.IHierarchy;
+import org.aspectj.asm.INameConvertor;
 import org.aspectj.asm.IProgramElement;
 import org.aspectj.asm.internal.ProgramElement;
 import org.aspectj.bridge.AbortException;
@@ -83,6 +84,8 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.problem.DefaultProblemFacto
 import org.aspectj.util.FileUtil;
 import org.aspectj.weaver.Dump;
 import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.TypeFactory;
+import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.World;
 import org.aspectj.weaver.bcel.BcelWeaver;
 import org.aspectj.weaver.bcel.BcelWorld;
@@ -631,7 +634,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
        AsmManager.setCreatingModel(config.isEmacsSymMode() || config.isGenerateModelMode());
        if (!AsmManager.isCreatingModel()) return;
 
-               AsmManager.getDefault().createNewASM();
+               AsmManager.getDefault().createNewASM(new NameConverter());
                // AsmManager.getDefault().getRelationshipMap().clear();
                IHierarchy model = AsmManager.getDefault().getHierarchy();
         String rootLabel = "<root>";
@@ -1276,5 +1279,15 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                }
                
        }
+       
+       private class NameConverter implements INameConvertor {
+
+               public char[] convertName(char[] name) {
+                       UnresolvedType ut = TypeFactory.createTypeFromSignature(new String(name));
+                       ResolvedType rt = getWorld().resolve(ut);
+                       return rt.getName().toCharArray();
+               }
+               
+       }
 }
 
index e254a5135040b37770c4a445fe608c899311ffd4..a7265f761ca38891bcbe834f247c3b1aa11b123e 100644 (file)
@@ -25,7 +25,14 @@ import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
 import org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment;
+import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
 import org.aspectj.asm.IProgramElement;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference;
+import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
 import org.aspectj.weaver.AdviceKind;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.UnresolvedType;
@@ -39,13 +46,6 @@ import org.aspectj.weaver.patterns.OrPointcut;
 import org.aspectj.weaver.patterns.ReferencePointcut;
 import org.aspectj.weaver.patterns.TypePattern;
 import org.aspectj.weaver.patterns.TypePatternList;
-import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
-import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
-import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
-import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
-import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
-import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference;
-import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
 
 /**
  * @author Mik Kersten
@@ -296,34 +296,31 @@ public class AsmElementFormatter {
                Argument[] argArray = md.arguments;
                if (argArray == null) {
                        pe.setParameterNames(Collections.EMPTY_LIST);
-                       pe.setParameterTypes(Collections.EMPTY_LIST);
+                       pe.setParameterSignatures(Collections.EMPTY_LIST);
                } else {
                        List names = new ArrayList();
-                       List types = new ArrayList();
-                       
+                       List paramSigs = new ArrayList();
                        for (int i = 0; i < argArray.length; i++) {
                                String argName = new String(argArray[i].name);
-                               String argType = "<UnknownType>"; // pr135052
-                               TypeReference typeR = argArray[i].type;
-                               if (typeR!=null) {
-                                       TypeBinding typeB = typeR.resolvedType;
-                                       if (typeB==null) {
-                                               if (typeR.getTypeName()!=null) 
-                                                         argType = CharOperation.toString(typeR.getTypeName());                                                
-                                       } else {
-                                               argType = typeB.debugName();
+                               //String argType = "<UnknownType>"; // pr135052
+                               if (acceptArgument(argName, argArray[i].type.toString())) {
+                                       TypeReference typeR = argArray[i].type;
+                                       if (typeR!=null) {
+                                               TypeBinding typeB = typeR.resolvedType;
+                                               if (typeB==null) {
+                                                       typeB = typeR.resolveType(md.scope);
+                                               }
+                                               EclipseFactory factory = EclipseFactory.fromScopeLookupEnvironment(md.scope);
+                                               UnresolvedType ut = factory.fromBinding(typeB);
+                                               paramSigs.add(ut.getSignature().toCharArray());
                                        }
-                               }
-                               
-                               
-//                             String argType = argArray[i].type.resolvedType.debugName();
-                               if (acceptArgument(argName, argArray[i].type.toString())) { 
                                        names.add(argName);
-                                       types.add(argType);
-                               }   
+                               }
                        }
                        pe.setParameterNames(names);
-                       pe.setParameterTypes(types);
+                       if (!paramSigs.isEmpty()) {
+                               pe.setParameterSignatures(paramSigs);
+                       }
                }
        }
 
index b9f2c966243b8aa11046430fd0fa1bef8a8b3078..4522a8b33187bfd20613003930ed2da755952adf 100644 (file)
@@ -52,7 +52,7 @@ public class IncrementalStateManager {
                        element.wipeAllKnowledge();
                }
                incrementalStates.clear();
-               AsmManager.getDefault().createNewASM(); // forget what you know...
+               AsmManager.getDefault().createNewASM(null); // forget what you know...
        }
        
        public static Set getConfigFilesKnown() {
diff --git a/tests/bugs152/pr141730.aj b/tests/bugs152/pr141730.aj
new file mode 100644 (file)
index 0000000..65b90d3
--- /dev/null
@@ -0,0 +1,46 @@
+import java.util.List;
+
+aspect A {
+
+       pointcut p() : execution(* *.*(..));
+       
+       before() : p() {}
+       
+       public void MyClass.method() {}
+       
+       public MyClass.new() {super();}
+}
+
+class C {
+       
+       public C() {}
+       
+       public void method() {}
+       
+       public void intMethod(int i) {}
+       
+       public void stringMethod(String s) {}
+       
+       public void myClassMethod(MyClass s) {}
+       
+       public void genericMethod(List<String> l) {}
+       
+       public void twoArgsMethod(int i, String s) {}
+       
+       public void genericMethod2(MyGenericClass<String,MyClass> m) {}
+       
+       public static void main(String[] args) {}
+       
+       public void multiMethod(String[][] s) {}
+       
+       public void intArray(int[] i) {}
+       
+}
+
+class MyClass {
+       
+       public MyClass(String s) {}
+       
+}
+
+class MyGenericClass<X,Y> {}
index 3f9896ab415d1cfef3c795bbbe2486e6eed42946..8e9d48fe82cac9aa6a10571026b6364c63a4c53c 100644 (file)
@@ -109,7 +109,7 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
          IProgramElement pe2 = top.findElementForType("pkg","printParameters");
          assertNotNull("Couldn't find 'printParameters' element in the tree",pe2);
          // the argument is org.aspectj.lang.JoinPoint, check that this is added
-         assertFalse("printParameters method should have arguments",pe2.getParameterTypes().isEmpty());          
+         assertFalse("printParameters method should have arguments",pe2.getParameterSignatures().isEmpty());     
   }
 
   public void testParameterizedEnum_pr126316() {
@@ -156,8 +156,8 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
                          IProgramElement.Kind.INTER_TYPE_FIELD,"Bar.children");                 
          assertNotNull("Couldn't find 'Bar.children' element in the tree",field);
          IProgramElement constructor = top.findElementForLabel(top.getRoot(),
-                         IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR,"Foo.Foo(List<T>)");               
-         assertNotNull("Couldn't find 'Foo.Foo(List<T>)' element in the tree",constructor);
+                         IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR,"Foo.Foo(java.util.List<T>)");             
+         assertNotNull("Couldn't find 'Foo.Foo(java.util.List<T>)' element in the tree",constructor);
          
          // check that the relationship map has 'itd method declared on bar'
          List matches = AsmManager.getDefault().getRelationshipMap().get(method);
index e27efeffa88cbd1616077b080c367ae9442e765a..0500cf75752ae894cd06c398ba748477dec45d08 100644 (file)
@@ -11,6 +11,7 @@
 package org.aspectj.systemtest.ajc152;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 
 import junit.framework.Test;
@@ -128,6 +129,60 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testJarChecking_pr137235_2() { runTest("directory with .jar extension"); }
   public void testMakePreMethodNPE_pr136393() { runTest("NPE in makePreMethod");}
 
+  public void testGetParameterHandles_pr141730() {
+         runTest("new IProgramElement handle methods");  
+         
+         checkParametersForIPE("intMethod(int)",IProgramElement.Kind.METHOD,"I",true);
+         checkParametersForIPE("stringMethod(java.lang.String)",IProgramElement.Kind.METHOD,"Ljava/lang/String;",true);
+         checkParametersForIPE("myClassMethod(MyClass)",IProgramElement.Kind.METHOD,"LMyClass;",true);
+         checkParametersForIPE("genericMethod(java.util.List<java.lang.String>)",IProgramElement.Kind.METHOD,"Pjava/util/List<Ljava/lang/String;>;",true);
+         checkParametersForIPE("genericMethod2(MyGenericClass<java.lang.String,MyClass>)",IProgramElement.Kind.METHOD,"PMyGenericClass<Ljava/lang/String;LMyClass;>;",true);
+         checkParametersForIPE("main(java.lang.String[])",IProgramElement.Kind.METHOD,"[Ljava/lang/String;",true);
+         checkParametersForIPE("multiMethod(java.lang.String[][])",IProgramElement.Kind.METHOD,"[[Ljava/lang/String;",true);
+         checkParametersForIPE("intArray(int[])",IProgramElement.Kind.METHOD,"[I",true);
+         
+         IHierarchy top = AsmManager.getDefault().getHierarchy();      
+         IProgramElement twoArgsMethod = top.findElementForLabel(
+                         top.getRoot(),IProgramElement.Kind.METHOD,"twoArgsMethod(int,java.lang.String)");
+      assertNotNull("Couldn't find 'twoArgsMethod(int,java.lang.String)' element in the tree",twoArgsMethod);
+      List l = twoArgsMethod.getParameterSignatures();
+      assertEquals("",((char[])l.get(0))[0],'I');
+      boolean eq = equals(((char[])l.get(1)),"Ljava/lang/String;".toCharArray());
+      assertTrue("expected parameter to be 'Ljava/lang/String;' but found '" +
+                       new String(((char[])l.get(1))) + "'",eq);
+  }
+  
+  public void testGetParameterTypes_pr141730() {
+         runTest("new IProgramElement handle methods"); 
+         
+         checkParametersForIPE("intMethod(int)",IProgramElement.Kind.METHOD,"int",false);
+         checkParametersForIPE("stringMethod(java.lang.String)",IProgramElement.Kind.METHOD,"java.lang.String",false);
+         checkParametersForIPE("myClassMethod(MyClass)",IProgramElement.Kind.METHOD,"MyClass",false);
+         checkParametersForIPE("genericMethod(java.util.List<java.lang.String>)",IProgramElement.Kind.METHOD,"java.util.List<java.lang.String>",false);
+         checkParametersForIPE("genericMethod2(MyGenericClass<java.lang.String,MyClass>)",IProgramElement.Kind.METHOD,"MyGenericClass<java.lang.String,MyClass>",false);
+         checkParametersForIPE("main(java.lang.String[])",IProgramElement.Kind.METHOD,"java.lang.String[]",false);
+         checkParametersForIPE("multiMethod(java.lang.String[][])",IProgramElement.Kind.METHOD,"java.lang.String[][]",false);
+         checkParametersForIPE("intArray(int[])",IProgramElement.Kind.METHOD,"int[]",false);
+  }
+  
+  public void testToSignatureString_pr141730() {
+         runTest("new IProgramElement handle methods"); 
+         
+         checkSignatureOfIPE("main(java.lang.String[])",IProgramElement.Kind.METHOD);
+         checkSignatureOfIPE("C",IProgramElement.Kind.CLASS);
+         checkSignatureOfIPE("C()",IProgramElement.Kind.CONSTRUCTOR);
+         checkSignatureOfIPE("method()",IProgramElement.Kind.METHOD);
+         checkSignatureOfIPE("p()",IProgramElement.Kind.POINTCUT);
+         checkSignatureOfIPE("before(): p..",IProgramElement.Kind.ADVICE,"before()");
+         checkSignatureOfIPE("MyClass.method()",IProgramElement.Kind.INTER_TYPE_METHOD);
+         checkSignatureOfIPE("multiMethod(java.lang.String[][])",IProgramElement.Kind.METHOD);
+         checkSignatureOfIPE("intArray(int[])",IProgramElement.Kind.METHOD);
+         checkSignatureOfIPE("MyClass.MyClass()",IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR);
+  }
+
+  
+
+  
 //  public void testFunkyGenericErrorWithITDs_pr126355_2() { 
 //       runTest("bizarre generic error with itds - 2");
 //       // public class Pair<F,S> affected by pertarget aspect
@@ -143,6 +198,55 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
   // Not valid whilst the ajc compiler forces debug on (ignores -g:none) - it will be green but is invalid, trust me
   // public void testLongWindedMessages_pr129408() { runTest("long winded ataj messages");}
+
+  // ---------------- helper methods ---------------
+  
+   /**
+    * taken from CharOperation
+    */
+       private final boolean equals(char[] first, char[] second) {
+               if (first == second)
+                       return true;
+               if (first == null || second == null)
+                       return false;
+               if (first.length != second.length)
+                       return false;
+
+               for (int i = first.length; --i >= 0;)
+                       if (first[i] != second[i])
+                               return false;
+               return true;
+       }
+  
+       private void checkParametersForIPE(String ipeLabel, IProgramElement.Kind kind, String expectedParm, boolean getHandles) {
+               IHierarchy top = AsmManager.getDefault().getHierarchy();
+               IProgramElement ipe = top.findElementForLabel(top.getRoot(),kind,ipeLabel);
+           assertNotNull("Couldn't find '" + ipeLabel + "' element in the tree",ipe);
+           List l = new ArrayList();
+           if (getHandles) {
+               l = ipe.getParameterSignatures();
+           } else {
+               l = ipe.getParameterTypes();
+           }
+           boolean eq = equals(((char[])l.get(0)),expectedParm.toCharArray());
+           assertTrue("expected parameter to be '" + expectedParm + "' but found '" +
+                       new String(((char[])l.get(0))) + "'",eq);
+       }
+  
+       private void checkSignatureOfIPE(String ipeLabel, IProgramElement.Kind kind) {
+               checkSignatureOfIPE(ipeLabel,kind,ipeLabel);
+       }
+       
+       private void checkSignatureOfIPE(String ipeLabel, IProgramElement.Kind kind, String expectedSig) {
+               IHierarchy top = AsmManager.getDefault().getHierarchy();
+               IProgramElement ipe = top.findElementForLabel(
+                                 top.getRoot(),kind,ipeLabel);
+           assertNotNull("Couldn't find '" + ipeLabel + "' element in the tree",ipe);
+       assertEquals("expected signature to be '"+ expectedSig + "' but was " +
+                                 ipe.toSignatureString(true),expectedSig,ipe.toSignatureString(true));
+               
+       }
+       
   /////////////////////////////////////////
   public static Test suite() {
     return XMLBasedAjcTestCase.loadSuite(Ajc152Tests.class);
index dbdbdeda453df0204f21b91aca57d752c170de41..54718c6c54abe43b2c917dbb9abcdb7ccbfa39fd 100644 (file)
       <compile files="Covariance.java" options="-1.5"/>
     </ajc-test>
     
+    <ajc-test dir="bugs152" title="new IProgramElement handle methods">
+      <compile files="pr141730.aj" options="-emacssym -1.5"/>
+    </ajc-test>
+
     <ajc-test dir="bugs152" title="declare @method relationship">
      <compile files="pr143924.aj" options="-1.5 -showWeaveInfo -emacssym">
         <message kind="weave" text="'public void BankAccount.debit(String,long)' (pr143924.aj:7) is annotated with @Secured"/>
diff --git a/util/src/org/aspectj/util/CharOperation.java b/util/src/org/aspectj/util/CharOperation.java
new file mode 100644 (file)
index 0000000..423d725
--- /dev/null
@@ -0,0 +1,48 @@
+/********************************************************************
+ * Copyright (c) 2006 Contributors. All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: IBM Corporation - initial API and implementation 
+ *                              Helen Hawkins   - initial version
+ *******************************************************************/
+package org.aspectj.util;
+
+
+/**
+ * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
+ *
+ */
+public class CharOperation {
+       
+       /**
+        * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
+        */     
+       public static final char[] subarray(char[] array, int start, int end) {
+               if (end == -1)
+                       end = array.length;
+               if (start > end)
+                       return null;
+               if (start < 0)
+                       return null;
+               if (end > array.length)
+                       return null;
+
+               char[] result = new char[end - start];
+               System.arraycopy(array, start, result, 0, end - start);
+               return result;
+       }
+       
+       /**
+        * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
+        */     
+       public static final int lastIndexOf(char toBeFound, char[] array) {
+               for (int i = array.length; --i >= 0;)
+                       if (toBeFound == array[i])
+                               return i;
+               return -1;
+       }
+       
+}