<?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>
handleProvider = new OptimizedFullPathHandleProvider();
}
- public void createNewASM() {
+ public void createNewASM(INameConvertor convertor) {
hierarchy = new AspectJElementHierarchy();
+ hierarchy.setNameConvertor(convertor);
mapper = new RelationshipMap(hierarchy);
}
public void flushHandleMap();
public void updateHandleMap(Set deletedFiles);
+
+ public void setNameConvertor(INameConvertor convertor);
+ public INameConvertor getNameConvertor();
}
\ No newline at end of file
--- /dev/null
+/********************************************************************
+ * 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);
+
+}
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.
protected IProgramElement root = null;
protected String configFile = null;
+ private transient INameConvertor convertor = null;
private Map fileMap = null;
private Map handleMap = null;
return hid.substring(0,hid.indexOf("|"));
}
+ public void setNameConvertor(INameConvertor convertor) {
+ this.convertor = convertor;
+ }
+
+ public INameConvertor getNameConvertor() {
+ return convertor;
+ }
+
}
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;
/**
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);
}
//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;
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;
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;
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>";
}
}
+
+ 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();
+ }
+
+ }
}
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;
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
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);
+ }
}
}
element.wipeAllKnowledge();
}
incrementalStates.clear();
- AsmManager.getDefault().createNewASM(); // forget what you know...
+ AsmManager.getDefault().createNewASM(null); // forget what you know...
}
public static Set getConfigFilesKnown() {
--- /dev/null
+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> {}
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() {
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);
package org.aspectj.systemtest.ajc152;
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
import junit.framework.Test;
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
// 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);
<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"/>
--- /dev/null
+/********************************************************************
+ * 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;
+ }
+
+}