From 888030ea4f862dbae121e4f7e6294ac8a139ed52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Tue, 9 Apr 2019 15:10:47 +0200 Subject: [PATCH] 10: Create SuppressWarningsPlugin --- .../com/bartek/esa/core/di/PluginModule.java | 6 +++++ .../core/plugin/SuppressWarningsPlugin.java | 25 +++++++++++++++++++ src/main/resources/description.properties | 6 ++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bartek/esa/core/plugin/SuppressWarningsPlugin.java diff --git a/src/main/java/com/bartek/esa/core/di/PluginModule.java b/src/main/java/com/bartek/esa/core/di/PluginModule.java index b1e574c..a549835 100644 --- a/src/main/java/com/bartek/esa/core/di/PluginModule.java +++ b/src/main/java/com/bartek/esa/core/di/PluginModule.java @@ -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); + } } diff --git a/src/main/java/com/bartek/esa/core/plugin/SuppressWarningsPlugin.java b/src/main/java/com/bartek/esa/core/plugin/SuppressWarningsPlugin.java new file mode 100644 index 0000000..ad4f7fc --- /dev/null +++ b/src/main/java/com/bartek/esa/core/plugin/SuppressWarningsPlugin.java @@ -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())); + } +} diff --git a/src/main/resources/description.properties b/src/main/resources/description.properties index 5d53f9a..0bd1c8d 100644 --- a/src/main/resources/description.properties +++ b/src/main/resources/description.properties @@ -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. \ No newline at end of file + 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. \ No newline at end of file