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

Update dependencies #1211

Merged
merged 3 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# throughout the whole project. This way of applying plugins was needed for the build-related code in buildSrc/src/main/,
# see https://docs.gradle.org/current/samples/sample_convention_plugins.html#things_to_note
[versions]
checker = "3.25.0"
checker = "3.26.0"
ideProbe = "0.45.0"
powerMock = "2.0.9"

[libraries]
# Libraries
archunit = "com.tngtech.archunit:archunit:0.23.1"
archunit = "com.tngtech.archunit:archunit:1.0.0"
betterStrings = "com.antkorwin:better-strings:0.5"
checker = { module = "org.checkerframework:checker", version.ref = "checker" }
checker-qual = { module = "org.checkerframework:checker-qual", version.ref = "checker" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void inner_classes_should_not_be_instantiated_from_constructor_of_enclosi
new DescribedPredicate<JavaConstructorCall>(
"an inner class is instantiated in a constructor of the enclosing class") {
@Override
public boolean apply(JavaConstructorCall input) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

from https://github.com/TNG/ArchUnit/releases/tag/v1.0.0-rc1:

DescribedPredicate now extends the JDK 8 Predicate, so apply(..) has to be replaced by test(..)

I think it only required change to get it working. However, all the changes and features may be worth reviewing and possibly applied

Copy link
Collaborator

Choose a reason for hiding this comment

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

Potentially relevant changes:

Accesses from inside of lambdas are now correctly detected. Before, the origin was set as a synthetic method like lambda$xxx$123 instead. JavaAccess can now be queried for isDeclaredInLambda() to distinguish this from an access outside of a lambda (see TNG/ArchUnit#847; thanks a lot to @oberprah, @FrederikFinckh)

New methods codeUnits().should().onlyBeCalled().by{Classes/Methods/...}That(..)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Opened #1212

Copy link
Collaborator

Choose a reason for hiding this comment

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

Accesses from inside of lambdas are now correctly detected

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, i got it

Copy link
Collaborator

Choose a reason for hiding this comment

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

somehow it lambdas pass this check:

if (method.getName().startsWith("access$") || method.getName().startsWith("lambda$")) {
     return;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

but we can now use:

if (call.isDeclaredInLambda()) {
    // ignore
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

To be fixed within #1212

public boolean test(JavaConstructorCall input) {
if (input.getOrigin().isConstructor()) {
JavaClass constructingClass = input.getOriginOwner();
JavaClass constructedClass = input.getTargetOwner();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public void actions_overriding_onUpdate_should_call_super_onUpdate() {
.areNotAssignableFrom(com.virtuslab.gitmachete.frontend.actions.base.BaseProjectDependentAction.class)
.and(new DescribedPredicate<JavaClass>("override onUpdate method") {
@Override
public boolean apply(JavaClass input) {
public boolean test(JavaClass input) {
return input.getMethods().stream().anyMatch(method -> method.getName().equals("onUpdate"));
}
})
.should()
.callMethodWhere(
new DescribedPredicate<JavaMethodCall>("name is onUpdate and owner is the direct superclass") {
@Override
public boolean apply(JavaMethodCall input) {
public boolean test(JavaMethodCall input) {
JavaCodeUnit origin = input.getOrigin(); // where is the method called from?
AccessTarget.MethodCallTarget target = input.getTarget(); // where is the method declared?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ public void check(JavaMethod method, ConditionEvents events) {
}
}

method.getCallsFromSelf().forEach(access -> {
AccessTarget accessTarget = access.getTarget();
if (accessTarget.isAnnotatedWith(UIThreadUnsafe.class)) {
method.getCallsFromSelf().forEach(call -> {
AccessTarget accessTarget = call.getTarget();
if (call.isDeclaredInLambda()) {
// ignore
} else if (accessTarget.isAnnotatedWith(UIThreadUnsafe.class)) {
String message = "a non-${UIThreadUnsafeName} method ${method.getFullName()} " +
"calls a ${UIThreadUnsafeName} method ${accessTarget.getFullName()}";
events.add(SimpleConditionEvent.violated(method, message));
Expand Down Expand Up @@ -156,7 +158,9 @@ public void check(JavaMethod method, ConditionEvents events) {
AccessTarget.CodeUnitCallTarget callTarget = call.getTarget();
String callTargetPackageName = callTarget.getOwner().getPackageName();
String calledMethodFullName = callTarget.getFullName();
if (callTargetPackageName.startsWith("git4idea")) {
if (call.isDeclaredInLambda()) {
// ignore
} else if (callTargetPackageName.startsWith("git4idea")) {
if (!Arrays.asList(whitelistedMethodFullNames_git4idea).contains(calledMethodFullName)) {
String message = "a non-${UIThreadUnsafeName} method ${method.getFullName()} " +
"calls method ${calledMethodFullName} from git4idea";
Expand Down