From a911ae4a6c832e9be4bb9843e313239e46406e9c Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Mon, 10 Jan 2011 11:49:21 -0800 Subject: [PATCH] Disallow Java keywords in resource names If you create a resource file that is a Java keyword, Bad Stuff happens - it doesn't even make it into the R file. This modifiers the resource name validator (used among other places in the New XML File wizard) to disallow these names along with a suitable error message. Change-Id: Ic807bb9194d316f227bf3435509632374113563d --- .../adt/internal/wizards/newxmlfile/ResourceNameValidator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/ResourceNameValidator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/ResourceNameValidator.java index ee91f6643..013e5e208 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/ResourceNameValidator.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/ResourceNameValidator.java @@ -26,6 +26,8 @@ import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources; import com.android.ide.eclipse.adt.internal.resources.manager.ResourceManager; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jdt.core.JavaConventions; import org.eclipse.jface.dialogs.IInputValidator; import java.util.HashSet; @@ -73,6 +75,12 @@ public class ResourceNameValidator implements IInputValidator { } } + String level = "1.5"; //$NON-NLS-1$ + IStatus validIdentifier = JavaConventions.validateIdentifier(newText, level, level); + if (!validIdentifier.isOK()) { + return String.format("%1$s is not a valid name (reserved Java keyword)", newText); + } + if (mExisting != null && mExisting.contains(newText)) { return String.format("%1$s already exists", newText); } -- 2.11.0