use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class NlPropertyOrderingTest method testGrouping.
public void testGrouping() {
@Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" >" + " <TextView />" + "</RelativeLayout>";
NlComponent component = getFirstComponent(source);
Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(component));
List<NlPropertyItem> propertyList = new ArrayList<>(properties.values());
List<PTableItem> items = new NlPropertiesGrouper().group(propertyList, ImmutableList.of(component));
// assert that all padding related attributes are grouped together
PTableItem padding = findItemByName(items, "Padding");
assertNotNull(padding);
assertNotNull("Attribute paddingStart missing inside padding attributes", findItemByName(padding.getChildren(), "paddingStart"));
assertNotNull("Attribute paddingEnd missing inside padding attributes", findItemByName(padding.getChildren(), "paddingEnd"));
// assert that textview attributes are grouped together (disabled for now)
//PTableItem textView = findItemByName(items, "TextView");
//assertNotNull("Missing group for TextView attributes", textView);
//assertNotNull("Attribute capitalize missing inside textview attributes", findItemByName(textView.getChildren(), "capitalize"));
//assertNotNull("Attribute password missing inside textview attributes", findItemByName(textView.getChildren(), "password"));
// certain special attrs should be at the top level
assertNotNull("Missing attribute id at the top level after grouping", findItemByName(items, "id"));
}
use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class NlPropertyOrderingTest method testSorting.
public void testSorting() {
@Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" >" + " <TextView android:text=\"Hello\" />" + "</RelativeLayout>";
NlComponent component = getFirstComponent(source);
Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(component));
List<NlPropertyItem> propertyList = new ArrayList<>(properties.values());
List<NlPropertyItem> sortedList = new NlPropertiesSorter().sort(propertyList, ImmutableList.of(component));
List<PTableItem> items = new NlPropertiesGrouper().group(sortedList, ImmutableList.of(component));
assertEquals("id attribute is not the first item", "id", items.get(0).getName());
assertEquals("Layout_width attribute is not the second item", "layout_width", items.get(1).getName());
assertEquals("Layout_height attribute is not the third item", "layout_height", items.get(2).getName());
assertEquals("Layout attributes group is not the fourth item", "Layout_Margin", items.get(3).getName());
assertEquals("Padding attributes group is not the fifth item", "Padding", items.get(4).getName());
assertTrue("TextView group not within the top 10 items", findItemIndex(items, "TextView") < 10);
assertTrue("Modified attribute text not in the top 10 items", findItemIndex(items, "text") < 10);
}
use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class NlPropertiesTest method setupCustomViewProject.
private XmlFile setupCustomViewProject() {
@Language("XML") String layoutSrc = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout>" + " <com.example.PieChart />" + "</LinearLayout>";
@Language("XML") String attrsSrc = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<resources>\n" + " <declare-styleable name=\"PieChart\">\n" + " <attr name=\"legend\" format=\"boolean\" />\n" + " <attr name=\"labelPosition\" format=\"enum\">\n" + " <enum name=\"left\" value=\"0\"/>\n" + " <enum name=\"right\" value=\"1\"/>\n" + " </attr>\n" + " </declare-styleable>\n" + "</resources>";
@Language("JAVA") String javaSrc = "package com.example;\n" + "\n" + "import android.content.Context;\n" + "import android.view.View;\n" + "\n" + "public class PieChart extends View {\n" + " public PieChart(Context context) {\n" + " super(context);\n" + " }\n" + "}\n";
XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", layoutSrc);
myFixture.addFileToProject("res/values/attrs.xml", attrsSrc);
myFixture.addFileToProject("src/com/example/PieChart.java", javaSrc);
return xmlFile;
}
use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class NlPropertiesTest method testViewAttributes.
public void testViewAttributes() {
@Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<View/>";
XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", source);
String tag = "View";
XmlTag rootTag = xmlFile.getRootTag();
assert rootTag != null;
Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(MockNlComponent.create(rootTag)));
// at least 124 attributes (view + layouts) are available as of API 22
assertTrue(properties.size() > 120);
// check that some of the View's attributes are there..
assertPresent(tag, properties, ANDROID_URI, ANDROID_VIEW_ATTRS);
assertPresent(tag, properties, "", NO_NAMESPACE_VIEW_ATTRS);
// check that non-existent properties haven't been added
assertAbsent(tag, properties, ANDROID_URI, TEXT_VIEW_ATTRS);
// Views that don't have a parent layout have all the layout attributes available to them..
assertPresent(tag, properties, ANDROID_URI, RELATIVE_LAYOUT_ATTRS);
assertPresent(tag, properties, ANDROID_URI, GRID_LAYOUT_ATTRS);
assertPresent(tag, properties, ANDROID_URI, FRAME_LAYOUT_ATTRS);
}
use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class NlPropertiesTest method testAppCompatIssues.
public void testAppCompatIssues() {
@Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout>" + " <TextView />" + "</RelativeLayout>";
XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", source);
@Language("XML") String attrsSrc = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<resources>\n" + " <declare-styleable name=\"View\">\n" + " <attr name=\"android:focusable\" />\n" + " <attr name=\"theme\" format=\"reference\" />\n" + " <attr name=\"android:theme\" />\n" + " <attr name=\"custom\" />\n" + " </declare-styleable>\n" + "</resources>";
myFixture.addFileToProject("res/values/attrs.xml", attrsSrc);
XmlTag rootTag = xmlFile.getRootTag();
assert rootTag != null;
XmlTag[] subTags = rootTag.getSubTags();
assertEquals(1, subTags.length);
Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(MockNlComponent.create(subTags[0])));
// at least 190 attributes are available as of API 22
assertTrue(properties.size() > 180);
// The attrs.xml in appcompat-22.0.0 includes android:focusable, theme and android:theme.
// The android:focusable refers to the platform attribute, and hence should not be duplicated..
assertPresent("TextView", properties, ANDROID_URI, "focusable", "theme");
assertPresent("TextView", properties, CUSTOM_NAMESPACE, "custom");
assertAbsent("TextView", properties, ANDROID_URI, "android:focusable", "android:theme");
}
Aggregations