Search in sources :

Example 6 with Language

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"));
}
Also used : Language(org.intellij.lang.annotations.Language) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ArrayList(java.util.ArrayList) PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem)

Example 7 with Language

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);
}
Also used : Language(org.intellij.lang.annotations.Language) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ArrayList(java.util.ArrayList) PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem)

Example 8 with Language

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;
}
Also used : Language(org.intellij.lang.annotations.Language) XmlFile(com.intellij.psi.xml.XmlFile)

Example 9 with Language

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);
}
Also used : Language(org.intellij.lang.annotations.Language) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag)

Example 10 with Language

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");
}
Also used : Language(org.intellij.lang.annotations.Language) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

Language (org.intellij.lang.annotations.Language)111 TableMetadata (com.facebook.presto.metadata.TableMetadata)25 Test (org.testng.annotations.Test)24 MaterializedResult (com.facebook.presto.testing.MaterializedResult)19 PsiFile (com.intellij.psi.PsiFile)18 MaterializedRow (com.facebook.presto.testing.MaterializedRow)11 List (java.util.List)11 Optional (java.util.Optional)11 Test (org.junit.Test)11 ImmutableList (com.google.common.collect.ImmutableList)10 Session (com.facebook.presto.Session)9 Constraint (com.facebook.presto.spi.Constraint)9 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)9 BasePlanTest (com.facebook.presto.sql.planner.assertions.BasePlanTest)8 ColumnConstraint (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)7 ExpectedValueProvider (com.facebook.presto.sql.planner.assertions.ExpectedValueProvider)7 PlanMatchPattern (com.facebook.presto.sql.planner.assertions.PlanMatchPattern)7 SortOrder (com.facebook.presto.common.block.SortOrder)6