aino-komal / mvp4g

Automatically exported from code.google.com/p/mvp4g
0 stars 0 forks source link

Improve error message when using a presenter with the wrong event bus #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It may be a bug or it may be that I don't fully understand how multi-module 
feature works in mvp4g, it which case I apologize for reporting this as a bug. 

I created a skeleton of an application which is certainly going to change but 
that's not the point - for now I'm just experimenting with the mvp4g 
multi-module feature. 

Here is the error message that I'm getting during compilation:

       [ERROR] presenter pl_ciborowski_konrad_peval_client_application_ApplicationPresenter: Invalid Event Bus. Can not convert pl.ciborowski.konrad.peval.client.main.MainEventBus to pl.ciborowski.konrad.peval.client.application.ApplicationEventBus
com.mvp4g.util.exception.InvalidTypeException: presenter 
pl_ciborowski_konrad_peval_client_application_ApplicationPresenter: Invalid 
Event Bus. Can not convert pl.ciborowski.konrad.peval.client.main.MainEventBus 
to pl.ciborowski.konrad.peval.client.application.ApplicationEventBus
        at com.mvp4g.util.config.Mvp4gConfiguration.validateEventHandlers(Mvp4gConfiguration.java:720)
        at com.mvp4g.util.config.Mvp4gConfiguration.load(Mvp4gConfiguration.java:212)
        at com.mvp4g.util.Mvp4gGenerator.writeClass(Mvp4gGenerator.java:144)
        at com.mvp4g.util.Mvp4gGenerator.createClass(Mvp4gGenerator.java:89)
        at com.mvp4g.util.Mvp4gGenerator.generate(Mvp4gGenerator.java:70)
        at com.google.gwt.dev.javac.StandardGeneratorContext.runGenerator(StandardGeneratorContext.java:418)
        at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:38)
        at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:108)
        at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:54)
        at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:154)
        at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:143)
        at com.google.gwt.dev.Precompile$DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(Precompile.java:317)
        at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:95)
        at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.process(AbstractCompiler.java:200)
        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
        at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:123)
        at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:234)
        at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.access$200(AbstractCompiler.java:109)
        at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:522)
        at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:112)
        at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:47)
        at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:430)
        at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:32)
        at com.google.gwt.dev.Precompile.precompile(Precompile.java:522)
        at com.google.gwt.dev.Precompile.precompile(Precompile.java:414)
        at com.google.gwt.dev.Compiler.run(Compiler.java:201)
        at com.google.gwt.dev.Compiler$1.run(Compiler.java:152)
        at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:87)
        at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:81)
        at com.google.gwt.dev.Compiler.main(Compiler.java:159)

So it says it cannot convert the MainEventButs to ApplicationEventBus. I'm not 
sure what this really means. Both are sublasses of EventBus so why is it 
attempting to convert one to another?

Here is my MainEventBus

@Events(startView = MainViewImpl.class, historyOnStart = false, debug = true)
@ChildModules({@ChildModule(moduleClass = LoginModule.class, async = false, 
autoDisplay = false),
@ChildModule(moduleClass = ApplicationModule.class, async = true, autoDisplay = 
false)})
public interface MainEventBus extends EventBus {

    @Start
    @Event(modulesToLoad = LoginModule.class, handlers = MainPresenter.class)
    public void goToLogin();

    @Event(modulesToLoad = ApplicationModule.class, handlers = ApplicationPresenter.class)
    public void goToAppMainScreen();

    @Event(handlers = MainPresenter.class)
    public void changeBodyContainer(Canvas bodyContainer);

}

Here is my application event bus

@Events(startView = ApplicationViewImpl.class, module = 
ApplicationModule.class, debug = true)
public interface ApplicationEventBus extends EventBus {

    @Event(forwardToParent = true)
    public void changeBodyContainer(Canvas bodyContainer);

    /**
     * @see MainEventBus#goToAppMainScreen()
     */
    @Event(handlers = ApplicationPresenter.class)
    public void goToAppMainScreen();

}

In case you need the ApplicationPresenter - here it is:

@Presenter(view = ApplicationViewImpl.class)
public class ApplicationPresenter extends BasePresenter<ApplicationView, 
ApplicationEventBus> {

    /**
     * Displays the application main screen.
     */
    public void onGoToAppMainScreen() {
        eventBus.changeBodyContainer(view.getViewCanvas());
    }

}

I am puzzled no end why this doesn't compile. Either it is indeed a bug or I'm 
missing something blindigly obvious.

Best regards,
Konrad Ciborowski
Kraków, Poland

PS The error message should say "Cannot convert" rather than "Can not convert".

Original issue reported on code.google.com by ci...@poczta.fm on 27 Sep 2010 at 8:43

GoogleCodeExporter commented 9 years ago
Your error here is that ApplicationPresenter shouldn't be an handler of 
MainEventBus & ApplicationEventBus. You should change your event bus to:

public interface MainEventBus extends EventBus {

    ...

    @Event(modulesToLoad = ApplicationModule.class)
    public void goToAppMainScreen();

}

Now the error message could be improved to help you understand why you have 
this error. I will change it for a future release.

Original comment by plcoir...@gmail.com on 27 Sep 2010 at 9:04

GoogleCodeExporter commented 9 years ago
Thanks for the quick reply. I was right that I had a slighly wrong 
understanding of how forwarding of events works.

Now it compiles fine.

Best regards,
Konrad Ciborowski
Kraków, Poland

Original comment by ci...@poczta.fm on 27 Sep 2010 at 9:31

GoogleCodeExporter commented 9 years ago

Original comment by plcoir...@gmail.com on 1 Oct 2010 at 11:48

GoogleCodeExporter commented 9 years ago

Original comment by plcoir...@gmail.com on 1 Oct 2010 at 11:48

GoogleCodeExporter commented 9 years ago
I also had this error message when my MainEventBus had a child module's view as 
its start view. I have a main module with two child modules, the application 
module itself and a login/registration module (might be a misuse, I'm just 
trying it out).
I put the startView=LoginPanel.class attribute on the MainEventBus, so Mvp4g 
wanted to bind the LoginPresenter with the MainEventBus, not the 
LoginModuleEventBus.

Another related exception I faced was "com.mvp4g.client.Mvp4gModule: child 
module ***.LoginMvp4gModule doesn't define any event to load its view." This 
was because the autoDisplay attribute of the ChildModule annotation defaults to 
true. There could be a hint in the exception about this property.

(Of course, I'm just trying the multi modules feature for the first time, so I 
don't yet clearly get the all concepts.)

Best regards,
Gabor

Original comment by hhcofc...@gmail.com on 1 Jun 2011 at 10:20