Merge branch 'master' of git@git.labs.intellij.net:idea/community
authorEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 11 Jan 2011 18:23:15 +0000 (21:23 +0300)
committerEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 11 Jan 2011 18:23:15 +0000 (21:23 +0300)
27 files changed:
plugins/android/src/org/jetbrains/android/dom/AndroidDomUtil.java
plugins/android/src/org/jetbrains/android/dom/converters/IntegerConverter.java
plugins/android/src/org/jetbrains/android/dom/resources/BoolElement.java [new file with mode: 0644]
plugins/android/src/org/jetbrains/android/dom/resources/IntegerArray.java [new file with mode: 0644]
plugins/android/src/org/jetbrains/android/dom/resources/IntegerArrayItem.java [new file with mode: 0644]
plugins/android/src/org/jetbrains/android/dom/resources/IntegerElement.java [new file with mode: 0644]
plugins/android/src/org/jetbrains/android/dom/resources/ResourceElement.java
plugins/android/src/org/jetbrains/android/dom/resources/Resources.java
plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java
plugins/android/src/org/jetbrains/android/resourceManagers/ResourceManager.java
plugins/android/testData/dom/layout/hl.xml
plugins/android/testData/dom/resources/array.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/array_after.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/bool.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/bool1.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/bool1_after.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/boolResReference.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/boolResReference_after.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/bool_after.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/intResReference.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/intResReference_after.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/intbool.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/integer.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/integerArray.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/integerArray_after.xml [new file with mode: 0644]
plugins/android/testData/dom/resources/moreTypes.xml [new file with mode: 0644]
plugins/android/testSrc/org/jetbrains/android/dom/AndroidValueResourcesTest.java

index 934ea92c8cd6bfc91f36b24baec321ffa84876d6..00a92338b3704ebe1ca2916899faeca99dd62d49 100644 (file)
@@ -74,6 +74,10 @@ public class AndroidDomUtil {
         return "dimen";
       case String:
         return "string";
+      case Integer:
+        return "integer";
+      case Boolean:
+        return "bool";
       default:
         return null;
     }
@@ -224,7 +228,7 @@ public class AndroidDomUtil {
     if (element instanceof LayoutElement) {
       return new String[]{"requestFocus"};
     }
-    if (element instanceof Group || element instanceof StringArray || element instanceof Style) {
+    if (element instanceof Group || element instanceof StringArray || element instanceof IntegerArray || element instanceof Style) {
       return new String[]{"item"};
     }
     if (element instanceof Item) {
@@ -240,8 +244,8 @@ public class AndroidDomUtil {
       return new String[]{"attr"};
     }
     if (element instanceof Resources) {
-      return new String[]{"string", "drawable", "dimen", "color", "style", "string-array", "declare-styleable", "attr", "item",
-        "eat-comment"};
+      return new String[]{"string", "drawable", "dimen", "color", "style", "string-array", "integer-array", "array", "declare-styleable",
+        "integer", "bool", "attr", "item", "eat-comment"};
     }
     if (element instanceof StyledText) {
       return new String[]{"b", "i", "u"};
index d14a86943d8d6abf8c4fba19052c80cff7df0179..ef6e734eff0806cab6fb8accd7deebc47eedb6f4 100644 (file)
@@ -31,7 +31,7 @@ import java.util.Collections;
 public class IntegerConverter extends ResolvingConverter<String> {
   public static final IntegerConverter INSTANCE = new IntegerConverter();
 
-  private IntegerConverter() {
+  public IntegerConverter() {
   }
 
   @NotNull
diff --git a/plugins/android/src/org/jetbrains/android/dom/resources/BoolElement.java b/plugins/android/src/org/jetbrains/android/dom/resources/BoolElement.java
new file mode 100644 (file)
index 0000000..31d755e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.android.dom.resources;
+
+import com.intellij.util.xml.Convert;
+import org.jetbrains.android.dom.converters.AndroidBooleanValueConverter;
+
+/**
+ * @author Eugene.Kudelevsky
+ */
+@Convert(AndroidBooleanValueConverter.class)
+public interface BoolElement extends ResourceElement {
+}
diff --git a/plugins/android/src/org/jetbrains/android/dom/resources/IntegerArray.java b/plugins/android/src/org/jetbrains/android/dom/resources/IntegerArray.java
new file mode 100644 (file)
index 0000000..847bc7a
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.android.dom.resources;
+
+import java.util.List;
+
+/**
+ * @author Eugene.Kudelevsky
+ */
+public interface IntegerArray extends ResourceElement {
+  List<IntegerArrayItem> getItems();
+}
diff --git a/plugins/android/src/org/jetbrains/android/dom/resources/IntegerArrayItem.java b/plugins/android/src/org/jetbrains/android/dom/resources/IntegerArrayItem.java
new file mode 100644 (file)
index 0000000..42737be
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.android.dom.resources;
+
+import com.intellij.util.xml.Convert;
+import com.intellij.util.xml.GenericDomValue;
+import org.jetbrains.android.dom.converters.IntegerConverter;
+
+/**
+ * @author Eugene.Kudelevsky
+ */
+@Convert(IntegerConverter.class)
+public interface IntegerArrayItem extends GenericDomValue {
+}
diff --git a/plugins/android/src/org/jetbrains/android/dom/resources/IntegerElement.java b/plugins/android/src/org/jetbrains/android/dom/resources/IntegerElement.java
new file mode 100644 (file)
index 0000000..c326aba
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.android.dom.resources;
+
+import com.intellij.util.xml.Convert;
+import org.jetbrains.android.dom.converters.IntegerConverter;
+
+/**
+ * @author Eugene.Kudelevsky
+ */
+@Convert(IntegerConverter.class)
+public interface IntegerElement extends ResourceElement {
+}
index 68866392af46b58276f7b0f20538cfe75a864b75..d870c99712405efa2a1e1963e49b6e316d87f577 100644 (file)
 package org.jetbrains.android.dom.resources;
 
 import com.intellij.util.xml.GenericAttributeValue;
+import com.intellij.util.xml.GenericDomValue;
 import com.intellij.util.xml.Required;
 import org.jetbrains.android.dom.AndroidDomElement;
 
 /**
  * @author yole
  */
-public interface ResourceElement extends AndroidDomElement {
+public interface ResourceElement extends GenericDomValue<String>, AndroidDomElement {
   @Required
   GenericAttributeValue<String> getName();
-
-  String getValue();
-
-  void setValue(String s);
 }
index 007f35f8c819d162f929c12e88d7580b82803b1d..77e5582f2785b0d345022e0103234dbe008c8ff9 100644 (file)
@@ -40,6 +40,18 @@ public interface Resources extends AndroidDomElement {
   List<Style> getStyles();
   Style addStyle();
 
+  List<StringArray> getArrays();
+  StringArray addArray();
+
+  List<BoolElement> getBools();
+  BoolElement addBool();
+
+  List<IntegerElement> getIntegers();
+  IntegerElement addInteger();
+
+  List<IntegerArray> getIntegerArrays();
+  IntegerArray addIntegerArray();
+
   List<StringArray> getStringArrays();
   StringArray addStringArray();
 
index ebf7af411cf623a21af47ec89c203acab886b424..4979eb642cf4d66f08c276ea94914ecaf23761aa 100644 (file)
@@ -272,22 +272,29 @@ public class LocalResourceManager extends ResourceManager {
     if (type.equals("string")) {
       return resources.addString();
     }
-    if (type.equals("dimen")) {
+    else if (type.equals("dimen")) {
       return resources.addDimen();
     }
-    if (type.equals("color")) {
+    else if (type.equals("color")) {
       return resources.addColor();
     }
-    if (type.equals("drawable")) {
+    else if (type.equals("drawable")) {
       return resources.addDrawable();
     }
-    if (type.equals("style")) {
+    else if (type.equals("style")) {
       return resources.addStyle();
     }
-    if (type.equals("array")) {
+    else if (type.equals("array")) {
+      // todo: choose among string-array, integer-array and array
       return resources.addStringArray();
     }
-    if (type.equals("id")) {
+    else if (type.equals("integer")) {
+      return resources.addInteger();
+    }
+    else if (type.equals("bool")) {
+      return resources.addBool();
+    }
+    else if (type.equals("id")) {
       Item item = resources.addItem();
       item.getType().setValue("id");
       return item;
index 7cfb26b7259af373e01a60433d6c331e7042cac0..082589eaeff10d462e9262bb36ec8b8c5bc0095d 100644 (file)
@@ -52,7 +52,8 @@ import static java.util.Collections.addAll;
 public abstract class ResourceManager {
   public static final Set<String> REFERABLE_RESOURCE_TYPES = new HashSet<String>();
   public static final String[] FILE_RESOURCE_TYPES = new String[]{"drawable", "anim", "layout", "values", "menu", "xml", "raw", "color"};
-  public static final String[] VALUE_RESOURCE_TYPES = new String[]{"drawable", "dimen", "color", "string", "style", "array", "id"};
+  public static final String[] VALUE_RESOURCE_TYPES =
+    new String[]{"drawable", "dimen", "color", "string", "style", "array", "id", "bool", "integer", "integer-array"};
   private static final String[] DRAWABLE_EXTENSIONS = new String[]{"png", "jpg", "gif"};
 
   protected final Module myModule;
@@ -266,20 +267,28 @@ public abstract class ResourceManager {
     if (resourceType.equals("string")) {
       result.addAll(resources.getStrings());
     }
-    if (resourceType.equals("drawable")) {
+    else if (resourceType.equals("drawable")) {
       result.addAll(resources.getDrawables());
     }
-    if (resourceType.equals("color")) {
+    else if (resourceType.equals("color")) {
       result.addAll(resources.getColors());
     }
-    if (resourceType.equals("dimen")) {
+    else if (resourceType.equals("dimen")) {
       result.addAll(resources.getDimens());
     }
-    if (resourceType.equals("style")) {
+    else if (resourceType.equals("style")) {
       result.addAll(resources.getStyles());
     }
-    if (resourceType.equals("array")) {
+    else if (resourceType.equals("array")) {
       result.addAll(resources.getStringArrays());
+      result.addAll(resources.getIntegerArrays());
+      result.addAll(resources.getArrays());
+    }
+    else if (resourceType.equals("integer")) {
+      result.addAll(resources.getIntegers());
+    }
+    else if (resourceType.equals("bool")) {
+      result.addAll(resources.getBools());
     }
     for (Item item : resources.getItems()) {
       String type = item.getType().getValue();
index eee46b4378637c23ce02e68328e3336dc685ef1e..519ff42443e34eccacb46d6beb0a141093b0ce16 100644 (file)
@@ -18,7 +18,7 @@
           android:text="<error>@string/animation_1_instructions</error>"
       />
 
-  <RadioGroup android:checkedButton="<error>lunch</error>" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
+  <RadioGroup android:layout_width="fill_parent" android:layout_height="wrap_content"/>
   <RadioGroup android:checkedButton="1" android:layout_width="fill_parent" android:layout_height="wrap_content">
     <requestFocus />
   </RadioGroup>
diff --git a/plugins/android/testData/dom/resources/array.xml b/plugins/android/testData/dom/resources/array.xml
new file mode 100644 (file)
index 0000000..a20878f
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+  <array>
+    <i<caret>
+  </array>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/array_after.xml b/plugins/android/testData/dom/resources/array_after.xml
new file mode 100644 (file)
index 0000000..6a2d454
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+  <array>
+    <item
+  </array>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/bool.xml b/plugins/android/testData/dom/resources/bool.xml
new file mode 100644 (file)
index 0000000..674dc2b
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+  <bool>tru<caret></bool>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/bool1.xml b/plugins/android/testData/dom/resources/bool1.xml
new file mode 100644 (file)
index 0000000..cf42c92
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+  <boo<caret>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/bool1_after.xml b/plugins/android/testData/dom/resources/bool1_after.xml
new file mode 100644 (file)
index 0000000..1a7bd6a
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+  <bool
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/boolResReference.xml b/plugins/android/testData/dom/resources/boolResReference.xml
new file mode 100644 (file)
index 0000000..544afdd
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="wrap_content"
+    android:layout_height="fill_parent"
+    >
+<ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:adjustViewBounds="@bo<caret>"/>
+</LinearLayout>
+
diff --git a/plugins/android/testData/dom/resources/boolResReference_after.xml b/plugins/android/testData/dom/resources/boolResReference_after.xml
new file mode 100644 (file)
index 0000000..a96b0b1
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="wrap_content"
+    android:layout_height="fill_parent"
+    >
+<ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:adjustViewBounds="@bool/myBoolResource"/>
+</LinearLayout>
+
diff --git a/plugins/android/testData/dom/resources/bool_after.xml b/plugins/android/testData/dom/resources/bool_after.xml
new file mode 100644 (file)
index 0000000..3505e30
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+  <bool>true</bool>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/intResReference.xml b/plugins/android/testData/dom/resources/intResReference.xml
new file mode 100644 (file)
index 0000000..f467238
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="wrap_content"
+    android:layout_height="fill_parent"
+    >
+<GridView android:layout_width="fill_parent" android:layout_height="wrap_content" android:numColumns="@int<caret>"/>
+</LinearLayout>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/intResReference_after.xml b/plugins/android/testData/dom/resources/intResReference_after.xml
new file mode 100644 (file)
index 0000000..ff86e48
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="wrap_content"
+    android:layout_height="fill_parent"
+    >
+<GridView android:layout_width="fill_parent" android:layout_height="wrap_content" android:numColumns="@integer/myIntResource"/>
+</LinearLayout>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/intbool.xml b/plugins/android/testData/dom/resources/intbool.xml
new file mode 100644 (file)
index 0000000..0092bd3
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+  <integer name="myIntResource">10</integer>
+  <bool name="myBoolResource">true</bool>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/integer.xml b/plugins/android/testData/dom/resources/integer.xml
new file mode 100644 (file)
index 0000000..569d804
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+  <integ<caret>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/integerArray.xml b/plugins/android/testData/dom/resources/integerArray.xml
new file mode 100644 (file)
index 0000000..d8e32fb
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+  <integer-array>
+    <i<caret>
+  </integer-array>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/integerArray_after.xml b/plugins/android/testData/dom/resources/integerArray_after.xml
new file mode 100644 (file)
index 0000000..cb0694e
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+  <integer-array>
+    <item
+  </integer-array>
+</resources>
\ No newline at end of file
diff --git a/plugins/android/testData/dom/resources/moreTypes.xml b/plugins/android/testData/dom/resources/moreTypes.xml
new file mode 100644 (file)
index 0000000..4d477de
--- /dev/null
@@ -0,0 +1,17 @@
+<resources>
+  <bool name="bool1">true</bool>
+  <bool name="bool2"><error>0</error></bool>
+  <integer name="int1">10</integer>
+  <integer name="int2"><error>false</error></integer>
+  <integer-array name="array">
+      <item>4</item>
+      <item>8</item>
+      <item>16</item>
+      <item><error>1.2</error></item>
+    </integer-array>
+  <array name="colors">
+      <item>#FFFF0000</item>
+      <item>#FF00FF00</item>
+      <item>#FF0000FF</item>
+  </array>
+</resources>
\ No newline at end of file
index 02bdd4ada5343bd1c266ddebc79a4183cf6398e7..0e52be1673443b62cd36c59b6b8894d1704c2626 100644 (file)
@@ -104,6 +104,42 @@ public class AndroidValueResourcesTest extends AndroidDomTest {
     doTestHighlighting("styles10.xml");
   }
 
+  public void testMoreTypes() throws Throwable {
+    doTestHighlighting("moreTypes.xml");
+  }
+
+  public void testBool() throws Throwable {
+    toTestCompletion("bool.xml", "bool_after.xml");
+  }
+
+  public void testBool1() throws Throwable {
+    toTestCompletion("bool1.xml", "bool1_after.xml");
+  }
+
+  public void testInteger() throws Throwable {
+    doTestCompletionVariants("integer.xml", "integer", "integer-array");
+  }
+
+  public void testIntegerArray() throws Throwable {
+    toTestCompletion("integerArray.xml", "integerArray_after.xml");
+  }
+
+  public void testArray() throws Throwable {
+    toTestCompletion("array.xml", "array_after.xml");
+  }
+
+  public void testIntResourceReference() throws Throwable {
+    myFixture.copyFileToProject(testFolder + "/intResReference.xml", "res/layout/main.xml");
+    myFixture.copyFileToProject(testFolder + "/intbool.xml", "res/values/values.xml");
+    myFixture.testCompletion("res/layout/main.xml", testFolder + "/intResReference_after.xml");
+  }
+
+  public void testBoolResourceReference() throws Throwable {
+    myFixture.copyFileToProject(testFolder + "/boolResReference.xml", "res/layout/main.xml");
+    myFixture.copyFileToProject(testFolder + "/intbool.xml", "res/values/values.xml");
+    myFixture.testCompletion("res/layout/main.xml", testFolder + "/boolResReference_after.xml");
+  }
+
   public void testParentStyleReference() throws Throwable {
     VirtualFile file = myFixture.copyFileToProject(testFolder + "/psreference.xml", getPathToCopy("psreference.xml"));
     myFixture.configureFromExistingVirtualFile(file);