IDEA-60997 support for "merge" tag in Android layout files

This commit is contained in:
Eugene Kudelevsky
2010-11-10 15:21:10 +03:00
parent fbb434e435
commit ef490640af
6 changed files with 27 additions and 4 deletions
@@ -88,6 +88,7 @@ public class AndroidCompletionContributor extends CompletionContributor {
}
else if (LayoutDomFileDescription.isLayoutFile(xmlFile)) {
resultSet.addElement(LookupElementBuilder.create("view"));
resultSet.addElement(LookupElementBuilder.create("merge"));
Map<String, PsiClass> viewClassMap = AndroidDomExtender.getViewClassMap(facet);
final PsiClass viewGroupClass = viewClassMap.get("ViewGroup");
for (String tagName : viewClassMap.keySet()) {
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Processor;
@@ -354,10 +355,13 @@ public class AndroidDomExtender extends DomExtender<AndroidDomElement> {
private static final MyAttributeProcessor ourLayoutAttrsProcessor = new MyAttributeProcessor() {
@Override
public void process(@NotNull XmlName attrName, @NotNull DomExtension extension, @NotNull DomElement element) {
if (element instanceof LayoutViewElement &&
SdkConstants.NS_RESOURCES.equals(attrName.getNamespaceKey()) &&
("layout_width".equals(attrName.getLocalName()) || "layout_height".equals(attrName.getLocalName()))) {
extension.addCustomAnnotation(new MyRequired());
if (element instanceof LayoutViewElement && SdkConstants.NS_RESOURCES.equals(attrName.getNamespaceKey())) {
XmlElement xmlElement = element.getXmlElement();
String tagName = xmlElement instanceof XmlTag ? ((XmlTag)xmlElement).getName() : null;
if (!"merge".equals(tagName) &&
("layout_width".equals(attrName.getLocalName()) || "layout_height".equals(attrName.getLocalName()))) {
extension.addCustomAnnotation(new MyRequired());
}
}
}
};
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
</merge>
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<mer<caret>
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<merge
@@ -149,6 +149,10 @@ public class AndroidLayoutDomTest extends AndroidDomTest {
toTestCompletion("tn4.xml", "tn4_after.xml");
}
public void testTagNameCompletion5() throws Throwable {
toTestCompletion("tn5.xml", "tn5_after.xml");
}
public void testIdCompletion1() throws Throwable {
doTestCompletionVariants("idcompl1.xml", "@android:", "@+id/", "@id/idd1", "@id/idd2");
}
@@ -189,6 +193,10 @@ public class AndroidLayoutDomTest extends AndroidDomTest {
toTestCompletion(getTestName(true) + ".xml", getTestName(true) + "_after.xml");
}
public void testMerge() throws Throwable {
doTestHighlighting("merge.xml");
}
/*public void testCustomAttrsPerformance() throws Throwable {
myFixture.copyFileToProject("dom/resources/bigfile.xml", "res/values/bigfile.xml");
myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs.xml");