From de508dd920831310f7bfac3a833d9920a4d133f2 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 25 Jan 2008 18:33:24 +0000 Subject: [PATCH] paramannos: improved annotation unpacking --- .../aspectj/apache/bcel/classfile/Method.java | 105 ++++++++++++------ 1 file changed, 69 insertions(+), 36 deletions(-) diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java index d54ddc62f..63db26e68 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java @@ -69,14 +69,17 @@ import org.aspectj.apache.bcel.generic.Type; * for a method in the class. See JVM specification for details. * A method has access flags, a name, a signature and a number of attributes. * - * @version $Id: Method.java,v 1.3 2008/01/25 02:28:23 aclement Exp $ + * @version $Id: Method.java,v 1.4 2008/01/25 18:33:24 aclement Exp $ * @author M. Dahm */ public final class Method extends FieldOrMethod { + public static final Annotation[][] NO_PARAMETER_ANNOTATIONS = new Annotation[][]{}; + public static final Annotation[] NO_ANNOTATIONS = new Annotation[]{}; + private boolean parameterAnnotationsOutOfDate; - private RuntimeVisibleParameterAnnotations parameterAnnotationsVis; // annotations on parameters of this method - private RuntimeInvisibleParameterAnnotations parameterAnnotationsInvis; + private Annotation[][] unpackedParameterAnnotations; + /** * Empty constructor, all attributes have to be defined via `setXXX' @@ -247,46 +250,76 @@ public final class Method extends FieldOrMethod { public Type[] getArgumentTypes() { return Type.getArgumentTypes(getSignature()); } - + private void ensureParameterAnnotationsUnpacked() { - if (parameterAnnotationsOutOfDate) { - // Find attributes that contain annotation data - Attribute[] attrs = getAttributes(); - List accumulatedAnnotations = new ArrayList(); - - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; - if (attribute instanceof RuntimeVisibleParameterAnnotations) { - parameterAnnotationsVis = (RuntimeVisibleParameterAnnotations)attribute; - } - if (attribute instanceof RuntimeInvisibleParameterAnnotations) { - parameterAnnotationsInvis = (RuntimeInvisibleParameterAnnotations)attribute; - } + if (!parameterAnnotationsOutOfDate) return; + parameterAnnotationsOutOfDate = false; + + int parameterCount = getArgumentTypes().length; + if (parameterCount == 0) { + unpackedParameterAnnotations = NO_PARAMETER_ANNOTATIONS; + return; + } + + RuntimeVisibleParameterAnnotations parameterAnnotationsVis = null; + RuntimeInvisibleParameterAnnotations parameterAnnotationsInvis = null; + + // Find attributes that contain annotation data + Attribute[] attrs = getAttributes(); + List accumulatedAnnotations = new ArrayList(); + + for (int i = 0; i < attrs.length; i++) { + Attribute attribute = attrs[i]; + if (attribute instanceof RuntimeVisibleParameterAnnotations) { + parameterAnnotationsVis = (RuntimeVisibleParameterAnnotations)attribute; + } else if (attribute instanceof RuntimeInvisibleParameterAnnotations) { + parameterAnnotationsInvis = (RuntimeInvisibleParameterAnnotations)attribute; } - parameterAnnotationsOutOfDate = false; - } + } + + // Build a list of annotation arrays, one per argument + List annotationsForEachParameter = new ArrayList(); + Annotation[] visibleOnes = null; + Annotation[] invisibleOnes = null; + boolean foundSome = false; + for (int i=0; i