-
Notifications
You must be signed in to change notification settings - Fork 299
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
#704: added onlyBeCalledByClassesThat conjuntion - initial part #810
Conversation
Thanks a lot for tackling this, we really appreciate it 😄 Also good idea to reach out early so we can discuss unclear points 👍 To answer your questions:
|
@@ -171,6 +171,12 @@ public JavaClass getRawReturnType() { | |||
return fieldAccesses; | |||
} | |||
|
|||
@PublicAPI(usage = ACCESS) | |||
public abstract Set<? extends JavaAccess<?>> getCallsOfSelf(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't the bound here be JavaCall
instead of JavaAccess
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
* @see #getCallsOfSelf() | ||
*/ | ||
@PublicAPI(usage = ACCESS) | ||
public static final ChainableFunction<JavaCodeUnit, Set<? extends JavaAccess<?>>> GET_CALLS_TO_SELF = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By convention the constant name should be the exact method name in upper case. I.e. if the getter is getCallsOfSelf
then the function should be GET_CALLS_OF_SELF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected.
@PublicAPI(usage = ACCESS) | ||
public Set<JavaConstructorCall> getCallsOfSelf() { | ||
return getReverseDependencies().getCallsTo(this); | ||
} | ||
|
||
@PublicAPI(usage = ACCESS) | ||
public Set<JavaConstructorCall> getMethodCallsOfSelf() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is confusing to me because "get method calls..." sounds to me as if it would return JavaMethodCall
. But instead it's returning JavaConstructorCall
which is no "method call". I know where you're coming from, but I think we need to find a different naming here 🤔 Maybe it would be something like getCallsOfSelfByMethods
or ...FromMethods
? 🤔 Or if we only need it in one place we don't add a new API method and simply filter in the one place 🤷♂️ We should ponder carefully if this is a common use case that should go in the API or not...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method was removed as all calls should be analyzed not only calls done by methods.
@Override | ||
@PublicAPI(usage = ACCESS) | ||
public boolean isMethod() { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to override this because the default is false
anyway, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I've missed that.
@Override | ||
@PublicAPI(usage = ACCESS) | ||
public boolean isConstructor() { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, the default is false
anyway. As long as we go with a default (which you could question 🤷♂️) we should use it then I guess...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Thanks @codecholeric for quick review and feedback :). I’ve made corrections and added methods onlyBeCalled().byConstructorsThat(DescribedPredicate predicate) / onlyBeCalled().byCodeUnitsThat(DescribedPredicate predicate). Ad. 2. I’ve implemented logic as follows: Currently below listed posibilities are implemented but I’m not sure if all of them are needed. constructors()/methods()/codeUnits().should().onlyBeCalledByClassesThat(DescribedPredicate predicate) |
Thanks a lot for all your hard work 🙏 😄 Yes, I think there are already enough separate ways to express the same thing, we should probably not introduce both versions |
Thanks for confirmation. |
* <br><br> | ||
* E.g. | ||
* <pre><code> | ||
* {@link ArchRuleDefinition#codeUnits() codeUnits()}.{@link GivenCodeUnits#should() should()}.{@link CodeUnitsShould#onlyBeCalled()} onlyBeCalled().{@link OnlyBeCalledSpecification#byClassesThat(DescribedPredicate)} byClassesThat(equivalentTo(SomeClass.class))} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the version with predicate byClassesThat(equivalentTo(SomeClass.class))
maybe we can give an example with the fluent API, e.g. byClassesThat().areAnnotatedWith(SomeAnnotation.class)
or something like that? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used example from tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for all this hard word, very nice 😍 To me your Javadoc looks good, I added some minor suggestions to adjust it, but in general it's exactly how I imagined it 😃 Doesn't need to be a novel, but the important point (e.g. that byConstructors
excludes methods) should be prominent 👍
I added some comments about minor things I noticed that could maybe be improved if you're still motivated?
In a future PR we can also fix the generics on MembersThat
/CodeUnitsThat
/... so that it can be offered as a fluent API completion of byCodeUnitsThat()
🙂 (But I consider that out of scope for this PR)
archunit/src/main/java/com/tngtech/archunit/core/domain/JavaCodeUnit.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/core/domain/JavaCodeUnit.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/conditions/CodeUnitCallsCondition.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/OnlyBeCalledSpecification.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/CodeUnitsShould.java
Outdated
Show resolved
Hide resolved
...main/java/com/tngtech/archunit/lang/syntax/OnlyBeCalledConstructorSpecificationInternal.java
Outdated
Show resolved
Hide resolved
archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/CodeUnitsShouldTest.java
Outdated
Show resolved
Hide resolved
archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/CodeUnitsShouldTest.java
Outdated
Show resolved
Hide resolved
archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/CodeUnitsShouldTest.java
Outdated
Show resolved
Hide resolved
Yes, still motivated😃 but I will be able to work on changes from Wednesday next week. |
Hi, I've added modification for almost all comments, hope my understanding was correct 😄 There is one which I'm not sure about: There are 4 methods in ArchConditions using the same class CodeUnitOnlyCallsCondition, each with different description (i.e. "only be called by classes that “, “only be called by methods that ")
I think I can work on that PR also. |
33f382b
to
e4bf93f
Compare
... which allows restricting callers of code units via * `...onlyBeCalled().byClassesThat(..)` * `...onlyBeCalled().byMethodsThat(..)` * `...onlyBeCalled().byConstructorsThat(..)` * `...onlyBeCalled().byCodeUnitsThat(..)` Signed-off-by: Justyna Kubica-Ledzion <justyna.kubica-ledzion@digitalnewagency.com>
e4bf93f
to
0bc8cef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing all the comments and all your hard work!! I've squashed it now and adjusted the message a little bit to make it ready to be merged 🙂
Gonna merge as soon as CI is green 🚀
BTW: I've already fixed up the generics on |
Initial part of work for issue #704. Work is in progress but it would be great to receive some feedback if it goes in right direction.
I’ve started from adding method onlyBeCalledByClassesThat(DescribedPredicate predicate) to CodeUnitsShould.
Now I’m working on possibility to have a rule like:
should().onlyBeCalled().{byClassesThat()/methodsThat()/constructorsThat()}.
Could you let me know if my understanding of the issue is correct for below points?
I would appreciate any feedback.
Justyna
Signed-off-by: Justyna Kubica-Ledzion justyna.kubica-ledzion@digitalnewagency.com