Skip to content

Commit f0081ce

Browse files
authored
Merge pull request #633 from h1alexbel/624
bug(#624): `LtInconsistentArgs` understands anonymous objects in path
2 parents cee4d59 + 6683d91 commit f0081ce

File tree

8 files changed

+112
-4
lines changed

8 files changed

+112
-4
lines changed

src/main/java/org/eolang/lints/LtInconsistentArgs.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private static String voidFqn(final String base, final Xnav object) {
279279
LtInconsistentArgs.parentTree(
280280
method
281281
),
282-
method.attribute("name").text().get(),
282+
LtInconsistentArgs.coordinates(method),
283283
base
284284
);
285285
}
@@ -293,7 +293,7 @@ private static String parentTree(final Xnav object) {
293293
final List<String> tree = new ListOf<>();
294294
Xnav current = LtInconsistentArgs.parentObject(object);
295295
while (!"object".equals(current.node().getNodeName())) {
296-
tree.add(current.attribute("name").text().get());
296+
tree.add(LtInconsistentArgs.coordinates(current));
297297
current = LtInconsistentArgs.parentObject(current);
298298
}
299299
final String result;
@@ -346,6 +346,21 @@ private static String relativizeToTopObject(final String base, final Xnav source
346346
return result;
347347
}
348348

349+
/**
350+
* Object coordinates.
351+
* @param object Object
352+
* @return Object coordinates
353+
*/
354+
private static String coordinates(final Xnav object) {
355+
final String result;
356+
if (object.attribute("name").text().isPresent()) {
357+
result = object.attribute("name").text().get();
358+
} else {
359+
result = ":anonymous";
360+
}
361+
return result;
362+
}
363+
349364
/**
350365
* Parent of the given object.
351366
* @param object Current object

src/main/java/org/eolang/lints/VoidXpath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public String asString() {
4242
IntStream.range(rstart + 1, normalized.size())
4343
.mapToObj(normalized::get)
4444
.collect(Collectors.joining(".", "$.", ""))
45-
);
45+
).replace("[@name=':anonymous']", "");
4646
}
4747
}

src/test/java/org/eolang/lints/VoidXpathTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ final class VoidXpathTest {
2020
@CsvSource(
2121
{
2222
"main.$.x.∅, //o[@name='main']/o[@base='$.x']",
23-
"foo.foo.foo.$.x.∅, //o[@name='foo']/o[@name='foo']/o[@name='foo']/o[@base='$.x']"
23+
"foo.foo.foo.$.x.∅, //o[@name='foo']/o[@name='foo']/o[@name='foo']/o[@base='$.x']",
24+
"@.foo.:anonymous.$.x.∅, //o[@name='@']/o[@name='foo']/o/o[@base='$.x']"
2425
}
2526
)
2627
void convertsToXpath(final String fqn, final String xpath) {

src/test/java/org/eolang/lints/WpaStory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.cactoos.map.MapEntry;
1818
import org.cactoos.map.MapOf;
1919
import org.eolang.parser.EoSyntax;
20+
import org.junit.jupiter.api.Assumptions;
2021
import org.xembly.Directives;
2122
import org.xembly.ImpossibleModificationException;
2223
import org.xembly.Xembler;
@@ -58,6 +59,7 @@ final class WpaStory {
5859
@SuppressWarnings("unchecked")
5960
public Map<List<String>, Map<XML, Map<String, XML>>> execute() throws IOException {
6061
final Map<String, Object> loaded = new Yaml().load(this.yaml);
62+
Assumptions.assumeTrue(loaded.get("skip") == null);
6163
final Map<String, XML> programs = new HashMap<>(0);
6264
loaded.forEach(
6365
(key, val) -> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
# yamllint disable rule:line-length
5+
# @todo #624:60min Enable `catches-inconsistency-in-nested-anonymous-formations` test story.
6+
# For now, its disabled because `LtInconsistentArgs` fails to convert parent tree with anonymous
7+
# objects to searchable XPath for the XMIR. We should change our logic in both
8+
# `LtInconsistentArgs#voidFqn()` and `VoidXpath`. Don't forget to enable
9+
# `catches-inconsistency-resolving-anonymous-path.yaml`,
10+
# `catches-inconsistency-when-parent-object-lacks-name.yaml`, and test stories as well.
11+
skip: true
12+
lints:
13+
- inconsistent-args
14+
asserts:
15+
- /defects[count(defect[@severity='warning'])=2]
16+
- /defects/defect[@line='9']
17+
- /defects/defect[@line='10']
18+
- /defects/defect[contains(normalize-space(), 'foo.@.:anonymous.@.:anonymous.@.:anonymous.$.x.∅')]
19+
- /defects/defect[contains(normalize-space(), 'clashes with [foo:9]')]
20+
- /defects/defect[contains(normalize-space(), 'clashes with [foo:10]')]
21+
foo.eo: |
22+
# Foo.
23+
[] > foo
24+
start > @
25+
[]
26+
i > @
27+
[]
28+
i > @
29+
[x]
30+
x 0 > x1
31+
x 0 1 > x2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
lints:
5+
- inconsistent-args
6+
asserts:
7+
- /defects[count(defect[@severity='warning'])=2]
8+
- /defects/defect[@line='5']
9+
- /defects/defect[@line='6']
10+
- /defects/defect[contains(normalize-space(), 'clashes with [foo:5]')]
11+
- /defects/defect[contains(normalize-space(), 'clashes with [foo:6]')]
12+
foo.eo: |
13+
# Foo.
14+
[x] > foo
15+
start > @
16+
[]
17+
x 0 > x1
18+
x 0 1 > x2
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
skip: true
5+
lints:
6+
- inconsistent-args
7+
asserts:
8+
- /defects[count(defect[@severity='warning'])=2]
9+
- /defects/defect[@line='7']
10+
- /defects/defect[@line='8']
11+
- /defects/defect[contains(normalize-space(), 'foo.@.:anonymous.$.x.∅')]
12+
- /defects/defect[contains(normalize-space(), 'clashes with [foo:7]')]
13+
- /defects/defect[contains(normalize-space(), 'clashes with [foo:8]')]
14+
foo.eo: |
15+
# Foo.
16+
[x] > foo
17+
x 0 > x1
18+
x 1 > x2
19+
start > @
20+
[x]
21+
$.x 0 > x1
22+
$.x 0 1 > x2
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
skip: true
5+
lints:
6+
- inconsistent-args
7+
asserts:
8+
- /defects[count(defect[@severity='warning'])=2]
9+
- /defects/defect[@line='5']
10+
- /defects/defect[@line='6']
11+
- /defects/defect[contains(normalize-space(), 'clashes with [foo:5]')]
12+
- /defects/defect[contains(normalize-space(), 'clashes with [foo:6]')]
13+
foo.eo: |
14+
# Foo.
15+
[] > foo
16+
start > @
17+
[x]
18+
x 0 > x1
19+
x 0 1 > x2

0 commit comments

Comments
 (0)