aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TypedVariable.java
diff options
context:
space:
mode:
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TypedVariable.java')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TypedVariable.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TypedVariable.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TypedVariable.java
new file mode 100644
index 000000000..468a10c77
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TypedVariable.java
@@ -0,0 +1,50 @@
+package com.android.ide.eclipse.adt.internal.wizards.templates;
+
+import java.util.Locale;
+
+import org.xml.sax.Attributes;
+
+public class TypedVariable {
+ public enum Type {
+ STRING,
+ BOOLEAN,
+ INTEGER;
+
+ public static Type get(String name) {
+ if (name == null) {
+ return STRING;
+ }
+ try {
+ return valueOf(name.toUpperCase(Locale.US));
+ } catch (IllegalArgumentException e) {
+ System.err.println("Unexpected global type '" + name + "'");
+ System.err.println("Expected one of :");
+ for (Type s : Type.values()) {
+ System.err.println(" " + s.name().toLowerCase(Locale.US));
+ }
+ }
+
+ return STRING;
+ }
+ }
+
+ public static Object parseGlobal(Attributes attributes) {
+ String value = attributes.getValue(TemplateHandler.ATTR_VALUE);
+ Type type = Type.get(attributes.getValue(TemplateHandler.ATTR_TYPE));
+
+ switch (type) {
+ case STRING:
+ return value;
+ case BOOLEAN:
+ return Boolean.parseBoolean(value);
+ case INTEGER:
+ try {
+ return Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ return value;
+ }
+ }
+
+ return value;
+ }
+}