Index: src/java/org/apache/lucene/analysis/TokenStream.java =================================================================== --- src/java/org/apache/lucene/analysis/TokenStream.java (revision 806450) +++ src/java/org/apache/lucene/analysis/TokenStream.java (working copy) @@ -196,7 +196,7 @@ return ((TokenStream) input).tokenWrapper; } // check that all attributes are implemented by the same TokenWrapper instance - final AttributeImpl att = addAttribute(TermAttribute.class); + final Attribute att = addAttribute(TermAttribute.class); if (att instanceof TokenWrapper && addAttribute(TypeAttribute.class) == att && addAttribute(PositionIncrementAttribute.class) == att && Index: src/java/org/apache/lucene/util/AttributeImpl.java =================================================================== --- src/java/org/apache/lucene/util/AttributeImpl.java (revision 806450) +++ src/java/org/apache/lucene/util/AttributeImpl.java (working copy) @@ -28,7 +28,7 @@ * Attributes are used to add data in a dynamic, yet type-safe way to a source * of usually streamed objects, e. g. a {@link org.apache.lucene.analysis.TokenStream}. */ -public abstract class AttributeImpl implements Cloneable, Serializable { +public abstract class AttributeImpl implements Cloneable, Serializable, Attribute { /** * Clears the values in this AttributeImpl and resets it to its * default value. If this implementation implements more than one Attribute interface Index: src/java/org/apache/lucene/util/AttributeSource.java =================================================================== --- src/java/org/apache/lucene/util/AttributeSource.java (revision 806450) +++ src/java/org/apache/lucene/util/AttributeSource.java (working copy) @@ -44,6 +44,7 @@ public static abstract class AttributeFactory { /** * returns an {@link AttributeImpl} for the supplied {@link Attribute} interface class. + *

Signature for Java 1.5: public AttributeImpl createAttributeInstance(Class%lt;? extends Attribute> attClass) */ public abstract AttributeImpl createAttributeInstance(Class attClass); @@ -128,16 +129,18 @@ /** Returns a new iterator that iterates the attribute classes * in the same order they were added in. + *

Signature for Java 1.5: public Iterator<Class<? extends Attribute>> getAttributeClassesIterator() */ - public Iterator/*>*/ getAttributeClassesIterator() { + public Iterator getAttributeClassesIterator() { return Collections.unmodifiableSet(attributes.keySet()).iterator(); } /** Returns a new iterator that iterates all unique Attribute implementations. * This iterator may contain less entries that {@link #getAttributeClassesIterator}, * if one instance implements more than one Attribute interface. + *

Signature for Java 1.5: public Iterator<AttributeImpl> getAttributeImplsIterator() */ - public Iterator/**/ getAttributeImplsIterator() { + public Iterator getAttributeImplsIterator() { if (hasAttributes()) { if (currentState == null) { computeCurrentState(); @@ -186,7 +189,7 @@ Class[] interfaces = actClazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { final Class curInterface = interfaces[i]; - if (Attribute.class.isAssignableFrom(curInterface)) { + if (curInterface != Attribute.class && Attribute.class.isAssignableFrom(curInterface)) { foundInterfaces.add(curInterface); } } @@ -213,12 +216,14 @@ * This method first checks if an instance of that class is * already in this AttributeSource and returns it. Otherwise a * new instance is created, added to this AttributeSource and returned. + *

Signature for Java 1.5: public T addAttribute(Class<T extends Attribute>) */ - public AttributeImpl addAttribute(Class attClass) { - AttributeImpl att = (AttributeImpl) attributes.get(attClass); + public Attribute addAttribute(Class attClass) { + Attribute att = (Attribute) attributes.get(attClass); if (att == null) { - att = this.factory.createAttributeInstance(attClass); - addAttributeImpl(att); + final AttributeImpl attImpl = this.factory.createAttributeInstance(attClass); + addAttributeImpl(attImpl); + att = attImpl; } return att; } @@ -231,6 +236,7 @@ /** * The caller must pass in a Class<? extends Attribute> value. * Returns true, iff this AttributeSource contains the passed-in Attribute. + *

Signature for Java 1.5: public boolean hasAttribute(Class<T extends Attribute>) */ public boolean hasAttribute(Class attClass) { return this.attributes.containsKey(attClass); @@ -239,12 +245,13 @@ /** * The caller must pass in a Class<? extends Attribute> value. * Returns the instance of the passed in Attribute contained in this AttributeSource + *

Signature for Java 1.5: public T getAttribute(Class<T extends Attribute>) * * @throws IllegalArgumentException if this AttributeSource does not contain the * Attribute */ - public AttributeImpl getAttribute(Class attClass) { - AttributeImpl att = (AttributeImpl) this.attributes.get(attClass); + public Attribute getAttribute(Class attClass) { + Attribute att = (Attribute) this.attributes.get(attClass); if (att == null) { throw new IllegalArgumentException("This AttributeSource does not have the attribute '" + attClass + "'."); }