Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return bean proxy for model. #911

Merged
merged 7 commits into from Jun 7, 2016
Merged

Return bean proxy for model. #911

merged 7 commits into from Jun 7, 2016

Conversation

denis-anisimov
Copy link
Contributor

@denis-anisimov denis-anisimov commented Jun 3, 2016

Provides a proxy for the given part of the model whose changes are
reflected back to the model

Fixes #731.


This change is Reviewable

pleku and others added 3 commits June 2, 2016 10:59
Provides a proxy for the given part of the model whose changes are
reflected back to the model

Fixes #731.
Conflicts:
	hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModel.java
Conflicts:
	hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModel.java
	hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelBeanUtil.java
	hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelProxyHandler.java
	hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java
modelType.getName()), e);
} catch (IllegalAccessException e) {
// this should not happen
throw new RuntimeException(String.format(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Define and throw a dedicated exception instead of using a generic one. rule


throw new UnsupportedOperationException(
getUnsupportedMethodMessage(method, args));
private static boolean isAccessor(MethodDescription method) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Private method 'isAccessor' is never used. rule

Conflicts:
	hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModel.java
	hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelBeanUtil.java
	hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelProxyHandler.java
@Artur-
Copy link
Member

Artur- commented Jun 6, 2016

Reviewed 2 of 6 files at r2, 3 of 4 files at r4, 1 of 2 files at r5.
Review status: 6 of 7 files reviewed at latest revision, 8 unresolved discussions.


hummingbird-server/pom.xml, line 102 [r5] (raw file):

      <dependency>
          <groupId>net.bytebuddy</groupId>
          <artifactId>byte-buddy</artifactId>

Does byte-buddy work with OSGi?


hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModel.java, line 125 [r5] (raw file):

    default <T> T getProxy(String modelPath, Class<T> beanType) {
        // The method is handled by proxy handler
        return null;

Should you rather throw an exception if you for whatever reason reach this code?


hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelBeanUtil.java, line 141 [r5] (raw file):

        StateNode node = stateNode;
        StringTokenizer tokenizer = new StringTokenizer(modelPath, ".");

FYI If you use String.split you do not have to loop an extra round and then undo the last loop using node.getParent() and last


hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelProxyHandler.java, line 130 [r5] (raw file):

                        ClassLoadingStrategy.Default.WRAPPER)
                .getLoaded();
        Optional<Constructor<?>> defaultCtor = Stream

Constructor defaultCtor = modelType.getConstructor() ?


Comments from Reviewable

@denis-anisimov
Copy link
Contributor Author

Review status: 5 of 7 files reviewed at latest revision, 7 unresolved discussions.


hummingbird-server/pom.xml, line 102 [r5] (raw file):

Previously, Artur- (Artur) wrote…

Does byte-buddy work with OSGi?

Should work. Didn't find any known issues. It's more about how it's used to be compatible with OSGi: is current implementation is good for OSGi ? There are two possible issues: correct class loader which is used to load proxy class and instantiation using reflection (see the code). But that's a bit different topic.

hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModel.java, line 125 [r5] (raw file):

Previously, Artur- (Artur) wrote…

Should you rather throw an exception if you for whatever reason reach this code?

Done.

hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelBeanUtil.java, line 141 [r5] (raw file):

Previously, Artur- (Artur) wrote…

FYI If you use String.split you do not have to loop an extra round and then undo the last loop using node.getParent() and last

With a split it will look like this:
modelPath.split("\\.'");

So the argument is 3 characters string and split will use real regexp to do split (for one/two characters string simplified logic is used).
It has no sense to use regexp here for such simple case. Although the code becomes shorter of course..

So it longer code vs unnecessary regexp usage : I\m not sure what's better.


hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelProxyHandler.java, line 130 [r5] (raw file):

Previously, Artur- (Artur) wrote…

Constructor defaultCtor = modelType.getConstructor() ?

The `modelType.getConstructor()` method throws an exception if there is no default CTOR (as almost any method in reflection API).

Comments from Reviewable

@Artur-
Copy link
Member

Artur- commented Jun 6, 2016

Reviewed 1 of 1 files at r6.
Review status: 6 of 7 files reviewed at latest revision, 6 unresolved discussions.


hummingbird-server/pom.xml, line 102 [r5] (raw file):

Previously, denis-anisimov wrote…

Should work. Didn't find any known issues.
It's more about how it's used to be compatible with OSGi: is current implementation is good for OSGi ?
There are two possible issues: correct class loader which is used to load proxy class and instantiation using reflection (see the code).
But that's a bit different topic.

Added comment to OSGi issue https://github.com//issues/455

hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelBeanUtil.java, line 141 [r5] (raw file):

Previously, denis-anisimov wrote…

With a split it will look like this:

modelPath.split("\\.'");

So the argument is 3 characters string and split will use real regexp to do split (for one/two characters string simplified logic is used).
It has no sense to use regexp here for such simple case. Although the code becomes shorter of course..

So it longer code vs unnecessary regexp usage : I\m not sure what's better.

"StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead."

hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelProxyHandler.java, line 130 [r5] (raw file):

Previously, denis-anisimov wrote…

The modelType.getConstructor() method throws an exception if there is no default CTOR (as almost any method in reflection API).

Which is what you also want to do here if there is no public constructor?

Comments from Reviewable

@denis-anisimov
Copy link
Contributor Author

Review status: 5 of 7 files reviewed at latest revision, 5 unresolved discussions.


hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelBeanUtil.java, line 141 [r5] (raw file):

Previously, Artur- (Artur) wrote…

"StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead."

Would be better if they just deprecated the class.

And by the way I cannot avoid extra loop and using node.getParent() because I need to call resolveStateNode method to satisfy getModelValue method which checks the value type.


hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelProxyHandler.java, line 130 [r5] (raw file):

Previously, Artur- (Artur) wrote…

Which is what you also want to do here if there is no public constructor?

Several reasons: 1) getConstructor() throws generic reflection checked exception. Which means it has to be caught and rethrown. 2) The constructor may be available but is not public. As a result the logic will contain one more catch that just rethrows an exception and still requires check for public modifier.

The easier way would be to avoid check for CTOR at all and just do proxy.newInstance();. But then messages in rethrown exceptions are not explanatory enough.


Comments from Reviewable

@Artur-
Copy link
Member

Artur- commented Jun 7, 2016

Reviewed 1 of 2 files at r5, 1 of 1 files at r7.
Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed.


hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelBeanUtil.java, line 293 [r7] (raw file):

                        + getSupportedTypesString());
    }
}

Newline


hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java, line 674 [r7] (raw file):

    }

    private void verifyBeanValue(ModelMap feature, Supplier<Object> getter,

verifyBeanValue sounds like it verifies a value in a bean but in reality it sets a property in a model map and validates that the given getter returns that value?


hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java, line 683 [r7] (raw file):

            String beanPath1, String beanPath2, String property,
            Serializable expected) {
        Serializable bean = template.getElement().getNode()

FYI Most of the three last verify* methods are about fetching the model map for a given path, which could be extracted to a helper taking a dot separated path


Comments from Reviewable

@denis-anisimov
Copy link
Contributor Author

Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed.


hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelBeanUtil.java, line 293 [r7] (raw file):

Previously, Artur- (Artur) wrote…

Newline

Done.

hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java, line 674 [r7] (raw file):

Previously, Artur- (Artur) wrote…

verifyBeanValue sounds like it verifies a value in a bean but in reality it sets a property in a model map and validates that the given getter returns that value?

Yes, and what do you suggest as a better name here ?

Comments from Reviewable

@Artur-
Copy link
Member

Artur- commented Jun 7, 2016

Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java, line 674 [r7] (raw file):

Previously, denis-anisimov wrote…

Yes, and what do you suggest as a better name here ?

setModelAndVerifyUsingGetter? setModelPropertyAndVerifyGetter?

Comments from Reviewable

@denis-anisimov
Copy link
Contributor Author

Review status: 5 of 7 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java, line 674 [r7] (raw file):

Previously, Artur- (Artur) wrote…

setModelAndVerifyUsingGetter?
setModelPropertyAndVerifyGetter?

Done.

hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java, line 683 [r7] (raw file):

Previously, Artur- (Artur) wrote…

FYI Most of the three last verify* methods are about fetching the model map for a given path, which could be extracted to a helper taking a dot separated path

I'm not sure that in the tests it's the best approach : it's absolutely clear what's going on with the model without cycle. But let it be.

Comments from Reviewable

@Artur-
Copy link
Member

Artur- commented Jun 7, 2016

Reviewed 1 of 2 files at r8, 3 of 3 files at r9.
Review status: all files reviewed at latest revision, 4 unresolved discussions.


hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java, line 683 [r7] (raw file):

Previously, denis-anisimov wrote…

I'm not sure that in the tests it's the best approach : it's absolutely clear what's going on with the model without cycle.
But let it be.

The test is easier to understand for me at least when there is one parameter for the path.

Now you just need to extract the duplicated code to a method like getModelMap(String beanPath)


Comments from Reviewable

Conflicts:
	hummingbird-server/src/main/java/com/vaadin/hummingbird/template/model/TemplateModelProxyHandler.java
@denis-anisimov
Copy link
Contributor Author

Review status: 6 of 7 files reviewed at latest revision, 4 unresolved discussions.


hummingbird-server/src/test/java/com/vaadin/hummingbird/template/model/TemplateModelTest.java, line 683 [r7] (raw file):

Previously, Artur- (Artur) wrote…

The test is easier to understand for me at least when there is one parameter for the path.

Now you just need to extract the duplicated code to a method like getModelMap(String beanPath)

Done.

Comments from Reviewable

@vaadin-tc
Copy link

SonarQube analysis reported 4 issues

  • MAJOR 4 major

Watch the comments in this conversation to review them.

1 extra issue

Note: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:

  1. MAJOR TemplateModelBeanUtil.java#L246: The Cyclomatic Complexity of this method "getModelValueBasicType" is 11 which is greater than 10 authorized. rule

@Artur-
Copy link
Member

Artur- commented Jun 7, 2016

Reviewed 1 of 1 files at r10.
Review status: all files reviewed at latest revision, 3 unresolved discussions.


Comments from Reviewable

@Artur- Artur- merged commit 8694dad into master Jun 7, 2016
@Artur- Artur- deleted the 731-proxy-bean branch June 7, 2016 10:49
@Artur- Artur- removed the in progress label Jun 7, 2016
@Artur- Artur- modified the milestone: 0.0.9 Jun 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants