Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve an inherited nested static class during compilation

The story is quite short and it starts with the few following excerpts from Lucene's classes:

Analyzer:

public abstract class Analyzer implements Closeable {

    (...)

    public static class TokenStreamComponents { ... }

    (...)
}

AnalyzerWrapper:

public abstract class AnalyzerWrapper extends Analyzer {

    (...)

    @Override
    protected final TokenStreamComponents createComponents(String fieldName, Reader aReader) {
        return wrapComponents(fieldName, getWrappedAnalyzer(fieldName).createComponents(fieldName, aReader));
    }

    (...)

}

Now inside a Grails application I define my own class, MyAnalyzer.groovy

class MyAnalyzer extends AnalyzerWrapper {

    private final PerFieldAnalyzerWrapper perFieldAnalyzerWrapper

    public MyAnalyzer() { ... }

    @Override
    protected Analyzer getWrappedAnalyzer(String fieldName) {
        perFieldAnalyzerWrapper.getWrappedAnalyzer(fieldName)
    }

    @Override
    protected TokenStreamComponents wrapComponents(String fieldName, TokenStreamComponents tokenStreamComponents) {
        perFieldAnalyzerWrapper.wrapComponents(fieldName, tokenStreamComponents)
    }
}

And when I try to run/compile the application, I get:

[groovyc] Compiling 2 source files to E:\somewhere\...\target\classes
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] E:\somewhere\...\MyAnalyzer.groovy: 31: unable to resolve class TokenStreamComponents 
[groovyc]  @ line 31, column 5.
[groovyc]        @Override
[groovyc]        ^
[groovyc] 
[groovyc] 1 error

However, if I change both occurences of TokenStreamComponents to Analyzer.TokenStreamComponents in the definition of the overridden method in MyAnalyzer, the class compiles fine.

Does anyone know if there is some logical reason behind such behavior, caused e.g. by the way Groovy or Grails behaves, or am I just missing something here?

like image 393
konradstrack Avatar asked Nov 02 '22 18:11

konradstrack


1 Answers

Just add the line import Analyzer.*; to the import section of your Program. ! let me know if it solved.!

like image 188
naushasame Avatar answered Nov 14 '22 22:11

naushasame