Author: tcurdt Date: Mon Jul 10 18:57:19 2006 New Revision: 420672 URL: http://svn.apache.org/viewvc?rev=420672&view=rev Log: GSoC: latest changes from Dmitriy Khayredinov
Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java jakarta/bcel/trunk/src/test/java/org/apache/bcel/AbstractTestCase.java jakarta/bcel/trunk/src/test/java/org/apache/bcel/CounterVisitorTestCase.java jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkedType.java jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotation.java jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotationInvisible.java Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java (original) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java Mon Jul 10 18:57:19 2006 @@ -106,7 +106,7 @@ */ public ElementValuePair[] getElementValuePairs() { // TOFO return List - return (ElementValuePair[]) element_value_pairs.toArray(); + return (ElementValuePair[]) element_value_pairs.toArray(new ElementValuePair[element_value_pairs.size()]); } @@ -124,5 +124,23 @@ public void addElementNameValuePair(ElementValuePair elementNameValuePair) { element_value_pairs.add(elementNameValuePair); + } + + public String toShortString() + { + StringBuffer result = new StringBuffer(); + result.append("@"); + result.append(getAnnotationType()); + if (getElementValuePairs().length > 0) + { + result.append("("); + for (int i = 0; i < getElementValuePairs().length; i++) + { + ElementValuePair element = getElementValuePairs()[i]; + result.append(element.toShortString()); + } + result.append(")"); + } + return result.toString(); } } Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java (original) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java Mon Jul 10 18:57:19 2006 @@ -87,12 +87,14 @@ } + // TODO: update method names /** * @return the annotation entry table */ + /* public final AnnotationEntry[] getAnnotationTable() { return annotation_table; - } + }*/ /** Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java (original) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java Mon Jul 10 18:57:19 2006 @@ -57,4 +57,12 @@ { return elementNameIndex; } + + public String toShortString() + { + StringBuffer result = new StringBuffer(); + result.append(getNameString()).append("=").append( + getValue().toShortString()); + return result.toString(); + } } Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java (original) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java Mon Jul 10 18:57:19 2006 @@ -19,7 +19,11 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.apache.bcel.Constants; +import org.apache.bcel.classfile.Attribute; +import org.apache.bcel.classfile.Signature; /** * Abstract super class for fields and methods. @@ -33,8 +37,15 @@ protected int signature_index; // Points to encoded signature protected int attributes_count; // No. of attributes protected Attribute[] attributes; // Collection of attributes + protected AnnotationEntry[] annotationEntries; // 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! + private boolean annotationsOutOfDate = true; FieldOrMethod() { } @@ -191,16 +202,87 @@ * @return deep copy of this field */ protected FieldOrMethod copy_( ConstantPool _constant_pool ) { + FieldOrMethod c = null; + try { - FieldOrMethod c = (FieldOrMethod) clone(); - c.constant_pool = _constant_pool; - c.attributes = new Attribute[attributes_count]; - for (int i = 0; i < attributes_count; i++) { - c.attributes[i] = attributes[i].copy(_constant_pool); - } - return c; - } catch (CloneNotSupportedException e) { - return null; - } - } + c = (FieldOrMethod)clone(); + } catch(CloneNotSupportedException e) {} + + c.constant_pool = constant_pool; + c.attributes = new Attribute[attributes_count]; + + for(int i=0; i < attributes_count; i++) + c.attributes[i] = attributes[i].copy(constant_pool); + + return c; + } + + /** + * Ensure we have unpacked any attributes that contain annotations. + * We don't remove these annotation attributes from the attributes list, they + * remain there. + */ + private void ensureAnnotationsUpToDate() + { + if (annotationsOutOfDate) + { + // 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 Annotations) + { + Annotations annotations = (Annotations) attribute; + for (int j = 0; i < annotations.getAnnotationEntries().length; i++) + accumulatedAnnotations.add(annotations + .getAnnotationEntries()[j]); + } + } + annotationEntries = (AnnotationEntry[]) accumulatedAnnotations + .toArray(new AnnotationEntry[] {}); + annotationsOutOfDate = false; + } + } + + public AnnotationEntry[] getAnnotationEntries() + { + ensureAnnotationsUpToDate(); + return annotationEntries; + } + + public void addAnnotationEntry(AnnotationEntry a) + { + ensureAnnotationsUpToDate(); + int len = annotationEntries.length; + AnnotationEntry[] newAnnotations = new AnnotationEntry[len + 1]; + System.arraycopy(annotationEntries, 0, newAnnotations, 0, len); + newAnnotations[len] = a; + annotationEntries = 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/lang/Vector<Ljava/lang/String>;' + * Coded for performance - searches for the attribute only when requested - only searches for it once. + */ + public final String getGenericSignature() + { + 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; + } } Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java (original) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/JavaClass.java Mon Jul 10 18:57:19 2006 @@ -61,12 +61,21 @@ private Field[] fields; // Fields, i.e., variables of class private Method[] methods; // methods defined in the class private Attribute[] attributes; // attributes defined in the class + private AnnotationEntry[] annotations; // annotations defined on the class private byte source = HEAP; // Generated in memory + private boolean isGeneric = false; + private boolean isAnonymous = false; + private boolean isNested = false; + private boolean computedNestedTypeStatus = false; public static final byte HEAP = 1; public static final byte FILE = 2; public static final byte ZIP = 3; static boolean debug = false; // Debugging on/off static char sep = '/'; // directory separator + + // Annotations are collected from certain attributes, don't do it more than necessary! + private boolean annotationsOutOfDate = true; + private static BCELComparator _cmp = new BCELComparator() { public boolean equals( Object o1, Object o2 ) { @@ -134,6 +143,7 @@ this.fields = fields; this.methods = methods; this.attributes = attributes; + annotationsOutOfDate = true; this.source = source; // Get source file name if available for (int i = 0; i < attributes.length; i++) { @@ -325,8 +335,25 @@ public Attribute[] getAttributes() { return attributes; } - - + + public AnnotationEntry[] getAnnotationEntries() { + if (annotationsOutOfDate) { + // 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 Annotations) { + Annotations runtimeAnnotations = (Annotations)attribute; + for(int j = 0; j < runtimeAnnotations.getAnnotationEntries().length; j++) + accumulatedAnnotations.add(runtimeAnnotations.getAnnotationEntries()[j]); + } + } + annotations = (AnnotationEntry[])accumulatedAnnotations.toArray(new AnnotationEntry[]{}); + annotationsOutOfDate = false; + } + return annotations; + } /** * @return Class name. */ @@ -615,6 +642,12 @@ buf.append(indent(attributes[i])); } } + AnnotationEntry[] annotations = getAnnotationEntries(); + if (annotations!=null && annotations.length>0) { + buf.append("\nAnnotation(s):\n"); + for (int i=0; i<annotations.length; i++) + buf.append(indent(annotations[i])); + } if (fields.length > 0) { buf.append("\n").append(fields.length).append(" fields:\n"); for (int i = 0; i < fields.length; i++) { @@ -676,6 +709,41 @@ public final boolean isClass() { return (access_flags & Constants.ACC_INTERFACE) == 0; + } + + public final boolean isAnonymous() { + computeNestedTypeStatus(); + return this.isAnonymous; + } + + public final boolean isNested() { + computeNestedTypeStatus(); + return this.isNested; + } + + private final void computeNestedTypeStatus() { + if (computedNestedTypeStatus) return; + for (int i = 0; i < this.attributes.length; i++) { + if (this.attributes[i] instanceof InnerClasses) { + InnerClass[] innerClasses = ((InnerClasses) this.attributes[i]).getInnerClasses(); + for (int j = 0; j < innerClasses.length; j++) { + boolean innerClassAttributeRefersToMe = false; + String inner_class_name = constant_pool.getConstantString(innerClasses[j].getInnerClassIndex(), + Constants.CONSTANT_Class); + inner_class_name = Utility.compactClassName(inner_class_name); + if (inner_class_name.equals(getClassName())) { + innerClassAttributeRefersToMe = true; + } + if (innerClassAttributeRefersToMe) { + this.isNested = true; + if (innerClasses[j].getInnerNameIndex() == 0) { + this.isAnonymous = true; + } + } + } + } + } + this.computedNestedTypeStatus = true; } Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java (original) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ClassGen.java Mon Jul 10 18:57:19 2006 @@ -21,12 +21,16 @@ import java.util.List; import org.apache.bcel.Constants; import org.apache.bcel.classfile.AccessFlags; +import org.apache.bcel.classfile.AnnotationEntry; import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.ConstantPool; import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import org.apache.bcel.classfile.RuntimeInvisibleAnnotations; +import org.apache.bcel.classfile.RuntimeVisibleAnnotations; import org.apache.bcel.classfile.SourceFile; +import org.apache.bcel.classfile.Utility; import org.apache.bcel.util.BCELComparator; /** @@ -50,6 +54,9 @@ private List method_vec = new ArrayList(); private List attribute_vec = new ArrayList(); private List interface_vec = new ArrayList(); + private List annotation_vec = new ArrayList(); + private boolean unpackedAnnotations = false; + private static BCELComparator _cmp = new BCELComparator() { public boolean equals( Object o1, Object o2 ) { @@ -127,6 +134,8 @@ major = clazz.getMajor(); minor = clazz.getMinor(); Attribute[] attributes = clazz.getAttributes(); + // J5TODO: Could make unpacking lazy, done on first reference + AnnotationEntryGen[] annotations = unpackAnnotations(attributes); Method[] methods = clazz.getMethods(); Field[] fields = clazz.getFields(); String[] interfaces = clazz.getInterfaceNames(); @@ -136,6 +145,9 @@ for (int i = 0; i < attributes.length; i++) { addAttribute(attributes[i]); } + for(int i=0; i < annotations.length; i++) { + addAnnotationEntry(annotations[i]); + } for (int i = 0; i < methods.length; i++) { addMethod(methods[i]); } @@ -143,6 +155,43 @@ addField(fields[i]); } } + + /** + * Look for attributes representing annotations and unpack them. + */ + private AnnotationEntryGen[] unpackAnnotations(Attribute[] attrs) + { + List /* AnnotationGen */annotationGenObjs = new ArrayList(); + for (int i = 0; i < attrs.length; i++) + { + Attribute attr = attrs[i]; + if (attr instanceof RuntimeVisibleAnnotations) + { + RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr; + AnnotationEntry[] annos = rva.getAnnotationEntries(); + for (int j = 0; i < annos.length; i++) + { + AnnotationEntry a = annos[i]; + annotationGenObjs.add(new AnnotationEntryGen(a, + getConstantPool(), false)); + } + } + else + if (attr instanceof RuntimeInvisibleAnnotations) + { + RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr; + AnnotationEntry[] annos = ria.getAnnotationEntries(); + for (int j = 0; i < annos.length; i++) + { + AnnotationEntry a = annos[i]; + annotationGenObjs.add(new AnnotationEntryGen(a, + getConstantPool(), false)); + } + } + } + return (AnnotationEntryGen[]) annotationGenObjs + .toArray(new AnnotationEntryGen[] {}); + } /** @@ -152,7 +201,16 @@ int[] interfaces = getInterfaces(); Field[] fields = getFields(); Method[] methods = getMethods(); - Attribute[] attributes = getAttributes(); + Attribute[] attributes = null; + if (annotation_vec.size()==0) { + attributes = getAttributes(); + } else { + // TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations' + Attribute[] annAttributes = Utility.getAnnotationAttributes(cp,annotation_vec); + attributes = new Attribute[attribute_vec.size()+annAttributes.length]; + attribute_vec.toArray(attributes); + System.arraycopy(annAttributes,0,attributes,attribute_vec.size(),annAttributes.length); + } // Must be last since the above calls may still add something to it ConstantPool _cp = this.cp.getFinalConstantPool(); return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor, @@ -217,6 +275,10 @@ public void addAttribute( Attribute a ) { attribute_vec.add(a); } + + public void addAnnotationEntry(AnnotationEntryGen a) { + annotation_vec.add(a); + } /** @@ -420,6 +482,11 @@ public Attribute[] getAttributes() { return (Attribute[]) attribute_vec.toArray(new Attribute[attribute_vec.size()]); + } + + // J5TODO: Should we make calling unpackAnnotations() lazy and put it in here? + public AnnotationEntryGen[] getAnnotationEntries() { + return (AnnotationEntryGen[]) annotation_vec.toArray(new AnnotationEntryGen[annotation_vec.size()]); } Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java (original) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java Mon Jul 10 18:57:19 2006 @@ -3,9 +3,10 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import org.apache.bcel.classfile.AnnotationElementValue; +import java.util.ArrayList; +import java.util.List; +import org.apache.bcel.classfile.AnnotationEntry; import org.apache.bcel.classfile.ArrayElementValue; -import org.apache.bcel.classfile.ClassElementValue; import org.apache.bcel.classfile.ElementValue; import org.apache.bcel.classfile.EnumElementValue; import org.apache.bcel.classfile.SimpleElementValue; @@ -98,21 +99,22 @@ case 'e': // Enum constant return new EnumElementValueGen(dis.readUnsignedShort(), dis .readUnsignedShort(), cpGen); - // case 'c': // Class - // return new ClassElementValueGen(dis.readUnsignedShort(), cpGen); - // - // case '@': // Annotation - // return new - // AnnotationElementValueGen(ANNOTATION,Annotation.read(dis,cpGen),cpGen); - // - // case '[': // Array - // int numArrayVals = dis.readUnsignedShort(); - // List arrayVals = new ArrayList(); - // ElementValue[] evalues = new ElementValue[numArrayVals]; - // for (int j=0;j<numArrayVals;j++) { - // evalues[j] = ElementValue.readElementValue(dis,cpGen); - // } - // return new ArrayElementValue(ARRAY,evalues,cpGen); + case 'c': // Class + return new ClassElementValueGen(dis.readUnsignedShort(), cpGen); + case '@': // Annotation + // TODO: isRuntimeVisible ?????????? + // FIXME + return new AnnotationElementValueGen(ANNOTATION, new AnnotationEntryGen(AnnotationEntry.read( + dis, cpGen.getConstantPool(), true), cpGen, false), cpGen); + case '[': // Array + int numArrayVals = dis.readUnsignedShort(); + List arrayVals = new ArrayList(); + ElementValue[] evalues = new ElementValue[numArrayVals]; + for (int j = 0; j < numArrayVals; j++) + { + evalues[j] = ElementValue.readElementValue(dis, cpGen.getConstantPool()); + } + return new ArrayElementValueGen(ARRAY, evalues, cpGen); default: throw new RuntimeException( "Unexpected element value kind in annotation: " + type); @@ -155,7 +157,7 @@ // copyPoolEntries); // case 'c': // Class // return new ClassElementValueGen((ClassElementValue) value, cpool, - // copyPoolEntries); + // copyPoolEntries); default: throw new RuntimeException("Not implemented yet! (" + value.getElementValueType() + ")"); Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java (original) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java Mon Jul 10 18:57:19 2006 @@ -35,6 +35,7 @@ protected Type type; protected ConstantPoolGen cp; private List attribute_vec = new ArrayList(); + protected ArrayList annotation_vec= new ArrayList(); protected FieldGenOrMethodGen() { @@ -87,6 +88,11 @@ public void addAttribute( Attribute a ) { attribute_vec.add(a); } + + public void addAnnotationEntry(AnnotationEntryGen ag) + { + annotation_vec.add(ag); + } /** @@ -95,6 +101,11 @@ public void removeAttribute( Attribute a ) { attribute_vec.remove(a); } + + public void removeAnnotationEntry(AnnotationEntryGen ag) + { + annotation_vec.remove(ag); + } /** @@ -103,6 +114,11 @@ public void removeAttributes() { attribute_vec.clear(); } + + public void removeAnnotationEntries() + { + annotation_vec.clear(); + } /** @@ -113,6 +129,12 @@ attribute_vec.toArray(attributes); return attributes; } + + public AnnotationEntryGen[] getAnnotationEntries() { + AnnotationEntryGen[] annotations = new AnnotationEntryGen[annotation_vec.size()]; + annotation_vec.toArray(annotations); + return annotations; + } /** @return signature of method/field. Modified: jakarta/bcel/trunk/src/test/java/org/apache/bcel/AbstractTestCase.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/test/java/org/apache/bcel/AbstractTestCase.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/test/java/org/apache/bcel/AbstractTestCase.java (original) +++ jakarta/bcel/trunk/src/test/java/org/apache/bcel/AbstractTestCase.java Mon Jul 10 18:57:19 2006 @@ -1,17 +1,32 @@ package org.apache.bcel; +import java.io.File; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; +import org.apache.bcel.classfile.AnnotationEntry; import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import org.apache.bcel.generic.AnnotationEntryGen; +import org.apache.bcel.generic.ConstantPoolGen; +import org.apache.bcel.generic.ElementValueGen; +import org.apache.bcel.generic.ElementValuePairGen; +import org.apache.bcel.generic.ObjectType; +import org.apache.bcel.generic.SimpleElementValueGen; +import org.apache.bcel.util.ClassPath; import org.apache.bcel.util.SyntheticRepository; public class AbstractTestCase extends TestCase { private boolean verbose = false; + protected File createTestdataFile(String name) + { + return new File("target" + File.separator + "testdata" + File.separator + + name); + } + protected JavaClass getTestClass(String name) throws ClassNotFoundException { return SyntheticRepository.getInstance().loadClass(name); @@ -31,6 +46,45 @@ return null; } + protected boolean wipe(String name) + { + return new File("target" + File.separator + "testdata" + File.separator + + name).delete(); + } + + protected boolean wipe(String dir, String name) + { + boolean b = wipe(dir + File.separator + name); + String[] files = new File(dir).list(); + if (files == null || files.length == 0) + { + new File(dir).delete(); // Why does this not succeed? stupid thing + } + return b; + } + + public SyntheticRepository createRepos(String cpentry) + { + ClassPath cp = new ClassPath("target" + File.separator + "testdata" + + File.separator + cpentry + File.pathSeparator + + System.getProperty("java.class.path")); + return SyntheticRepository.getInstance(cp); + } + + protected Attribute[] findAttribute(String name, JavaClass clazz) + { + Attribute[] all = clazz.getAttributes(); + List chosenAttrsList = new ArrayList(); + for (int i = 0; i < all.length; i++) + { + if (verbose) + System.err.println("Attribute: " + all[i].getName()); + if (all[i].getName().equals(name)) + chosenAttrsList.add(all[i]); + } + return (Attribute[]) chosenAttrsList.toArray(new Attribute[] {}); + } + protected Attribute findAttribute(String name, Attribute[] all) { List chosenAttrsList = new ArrayList(); @@ -44,5 +98,60 @@ assertTrue("Should be one match: " + chosenAttrsList.size(), chosenAttrsList.size() == 1); return (Attribute) chosenAttrsList.get(0); + } + + protected String dumpAttributes(Attribute[] as) + { + StringBuffer result = new StringBuffer(); + result.append("AttributeArray:["); + for (int i = 0; i < as.length; i++) + { + Attribute attr = as[i]; + result.append(attr.toString()); + if (i + 1 < as.length) + result.append(","); + } + result.append("]"); + return result.toString(); + } + + protected String dumpAnnotationEntries(AnnotationEntry[] as) + { + StringBuffer result = new StringBuffer(); + result.append("["); + for (int i = 0; i < as.length; i++) + { + AnnotationEntry annotation = as[i]; + result.append(annotation.toShortString()); + if (i + 1 < as.length) + result.append(","); + } + result.append("]"); + return result.toString(); + } + + protected String dumpAnnotationEntries(AnnotationEntryGen[] as) { + StringBuffer result = new StringBuffer(); + result.append("["); + for (int i = 0; i < as.length; i++) { + AnnotationEntryGen annotation = as[i]; + result.append(annotation.toShortString()); + if (i+1<as.length) result.append(","); + } + result.append("]"); + return result.toString(); + } + + public AnnotationEntryGen createFruitAnnotationEntry(ConstantPoolGen cp, + String aFruit, boolean visibility) + { + SimpleElementValueGen evg = new SimpleElementValueGen( + ElementValueGen.STRING, cp, aFruit); + ElementValuePairGen nvGen = new ElementValuePairGen("fruit", + evg, cp); + ObjectType t = new ObjectType("SimpleStringAnnotation"); + List elements = new ArrayList(); + elements.add(nvGen); + return new AnnotationEntryGen(t, elements, visibility, cp); } } Modified: jakarta/bcel/trunk/src/test/java/org/apache/bcel/CounterVisitorTestCase.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/test/java/org/apache/bcel/CounterVisitorTestCase.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/test/java/org/apache/bcel/CounterVisitorTestCase.java (original) +++ jakarta/bcel/trunk/src/test/java/org/apache/bcel/CounterVisitorTestCase.java Mon Jul 10 18:57:19 2006 @@ -6,7 +6,7 @@ { protected JavaClass getTestClass() throws ClassNotFoundException { - return getTestClass("org.apache.bcel.data.MarkedType$1"); + return getTestClass("org.apache.bcel.data.MarkedType"); } public void testAnnotationsCount() Modified: jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkedType.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkedType.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkedType.java (original) +++ jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkedType.java Mon Jul 10 18:57:19 2006 @@ -0,0 +1,7 @@ +package org.apache.bcel.data; + [EMAIL PROTECTED] [EMAIL PROTECTED] +public class MarkedType +{ +} Modified: jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotation.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotation.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotation.java (original) +++ jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotation.java Mon Jul 10 18:57:19 2006 @@ -0,0 +1,8 @@ +package org.apache.bcel.data; + +import java.lang.annotation.*; + [EMAIL PROTECTED](RetentionPolicy.RUNTIME) +public @interface MarkerAnnotation +{ +} Modified: jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotationInvisible.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotationInvisible.java?rev=420672&r1=420671&r2=420672&view=diff ============================================================================== --- jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotationInvisible.java (original) +++ jakarta/bcel/trunk/src/test/java/org/apache/bcel/data/MarkerAnnotationInvisible.java Mon Jul 10 18:57:19 2006 @@ -0,0 +1,6 @@ +package org.apache.bcel.data; + +import java.lang.annotation.*; + [EMAIL PROTECTED](RetentionPolicy.CLASS) +public @interface MarkerAnnotationInvisible { } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]