Skip to content

Commit 86d6a8d

Browse files
committed
fix #12
Signed-off-by: Nicklas Körtge <[email protected]>
1 parent af7d128 commit 86d6a8d

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

engine/src/main/java/com/ibm/engine/detection/DetectionStore.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,25 @@ public void attach(int index, @Nonnull final DetectionStore<R, T, S, P> detectio
222222
}
223223

224224
void addValue(int index, @Nonnull final IValue<T> iValue) {
225-
this.detectionValues.compute(
225+
addValue(this, index, iValue);
226+
}
227+
228+
void addValue(
229+
@Nonnull DetectionStore<R, T, S, P> detectionStore,
230+
int index,
231+
@Nonnull final IValue<T> iValue) {
232+
detectionStore.detectionValues.compute(
226233
index,
227234
(i, list) -> {
228235
if (list == null) {
236+
// If the list is null, create a new ArrayList
237+
// with the iValue and return it
229238
final List<IValue<T>> values = new ArrayList<>();
230239
values.add(iValue);
231240
return values;
232241
} else {
242+
// If the list is not null, add the iValue to it
243+
// and return the modified list
233244
list.add(iValue);
234245
return list;
235246
}
@@ -289,7 +300,7 @@ public void onReceivingNewDetection(@Nonnull IDetection<T> detection) {
289300
final Optional<Integer> positionMove = detectableParameter.getShouldBeMovedUnder();
290301
// Check if the parameter should be moved under
291302
if (positionMove.isPresent()) {
292-
final Integer id = positionMove.get();
303+
final int id = positionMove.get();
293304
// Get the iValue to be detected and store it in a variable
294305
valueDetection
295306
.toValue(valueDetection.detectableParameter().getiValueFactory())
@@ -304,30 +315,15 @@ public void onReceivingNewDetection(@Nonnull IDetection<T> detection) {
304315
handler,
305316
statusReporting);
306317
// Compute the detection values for the given id
307-
detectionStore.detectionValues.compute(
308-
id,
309-
(i, list) -> {
310-
if (list == null) {
311-
// If the list is null, create a new ArrayList
312-
// with the iValue and return it
313-
final List<IValue<T>> values =
314-
new ArrayList<>();
315-
values.add(iValue);
316-
return values;
317-
} else {
318-
// If the list is not null, add the iValue to it
319-
// and return the modified list
320-
list.add(iValue);
321-
return list;
322-
}
323-
});
318+
addValue(detectionStore, id, iValue);
324319
// Attach the detection store to the given id
325320
this.attach(id, detectionStore);
326321
});
327322
} else {
328323
valueDetection
329324
.toValue(valueDetection.detectableParameter().getiValueFactory())
330-
.ifPresent(iValue -> addValue(detectableParameter.getIndex(), iValue));
325+
.ifPresent(
326+
iValue -> addValue(this, detectableParameter.getIndex(), iValue));
331327
}
332328

333329
// follow method parameter related detection rules
@@ -350,7 +346,13 @@ public void onReceivingNewDetection(@Nonnull IDetection<T> detection) {
350346
// follow invoked object (object where the method was executed on) related detection
351347
// rules
352348
final TraceSymbol<S> traceSymbol = getAssignedTraceSymbol(valueDetection.expression());
353-
final List<IDetectionRule<T>> nextDetectionRules = detectionRule.nextDetectionRules();
349+
350+
final List<IDetectionRule<T>> nextDetectionRules;
351+
if (positionMove.isPresent()) {
352+
nextDetectionRules = List.of();
353+
} else {
354+
nextDetectionRules = detectionRule.nextDetectionRules();
355+
}
354356
this.statusReporting.addAdditionalExpectedRuleVisits(nextDetectionRules.size());
355357
handler.getLanguageSupport()
356358
.getEnclosingMethod(detection.expression())

java/src/test/java/com/ibm/plugin/rules/issues/DuplicateDependingRules2Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.sonar.plugins.java.api.semantic.Symbol;
4242
import org.sonar.plugins.java.api.tree.Tree;
4343

44-
public class DuplicateDependingRules2Test extends TestBase {
44+
class DuplicateDependingRules2Test extends TestBase {
4545

4646
static IDetectionContext detectionContext =
4747
new IDetectionContext() {
@@ -96,7 +96,7 @@ public void asserts(
9696

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

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

0 commit comments

Comments
 (0)