5: Add Severity to Issue model
This commit is contained in:
@@ -7,7 +7,7 @@ import java.io.File;
|
||||
public abstract class AndroidManifestPlugin extends XmlPlugin {
|
||||
private final GlobMatcher globMatcher;
|
||||
|
||||
protected AndroidManifestPlugin(GlobMatcher globMatcher) {
|
||||
public AndroidManifestPlugin(GlobMatcher globMatcher) {
|
||||
super(globMatcher);
|
||||
this.globMatcher = globMatcher;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartek.esa.core.archetype;
|
||||
|
||||
import com.bartek.esa.core.model.Issue;
|
||||
import com.bartek.esa.core.model.enumeration.Severity;
|
||||
import com.bartek.esa.core.model.object.Issue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -24,12 +25,13 @@ public abstract class BasePlugin implements Plugin {
|
||||
|
||||
protected abstract void run(File file);
|
||||
|
||||
protected void addIssue(Integer lineNumber, String line) {
|
||||
addIssue("", lineNumber, line);
|
||||
protected void addIssue(Severity severity, Integer lineNumber, String line) {
|
||||
addIssue(severity, "", lineNumber, line);
|
||||
}
|
||||
|
||||
protected void addIssue(String descriptionCode, Integer lineNumber, String line) {
|
||||
protected void addIssue(Severity severity, String descriptionCode, Integer lineNumber, String line) {
|
||||
Issue issue = Issue.builder()
|
||||
.severity(severity)
|
||||
.issuer(this.getClass())
|
||||
.descriptionCode(descriptionCode)
|
||||
.file(file)
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.bartek.esa.core.archetype;
|
||||
|
||||
import com.bartek.esa.file.matcher.GlobMatcher;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.body.TypeDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class JavaMethodBodyStatementPlugin extends JavaPlugin {
|
||||
|
||||
public JavaMethodBodyStatementPlugin(GlobMatcher globMatcher) {
|
||||
super(globMatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CompilationUnit compilationUnit) {
|
||||
Stream<Statement> statements = compilationUnit.getTypes().stream()
|
||||
.map(TypeDeclaration::getMembers)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(BodyDeclaration::isMethodDeclaration)
|
||||
.map(b -> (MethodDeclaration) b)
|
||||
.map(MethodDeclaration::getBody)
|
||||
.flatMap(Optional::stream)
|
||||
.map(BlockStmt::getStatements)
|
||||
.flatMap(Collection::stream);
|
||||
|
||||
checkStatements(statements);
|
||||
}
|
||||
|
||||
protected abstract void checkStatements(Stream<Statement> statements);
|
||||
|
||||
protected Integer getLineNumberOfStatement(Statement statement) {
|
||||
return statement.getRange()
|
||||
.map(range -> range.begin)
|
||||
.map(begin -> begin.line)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import java.io.File;
|
||||
public abstract class JavaPlugin extends BasePlugin {
|
||||
private final GlobMatcher globMatcher;
|
||||
|
||||
protected JavaPlugin(GlobMatcher globMatcher) {
|
||||
public JavaPlugin(GlobMatcher globMatcher) {
|
||||
this.globMatcher = globMatcher;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.bartek.esa.core.archetype;
|
||||
|
||||
import com.bartek.esa.core.model.Issue;
|
||||
import com.bartek.esa.core.model.object.Issue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.io.File;
|
||||
public abstract class XmlPlugin extends BasePlugin {
|
||||
private final GlobMatcher globMatcher;
|
||||
|
||||
protected XmlPlugin(GlobMatcher globMatcher) {
|
||||
public XmlPlugin(GlobMatcher globMatcher) {
|
||||
this.globMatcher = globMatcher;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.bartek.esa.core.desc.provider;
|
||||
|
||||
import com.bartek.esa.core.model.Issue;
|
||||
import com.bartek.esa.core.model.object.Issue;
|
||||
import com.bartek.esa.error.EsaException;
|
||||
import io.vavr.control.Try;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.bartek.esa.core.executor;
|
||||
|
||||
import com.bartek.esa.core.archetype.Plugin;
|
||||
import com.bartek.esa.core.model.Issue;
|
||||
import com.bartek.esa.core.model.object.Issue;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.bartek.esa.core.model.enumeration;
|
||||
|
||||
public enum Severity {
|
||||
WARNING,
|
||||
ERROR
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bartek.esa.core.model;
|
||||
package com.bartek.esa.core.model.object;
|
||||
|
||||
import com.bartek.esa.core.model.enumeration.Severity;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -9,6 +10,7 @@ import java.io.File;
|
||||
@Builder
|
||||
public class Issue {
|
||||
private final Class<?> issuer;
|
||||
private final Severity severity;
|
||||
private final String descriptionCode;
|
||||
private final File file;
|
||||
private final Integer lineNumber;
|
||||
Reference in New Issue
Block a user