walk = Files.walk(dir)) {
+ return walk
+ .filter(Files::isRegularFile)
+ .collect(
+ Collectors.toMap(
+ path -> new XmirKey(path, dir).asString(),
+ path -> {
+ try {
+ return new XMLDocument(path);
+ } catch (final FileNotFoundException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+ }
+ )
+ );
+ }
+ }
+
+}
diff --git a/src/main/java/org/eolang/lints/PkWpa.java b/src/main/java/org/eolang/lints/PkWpa.java
index f8834bc07..f03ab2b2f 100644
--- a/src/main/java/org/eolang/lints/PkWpa.java
+++ b/src/main/java/org/eolang/lints/PkWpa.java
@@ -13,8 +13,8 @@
import org.cactoos.list.ListOf;
/**
- * A collection of lints for Whole Program Analysis (WPA),
- * provided by the {@link Program} class.
+ * A collection of lints for Whole Package Analysis (WPA),
+ * provided by the {@link EoPackage} class.
*
* This class is thread-safe.
*
diff --git a/src/main/java/org/eolang/lints/Program.java b/src/main/java/org/eolang/lints/Program.java
index 3d5fbfec8..bfda076fc 100644
--- a/src/main/java/org/eolang/lints/Program.java
+++ b/src/main/java/org/eolang/lints/Program.java
@@ -5,22 +5,15 @@
package org.eolang.lints;
import com.jcabi.xml.XML;
-import com.jcabi.xml.XMLDocument;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.cactoos.iterable.Sticky;
-import org.cactoos.list.ListOf;
-import org.cactoos.list.Synced;
+import org.cactoos.func.CheckedFunc;
/**
* Whole EO program, as collection of XMIR sources to analyze.
@@ -29,43 +22,38 @@
*
* {@code
* import com.jcabi.manifests.Manifests;
- *
* final String version = Manifests.read("Lints-Version");
* }
*
+ *
* @see XMIR
- * @since 0.1.0
+ * @since 0.0.49
*/
-public final class Program {
-
- /**
- * Collection of mono lints, preloaded on JVM start.
- */
- private static final Iterable>> WPA = new Synced<>(
- new ListOf<>(
- new Sticky<>(
- new PkWpa()
- )
- )
- );
-
+public class Program {
/**
- * Lints to use.
+ * EO package.
*/
- private final Iterable>> lints;
+ private final EoPackage pkg;
/**
- * The program package of XMIR files.
+ * All sources of EO package {@link #pkg}.
*/
- private final Map pkg;
+ private final Collection srcs;
/**
* Ctor.
+ *
* @param dirs The directory
* @throws IOException If fails
*/
public Program(final Path... dirs) throws IOException {
- this(Arrays.asList(dirs));
+ this(
+ new EoPackage(dirs),
+ Program.sources(
+ Arrays.asList(dirs),
+ new CheckedFunc<>(Source::new, IOException.class::cast)
+ )
+ );
}
/**
@@ -78,103 +66,68 @@ public Program(final Path... dirs) throws IOException {
* @throws IOException If fails
*/
public Program(final Collection dirs) throws IOException {
- this(Program.discover(dirs));
+ this(
+ new EoPackage(dirs),
+ Program.sources(dirs, new CheckedFunc<>(Source::new, IOException.class::cast))
+ );
}
/**
* Ctor.
+ *
* @param map The map with them
*/
public Program(final Map map) {
- this(map, Program.WPA);
+ this(
+ new EoPackage(map),
+ Program.sources(
+ map.values(),
+ new CheckedFunc<>(Source::new, RuntimeException.class::cast)
+ )
+ );
}
- /**
- * Ctor.
- *
- * This constructor is for internal use only. It is not supposed
- * to be visible by end-users. Keep it this way!
- *
- * @param map The map with them
- * @param list The lints
- */
- Program(final Map map, final Iterable>> list) {
- this.pkg = Collections.unmodifiableMap(map);
- this.lints = list;
+ Program(final EoPackage pkg, final Collection srcs) {
+ this.pkg = pkg;
+ this.srcs = srcs;
}
/**
* Program with disabled lints.
+ *
* @param names Lint names
* @return Program analysis without specifics names
*/
public Program without(final String... names) {
- return new Program(this.pkg, new WpaWithout(names));
+ return new Program(
+ this.pkg.without(names),
+ this.srcs.stream()
+ .map(source -> source.without(names))
+ .collect(Collectors.toList())
+ );
}
/**
* Find all possible defects in the EO program.
+ *
* @return All defects found
* @see XMIR guide
* @see XMIR specification
* @see XMIR schema
*/
public Collection defects() {
- final Collection messages = new ArrayList<>(0);
- for (final Lint