warning: import should introduce unique simple name

Importing two different types with the same simple name is not allowed.

- collision with other imports

  import q.Bar;
  import r.Bar; // error

- collision with top-level type decl's name

  import q.Bar; // error
  parcelable Bar { .. }

Bug: 190782365
Test: aidl_unittests
Test: m
Change-Id: I13c0bde3f710d8230c61c1f0bb9680ea32f980eb
diff --git a/diagnostics_unittest.cpp b/diagnostics_unittest.cpp
index 0ea3141..eed824c 100644
--- a/diagnostics_unittest.cpp
+++ b/diagnostics_unittest.cpp
@@ -178,3 +178,41 @@
                "}"},
               {"Bar.aidl", "parcelable Bar {}"}});
 }
+
+TEST_F(DiagnosticsTest, RejectImportsCollisionWithTopLevelDecl) {
+  expect_diagnostics = {DiagnosticID::unique_import};
+  ParseFiles({{"p/IFoo.aidl",
+               "package p;\n"
+               "import q.IFoo;\n"  // should collide with previous import
+               "interface IFoo{}"},
+              {"q/IFoo.aidl", "package q; interface IFoo{}"}});
+}
+
+TEST_F(DiagnosticsTest, RejectImportsCollision) {
+  expect_diagnostics = {DiagnosticID::unique_import};
+  ParseFiles({{"p/IFoo.aidl",
+               "package p;\n"
+               "import q.IBar;\n"
+               "import r.IBar;\n"  // should collide with previous import
+               "interface IFoo{}"},
+              {"q/IBar.aidl", "package q; interface IBar{}"},
+              {"r/IBar.aidl", "package r; interface IBar{}"}});
+}
+
+TEST_F(DiagnosticsTest, AllowImportingSelf) {
+  expect_diagnostics = {};
+  ParseFiles({{"p/IFoo.aidl",
+               "package p;\n"
+               "import p.IFoo;\n"
+               "interface IFoo{}"}});
+}
+
+TEST_F(DiagnosticsTest, AllowRedundantImports) {
+  expect_diagnostics = {};
+  ParseFiles({{"p/IFoo.aidl",
+               "package p;\n"
+               "import q.IBar;\n"
+               "import q.IBar;\n"  // ugly, but okay
+               "interface IFoo{}"},
+              {"q/IBar.aidl", "package q; interface IBar{}"}});
+}
\ No newline at end of file