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

Fix issue #12 #142

Merged
merged 1 commit into from
Sep 16, 2024
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
44 changes: 23 additions & 21 deletions engine/src/main/java/com/ibm/engine/detection/DetectionStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,25 @@ public void attach(int index, @Nonnull final DetectionStore<R, T, S, P> detectio
}

void addValue(int index, @Nonnull final IValue<T> iValue) {
this.detectionValues.compute(
addValue(this, index, iValue);
}

void addValue(
@Nonnull DetectionStore<R, T, S, P> detectionStore,
int index,
@Nonnull final IValue<T> iValue) {
detectionStore.detectionValues.compute(
index,
(i, list) -> {
if (list == null) {
// If the list is null, create a new ArrayList
// with the iValue and return it
final List<IValue<T>> values = new ArrayList<>();
values.add(iValue);
return values;
} else {
// If the list is not null, add the iValue to it
// and return the modified list
list.add(iValue);
return list;
}
Expand Down Expand Up @@ -289,7 +300,7 @@ public void onReceivingNewDetection(@Nonnull IDetection<T> detection) {
final Optional<Integer> positionMove = detectableParameter.getShouldBeMovedUnder();
// Check if the parameter should be moved under
if (positionMove.isPresent()) {
final Integer id = positionMove.get();
final int id = positionMove.get();
// Get the iValue to be detected and store it in a variable
valueDetection
.toValue(valueDetection.detectableParameter().getiValueFactory())
Expand All @@ -304,30 +315,15 @@ public void onReceivingNewDetection(@Nonnull IDetection<T> detection) {
handler,
statusReporting);
// Compute the detection values for the given id
detectionStore.detectionValues.compute(
id,
(i, list) -> {
if (list == null) {
// If the list is null, create a new ArrayList
// with the iValue and return it
final List<IValue<T>> values =
new ArrayList<>();
values.add(iValue);
return values;
} else {
// If the list is not null, add the iValue to it
// and return the modified list
list.add(iValue);
return list;
}
});
addValue(detectionStore, id, iValue);
// Attach the detection store to the given id
this.attach(id, detectionStore);
});
} else {
valueDetection
.toValue(valueDetection.detectableParameter().getiValueFactory())
.ifPresent(iValue -> addValue(detectableParameter.getIndex(), iValue));
.ifPresent(
iValue -> addValue(this, detectableParameter.getIndex(), iValue));
}

// follow method parameter related detection rules
Expand All @@ -350,7 +346,13 @@ public void onReceivingNewDetection(@Nonnull IDetection<T> detection) {
// follow invoked object (object where the method was executed on) related detection
// rules
final TraceSymbol<S> traceSymbol = getAssignedTraceSymbol(valueDetection.expression());
final List<IDetectionRule<T>> nextDetectionRules = detectionRule.nextDetectionRules();

final List<IDetectionRule<T>> nextDetectionRules;
if (positionMove.isPresent()) {
nextDetectionRules = List.of();
} else {
nextDetectionRules = detectionRule.nextDetectionRules();
}
this.statusReporting.addAdditionalExpectedRuleVisits(nextDetectionRules.size());
handler.getLanguageSupport()
.getEnclosingMethod(detection.expression())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.sonar.plugins.java.api.semantic.Symbol;
import org.sonar.plugins.java.api.tree.Tree;

public class DuplicateDependingRules2Test extends TestBase {
class DuplicateDependingRules2Test extends TestBase {

static IDetectionContext detectionContext =
new IDetectionContext() {
Expand Down Expand Up @@ -96,7 +96,7 @@ public void asserts(

List<DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext>> stores =
getStoresOfValueType(Algorithm.class, detectionStore.getChildren());
assertThat(stores).hasSize(3);
assertThat(stores).hasSize(2);

DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext> store_1 = stores.get(0);
assertThat(store_1.getDetectionValues()).hasSize(1);
Expand Down
Loading