10: Create SuppressWarningsPlugin

This commit is contained in:
Bartłomiej Pluta
2019-04-09 15:10:47 +02:00
parent 44608456eb
commit 888030ea4f
3 changed files with 36 additions and 1 deletions

View File

@@ -89,4 +89,10 @@ public class PluginModule {
public Plugin externalStoragePlugin(GlobMatcher globMatcher, XmlHelper xmlHelper, ParentNodeFinder parentNodeFinder) {
return new ExternalStoragePlugin(globMatcher, xmlHelper, parentNodeFinder);
}
@Provides
@IntoSet
public Plugin suppressWarningsPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) {
return new SuppressWarningsPlugin(globMatcher, xmlHelper);
}
}

View File

@@ -0,0 +1,25 @@
package com.bartek.esa.core.plugin;
import com.bartek.esa.core.archetype.JavaPlugin;
import com.bartek.esa.core.model.enumeration.Severity;
import com.bartek.esa.core.xml.XmlHelper;
import com.bartek.esa.file.matcher.GlobMatcher;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.expr.AnnotationExpr;
import javax.inject.Inject;
public class SuppressWarningsPlugin extends JavaPlugin {
@Inject
public SuppressWarningsPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) {
super(globMatcher, xmlHelper);
}
@Override
public void run(CompilationUnit compilationUnit) {
compilationUnit.findAll(AnnotationExpr.class).stream()
.filter(expr -> expr.getName().getIdentifier().equals("SuppressWarnings"))
.forEach(expr -> addIssue(Severity.WARNING, getLineNumberFromExpression(expr), expr.toString()));
}
}

View File

@@ -82,4 +82,8 @@ com.bartek.esa.core.plugin.StrictModePlugin=Strict mode is turned on.\n\
com.bartek.esa.core.plugin.ExternalStoragePlugin=External storage state is not checked.\n\
There is attempt to access to external storage without checking its state.\n\
External storage state should be checked through 'Environment.getExternalStorageState()' method.
External storage state should be checked through 'Environment.getExternalStorageState()' method.
com.bartek.esa.core.plugin.SuppressWarningsPlugin=@SuppressWarnings annotation was found.\n\
The @SuppressWarnings annotation might be hiding useful warnings.\n\
Consider removing it.