Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class LintsItTest {
void lintsProgram() throws IOException {
MatcherAssert.assertThat(
"passes with no exceptions",
new Program(new XMLDocument("<program name='it'/>")).defects(),
new Project(new XMLDocument("<program name='it'/>")).singleDefects(),
Matchers.notNullValue()
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/eolang/lints/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see <a href="https://news.eolang.org/2022-11-25-xmir-guide.html">XMIR</a>
* @since 0.1.0
*/
public final class Program {
final class Program {

/**
* Collection of mono lints, preloaded on JVM start.
Expand All @@ -48,15 +48,15 @@ public final class Program {
* @param file The absolute path of the XMIR file
* @throws FileNotFoundException If file isn't found
*/
public Program(final Path file) throws FileNotFoundException {
Program(final Path file) throws FileNotFoundException {
this(new XMLDocument(file));
}

/**
* Ctor.
* @param xml The XMIR
*/
public Program(final XML xml) {
Program(final XML xml) {
this(xml, Program.MONO);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/eolang/lints/Programs.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @see <a href="https://news.eolang.org/2022-11-25-xmir-guide.html">XMIR</a>
* @since 0.1.0
*/
public final class Programs {
final class Programs {

/**
* Collection of mono lints, preloaded on JVM start.
Expand Down Expand Up @@ -65,7 +65,7 @@ public final class Programs {
* @param dirs The directory
* @throws IOException If fails
*/
public Programs(final Path... dirs) throws IOException {
Programs(final Path... dirs) throws IOException {
this(Arrays.asList(dirs));
}

Expand All @@ -78,15 +78,15 @@ public Programs(final Path... dirs) throws IOException {
* @param dirs The directory
* @throws IOException If fails
*/
public Programs(final Collection<Path> dirs) throws IOException {
Programs(final Collection<Path> dirs) throws IOException {
this(Programs.discover(dirs));
}

/**
* Ctor.
* @param map The map with them
*/
public Programs(final Map<String, XML> map) {
Programs(final Map<String, XML> map) {
this(map, Programs.WPA);
}

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/eolang/lints/Project.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
* SPDX-License-Identifier: MIT
*/
package org.eolang.lints;

import java.util.Collection;

/**
* Project, files of which can be analyzed separately or together.
*
* @since 0.0.9
*/
public interface Project {

/**
* Defects found by analyzing each file independently.
* @return Collection of defects from all files
*/
Collection<Defect> singleDefects();

/**
* Defects found by analyzing all files together.
* @return Collection of defects from all files
*/
Collection<Defect> wpaDefects();
}
123 changes: 123 additions & 0 deletions src/main/java/org/eolang/lints/ProjectOf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
* SPDX-License-Identifier: MIT
*/
package org.eolang.lints;

import com.jcabi.xml.XML;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.cactoos.func.Chained;
import org.cactoos.iterable.Mapped;
import org.cactoos.list.Joined;
import org.cactoos.list.ListOf;

/**
* Implementation of Project. Provides several ways to make Project object.
*
* @since 0.0.9
*/
public final class ProjectOf implements Project {

/**
* Collection of programs that should be analyzed independently.
*/
private final Iterable<Program> programs;

/**
* Programs that should be analyzed together.
*/
private final Programs wpa;

/**
* Ctor.
* @param xml XML source.
*/
public ProjectOf(final XML xml) {
this(xml, "single");
}

/**
* Ctor.
* @param xml XML source.
* @param name File name.
*/
public ProjectOf(final XML xml, final String name) {
this(
new Program(xml),
new Programs(Map.of(name, xml))
);
}

/**
* Ctor.
* @param home Path to file.
* @throws IOException Throw IOException in case of problems working with files.
*/
public ProjectOf(final Path home) throws IOException {
this(
new Program(home),
new Programs(home)
);
}

/**
* Ctor.
* @param programs Set of programs XMLs with names.
* @param list List of lints for independent analyze.
* @param wpa List of lints for full project analyze.
*/
public ProjectOf(
final Map<String, XML> programs,
final Iterable<Lint<XML>> list,
final Iterable<Lint<Map<String, XML>>> wpa
) {
this(
new Mapped<>(
xml -> new Program(xml, list),
programs.values()
),
new Programs(programs, wpa)
);
}

/**
* Ctor.
* @param program Single program.
* @param wpa Programs for whole program analysis.
*/
ProjectOf(final Program program, final Programs wpa) {
this(
new ListOf<>(program),
wpa
);
}

/**
* Ctor.
* @param programs List of single programs.
* @param wpa Programs for whole program analysis.
*/
ProjectOf(final Iterable<Program> programs, final Programs wpa) {
this.programs = programs;
this.wpa = wpa;
}

@Override
public Collection<Defect> singleDefects() {
return new Joined<>(
new Mapped<List<Defect>>(
new Chained<>(Program::defects, ListOf::new),
this.programs
)
);
}

@Override
public Collection<Defect> wpaDefects() {
return this.wpa.defects();
}
}
9 changes: 5 additions & 4 deletions src/test/java/benchmarks/ProgramBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import fixtures.LargeXmir;
import java.util.concurrent.TimeUnit;
import org.cactoos.scalar.Unchecked;
import org.eolang.lints.Program;
import org.eolang.lints.Project;
import org.eolang.lints.ProjectOf;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand All @@ -21,7 +22,7 @@
import org.openjdk.jmh.annotations.Warmup;

/**
* Benchmark for {@link Program}.
* Benchmark for {@link Project}::singleDefects.
*
* @since 0.0.34
* @checkstyle DesignForExtensionCheck (10 lines)
Expand All @@ -47,11 +48,11 @@ public class ProgramBench {

@Benchmark
public final void scansLargeXmir() {
new Program(ProgramBench.LARGE).defects();
new ProjectOf(ProgramBench.LARGE).singleDefects();
}

@Benchmark
public final void scansSmallXmir() {
new Program(ProgramBench.SMALL).defects();
new ProjectOf(ProgramBench.SMALL).singleDefects();
}
}
8 changes: 4 additions & 4 deletions src/test/java/benchmarks/ProgramsBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import org.cactoos.scalar.IoChecked;
import org.eolang.lints.Program;
import org.eolang.lints.Programs;
import org.eolang.lints.Project;
import org.eolang.lints.ProjectOf;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand All @@ -24,7 +24,7 @@
import org.openjdk.jmh.annotations.Warmup;

/**
* Benchmark for {@link Program}.
* Benchmark for {@link Project}::wpaDefects.
*
* @since 0.0.34
* @checkstyle DesignForExtensionCheck (10 lines)
Expand Down Expand Up @@ -62,6 +62,6 @@ public ProgramsBench() {

@Benchmark
public final void scansLargeProgram() throws IOException {
new Programs(this.home).defects();
new ProjectOf(this.home).wpaDefects();
}
}
Loading