Search in sources :

Example 11 with Language

use of org.intellij.lang.annotations.Language in project android by JetBrains.

the class LombokPsiConverterTest method testPsiToLombokConversion10.

public void testPsiToLombokConversion10() {
    // Checks that annotations on variable declarations are preserved
    @Language("JAVA") String testClass = "package test.pkg;\n" + "\n" + "import android.annotation.SuppressLint;\n" + "import android.annotation.TargetApi;\n" + "import android.os.Build;\n" + "\n" + "public class SuppressTest {\n" + "    @SuppressLint(\"ResourceAsColor\")\n" + "    @TargetApi(Build.VERSION_CODES.HONEYCOMB)\n" + "    private void test() {\n" + "        @SuppressLint(\"SdCardPath\") String s = \"/sdcard/fyfaen\";\n" + "        setTitleColor(android.R.color.black);\n" + "    }\n" + "\n" + "    private void setTitleColor(int color) {\n" + "        //To change body of created methods use File | Settings | File Templates.\n" + "    }\n" + "}\n";
    PsiFile file = myFixture.addFileToProject("src/test/pkg/SuppressTest.java", testClass);
    check(file, testClass);
}
Also used : Language(org.intellij.lang.annotations.Language) PsiFile(com.intellij.psi.PsiFile)

Example 12 with Language

use of org.intellij.lang.annotations.Language in project android by JetBrains.

the class InteractionManagerTest method testDragAndDrop.

public void testDragAndDrop() throws Exception {
    // Drops a fragment (xmlFragment below) into the design surface (via drag & drop events) and verifies that
    // the resulting document ends up modified as expected.
    @Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_width=\"0dp\"\n" + "    android:layout_height=\"0dp\"\n" + "    android:orientation=\"vertical\">\n" + "\n" + "</LinearLayout>\n";
    XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", source);
    DesignSurface surface = createSurface();
    NlModel model = createModel(surface, myFacet, xmlFile);
    ScreenView screenView = createScreen(surface, model, new SelectionModel());
    DesignSurface designSurface = screenView.getSurface();
    InteractionManager manager = createManager(designSurface);
    @Language("XML") String xmlFragment = "" + "<TextView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "     android:layout_width=\"wrap_content\"\n" + "     android:layout_height=\"wrap_content\"\n" + "     android:text=\"Hello World\"\n" + "/>";
    Transferable transferable = createTransferable(DataFlavor.stringFlavor, xmlFragment);
    dragDrop(manager, 0, 0, 100, 100, transferable);
    Disposer.dispose(model);
    @Language("XML") String expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_width=\"0dp\"\n" + "    android:layout_height=\"0dp\"\n" + "    android:orientation=\"vertical\">\n" + "\n" + "    <TextView\n" + "        android:id=\"@+id/textView\"\n" + "        android:layout_width=\"match_parent\"\n" + "        android:layout_height=\"wrap_content\"\n" + "        android:text=\"Hello World\" />\n" + "</LinearLayout>\n";
    assertEquals(expected, xmlFile.getText());
}
Also used : Language(org.intellij.lang.annotations.Language) XmlFile(com.intellij.psi.xml.XmlFile) Transferable(java.awt.datatransfer.Transferable) NlModel(com.android.tools.idea.uibuilder.model.NlModel) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel)

Example 13 with Language

use of org.intellij.lang.annotations.Language in project android by JetBrains.

the class AndroidResolveHelperTest method testIntDefResolution.

public void testIntDefResolution() {
    @Language("JAVA") String text = "package p1.p2;\n" + "\n" + "import java.lang.annotation.Retention;\n" + "import java.lang.annotation.RetentionPolicy;\n" + "\n" + "public class Foo {\n" + "    public static final int INVISIBLE = 0x00000004;\n" + "    public static final int VISIBLE = 0x00000000;\n" + "    public static final int GONE = 0x00000008;\n" + "\n" + "    @android.support.annotation.IntDef({VISIBLE, INVISIBLE, GONE})\n" + "    @Retention(RetentionPolicy.SOURCE)\n" + "    public @interface Visibility {}\n" + "\n" + "    @Foo.Visibility\n" + "    private int mVisibility;  \n" + "\n" + "    public void setVisibility(@Foo.Visibility int v) {\n" + "        mVis<caret>ibility = v;\n" + "    }\n" + "}\n";
    PsiElement element = getPsiElement(text);
    assertNotNull(element);
    PsiAnnotation annotation = AndroidResolveHelper.getAnnotationForLocal(element, "v");
    assertNotNull(annotation);
    assertEquals(SdkConstants.INT_DEF_ANNOTATION, annotation.getQualifiedName());
    AndroidResolveHelper.IntDefResolution result = AndroidResolveHelper.resolveIntDef(annotation);
    assertFalse(result.canBeOred);
    Map<Integer, String> map = result.valuesMap;
    assertNotNull(map);
    assertEquals(3, map.size());
    assertEquals("INVISIBLE", map.get(4));
    assertEquals("VISIBLE", map.get(0));
    assertEquals("GONE", map.get(8));
}
Also used : Language(org.intellij.lang.annotations.Language) PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiElement(com.intellij.psi.PsiElement)

Example 14 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestHiveIntegrationSmokeTest method insertPartitionedTable.

private void insertPartitionedTable(Session session, HiveStorageFormat storageFormat) throws Exception {
    @Language("SQL") String createTable = "" + "CREATE TABLE test_insert_partitioned_table " + "(" + "  ORDER_KEY BIGINT," + "  SHIP_PRIORITY INTEGER," + "  ORDER_STATUS VARCHAR" + ") " + "WITH (" + "format = '" + storageFormat + "', " + "partitioned_by = ARRAY[ 'SHIP_PRIORITY', 'ORDER_STATUS' ]" + ") ";
    assertUpdate(session, createTable);
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_insert_partitioned_table");
    assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
    assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("ship_priority", "order_status"));
    assertQuery(session, "SHOW PARTITIONS FROM test_insert_partitioned_table", "SELECT shippriority, orderstatus FROM orders LIMIT 0");
    // Hive will reorder the partition keys, so we must insert into the table assuming the partition keys have been moved to the end
    assertUpdate(session, "" + "INSERT INTO test_insert_partitioned_table " + "SELECT orderkey, shippriority, orderstatus " + "FROM tpch.tiny.orders", "SELECT count(*) from orders");
    // verify the partitions
    List<?> partitions = getPartitions("test_insert_partitioned_table");
    assertEquals(partitions.size(), 3);
    assertQuery(session, "SELECT * from test_insert_partitioned_table", "SELECT orderkey, shippriority, orderstatus FROM orders");
    assertQuery(session, "SHOW PARTITIONS FROM test_insert_partitioned_table", "SELECT DISTINCT shippriority, orderstatus FROM orders");
    assertQuery(session, "SHOW PARTITIONS FROM test_insert_partitioned_table ORDER BY order_status LIMIT 2", "SELECT DISTINCT shippriority, orderstatus FROM orders ORDER BY orderstatus LIMIT 2");
    assertQuery(session, "SHOW PARTITIONS FROM test_insert_partitioned_table WHERE order_status = 'O'", "SELECT DISTINCT shippriority, orderstatus FROM orders WHERE orderstatus = 'O'");
    assertUpdate(session, "DROP TABLE test_insert_partitioned_table");
    assertFalse(getQueryRunner().tableExists(session, "test_insert_partitioned_table"));
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) Language(org.intellij.lang.annotations.Language)

Example 15 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestHiveIntegrationSmokeTest method createPartitionedTableAs.

public void createPartitionedTableAs(Session session, HiveStorageFormat storageFormat) throws Exception {
    @Language("SQL") String createTable = "" + "CREATE TABLE test_create_partitioned_table_as " + "WITH (" + "format = '" + storageFormat + "', " + "partitioned_by = ARRAY[ 'SHIP_PRIORITY', 'ORDER_STATUS' ]" + ") " + "AS " + "SELECT orderkey AS order_key, shippriority AS ship_priority, orderstatus AS order_status " + "FROM tpch.tiny.orders";
    assertUpdate(session, createTable, "SELECT count(*) from orders");
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_create_partitioned_table_as");
    assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
    assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("ship_priority", "order_status"));
    List<?> partitions = getPartitions("test_create_partitioned_table_as");
    assertEquals(partitions.size(), 3);
    assertQuery(session, "SELECT * from test_create_partitioned_table_as", "SELECT orderkey, shippriority, orderstatus FROM orders");
    assertUpdate(session, "DROP TABLE test_create_partitioned_table_as");
    assertFalse(getQueryRunner().tableExists(session, "test_create_partitioned_table_as"));
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) Language(org.intellij.lang.annotations.Language)

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