From b331fa862e3296cb26b3d6b47a5c8a4dfe2110a8 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 4 Mar 2009 03:00:28 +0000 Subject: [PATCH] declaremixin: check signature of factory method --- .../aspectj/weaver/bcel/AtAjAttributes.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java index c2fb10049..e77ef9313 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -828,6 +828,28 @@ public class AtAjAttributes { return false; } + /** + * Return a nicely formatted method string, for example: int X.foo(java.lang.String) + */ + public static String getMethodForMessage(AjAttributeMethodStruct methodstructure) { + StringBuffer sb = new StringBuffer(); + sb.append("Method '"); + sb.append(methodstructure.method.getReturnType().toString()); + sb.append(" ").append(methodstructure.enclosingType).append(".").append(methodstructure.method.getName()); + sb.append("("); + Type[] args = methodstructure.method.getArgumentTypes(); + if (args != null) { + for (int t = 0; t < args.length; t++) { + if (t > 0) { + sb.append(","); + } + sb.append(args[t].toString()); + } + } + sb.append(")'"); + return sb.toString(); + } + /** * Process any @DeclareMixin annotation. * @@ -858,6 +880,17 @@ public class AtAjAttributes { // Return value of the annotated method is the interface or class that the mixin delegate should have ResolvedType methodReturnType = UnresolvedType.forSignature(annotatedMethod.getReturnType().getSignature()).resolve(world); + if (methodReturnType.isPrimitiveType()) { + reportError(getMethodForMessage(struct) + ": factory methods for a mixin cannot return void or a primitive type", + struct); + return false; + } + + if (annotatedMethod.getArgumentTypes().length > 1) { + reportError(getMethodForMessage(struct) + ": factory methods for a mixin can take a maximum of one parameter", struct); + return false; + } + // The set of interfaces to be mixed in is either: // supplied as a list in the 'Class[] interfaces' value in the annotation value // supplied as just the interface return value of the annotated method -- 2.39.5