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

Improve numberOfUsages calculation #10

Open
neiser opened this issue Nov 30, 2020 · 0 comments · May be fixed by #15
Open

Improve numberOfUsages calculation #10

neiser opened this issue Nov 30, 2020 · 0 comments · May be fixed by #15

Comments

@neiser
Copy link
Collaborator

neiser commented Nov 30, 2020

Currently, the numberOfUsages parameter for ReferenceDeciderForType is calculated by the number of setters which are going to consume the referenced item. This is a good estimate, but in general not correct for any case: For example, consider a Schema which is multiply used by identical ApiResponses, but in turn this ApiResponse is also referenced itself. Then the actual usage of that schema is 1, as the Schema is only used by one ApiResponse, but the number of setters is not merged in AbstractReferencedItemStorage, as the referencing of ApiResponses happens later than the referencing of Schemas.

Have a look at AbstractReferencedItemStorage method for a starting idea:

    @Nullable
    private Object findSetterTarget(Consumer<T> setter) {
        Field[] declaredFields = setter.getClass().getDeclaredFields();
        if (declaredFields.length == 1) {
            Field declaredField = declaredFields[0];
            declaredField.setAccessible(true);
            try {
                return declaredField.get(setter);
            } catch (IllegalAccessException e) {
                // this should not happen, as we've made it accessible...
                return null;
            }
        }
        return null;
    }

This is a hard issue, but you can learn a lot about how referencing of items is done internally in this library.

neiser added a commit that referenced this issue Nov 30, 2020
neiser added a commit that referenced this issue Dec 7, 2020
@neiser neiser linked a pull request Dec 7, 2020 that will close this issue
neiser added a commit that referenced this issue Jun 28, 2021
@neiser neiser linked a pull request Sep 26, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

1 participant