lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r932864 - in /lucene/dev/trunk/lucene: ./ backwards/src/test/org/apache/lucene/analysis/ backwards/src/test/org/apache/lucene/queryParser/ backwards/src/test/org/apache/lucene/search/ backwards/src/test/org/apache/lucene/search/payloads/ ba...
Date Sun, 11 Apr 2010 10:37:39 GMT
Author: uschindler
Date: Sun Apr 11 10:37:38 2010
New Revision: 932864

URL: http://svn.apache.org/viewvc?rev=932864&view=rev
Log:
LUCENE-2389: Removed the now obsolete and deprecated Analyzer.setOverridesTokenStreamMethod().
Analyzer and TokenStream base classes now have an assertion in their ctor, that check subclasses
to be final or at least have final implementations of incrementToken(), tokenStream(), and
reusableTokenStream()

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/analysis/TestAnalyzers.java
    lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/queryParser/TestQueryParser.java
    lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/TestPositionIncrement.java
    lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
    lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
    lucene/dev/trunk/lucene/contrib/analyzers/common/src/test/org/apache/lucene/analysis/shingle/TestShingleMatrixFilter.java
    lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java
    lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java
    lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
    lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java
    lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/IndexTimeSynonymTest.java
    lucene/dev/trunk/lucene/contrib/icu/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/Analyzer.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/TokenStream.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/WhitespaceTokenizer.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/collation/CollationKeyAnalyzer.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestAssertions.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestAnalyzers.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestKeywordMarkerFilter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Sun Apr 11 10:37:38 2010
@@ -97,9 +97,13 @@ Changes in backwards compatibility polic
   TODO: Point to new attribute inspection API coming with LUCENE-2374.
   (Uwe Schindler, Robert Muir)
 
-* LUCENE-2372: StandardAnalyzer, KeywordAnalyzer, PerFieldAnalyzerWrapper
-  are now final.  Also removed the now obsolete and deprecated
-  Analyzer.setOverridesTokenStreamMethod().  (Uwe Schindler)
+* LUCENE-2372, LUCENE-2389: StandardAnalyzer, KeywordAnalyzer,
+  PerFieldAnalyzerWrapper, WhitespaceTokenizer are now final.  Also removed
+  the now obsolete and deprecated Analyzer.setOverridesTokenStreamMethod().
+  Analyzer and TokenStream base classes now have an assertion in their ctor,
+  that check subclasses to be final or at least have final implementations
+  of incrementToken(), tokenStream(), and reusableTokenStream().
+  (Uwe Schindler, Robert Muir)
 
 Changes in runtime behavior
 

Modified: lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/analysis/TestAnalyzers.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/analysis/TestAnalyzers.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/analysis/TestAnalyzers.java
(original)
+++ lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/analysis/TestAnalyzers.java
Sun Apr 11 10:37:38 2010
@@ -143,7 +143,7 @@ public class TestAnalyzers extends BaseT
   */
 }
 
-class PayloadSetter extends TokenFilter {
+final class PayloadSetter extends TokenFilter {
   PayloadAttribute payloadAtt;
   public  PayloadSetter(TokenStream input) {
     super(input);

Modified: lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/queryParser/TestQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/queryParser/TestQueryParser.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/queryParser/TestQueryParser.java
(original)
+++ lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/queryParser/TestQueryParser.java
Sun Apr 11 10:37:38 2010
@@ -81,7 +81,7 @@ public class TestQueryParser extends Loc
   
   public static Analyzer qpAnalyzer = new QPTestAnalyzer();
 
-  public static class QPTestFilter extends TokenFilter {
+  public static final class QPTestFilter extends TokenFilter {
     TermAttribute termAtt;
     OffsetAttribute offsetAtt;
         
@@ -122,7 +122,7 @@ public class TestQueryParser extends Loc
   }
 
   
-  public static class QPTestAnalyzer extends Analyzer {
+  public static final class QPTestAnalyzer extends Analyzer {
 
     /** Filters LowerCaseTokenizer with StopFilter. */
     @Override

Modified: lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/TestPositionIncrement.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/TestPositionIncrement.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/TestPositionIncrement.java
(original)
+++ lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/TestPositionIncrement.java
Sun Apr 11 10:37:38 2010
@@ -317,7 +317,7 @@ public class TestPositionIncrement exten
   }
 }
 
-class TestPayloadAnalyzer extends Analyzer {
+final class TestPayloadAnalyzer extends Analyzer {
 
   @Override
   public TokenStream tokenStream(String fieldName, Reader reader) {
@@ -326,7 +326,7 @@ class TestPayloadAnalyzer extends Analyz
   }
 }
 
-class PayloadFilter extends TokenFilter {
+final class PayloadFilter extends TokenFilter {
   String fieldName;
 
   int pos;

Modified: lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/payloads/PayloadHelper.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
(original)
+++ lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
Sun Apr 11 10:37:38 2010
@@ -44,7 +44,7 @@ public class PayloadHelper {
   public static final String MULTI_FIELD = "multiField";
   public static final String FIELD = "field";
 
-  public class PayloadAnalyzer extends Analyzer {
+  public final class PayloadAnalyzer extends Analyzer {
 
 
 
@@ -56,7 +56,7 @@ public class PayloadHelper {
     }
   }
 
-  public class PayloadFilter extends TokenFilter {
+  public final class PayloadFilter extends TokenFilter {
     String fieldName;
     int numSeen = 0;
     PayloadAttribute payloadAtt;

Modified: lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
(original)
+++ lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
Sun Apr 11 10:37:38 2010
@@ -471,7 +471,7 @@ public class TestPayloadSpans extends Lu
     assertEquals(numSpans, cnt);
   }
 
-  class PayloadAnalyzer extends Analyzer {
+  final class PayloadAnalyzer extends Analyzer {
 
     @Override
     public TokenStream tokenStream(String fieldName, Reader reader) {
@@ -481,7 +481,7 @@ public class TestPayloadSpans extends Lu
     }
   }
 
-  class PayloadFilter extends TokenFilter {
+  final class PayloadFilter extends TokenFilter {
     String fieldName;
     int numSeen = 0;
     Set entities = new HashSet();
@@ -523,7 +523,7 @@ public class TestPayloadSpans extends Lu
     }
   }
   
-  public class TestPayloadAnalyzer extends Analyzer {
+  public final class TestPayloadAnalyzer extends Analyzer {
 
     @Override
     public TokenStream tokenStream(String fieldName, Reader reader) {

Modified: lucene/dev/trunk/lucene/contrib/analyzers/common/src/test/org/apache/lucene/analysis/shingle/TestShingleMatrixFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/analyzers/common/src/test/org/apache/lucene/analysis/shingle/TestShingleMatrixFilter.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/analyzers/common/src/test/org/apache/lucene/analysis/shingle/TestShingleMatrixFilter.java
(original)
+++ lucene/dev/trunk/lucene/contrib/analyzers/common/src/test/org/apache/lucene/analysis/shingle/TestShingleMatrixFilter.java
Sun Apr 11 10:37:38 2010
@@ -482,7 +482,7 @@ public class TestShingleMatrixFilter ext
   }
 
 
-  public static class TokenListStream extends TokenStream {
+  public final static class TokenListStream extends TokenStream {
 
     private Collection<Token> tokens;
     TermAttribute termAtt;

Modified: lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java
(original)
+++ lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java
Sun Apr 11 10:37:38 2010
@@ -148,7 +148,7 @@ public class TokenSources {
     }
 
     // an object used to iterate across an array of tokens
-    class StoredTokenStream extends TokenStream {
+    final class StoredTokenStream extends TokenStream {
       Token tokens[];
 
       int currentToken = 0;

Modified: lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java
(original)
+++ lucene/dev/trunk/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenStreamFromTermPositionVector.java
Sun Apr 11 10:37:38 2010
@@ -31,10 +31,7 @@ import org.apache.lucene.analysis.tokena
 import org.apache.lucene.index.TermPositionVector;
 import org.apache.lucene.index.TermVectorOffsetInfo;
 
-/**
- * @author CMorris
- */
-public class TokenStreamFromTermPositionVector extends TokenStream {
+public final class TokenStreamFromTermPositionVector extends TokenStream {
 
   private final List<Token> positionedTokens = new ArrayList<Token>();
 

Modified: lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
(original)
+++ lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
Sun Apr 11 10:37:38 2010
@@ -1783,7 +1783,7 @@ public class HighlighterTest extends Bas
 // behaviour to synonyms
 // ===================================================================
 
-class SynonymAnalyzer extends Analyzer {
+final class SynonymAnalyzer extends Analyzer {
   private Map<String,String> synonyms;
 
   public SynonymAnalyzer(Map<String,String> synonyms) {
@@ -1810,7 +1810,7 @@ class SynonymAnalyzer extends Analyzer {
  * Expands a token stream with synonyms (TODO - make the synonyms analyzed by choice of analyzer)
  *
  */
-class SynonymTokenizer extends TokenStream {
+final class SynonymTokenizer extends TokenStream {
   private TokenStream realStream;
   private Token currentRealToken = null;
   private Map<String,String> synonyms;

Modified: lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java
(original)
+++ lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java
Sun Apr 11 10:37:38 2010
@@ -170,14 +170,14 @@ public abstract class AbstractTestCase e
     }
   }
 
-  static class BigramAnalyzer extends Analyzer {
+  static final class BigramAnalyzer extends Analyzer {
     @Override
     public TokenStream tokenStream(String fieldName, Reader reader) {
       return new BasicNGramTokenizer( reader );
     }
   }
   
-  static class BasicNGramTokenizer extends Tokenizer {
+  static final class BasicNGramTokenizer extends Tokenizer {
 
     public static final int DEFAULT_N_SIZE = 2;
     public static final String DEFAULT_DELIMITERS = " \t\n.,";

Modified: lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/IndexTimeSynonymTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/IndexTimeSynonymTest.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/IndexTimeSynonymTest.java
(original)
+++ lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/IndexTimeSynonymTest.java
Sun Apr 11 10:37:38 2010
@@ -292,7 +292,7 @@ public class IndexTimeSynonymTest extend
     return token;
   }
   
-  public static class TokenArrayAnalyzer extends Analyzer {
+  public static final class TokenArrayAnalyzer extends Analyzer {
     Token[] tokens;
     public TokenArrayAnalyzer( Token... tokens ){
       this.tokens = tokens;

Modified: lucene/dev/trunk/lucene/contrib/icu/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/icu/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/icu/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java
(original)
+++ lucene/dev/trunk/lucene/contrib/icu/src/test/org/apache/lucene/collation/TestICUCollationKeyFilter.java
Sun Apr 11 10:37:38 2010
@@ -42,7 +42,7 @@ public class TestICUCollationKeyFilter e
     (collator.getCollationKey(secondRangeEndOriginal).toByteArray());
 
   
-  public class TestAnalyzer extends Analyzer {
+  public final class TestAnalyzer extends Analyzer {
     private Collator _collator;
 
     TestAnalyzer(Collator collator) {

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java
(original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java
Sun Apr 11 10:37:38 2010
@@ -105,7 +105,7 @@ public class TestAnalyzingQueryParser ex
 
 }
 
-class ASCIIAnalyzer extends org.apache.lucene.analysis.Analyzer {
+final class ASCIIAnalyzer extends org.apache.lucene.analysis.Analyzer {
   public ASCIIAnalyzer() {
   }
 

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
(original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
Sun Apr 11 10:37:38 2010
@@ -56,7 +56,7 @@ public class TestPrecedenceQueryParser e
 
   public static Analyzer qpAnalyzer = new QPTestAnalyzer();
 
-  public static class QPTestFilter extends TokenFilter {
+  public static final class QPTestFilter extends TokenFilter {
     /**
      * Filter which discards the token 'stop' and which expands the
      * token 'phrase' into 'phrase1 phrase2'
@@ -94,7 +94,7 @@ public class TestPrecedenceQueryParser e
     }
   }
 
-  public static class QPTestAnalyzer extends Analyzer {
+  public static final class QPTestAnalyzer extends Analyzer {
 
     /** Filters LowerCaseTokenizer with StopFilter. */
     @Override

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java
(original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java
Sun Apr 11 10:37:38 2010
@@ -342,7 +342,7 @@ public class TestMultiFieldQPHelper exte
   /**
    * Return empty tokens for field "f1".
    */
-  private static class AnalyzerReturningNull extends Analyzer {
+  private static final class AnalyzerReturningNull extends Analyzer {
     StandardAnalyzer stdAnalyzer = new StandardAnalyzer(TEST_VERSION_CURRENT);
 
     public AnalyzerReturningNull() {

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
(original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
Sun Apr 11 10:37:38 2010
@@ -97,7 +97,7 @@ public class TestQPHelper extends Locali
 
   public static Analyzer qpAnalyzer = new QPTestAnalyzer();
 
-  public static class QPTestFilter extends TokenFilter {
+  public static final class QPTestFilter extends TokenFilter {
     TermAttribute termAtt;
     OffsetAttribute offsetAtt;
 
@@ -138,7 +138,7 @@ public class TestQPHelper extends Locali
     }
   }
 
-  public static class QPTestAnalyzer extends Analyzer {
+  public static final class QPTestAnalyzer extends Analyzer {
 
     /** Filters LowerCaseTokenizer with StopFilter. */
     @Override

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
(original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
Sun Apr 11 10:37:38 2010
@@ -94,7 +94,7 @@ public class TestQueryParserWrapper exte
   
   public static Analyzer qpAnalyzer = new QPTestAnalyzer();
 
-  public static class QPTestFilter extends TokenFilter {
+  public static final class QPTestFilter extends TokenFilter {
     TermAttribute termAtt;
     OffsetAttribute offsetAtt;
 
@@ -135,7 +135,7 @@ public class TestQueryParserWrapper exte
     }
   }
 
-  public static class QPTestAnalyzer extends Analyzer {
+  public static final class QPTestAnalyzer extends Analyzer {
 
     /** Filters LowerCaseTokenizer with StopFilter. */
     @Override

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/Analyzer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/Analyzer.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/Analyzer.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/Analyzer.java Sun Apr 11 10:37:38
2010
@@ -20,9 +20,9 @@ package org.apache.lucene.analysis;
 import java.io.Reader;
 import java.io.IOException;
 import java.io.Closeable;
+import java.lang.reflect.Modifier;
 
 import org.apache.lucene.util.CloseableThreadLocal;
-import org.apache.lucene.util.VirtualMethod;
 import org.apache.lucene.store.AlreadyClosedException;
 
 import org.apache.lucene.document.Fieldable;
@@ -33,8 +33,34 @@ import org.apache.lucene.document.Fielda
  *  Typical implementations first build a Tokenizer, which breaks the stream of
  *  characters from the Reader into raw Tokens.  One or more TokenFilters may
  *  then be applied to the output of the Tokenizer.
+ * <p>The {@code Analyzer}-API in Lucene is based on the decorator pattern.
+ * Therefore all non-abstract subclasses must be final or their {@link #tokenStream}
+ * and {@link #reusableTokenStream} implementations must be final! This is checked
+ * when Java assertions are enabled.
  */
 public abstract class Analyzer implements Closeable {
+
+  protected Analyzer() {
+    super();
+    assert assertFinal();
+  }
+  
+  private boolean assertFinal() {
+    try {
+      final Class<?> clazz = getClass();
+      assert clazz.isAnonymousClass() ||
+        (clazz.getModifiers() & (Modifier.FINAL | Modifier.PRIVATE)) != 0 ||
+        (
+          Modifier.isFinal(clazz.getMethod("tokenStream", String.class, Reader.class).getModifiers())
&&
+          Modifier.isFinal(clazz.getMethod("reusableTokenStream", String.class, Reader.class).getModifiers())
+        ) :
+        "Analyzer implementation classes or at least their tokenStream() and reusableTokenStream()
implementations must be final";
+      return true;
+    } catch (NoSuchMethodException nsme) {
+      return false;
+    }
+  }
+
   /** Creates a TokenStream which tokenizes all the text in the provided
    * Reader.  Must be able to handle null field name for
    * backward compatibility.

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/TokenStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/TokenStream.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/TokenStream.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/TokenStream.java Sun Apr 11
10:37:38 2010
@@ -19,6 +19,7 @@ package org.apache.lucene.analysis;
 
 import java.io.IOException;
 import java.io.Closeable;
+import java.lang.reflect.Modifier;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -76,6 +77,10 @@ import org.apache.lucene.util.AttributeS
  * {@link TeeSinkTokenFilter}). For this usecase
  * {@link AttributeSource#captureState} and {@link AttributeSource#restoreState}
  * can be used.
+ * <p>The {@code TokenStream}-API in Lucene is based on the decorator pattern.
+ * Therefore all non-abstract subclasses must be final or have at least a final
+ * implementation of {@link #incrementToken}! This is checked when Java
+ * assertions are enabled.
  */
 public abstract class TokenStream extends AttributeSource implements Closeable {
 
@@ -84,6 +89,7 @@ public abstract class TokenStream extend
    */
   protected TokenStream() {
     super();
+    assert assertFinal();
   }
   
   /**
@@ -91,6 +97,7 @@ public abstract class TokenStream extend
    */
   protected TokenStream(AttributeSource input) {
     super(input);
+    assert assertFinal();
   }
   
   /**
@@ -98,6 +105,20 @@ public abstract class TokenStream extend
    */
   protected TokenStream(AttributeFactory factory) {
     super(factory);
+    assert assertFinal();
+  }
+  
+  private boolean assertFinal() {
+    try {
+      final Class<?> clazz = getClass();
+      assert clazz.isAnonymousClass() ||
+        (clazz.getModifiers() & (Modifier.FINAL | Modifier.PRIVATE)) != 0 ||
+        Modifier.isFinal(clazz.getMethod("incrementToken").getModifiers()) :
+        "TokenStream implementation classes or at least their incrementToken() implementation
must be final";
+      return true;
+    } catch (NoSuchMethodException nsme) {
+      return false;
+    }
   }
   
   /**

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/WhitespaceTokenizer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/WhitespaceTokenizer.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/WhitespaceTokenizer.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/WhitespaceTokenizer.java Sun
Apr 11 10:37:38 2010
@@ -35,7 +35,7 @@ import org.apache.lucene.util.Version;
  * {@link CharTokenizer#normalize(int)} for details.</li>
  * </ul>
  */
-public class WhitespaceTokenizer extends CharTokenizer {
+public final class WhitespaceTokenizer extends CharTokenizer {
   
   /**
    * Construct a new WhitespaceTokenizer. * @param matchVersion Lucene version

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/collation/CollationKeyAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/collation/CollationKeyAnalyzer.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/collation/CollationKeyAnalyzer.java
(original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/collation/CollationKeyAnalyzer.java
Sun Apr 11 10:37:38 2010
@@ -76,7 +76,7 @@ import java.io.IOException;
  *   ICUCollationKeyAnalyzer on the query side, or vice versa.
  * </p>
  */
-public class CollationKeyAnalyzer extends Analyzer {
+public final class CollationKeyAnalyzer extends Analyzer {
   private Collator collator;
 
   public CollationKeyAnalyzer(Collator collator) {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestAssertions.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestAssertions.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestAssertions.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestAssertions.java Sun Apr 11 10:37:38
2010
@@ -17,11 +17,15 @@ package org.apache.lucene;
  * limitations under the License.
  */
 
+import java.io.Reader;
+
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
 
 public class TestAssertions extends LuceneTestCase {
 
-  public void test() {
+  public void testBasics() {
     try {
       assert Boolean.FALSE.booleanValue();
       fail("assertions are not enabled!");
@@ -29,5 +33,65 @@ public class TestAssertions extends Luce
       assert Boolean.TRUE.booleanValue();
     }
   }
+  
+  static class TestAnalyzer1 extends Analyzer {
+    public final TokenStream tokenStream(String s, Reader r) { return null; }
+    public final TokenStream reusableTokenStream(String s, Reader r) { return null; }
+  }
+
+  static final class TestAnalyzer2 extends Analyzer {
+    public TokenStream tokenStream(String s, Reader r) { return null; }
+    public TokenStream reusableTokenStream(String s, Reader r) { return null; }
+  }
+
+  static class TestAnalyzer3 extends Analyzer {
+    public TokenStream tokenStream(String s, Reader r) { return null; }
+    public TokenStream reusableTokenStream(String s, Reader r) { return null; }
+  }
+
+  static class TestAnalyzer4 extends Analyzer {
+    public final TokenStream tokenStream(String s, Reader r) { return null; }
+    public TokenStream reusableTokenStream(String s, Reader r) { return null; }
+  }
+
+  static class TestTokenStream1 extends TokenStream {
+    public final boolean incrementToken() { return false; }
+  }
+
+  static final class TestTokenStream2 extends TokenStream {
+    public boolean incrementToken() { return false; }
+  }
+
+  static class TestTokenStream3 extends TokenStream {
+    public boolean incrementToken() { return false; }
+  }
+
+  public void testTokenStreams() {
+    new TestAnalyzer1();
+    
+    new TestAnalyzer2();
+    
+    try {
+      new TestAnalyzer3();
+      fail("TestAnalyzer3 should fail assertion");
+    } catch (AssertionError e) {
+    }
+    
+    try {
+      new TestAnalyzer4();
+      fail("TestAnalyzer4 should fail assertion");
+    } catch (AssertionError e) {
+    }
+    
+    new TestTokenStream1();
+    
+    new TestTokenStream2();
+    
+    try {
+      new TestTokenStream3();
+      fail("TestTokenStream3 should fail assertion");
+    } catch (AssertionError e) {
+    }
+  }
 
 }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestAnalyzers.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestAnalyzers.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestAnalyzers.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestAnalyzers.java Sun Apr
11 10:37:38 2010
@@ -216,7 +216,7 @@ public class TestAnalyzers extends BaseT
   
 }
 
-class PayloadSetter extends TokenFilter {
+final class PayloadSetter extends TokenFilter {
   PayloadAttribute payloadAtt;
   public  PayloadSetter(TokenStream input) {
     super(input);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java Sun
Apr 11 10:37:38 2010
@@ -162,7 +162,7 @@ public class TestCharTokenizers extends 
     }
   }
 
-  static class TestingCharTokenizer extends CharTokenizer {
+  static final class TestingCharTokenizer extends CharTokenizer {
     public TestingCharTokenizer(Version matchVersion, Reader input) {
       super(matchVersion, input);
     }
@@ -178,7 +178,7 @@ public class TestCharTokenizers extends 
     }
   }
 
-  static class TestingCharTokenizerNormalize extends CharTokenizer {
+  static final class TestingCharTokenizerNormalize extends CharTokenizer {
     public TestingCharTokenizerNormalize(Version matchVersion, Reader input) {
       super(matchVersion, input);
     }
@@ -194,7 +194,7 @@ public class TestCharTokenizers extends 
     }
   }
 
-  static class TestingCharTokenizerNormalizeIsTokenChar extends CharTokenizer {
+  static final class TestingCharTokenizerNormalizeIsTokenChar extends CharTokenizer {
     public TestingCharTokenizerNormalizeIsTokenChar(Version matchVersion,
         Reader input) {
       super(matchVersion, input);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestKeywordMarkerFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestKeywordMarkerFilter.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestKeywordMarkerFilter.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestKeywordMarkerFilter.java
Sun Apr 11 10:37:38 2010
@@ -51,7 +51,7 @@ public class TestKeywordMarkerFilter ext
             "The quIck browN LuceneFox Jumps")), set2)), output);
   }
 
-  public static class LowerCaseFilterMock extends TokenFilter {
+  public static final class LowerCaseFilterMock extends TokenFilter {
 
     private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
     private final KeywordAttribute keywordAttr = addAttribute(KeywordAttribute.class);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/collation/TestCollationKeyFilter.java
Sun Apr 11 10:37:38 2010
@@ -45,7 +45,7 @@ public class TestCollationKeyFilter exte
     (collator.getCollationKey(secondRangeEndOriginal).toByteArray());
 
   
-  public class TestAnalyzer extends Analyzer {
+  public final class TestAnalyzer extends Analyzer {
     private Collator _collator;
 
     TestAnalyzer(Collator collator) {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java Sun
Apr 11 10:37:38 2010
@@ -81,7 +81,7 @@ public class TestQueryParser extends Loc
   
   public static Analyzer qpAnalyzer = new QPTestAnalyzer();
 
-  public static class QPTestFilter extends TokenFilter {
+  public static final class QPTestFilter extends TokenFilter {
     CharTermAttribute termAtt;
     OffsetAttribute offsetAtt;
         
@@ -123,7 +123,7 @@ public class TestQueryParser extends Loc
   }
 
   
-  public static class QPTestAnalyzer extends Analyzer {
+  public static final class QPTestAnalyzer extends Analyzer {
 
     /** Filters LowerCaseTokenizer with StopFilter. */
     @Override

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java Sun
Apr 11 10:37:38 2010
@@ -329,7 +329,7 @@ public class TestPositionIncrement exten
   }
 }
 
-class TestPayloadAnalyzer extends Analyzer {
+final class TestPayloadAnalyzer extends Analyzer {
 
   @Override
   public TokenStream tokenStream(String fieldName, Reader reader) {
@@ -338,7 +338,7 @@ class TestPayloadAnalyzer extends Analyz
   }
 }
 
-class PayloadFilter extends TokenFilter {
+final class PayloadFilter extends TokenFilter {
   String fieldName;
 
   int pos;

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java
Sun Apr 11 10:37:38 2010
@@ -46,7 +46,7 @@ public class PayloadHelper {
   public static final String MULTI_FIELD = "multiField";
   public static final String FIELD = "field";
 
-  public class PayloadAnalyzer extends Analyzer {
+  public final class PayloadAnalyzer extends Analyzer {
 
 
 
@@ -58,7 +58,7 @@ public class PayloadHelper {
     }
   }
 
-  public class PayloadFilter extends TokenFilter {
+  public final class PayloadFilter extends TokenFilter {
     String fieldName;
     int numSeen = 0;
     PayloadAttribute payloadAtt;

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java?rev=932864&r1=932863&r2=932864&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
Sun Apr 11 10:37:38 2010
@@ -462,7 +462,7 @@ public class TestPayloadSpans extends Lu
     assertEquals(numSpans, cnt);
   }
 
-  class PayloadAnalyzer extends Analyzer {
+  final class PayloadAnalyzer extends Analyzer {
 
     @Override
     public TokenStream tokenStream(String fieldName, Reader reader) {
@@ -472,7 +472,7 @@ public class TestPayloadSpans extends Lu
     }
   }
 
-  class PayloadFilter extends TokenFilter {
+  final class PayloadFilter extends TokenFilter {
     String fieldName;
     int numSeen = 0;
     Set<String> entities = new HashSet<String>();
@@ -514,7 +514,7 @@ public class TestPayloadSpans extends Lu
     }
   }
   
-  public class TestPayloadAnalyzer extends Analyzer {
+  public final class TestPayloadAnalyzer extends Analyzer {
 
     @Override
     public TokenStream tokenStream(String fieldName, Reader reader) {



Mime
View raw message