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 2786ae4..5a220e9 100644 --- a/src/main/java/com/bartek/esa/core/di/PluginModule.java +++ b/src/main/java/com/bartek/esa/core/di/PluginModule.java @@ -107,4 +107,10 @@ public class PluginModule { public Plugin dangerousPermissionPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) { return new DangerousPermissionPlugin(globMatcher, xmlHelper); } + + @Provides + @IntoSet + public Plugin textInputValidationPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) { + return new TextInputValidationPlugin(globMatcher, xmlHelper); + } } diff --git a/src/main/java/com/bartek/esa/core/plugin/TextInputValidationPlugin.java b/src/main/java/com/bartek/esa/core/plugin/TextInputValidationPlugin.java new file mode 100644 index 0000000..f9c5054 --- /dev/null +++ b/src/main/java/com/bartek/esa/core/plugin/TextInputValidationPlugin.java @@ -0,0 +1,36 @@ +package com.bartek.esa.core.plugin; + +import com.bartek.esa.core.archetype.ResourceLayoutPlugin; +import com.bartek.esa.core.model.enumeration.Severity; +import com.bartek.esa.core.xml.XmlHelper; +import com.bartek.esa.file.matcher.GlobMatcher; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.inject.Inject; +import java.util.Optional; + +public class TextInputValidationPlugin extends ResourceLayoutPlugin { + + @Inject + public TextInputValidationPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) { + super(globMatcher, xmlHelper); + } + + @Override + protected void run(Document xml) { + NodeList editTextNodes = xml.getElementsByTagName("EditText"); + stream(editTextNodes) + .filter(this::doesNotHaveInputType) + .forEach(n -> addIssue(Severity.WARNING, null, tagString(n))); + } + + private boolean doesNotHaveInputType(Node editText) { + Boolean doesHaveInputType = Optional.ofNullable(editText.getAttributes().getNamedItem("android:inputType")) + .map(Node::getNodeValue) + .map(v -> !v.isEmpty()) + .orElse(false); + return !doesHaveInputType; + } +} diff --git a/src/main/resources/description.properties b/src/main/resources/description.properties index b73dbc1..f55f748 100644 --- a/src/main/resources/description.properties +++ b/src/main/resources/description.properties @@ -112,3 +112,8 @@ com.bartek.esa.core.plugin.DangerousPermissionPlugin=Custom permission without d Custom permission with 'dangerous' protection level was found and it doesn't have any description.\n\ As long as the permission requires user attention, he should have provided a meaningful description about\n\ permission. + +com.bartek.esa.core.plugin.TextInputValidationPlugin=Input type is no selected.\n\ + The EditText view doesn't have a input type selected.\n\ + Consider associating a input type with this view.\n\ + For example: