czyzby / gdx-lml

:octocat: LibGDX utility libraries.
Apache License 2.0
159 stars 25 forks source link

[Autumn] ViewStageAnnotationProcessor doesn't work for subsclasses #70

Closed metaphore closed 6 years ago

metaphore commented 6 years ago

I'm not sure if this is by design for Autumn to not support injection for fields of a superclass, but since @Inject works fine in that case, I think it would be nice to change ViewStageAnnotationProcessor so it does the same too.

Here is one line I've changed in ViewStageAnnotationProcessor and looks like there is no problem with it:

@Override
public void processField(final Field field, final ViewStage annotation, final Object component,
        final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
    if (!Stage.class.equals(field.getType())) {
        throw new GdxRuntimeException("Only Scene2D stages can be annotated with @ViewStage. Found type:"
                + field.getType() + " in field: " + field + " of component: " + component + ".");
    }
//  final Class<?> controllerClass = field.getDeclaringClass(); // Old line
    final Class<?> controllerClass = component.getClass();  // New line
    if (!registerField(field, interfaceService.getController(controllerClass))) {
        // If view controller not found, trying out dialog controllers:
        if (!registerField(field, interfaceService.getDialogController(controllerClass))) {
            throw new GdxRuntimeException(
                    "Unable to assign stage in field: " + field + " of component: " + component + ".");
        }
    }
}
czyzby commented 6 years ago

Pretty sure it's just the way it happened to be implemented. Would you mind submitting a pull request and checking if it works on GWT?

metaphore commented 6 years ago

Sure, will do

metaphore commented 6 years ago

@czyzby I guess you mean made PR and then try maven snapshot? But I'm just curious, is there an easy way to test lib from sources on GWT?

czyzby commented 6 years ago

gradle build install adds the lib to your Maven Local repo. Add mavenLocal() at the top of your project's build.gradle repositories and it will automatically choose your local version.

metaphore commented 6 years ago

Oh, that's the way, thanks!