return "dimen";
case String:
return "string";
+ case Integer:
+ return "integer";
+ case Boolean:
+ return "bool";
default:
return null;
}
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) {
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"};
public class IntegerConverter extends ResolvingConverter<String> {
public static final IntegerConverter INSTANCE = new IntegerConverter();
- private IntegerConverter() {
+ public IntegerConverter() {
}
@NotNull
--- /dev/null
+/*
+ * 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 {
+}
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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 {
+}
--- /dev/null
+/*
+ * 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 {
+}
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);
}
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();
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;
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;
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();
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>
--- /dev/null
+<resources>
+ <array>
+ <i<caret>
+ </array>
+</resources>
\ No newline at end of file
--- /dev/null
+<resources>
+ <array>
+ <item
+ </array>
+</resources>
\ No newline at end of file
--- /dev/null
+<resources>
+ <bool>tru<caret></bool>
+</resources>
\ No newline at end of file
--- /dev/null
+<resources>
+ <boo<caret>
+</resources>
\ No newline at end of file
--- /dev/null
+<resources>
+ <bool
+</resources>
\ No newline at end of file
--- /dev/null
+<?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>
+
--- /dev/null
+<?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>
+
--- /dev/null
+<resources>
+ <bool>true</bool>
+</resources>
\ No newline at end of file
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<resources>
+ <integ<caret>
+</resources>
\ No newline at end of file
--- /dev/null
+<resources>
+ <integer-array>
+ <i<caret>
+ </integer-array>
+</resources>
\ No newline at end of file
--- /dev/null
+<resources>
+ <integer-array>
+ <item
+ </integer-array>
+</resources>
\ No newline at end of file
--- /dev/null
+<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
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);