Skip to content

Commit 685ef46

Browse files
committed
feat(#117): clean
1 parent 7525a7f commit 685ef46

File tree

10 files changed

+118
-43
lines changed

10 files changed

+118
-43
lines changed

src/main/java/org/eolang/lints/errors/LtAtomIsNotUnique.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,18 @@
2626
import com.jcabi.xml.XML;
2727
import com.jcabi.xml.XSL;
2828
import com.jcabi.xml.XSLDocument;
29-
import java.io.IOException;
3029
import java.util.Collection;
3130
import java.util.HashSet;
3231
import java.util.LinkedList;
3332
import java.util.List;
3433
import java.util.Map;
3534
import java.util.Objects;
36-
import java.util.function.BiConsumer;
3735
import java.util.function.Function;
3836
import java.util.stream.Collectors;
3937
import java.util.stream.IntStream;
40-
import org.cactoos.io.InputOf;
4138
import org.cactoos.io.ResourceOf;
4239
import org.cactoos.io.UncheckedInput;
4340
import org.cactoos.list.ListOf;
44-
import org.cactoos.scalar.IoChecked;
45-
import org.cactoos.scalar.Unchecked;
4641
import org.cactoos.text.TextOf;
4742
import org.cactoos.text.UncheckedText;
4843
import org.eolang.lints.Defect;
@@ -51,8 +46,8 @@
5146

5247
/**
5348
* All FQNs that have `@atom` in the entire scope must be unique.
54-
* This lint already expects the presence of `@fqn` attribute for each atom `o`
55-
* in XMIR.
49+
* This lint firstly transforms the original XMIR into XMIR that contains `@fqn`
50+
* attributes for each atom `o`, and then lints it.
5651
*
5752
* @since 0.0.31
5853
*/
@@ -61,7 +56,7 @@ public final class LtAtomIsNotUnique implements Lint<Map<String, XML>> {
6156
/**
6257
* Stylesheet for adding `@fqn` attribute for atoms.
6358
*/
64-
private final XSL fqns;
59+
private final XSL pre;
6560

6661
/**
6762
* Ctor.
@@ -82,7 +77,7 @@ public LtAtomIsNotUnique() {
8277
* @param sheet Sheet
8378
*/
8479
public LtAtomIsNotUnique(final XSL sheet) {
85-
this.fqns = sheet;
80+
this.pre = sheet;
8681
}
8782

8883
@Override
@@ -94,7 +89,7 @@ public String name() {
9489
public Collection<Defect> defects(final Map<String, XML> pkg) {
9590
final Collection<Defect> defects = new LinkedList<>();
9691
final Map<XML, List<String>> index = pkg.values().stream()
97-
.map(this.fqns::transform)
92+
.map(this.pre::transform)
9893
.collect(Collectors.toMap(Function.identity(), LtAtomIsNotUnique::fqns));
9994
final Collection<String> checked = new HashSet<>(0);
10095
index.forEach(
@@ -186,7 +181,19 @@ private Defect sharedDefect(final XML xmir, final XML original, final String fqn
186181
}
187182

188183
private static List<String> fqns(final XML xmir) {
189-
return new ListOf<>(xmir.xpath("//o[@fqn]/@fqn"));
184+
final List<String> result;
185+
final List<String> fqns = xmir.xpath("//o[@fqn]/@fqn");
186+
if (xmir.nodes("/program/metas/meta[head='package']").size() == 1) {
187+
final String pack = xmir.xpath("/program/metas/meta[head='package']/tail/text()")
188+
.get(0);
189+
result = fqns.stream().map(fqn -> String.format("%s.%s", pack, fqn))
190+
.collect(Collectors.toList());
191+
} else {
192+
result = fqns;
193+
}
194+
return result.stream()
195+
.map(fqn -> String.format("Ф.%s", fqn))
196+
.collect(Collectors.toList());
190197
}
191198

192199
private static String oname(final String fqn) {

src/main/resources/org/eolang/funcs/atom-fqns.xsl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
The MIT License (MIT)
4+
5+
Copyright (c) 2016-2024 Objectionary.com
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included
15+
in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
-->
25+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="atom-fqns" version="2.0">
226
<xsl:template match="node()|@*">
327
<xsl:copy>
428
<xsl:apply-templates select="@*|node()"/>

src/test/java/org/eolang/lints/errors/LtAtomIsNotUniqueTest.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,43 @@ void allowsSameAtomsWithDifferentFqns() throws Exception {
8989
@Test
9090
void catchesAtomDuplicatesWithinSamePackage() throws Exception {
9191
MatcherAssert.assertThat(
92-
"Defects are empty, but they should not",
92+
"Defects should be reported",
9393
new LtAtomIsNotUnique().defects(
9494
new MapOf<String, XML>(
9595
new MapEntry<>(
9696
"foo-packaged",
9797
new ParsedEo(
98-
"org/eolang/lints/errors/atom-is-not-unique/foo-packaged.eo"
98+
"org/eolang/lints/errors/atom-is-not-unique/app-1.eo"
9999
).value()
100100
),
101101
new MapEntry<>(
102102
"bar-packaged",
103103
new ParsedEo(
104-
"org/eolang/lints/errors/atom-is-not-unique/bar-packaged.eo"
104+
"org/eolang/lints/errors/atom-is-not-unique/app-2.eo"
105+
).value()
106+
)
107+
)
108+
),
109+
Matchers.hasSize(2)
110+
);
111+
}
112+
113+
@Test
114+
void catchesNestedAtomDuplicates() throws Exception {
115+
MatcherAssert.assertThat(
116+
"Defects are empty, but they should not",
117+
new LtAtomIsNotUnique().defects(
118+
new MapOf<String, XML>(
119+
new MapEntry<>(
120+
"nested",
121+
new ParsedEo(
122+
"org/eolang/lints/errors/atom-is-not-unique/nested.eo"
123+
).value()
124+
),
125+
new MapEntry<>(
126+
"nested-dup",
127+
new ParsedEo(
128+
"org/eolang/lints/errors/atom-is-not-unique/nested-dup.eo"
105129
).value()
106130
)
107131
)
@@ -195,7 +219,7 @@ void allowsAtomsWithUniqueFqnsInSingleFile() throws Exception {
195219
}
196220

197221
@Test
198-
void allowsSameNameInComplexPackage() throws Exception {
222+
void allowsSameNameWithPackageDifference() throws Exception {
199223
MatcherAssert.assertThat(
200224
"Defects aren't empty, but they should",
201225
new LtAtomIsNotUnique().defects(

src/test/resources/org/eolang/lints/errors/atom-is-not-unique/foo-packaged.eo renamed to src/test/resources/org/eolang/lints/errors/atom-is-not-unique/app-1.eo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
+package xyz
2424

2525
# Foo.
26-
[] > foo
27-
[] > a /int
26+
[] > app
27+
[] > foo /int

src/test/resources/org/eolang/lints/errors/atom-is-not-unique/dup.eo renamed to src/test/resources/org/eolang/lints/errors/atom-is-not-unique/app-2.eo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
# Dup.
24-
[attr] > dup
25-
[] > foo /int
26-
[] > @
23+
+package xyz
24+
25+
# Foo app duplicate.
26+
[] > app
2727
[] > foo /int

src/test/resources/org/eolang/lints/errors/atom-is-not-unique/fqns.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/test/resources/org/eolang/lints/errors/atom-is-not-unique/bar-packaged.eo renamed to src/test/resources/org/eolang/lints/errors/atom-is-not-unique/nested-dup.eo

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
+package xyz
24-
25-
# Bar.
26-
[] > bar
27-
[] > a /int
23+
# Top object with nested atoms inside.
24+
[] > top
25+
[] > f
26+
[] > a
27+
[] > bar
28+
[] > abr /string
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2016-2024 Objectionary.com
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included
13+
# in all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
# Top object with nested atoms inside.
24+
[] > top
25+
[] > test /int
26+
[] > f
27+
[] > a
28+
[] > bar
29+
[] > abr /string

src/test/resources/org/eolang/lints/errors/atom-is-not-unique/x-packaged.eo

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
+package y
23+
+package xyz
2424

25-
# X.
26-
[] > x /string
25+
# X packaged.
26+
[] > app
27+
[] > x /string

src/test/resources/org/eolang/lints/errors/atom-is-not-unique/x.eo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
# SOFTWARE.
2222

2323
# X.
24-
[] > x /string
24+
[] > app
25+
[] > x /string

0 commit comments

Comments
 (0)