-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into natparse/allow-emhdpm…
…-on-untyped-view * origin/main: Implement parameter check for external modules (#518)
- Loading branch information
Showing
42 changed files
with
2,039 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
libs/natlint/src/main/java/org/amshove/natlint/cli/AnalyzerPredicates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.amshove.natlint.cli; | ||
|
||
import org.amshove.natlint.cli.predicates.DiagnosticPredicate; | ||
import org.amshove.natlint.cli.predicates.IFilePredicate; | ||
import org.amshove.natparse.DiagnosticSeverity; | ||
import org.amshove.natparse.IDiagnostic; | ||
import org.amshove.natparse.natural.project.NaturalFile; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@SuppressWarnings("java:S106") | ||
public class AnalyzerPredicates | ||
{ | ||
private final List<IFilePredicate> filePredicates = new ArrayList<>(); | ||
private final List<DiagnosticPredicate> diagnosticPredicates = new ArrayList<>(); | ||
private final DiagnosticSeverity minimumSeverity; | ||
|
||
public AnalyzerPredicates(DiagnosticSeverity minimumSeverity) | ||
{ | ||
this.minimumSeverity = minimumSeverity; | ||
} | ||
|
||
void addFilePredicate(IFilePredicate predicate) | ||
{ | ||
filePredicates.add(predicate); | ||
} | ||
|
||
void addDiagnosticPredicate(DiagnosticPredicate predicate) | ||
{ | ||
diagnosticPredicates.add(predicate); | ||
} | ||
|
||
public boolean shouldAnalyzeFile(NaturalFile file) | ||
{ | ||
return filePredicates.isEmpty() || filePredicates.stream().anyMatch(p -> p.predicate().test(file)); | ||
} | ||
|
||
public boolean shouldPrintDiagnostic(IDiagnostic diagnostic) | ||
{ | ||
if (!diagnostic.severity().isWorseOrEqualTo(minimumSeverity)) | ||
{ | ||
return false; | ||
} | ||
|
||
return diagnosticPredicates.isEmpty() || diagnosticPredicates.stream().anyMatch(p -> p.predicate().test(diagnostic)); | ||
} | ||
|
||
public void printSettings() | ||
{ | ||
var hasPredicates = minimumSeverity != DiagnosticSeverity.INFO | ||
|| !filePredicates.isEmpty() | ||
|| !diagnosticPredicates.isEmpty(); | ||
|
||
if (!hasPredicates) | ||
{ | ||
return; | ||
} | ||
|
||
if (!filePredicates.isEmpty()) | ||
{ | ||
System.out.println("Only the following files will be analyzed:"); | ||
filePredicates.forEach(fp -> System.out.println("- " + fp.description())); | ||
} | ||
|
||
System.out.println("Only the following diagnostics will be printed:"); | ||
System.out.printf("- minimum severity %s%n", minimumSeverity); | ||
diagnosticPredicates.forEach(dp -> System.out.println("- " + dp.description())); | ||
|
||
System.out.println(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
libs/natlint/src/main/java/org/amshove/natlint/cli/predicates/DiagnosticPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.amshove.natlint.cli.predicates; | ||
|
||
import org.amshove.natparse.IDiagnostic; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public record DiagnosticPredicate(String description, Predicate<IDiagnostic> predicate) | ||
{} |
8 changes: 8 additions & 0 deletions
8
libs/natlint/src/main/java/org/amshove/natlint/cli/predicates/FilePredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.amshove.natlint.cli.predicates; | ||
|
||
import org.amshove.natparse.natural.project.NaturalFile; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public record FilePredicate(String description, Predicate<NaturalFile> predicate) implements IFilePredicate | ||
{} |
31 changes: 31 additions & 0 deletions
31
libs/natlint/src/main/java/org/amshove/natlint/cli/predicates/GlobFilePredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.amshove.natlint.cli.predicates; | ||
|
||
import org.amshove.natparse.natural.project.NaturalFile; | ||
|
||
import java.nio.file.FileSystems; | ||
import java.nio.file.PathMatcher; | ||
import java.util.function.Predicate; | ||
|
||
public class GlobFilePredicate implements IFilePredicate | ||
{ | ||
private final String glob; | ||
private final PathMatcher matcher; | ||
|
||
public GlobFilePredicate(String glob) | ||
{ | ||
this.glob = glob; | ||
matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); | ||
} | ||
|
||
@Override | ||
public String description() | ||
{ | ||
return "glob: " + glob; | ||
} | ||
|
||
@Override | ||
public Predicate<NaturalFile> predicate() | ||
{ | ||
return f -> matcher.matches(f.getPath()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
libs/natlint/src/main/java/org/amshove/natlint/cli/predicates/IFilePredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.amshove.natlint.cli.predicates; | ||
|
||
import org.amshove.natparse.natural.project.NaturalFile; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public interface IFilePredicate | ||
{ | ||
String description(); | ||
|
||
Predicate<NaturalFile> predicate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.