diff options
author | acolyer <acolyer> | 2005-10-03 16:17:15 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-10-03 16:17:15 +0000 |
commit | 0fae66242efd3fd91dc7ace349cdcf7e5ebc2ade (patch) | |
tree | 85dda17da70b10b31b422853d1323421a82b3a21 /aspectj5rt | |
parent | c86fa6de889e521ebe8224d1a7579269c53ac357 (diff) | |
download | aspectj-0fae66242efd3fd91dc7ace349cdcf7e5ebc2ade.tar.gz aspectj-0fae66242efd3fd91dc7ace349cdcf7e5ebc2ade.zip |
completes all of the MAP bar ITDs
Diffstat (limited to 'aspectj5rt')
20 files changed, 842 insertions, 14 deletions
diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareAnnotation.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareAnnotation.java new file mode 100644 index 000000000..5835f3767 --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareAnnotation.java @@ -0,0 +1,25 @@ +/* ******************************************************************* + * Copyright (c) 2005 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: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.internal.lang.annotation; + +import java.lang.annotation.*; + +/** + * internal representation of declare annotation statement, used by reflect api + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ajcDeclareAnnotation { + String pattern(); + String annotation(); + String kind(); +} diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareParents.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareParents.java new file mode 100644 index 000000000..14860e006 --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareParents.java @@ -0,0 +1,31 @@ +/* ******************************************************************* + * Copyright (c) 2005 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: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.internal.lang.annotation; + +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + + +/** + * @author colyer + * Marker annotation for code style declare parent declarations + * ajc prefix used to indicate that this annotation is *internal* + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ajcDeclareParents { + String targetTypePattern(); + String parentTypes(); + boolean isExtends(); +} diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclarePrecedence.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclarePrecedence.java new file mode 100644 index 000000000..ef6197557 --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclarePrecedence.java @@ -0,0 +1,32 @@ +/* ******************************************************************* + * Copyright (c) 2005 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: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.internal.lang.annotation; + +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + + +/** + * @author colyer + * Marker annotation for code style declare precedence declarations + * ajc prefix used to indicate that this annotation is *internal* + * Can't use DeclarePrecedence as that has target = type and we + * need method to cope with the (rare) case of multiple declare + * precendence statements in the same aspect. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ajcDeclarePrecedence { + String value(); +} diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java index 3a9005146..f97de09e2 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/annotation/ajcDeclareSoft.java @@ -25,6 +25,6 @@ import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface ajcDeclareSoft { - Class exceptionType(); + String exceptionType(); String pointcut(); } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AdviceImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AdviceImpl.java index 7bfba4ca1..0cdf0bc96 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AdviceImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AdviceImpl.java @@ -12,6 +12,7 @@ package org.aspectj.internal.lang.reflect; import java.lang.reflect.Method; +import java.lang.reflect.Type; import org.aspectj.lang.annotation.AdviceName; import org.aspectj.lang.reflect.Advice; @@ -25,10 +26,16 @@ import org.aspectj.lang.reflect.PointcutExpression; * */ public class AdviceImpl implements Advice { + + private static final String AJC_INTERNAL = "org.aspectj.runtime.internal"; private final AdviceKind kind; private final Method adviceMethod; private PointcutExpression pointcutExpression; + private boolean hasExtraParam = false; + private Type[] genericParameterTypes; + private AjType[] parameterTypes; + private AjType[] exceptionTypes; protected AdviceImpl(Method method, String pointcut, AdviceKind type) { this.kind = type; @@ -36,10 +43,62 @@ public class AdviceImpl implements Advice { this.pointcutExpression = new PointcutExpressionImpl(pointcut); } + protected AdviceImpl(Method method, String pointcut, AdviceKind type, String extraParamName) { + this(method,pointcut,type); + this.hasExtraParam = true; + } + public AjType getDeclaringType() { return AjTypeSystem.getAjType(adviceMethod.getDeclaringClass()); } + public Type[] getGenericParameterTypes() { + if (this.genericParameterTypes == null) { + Type[] genTypes = adviceMethod.getGenericParameterTypes(); + int syntheticCount = 0; + for (Type t : genTypes) { + if (t instanceof Class) { + if (((Class)t).getPackage().getName().equals(AJC_INTERNAL)) syntheticCount++; + } + } + this.genericParameterTypes = new Type[genTypes.length - syntheticCount]; + for (int i = 0; i < genericParameterTypes.length; i++) { + if (genTypes[i] instanceof Class) { + this.genericParameterTypes[i] = AjTypeSystem.getAjType((Class)genTypes[i]); + } else { + this.genericParameterTypes[i] = genTypes[i]; + } + } + } + return this.genericParameterTypes; + } + + public AjType<?>[] getParameterTypes() { + if (this.parameterTypes == null) { + Class<?>[] ptypes = adviceMethod.getParameterTypes(); + int syntheticCount = 0; + for(Class<?> c : ptypes) { + if (c.getPackage().getName().equals(AJC_INTERNAL)) syntheticCount++; + } + this.parameterTypes = new AjType<?>[ptypes.length - syntheticCount]; + for (int i = 0; i < parameterTypes.length; i++) { + this.parameterTypes[i] = AjTypeSystem.getAjType(ptypes[i]); + } + } + return this.parameterTypes; + } + + public AjType<?>[] getExceptionTypes() { + if (this.exceptionTypes == null) { + Class<?>[] exTypes = adviceMethod.getExceptionTypes(); + this.exceptionTypes = new AjType<?>[exTypes.length]; + for (int i = 0; i < exTypes.length; i++) { + this.exceptionTypes[i] = AjTypeSystem.getAjType(exTypes[i]); + } + } + return this.exceptionTypes; + } + public AdviceKind getKind() { return kind; } @@ -58,4 +117,71 @@ public class AdviceImpl implements Advice { return pointcutExpression; } + public String toString() { + StringBuffer sb = new StringBuffer(); + if (getName().length() > 0) { + sb.append("@AdviceName(\""); + sb.append(getName()); + sb.append("\") "); + } + if (getKind() == AdviceKind.AROUND) { + sb.append(adviceMethod.getGenericReturnType().toString()); + sb.append(" "); + } + switch(getKind()) { + case AFTER: + sb.append("after("); + break; + case AFTER_RETURNING: + sb.append("after("); + break; + case AFTER_THROWING: + sb.append("after("); + break; + case AROUND: + sb.append("around("); + break; + case BEFORE: + sb.append("before("); + break; + } + AjType<?>[] ptypes = getParameterTypes(); + int len = ptypes.length; + if (hasExtraParam) len--; + for (int i = 0; i < len; i++) { + sb.append(ptypes[i].getName()); + if (i+1 < len) sb.append(","); + } + sb.append(") "); + switch(getKind()) { + case AFTER_RETURNING: + sb.append("returning"); + if (hasExtraParam) { + sb.append("("); + sb.append(ptypes[len-1].getName()); + sb.append(") "); + } + case AFTER_THROWING: + sb.append("throwing"); + if (hasExtraParam) { + sb.append("("); + sb.append(ptypes[len-1].getName()); + sb.append(") "); + } + default: // no-op + } + AjType<?>[] exTypes = getExceptionTypes(); + if (exTypes.length > 0) { + sb.append("throws "); + for (int i = 0; i < exTypes.length; i++) { + sb.append(exTypes[i].getName()); + if (i+1 < exTypes.length) sb.append(","); + } + sb.append(" "); + } + sb.append(": "); + sb.append(getPointcutExpression().asString()); + return sb.toString(); + } + } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java index bb5faf655..7ecebd13b 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AjTypeImpl.java @@ -24,7 +24,11 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; +import org.aspectj.internal.lang.annotation.ajcDeclareAnnotation; import org.aspectj.internal.lang.annotation.ajcDeclareEoW; +import org.aspectj.internal.lang.annotation.ajcDeclareParents; +import org.aspectj.internal.lang.annotation.ajcDeclarePrecedence; +import org.aspectj.internal.lang.annotation.ajcDeclareSoft; import org.aspectj.internal.lang.annotation.ajcPrivileged; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; @@ -526,13 +530,13 @@ public class AjTypeImpl<T> implements AjType<T> { if (afterReturningAnn != null) { String pcExpr = afterReturningAnn.pointcut(); if (pcExpr.equals("")) pcExpr = afterReturningAnn.value(); - return new AdviceImpl(method,pcExpr,AdviceKind.AFTER_RETURNING); + return new AdviceImpl(method,pcExpr,AdviceKind.AFTER_RETURNING,afterReturningAnn.returning()); } AfterThrowing afterThrowingAnn = method.getAnnotation(AfterThrowing.class); if (afterThrowingAnn != null) { String pcExpr = afterThrowingAnn.pointcut(); if (pcExpr == null) pcExpr = afterThrowingAnn.value(); - return new AdviceImpl(method,pcExpr,AdviceKind.AFTER_THROWING); + return new AdviceImpl(method,pcExpr,AdviceKind.AFTER_THROWING,afterThrowingAnn.throwing()); } Around aroundAnn = method.getAnnotation(Around.class); if (aroundAnn != null) return new AdviceImpl(method,aroundAnn.value(),AdviceKind.AROUND); @@ -684,31 +688,121 @@ public class AjTypeImpl<T> implements AjType<T> { * @see org.aspectj.lang.reflect.AjType#getDeclareParents() */ public DeclareParents[] getDeclareParents() { - // TODO Auto-generated method stub - return null; + List<DeclareParents> decps = new ArrayList<DeclareParents>(); + for (Method method : clazz.getDeclaredMethods()) { + if (method.isAnnotationPresent(ajcDeclareParents.class)) { + ajcDeclareParents decPAnn = method.getAnnotation(ajcDeclareParents.class); + DeclareParentsImpl decp = new DeclareParentsImpl( + decPAnn.targetTypePattern(), + decPAnn.parentTypes(), + decPAnn.isExtends(), + this + ); + decps.add(decp); + } + } + if (getSupertype().isAspect()) { + decps.addAll(Arrays.asList(getSupertype().getDeclareParents())); + } + DeclareParents[] ret = new DeclareParents[decps.size()]; + decps.toArray(ret); + return ret; } /* (non-Javadoc) * @see org.aspectj.lang.reflect.AjType#getDeclareSofts() */ public DeclareSoft[] getDeclareSofts() { - return null; + List<DeclareSoft> decs = new ArrayList<DeclareSoft>(); + for (Method method : clazz.getDeclaredMethods()) { + if (method.isAnnotationPresent(ajcDeclareSoft.class)) { + ajcDeclareSoft decSAnn = method.getAnnotation(ajcDeclareSoft.class); + DeclareSoftImpl ds = new DeclareSoftImpl( + this, + decSAnn.pointcut(), + decSAnn.exceptionType() + ); + decs.add(ds); + } + } + if (getSupertype().isAspect()) { + decs.addAll(Arrays.asList(getSupertype().getDeclareSofts())); + } + DeclareSoft[] ret = new DeclareSoft[decs.size()]; + decs.toArray(ret); + return ret; } /* (non-Javadoc) * @see org.aspectj.lang.reflect.AjType#getDeclareAnnotations() */ public DeclareAnnotation[] getDeclareAnnotations() { - // TODO Auto-generated method stub - return null; + List<DeclareAnnotation> decAs = new ArrayList<DeclareAnnotation>(); + for (Method method : clazz.getDeclaredMethods()) { + if (method.isAnnotationPresent(ajcDeclareAnnotation.class)) { + ajcDeclareAnnotation decAnn = method.getAnnotation(ajcDeclareAnnotation.class); + // the target annotation is on this method... + Annotation targetAnnotation = null; + Annotation[] anns = method.getAnnotations(); + for (Annotation ann: anns) { + if (ann.annotationType() != ajcDeclareAnnotation.class) { + // this must be the one... + targetAnnotation = ann; + break; + } + } + DeclareAnnotationImpl da = new DeclareAnnotationImpl( + this, + decAnn.kind(), + decAnn.pattern(), + targetAnnotation, + decAnn.annotation() + ); + decAs.add(da); + } + } + if (getSupertype().isAspect()) { + decAs.addAll(Arrays.asList(getSupertype().getDeclareAnnotations())); + } + DeclareAnnotation[] ret = new DeclareAnnotation[decAs.size()]; + decAs.toArray(ret); + return ret; } /* (non-Javadoc) * @see org.aspectj.lang.reflect.AjType#getDeclarePrecedence() */ public DeclarePrecedence[] getDeclarePrecedence() { - // TODO Auto-generated method stub - return null; + List<DeclarePrecedence> decps = new ArrayList<DeclarePrecedence>(); + + // @AspectJ Style + if (clazz.isAnnotationPresent(org.aspectj.lang.annotation.DeclarePrecedence.class)) { + org.aspectj.lang.annotation.DeclarePrecedence ann = + clazz.getAnnotation(org.aspectj.lang.annotation.DeclarePrecedence.class); + DeclarePrecedenceImpl decp = new DeclarePrecedenceImpl( + ann.value(), + this + ); + decps.add(decp); + } + + // annotated code-style + for (Method method : clazz.getDeclaredMethods()) { + if (method.isAnnotationPresent(ajcDeclarePrecedence.class)) { + ajcDeclarePrecedence decPAnn = method.getAnnotation(ajcDeclarePrecedence.class); + DeclarePrecedenceImpl decp = new DeclarePrecedenceImpl( + decPAnn.value(), + this + ); + decps.add(decp); + } + } + if (getSupertype().isAspect()) { + decps.addAll(Arrays.asList(getSupertype().getDeclarePrecedence())); + } + DeclarePrecedence[] ret = new DeclarePrecedence[decps.size()]; + decps.toArray(ret); + return ret; } /* (non-Javadoc) @@ -819,5 +913,7 @@ public class AjTypeImpl<T> implements AjType<T> { } return classes; } + + public String toString() { return getName(); } } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareAnnotationImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareAnnotationImpl.java new file mode 100644 index 000000000..bcc91b987 --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareAnnotationImpl.java @@ -0,0 +1,115 @@ +/* ******************************************************************* + * Copyright (c) 2005 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: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.internal.lang.reflect; + +import java.lang.annotation.Annotation; + +import org.aspectj.lang.reflect.AjType; +import org.aspectj.lang.reflect.DeclareAnnotation; +import org.aspectj.lang.reflect.SignaturePattern; +import org.aspectj.lang.reflect.TypePattern; + +/** + * @author colyer + * + */ +public class DeclareAnnotationImpl implements DeclareAnnotation { + + private Annotation theAnnotation; + private String annText; + private AjType<?> declaringType; + private DeclareAnnotation.Kind kind; + private TypePattern typePattern; + private SignaturePattern signaturePattern; + + public DeclareAnnotationImpl(AjType<?> declaring, String kindString, String pattern, Annotation ann, String annText) { + this.declaringType = declaring; + if (kindString.equals("at_type")) this.kind = DeclareAnnotation.Kind.Type; + else if (kindString.equals("at_field")) this.kind = DeclareAnnotation.Kind.Field; + else if (kindString.equals("at_method")) this.kind = DeclareAnnotation.Kind.Method; + else if (kindString.equals("at_constructor")) this.kind = DeclareAnnotation.Kind.Constructor; + else throw new IllegalStateException("Unknown declare annotation kind: " + kindString); + if (kind == DeclareAnnotation.Kind.Type) { + this.typePattern = new TypePatternImpl(pattern); + } else { + this.signaturePattern = new SignaturePatternImpl(pattern); + } + this.theAnnotation = ann; + this.annText = annText; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareAnnotation#getDeclaringType() + */ + public AjType<?> getDeclaringType() { + return this.declaringType; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareAnnotation#getKind() + */ + public Kind getKind() { + return this.kind; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareAnnotation#getSignaturePattern() + */ + public SignaturePattern getSignaturePattern() { + return this.signaturePattern; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareAnnotation#getTypePattern() + */ + public TypePattern getTypePattern() { + return this.typePattern; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareAnnotation#getAnnotation() + */ + public Annotation getAnnotation() { + return this.theAnnotation; + } + + public String getAnnotationAsText() { + return this.annText; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("declare @"); + switch(getKind()) { + case Type: + sb.append("type : "); + sb.append(getTypePattern().asString()); + break; + case Method: + sb.append("method : "); + sb.append(getSignaturePattern().asString()); + break; + case Field: + sb.append("field : "); + sb.append(getSignaturePattern().asString()); + break; + case Constructor: + sb.append("constructor : "); + sb.append(getSignaturePattern().asString()); + break; + } + sb.append(" : "); + sb.append(getAnnotationAsText()); + return sb.toString(); + } + +} diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java index f474698ea..5420f8274 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java @@ -55,5 +55,17 @@ public class DeclareErrorOrWarningImpl implements DeclareErrorOrWarning { public boolean isError() { return isError; } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("declare "); + sb.append(isError() ? "error : " : "warning : "); + sb.append(getPointcutExpression().asString()); + sb.append(" : "); + sb.append("\""); + sb.append(getMessage()); + sb.append("\""); + return sb.toString(); + } } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareParentsImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareParentsImpl.java new file mode 100644 index 000000000..1a04fc507 --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareParentsImpl.java @@ -0,0 +1,151 @@ +/* ******************************************************************* + * Copyright (c) 2005 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: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.internal.lang.reflect; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.util.StringTokenizer; + +import org.aspectj.lang.reflect.AjType; +import org.aspectj.lang.reflect.AjTypeSystem; +import org.aspectj.lang.reflect.DeclareParents; +import org.aspectj.lang.reflect.TypePattern; + +/** + * @author colyer + * + */ +public class DeclareParentsImpl implements DeclareParents { + + private AjType<?> declaringType; + private TypePattern targetTypesPattern; + private Type[] parents; + private String parentsString; + private String firstMissingTypeName; + private boolean isExtends; + private boolean parentsError = false; + + /** + * Parents arg is a comma-separate list of type names that needs to be turned into + * AjTypes + */ + public DeclareParentsImpl(String targets, String parentsAsString, boolean isExtends, AjType<?> declaring) + { + this.targetTypesPattern = new TypePatternImpl(targets); + this.isExtends = isExtends; + this.declaringType = declaring; + this.parentsString = parentsAsString; + this.parents = commaSeparatedListToTypeArray(parentsAsString); + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareParents#getDeclaringType() + */ + public AjType getDeclaringType() { + return this.declaringType; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareParents#getTargetTypesPattern() + */ + public TypePattern getTargetTypesPattern() { + return this.targetTypesPattern; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareParents#isExtends() + */ + public boolean isExtends() { + return this.isExtends; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareParents#isImplements() + */ + public boolean isImplements() { + return !this.isExtends; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareParents#getParentTypes() + */ + public Type[] getParentTypes() throws ClassNotFoundException { + if (parentsError) { + throw new ClassNotFoundException(this.firstMissingTypeName); + } + return this.parents; + } + + private Type[] commaSeparatedListToTypeArray(String typeNames) { + StringTokenizer strTok = new StringTokenizer(typeNames,","); + Type[] ret = new Type[strTok.countTokens()]; + int index = 0; + outer: while (strTok.hasMoreTokens()) { + String parentTypeName = strTok.nextToken().trim(); + try { + if (parentTypeName.indexOf("<") == -1) { + ret[index] = AjTypeSystem.getAjType(Class.forName(parentTypeName)); + } else { + ret[index] = makeParameterizedType(parentTypeName); + } + } catch (ClassNotFoundException e) { + // could be a type variable + TypeVariable[] tVars = this.declaringType.getJavaClass().getTypeParameters(); + for (int i = 0; i < tVars.length; i++) { + if (tVars[i].getName().equals(parentTypeName)) { + ret[index] = tVars[i]; + continue outer; + } + } + ret[index] = null; + if (this.firstMissingTypeName == null) this.firstMissingTypeName = parentTypeName; + this.parentsError = true; + } + index++; + } + return ret; + } + + private Type makeParameterizedType(String typeName) + throws ClassNotFoundException { + int paramStart = typeName.indexOf('<'); + String baseName = typeName.substring(0, paramStart); + final Class baseClass = Class.forName(baseName); + int paramEnd = typeName.lastIndexOf('>'); + String params = typeName.substring(paramStart+1,paramEnd); + final Type[] typeParams = commaSeparatedListToTypeArray(params); + return new ParameterizedType() { + + public Type[] getActualTypeArguments() { + return typeParams; + } + + public Type getRawType() { + return baseClass; + } + + public Type getOwnerType() { + return baseClass.getEnclosingClass(); + } + }; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("declare parents : "); + sb.append(getTargetTypesPattern().asString()); + sb.append(isExtends() ? " extends " : " implements "); + sb.append(this.parentsString); + return sb.toString(); + } +} diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclarePrecedenceImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclarePrecedenceImpl.java new file mode 100644 index 000000000..7188606c6 --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclarePrecedenceImpl.java @@ -0,0 +1,62 @@ +/* ******************************************************************* + * Copyright (c) 2005 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: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.internal.lang.reflect; + +import java.util.StringTokenizer; + +import org.aspectj.lang.reflect.AjType; +import org.aspectj.lang.reflect.DeclarePrecedence; +import org.aspectj.lang.reflect.TypePattern; + +/** + * @author colyer + * + */ +public class DeclarePrecedenceImpl implements DeclarePrecedence { + + private AjType<?> declaringType; + private TypePattern[] precedenceList; + private String precedenceString; + + public DeclarePrecedenceImpl(String precedenceList, AjType declaring) { + this.declaringType = declaring; + this.precedenceString = precedenceList; + String toTokenize = precedenceList; + if (toTokenize.startsWith("(")) { + toTokenize = toTokenize.substring(1,toTokenize.length() - 1); + } + StringTokenizer strTok = new StringTokenizer(toTokenize,","); + this.precedenceList = new TypePattern[strTok.countTokens()]; + for (int i = 0; i < this.precedenceList.length; i++) { + this.precedenceList[i] = new TypePatternImpl(strTok.nextToken().trim()); + } + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclarePrecedence#getDeclaringType() + */ + public AjType getDeclaringType() { + return this.declaringType; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclarePrecedence#getPrecedenceOrder() + */ + public TypePattern[] getPrecedenceOrder() { + return this.precedenceList; + } + + public String toString() { + return "declare precedence : " + this.precedenceString; + } + +} diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareSoftImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareSoftImpl.java new file mode 100644 index 000000000..c980cdf8f --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareSoftImpl.java @@ -0,0 +1,75 @@ +/* ******************************************************************* + * Copyright (c) 2005 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: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.internal.lang.reflect; + +import org.aspectj.lang.reflect.AjType; +import org.aspectj.lang.reflect.AjTypeSystem; +import org.aspectj.lang.reflect.DeclareSoft; +import org.aspectj.lang.reflect.PointcutExpression; + +/** + * @author colyer + * + */ +public class DeclareSoftImpl implements DeclareSoft { + + private AjType<?> declaringType; + private PointcutExpression pointcut; + private AjType<?> exceptionType; + private String missingTypeName; + + + public DeclareSoftImpl(AjType declaringType, String pcut, String exceptionTypeName) { + this.declaringType = declaringType; + this.pointcut = new PointcutExpressionImpl(pcut); + try { + this.exceptionType = AjTypeSystem.getAjType(Class.forName(exceptionTypeName)); + } catch (ClassNotFoundException ex) { + this.missingTypeName = exceptionTypeName; + } + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareSoft#getDeclaringType() + */ + public AjType getDeclaringType() { + return this.declaringType; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareSoft#getSoftenedExceptionType() + */ + public AjType getSoftenedExceptionType() throws ClassNotFoundException { + if (this.missingTypeName != null) throw new ClassNotFoundException(this.missingTypeName); + return this.exceptionType; + } + + /* (non-Javadoc) + * @see org.aspectj.lang.reflect.DeclareSoft#getPointcutExpression() + */ + public PointcutExpression getPointcutExpression() { + return this.pointcut; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("declare soft : "); + if (this.missingTypeName != null) { + sb.append(this.exceptionType.getName()); + } else { + sb.append(this.missingTypeName); + } + sb.append(" : "); + sb.append(getPointcutExpression().asString()); + return sb.toString(); + } +} diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PerClauseImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PerClauseImpl.java index 779e3a46e..663a44c20 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PerClauseImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PerClauseImpl.java @@ -33,4 +33,7 @@ public class PerClauseImpl implements PerClause { return kind; } + public String toString() { + return "issingleton()"; + } } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutBasedPerClauseImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutBasedPerClauseImpl.java index 3e3eb2f8e..5049d3a42 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutBasedPerClauseImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutBasedPerClauseImpl.java @@ -34,4 +34,16 @@ public class PointcutBasedPerClauseImpl extends PerClauseImpl implements return pointcutExpression; } + public String toString() { + StringBuffer sb = new StringBuffer(); + switch(getKind()) { + case PERCFLOW: sb.append("percflow("); break; + case PERCFLOWBELOW: sb.append("percflowbelow("); break; + case PERTARGET: sb.append("pertarget("); break; + case PERTHIS: sb.append("perthis("); break; + } + sb.append(this.pointcutExpression.asString()); + sb.append(")"); + return sb.toString(); + } } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutImpl.java index 63c8764a3..b94f1c864 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutImpl.java @@ -79,4 +79,22 @@ public class PointcutImpl implements Pointcut { } return ret; } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(getName()); + sb.append("("); + AjType<?>[] ptypes = getParameterTypes(); + for (int i = 0; i < ptypes.length; i++) { + sb.append(ptypes[i].getName()); + if (this.parameterNames != null && this.parameterNames[i] != null) { + sb.append(" "); + sb.append(this.parameterNames[i]); + } + if (i+1 < ptypes.length) sb.append(","); + } + sb.append(") : "); + sb.append(getPointcutExpression().asString()); + return sb.toString(); + } } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/TypePatternBasedPerClauseImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/TypePatternBasedPerClauseImpl.java index df80a0e08..e9bb08573 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/TypePatternBasedPerClauseImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/TypePatternBasedPerClauseImpl.java @@ -35,5 +35,9 @@ public class TypePatternBasedPerClauseImpl extends PerClauseImpl implements public TypePattern getTypePattern() { return this.typePattern; } + + public String toString() { + return "pertypewithin(" + typePattern.asString() + ")"; + } } diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/Advice.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/Advice.java index 581c5a5fb..03be6c7f1 100644 --- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/Advice.java +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/Advice.java @@ -11,6 +11,8 @@ * ******************************************************************/ package org.aspectj.lang.reflect; +import java.lang.reflect.Type; + /** * Runtime representation of an advice declaration inside an aspect */ @@ -36,6 +38,21 @@ public interface Advice { String getName(); /** + * The advice parameters + */ + AjType<?>[] getParameterTypes(); + + /** + * The generic parameter types, @see java.lang.reflect.Method.getGenericParameterTypes + */ + Type[] getGenericParameterTypes(); + + /** + * The declared thrown exceptions by the advice + */ + AjType<?>[] getExceptionTypes(); + + /** * The pointcut expression associated with the advice declaration. */ PointcutExpression getPointcutExpression(); diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareAnnotation.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareAnnotation.java index 4e0f78aa7..faee5d495 100644 --- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareAnnotation.java +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareAnnotation.java @@ -11,10 +11,46 @@ * ******************************************************************/ package org.aspectj.lang.reflect; +import java.lang.annotation.Annotation; + /** * The AspectJ runtime representation of a declare annotation member in an aspect. * */ public interface DeclareAnnotation { - + + public enum Kind { Field, Method, Constructor, Type }; + + /** + * The aspect that declared this member. + */ + AjType<?> getDeclaringType(); + + /** + * The target element kind + */ + Kind getKind(); + + /** + * The target signature pattern. Returns null if getKind() == Type + */ + SignaturePattern getSignaturePattern(); + + /** + * The target type pattern. Returns null if getKind() != Type + */ + TypePattern getTypePattern(); + + /** + * The declared annotation. If the declared annotation does not have runtime retention, + * this method returns null. + */ + Annotation getAnnotation(); + + /** + * Returns the text of the annotation as declared in this member. Available for + * both runtime and class-file retention annotations + */ + String getAnnotationAsText(); + } diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareParents.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareParents.java index f8ee5c99d..8d3c98b78 100644 --- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareParents.java +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareParents.java @@ -11,6 +11,8 @@ * ******************************************************************/ package org.aspectj.lang.reflect; +import java.lang.reflect.Type; + /** * A declare parents member defined inside an aspect */ @@ -40,6 +42,6 @@ public interface DeclareParents { * The set of types that the types matching getTargetTypesPattern are * declared to implement or extend */ - AjType[] getParentTypes(); + Type[] getParentTypes() throws ClassNotFoundException; } diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareSoft.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareSoft.java index b397c94f3..cc607d680 100644 --- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareSoft.java +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareSoft.java @@ -24,7 +24,7 @@ public interface DeclareSoft { /** * The softened exception type */ - AjType getSoftenedExceptionType(); + AjType getSoftenedExceptionType() throws ClassNotFoundException; /** * The pointcut determining the join points at which the exception is to be softened. diff --git a/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java b/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java index a01287d0a..7b15d3e64 100644 --- a/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java +++ b/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java @@ -59,22 +59,27 @@ public class AjTypeTestsWithAspects extends TestCase { PerClause pc = perThisA.getPerClause(); assertEquals(PerClauseKind.PERTHIS,pc.getKind()); assertEquals("pc()",((PointcutBasedPerClause)pc).getPointcutExpression().asString()); + assertEquals("perthis(pc())",pc.toString()); pc= perTargetA.getPerClause(); assertEquals(PerClauseKind.PERTARGET,pc.getKind()); assertEquals("pc()",((PointcutBasedPerClause)pc).getPointcutExpression().asString()); + assertEquals("pertarget(pc())",pc.toString()); pc= perCflowA.getPerClause(); assertEquals(PerClauseKind.PERCFLOW,pc.getKind()); assertEquals("pc()",((PointcutBasedPerClause)pc).getPointcutExpression().asString()); + assertEquals("percflow(pc())",pc.toString()); pc= perCflowbelowA.getPerClause(); assertEquals(PerClauseKind.PERCFLOWBELOW,pc.getKind()); assertEquals("pc()",((PointcutBasedPerClause)pc).getPointcutExpression().asString()); + assertEquals("percflowbelow(pc())",pc.toString()); pc= perTypeWithinA.getPerClause(); assertEquals(PerClauseKind.PERTYPEWITHIN,pc.getKind()); assertEquals("org.aspectj..*",((TypePatternBasedPerClause)pc).getTypePattern().asString()); + assertEquals("pertypewithin(org.aspectj..*)",pc.toString()); } @@ -151,6 +156,7 @@ public class AjTypeTestsWithAspects extends TestCase { Pointcut p1 = sa.getDeclaredPointcut("simpleAspectMethodExecution"); assertEquals("simpleAspectMethodExecution",p1.getName()); assertEquals("execution(* SimpleAspect.*(..))",p1.getPointcutExpression().asString()); + assertEquals("simpleAspectMethodExecution() : execution(* SimpleAspect.*(..))",p1.toString()); assertEquals(sa,p1.getDeclaringType()); assertEquals(0,p1.getParameterTypes().length); assertTrue(Modifier.isPublic(p1.getModifiers())); @@ -231,10 +237,12 @@ public class AjTypeTestsWithAspects extends TestCase { atwo = advice[0]; } assertEquals("execution(* SimpleAspect.*(..))",aone.getPointcutExpression().toString()); + assertEquals("@AdviceName(\"logEntry\") before() : execution(* SimpleAspect.*(..))",aone.toString()); assertEquals("logEntry",aone.getName()); assertEquals(AdviceKind.BEFORE,aone.getKind()); assertEquals("execution(* SimpleAspect.*(..))",atwo.getPointcutExpression().toString()); assertEquals("",atwo.getName()); + assertEquals("before() : execution(* SimpleAspect.*(..))",atwo.toString()); } public void testGetAdvice() { @@ -320,7 +328,10 @@ public class AjTypeTestsWithAspects extends TestCase { boolean foundAnnError = false; for (DeclareErrorOrWarning deow : deows) { if (deow.isError()) { - if (deow.getMessage().equals("dont call this method code")) foundCodeError = true; + if (deow.getMessage().equals("dont call this method code")) { + foundCodeError = true; + assertEquals("declare error : call(* DontDoIt.*(..)) : \"dont call this method code\"",deow.toString()); + } if (deow.getMessage().equals("dont call this method ann")) foundAnnError = true; assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression().toString()); } else { |