From a2face5f02864185f69466416034c1530af8a275 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 1 Jun 2005 14:55:44 +0000 Subject: [PATCH] GenericsWork: Members now recognize that they can have a signature attribute attached that records the signature pre-erasure. It is accessible through 'getDeclaredSignature()' and is resolved lazily. --- .../apache/bcel/classfile/FieldOrMethod.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java index 2780e7c44..58a535571 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java @@ -64,7 +64,7 @@ import java.util.List; /** * Abstract super class for fields and methods. * - * @version $Id: FieldOrMethod.java,v 1.3 2005/03/10 12:15:04 aclement Exp $ + * @version $Id: FieldOrMethod.java,v 1.4 2005/06/01 14:55:44 aclement Exp $ * @author M. Dahm */ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node { @@ -74,6 +74,9 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No protected Attribute[] attributes; // Collection of attributes private Annotation[] annotations; // annotations defined on the field or method protected ConstantPool constant_pool; + + private String signatureAttributeString = null; + private boolean searchedForSignatureAttribute = false; // Annotations are collected from certain attributes, don't do it more than necessary! @@ -212,6 +215,16 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No return c.getBytes(); } + /** + * This will return the contents of a signature attribute attached to a member, or if there + * is none it will return the same as 'getSignature()'. Signature attributes are attached + * to members that were declared generic. + */ + public final String getDeclaredSignature() { + if (getRealSignatureFromAttribute()!=null) return getRealSignatureFromAttribute(); + return getSignature(); + } + /** * @return deep copy of this field */ @@ -267,4 +280,25 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No newAnnotations[len] = a; annotations = newAnnotations; } + + + /** + * Hunts for a signature attribute on the member and returns its contents. So where the 'regular' signature + * may be (Ljava/util/Vector;)V the signature attribute may in fact say '(Ljava/util/Vector;)V' + * Coded for performance - searches for the attribute only when requested - only searches for it once. + */ + public final String getRealSignatureFromAttribute() { + if (!searchedForSignatureAttribute) { + boolean found=false; + for(int i=0; !found && i < attributes_count; i++) { + if(attributes[i] instanceof Signature) { + signatureAttributeString = ((Signature)attributes[i]).getSignature(); + found=true; + } + } + searchedForSignatureAttribute=true; + } + return signatureAttributeString; + } + } -- 2.39.5