changeset 146:90f52517b764

Improve package name validator Defer to the JDT's built-in package name validator which more accurately verifies that a package name is valid. This makes the project wizard identify and reject a greater number of malformed package names (including those beggining with a dot or those that contain keywords).
author Omair Majid <omajid@redhat.com>
date Thu, 17 Jul 2014 15:08:31 -0400
parents 0e2970e18eb6
children ee8e92ed83ba
files com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Validators.java
diffstat 1 files changed, 3 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Validators.java	Thu Jun 26 09:02:18 2014 -0400
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Validators.java	Thu Jul 17 15:08:31 2014 -0400
@@ -5,6 +5,8 @@
 import org.eclipse.core.databinding.validation.IValidator;
 import org.eclipse.core.databinding.validation.ValidationStatus;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaCore;
 
 public class Validators {
 
@@ -36,18 +38,7 @@
 
         @Override
         public IStatus validate(Object value) {
-            Objects.requireNonNull(value);
-            if (!(value instanceof String)) {
-                throw new AssertionError("Expected String, but got '" + value + "' (" + value.getClass() + ").");
-            }
-            String packageName = (String) value;
-            if (packageName.length() == 0) {
-                return ValidationStatus.error("Package name must be specified");
-            }
-            if (packageName.contains(" ")) {
-                return ValidationStatus.error("Package name must be valid");
-            }
-            return ValidationStatus.ok();
+            return JavaConventions.validatePackageName((String)value, JavaCore.VERSION_1_7, JavaCore.VERSION_1_7);
         }
     }