From b649b3a3feab5d07efa1e14dd25b5f9f6a787499 Mon Sep 17 00:00:00 2001 From: smolcoder Date: Mon, 22 Dec 2014 12:00:46 +0300 Subject: [PATCH] "Import directive overrides auto-imported BIF" inspection --- ...portDirectiveOverridesAutoimportedBif.html | 21 ++++++++ src/META-INF/plugin.xml | 3 ++ ...iveOverridesAutoimportedBifInspection.java | 52 +++++++++++++++++++ ...ErlangRemoveFunctionFromImportFixBase.java | 15 ++++++ testData/highlighting/ImportAutoimported.erl | 3 ++ .../import/importAutoimported-after.erl | 1 + .../quickfixes/import/importAutoimported.erl | 1 + .../highlighting/ErlangHighlightingTest.java | 15 ++++++ .../ErlangHighlightingTestBase.java | 3 +- .../quickfixes/ErlangImportFixTest.java | 6 ++- 10 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 resources/inspectionDescriptions/ErlangImportDirectiveOverridesAutoimportedBif.html create mode 100644 src/org/intellij/erlang/inspection/ErlangImportDirectiveOverridesAutoimportedBifInspection.java create mode 100644 testData/highlighting/ImportAutoimported.erl create mode 100644 testData/quickfixes/import/importAutoimported-after.erl create mode 100644 testData/quickfixes/import/importAutoimported.erl diff --git a/resources/inspectionDescriptions/ErlangImportDirectiveOverridesAutoimportedBif.html b/resources/inspectionDescriptions/ErlangImportDirectiveOverridesAutoimportedBif.html new file mode 100644 index 000000000..d29a283d5 --- /dev/null +++ b/resources/inspectionDescriptions/ErlangImportDirectiveOverridesAutoimportedBif.html @@ -0,0 +1,21 @@ + + + + +Import directive overrides pre R14 auto-imported BIF. + + \ No newline at end of file diff --git a/src/META-INF/plugin.xml b/src/META-INF/plugin.xml index fa505929c..1b44f726f 100755 --- a/src/META-INF/plugin.xml +++ b/src/META-INF/plugin.xml @@ -181,6 +181,9 @@ + getAttributesForProcessing(@NotN return ((ErlangFile) descriptorElement.getContainingFile()).getAttributes(); } } + + public static class ErlangRemoveFunctionFromImportFix extends ErlangRemoveFunctionFromImportFixBase { + @Nullable + @Override + protected String getSignature(@NotNull PsiElement function) { + ErlangImportFunction f = PsiTreeUtil.getParentOfType(function, ErlangImportFunction.class, false); + return f != null ? ErlangPsiImplUtil.createFunctionPresentation(f) : null; + } + + @NotNull + @Override + protected Collection getAttributesForProcessing(@NotNull PsiElement descriptorElement) { + return ContainerUtil.createMaybeSingletonList(PsiTreeUtil.getParentOfType(descriptorElement, ErlangAttribute.class)); + } + } } diff --git a/testData/highlighting/ImportAutoimported.erl b/testData/highlighting/ImportAutoimported.erl new file mode 100644 index 000000000..15c7b8486 --- /dev/null +++ b/testData/highlighting/ImportAutoimported.erl @@ -0,0 +1,3 @@ +-import(incl, [dt_get_tag/0, crc32/1, abs/1]). +-export([foo/0]). +foo() -> ok. \ No newline at end of file diff --git a/testData/quickfixes/import/importAutoimported-after.erl b/testData/quickfixes/import/importAutoimported-after.erl new file mode 100644 index 000000000..95169ccee --- /dev/null +++ b/testData/quickfixes/import/importAutoimported-after.erl @@ -0,0 +1 @@ +-import(incl, [dt_get_tag/0, crc32/1]). \ No newline at end of file diff --git a/testData/quickfixes/import/importAutoimported.erl b/testData/quickfixes/import/importAutoimported.erl new file mode 100644 index 000000000..03f06da4e --- /dev/null +++ b/testData/quickfixes/import/importAutoimported.erl @@ -0,0 +1 @@ +-import(incl, [dt_get_tag/0, crc32/1, abs / 1]). \ No newline at end of file diff --git a/tests/org/intellij/erlang/highlighting/ErlangHighlightingTest.java b/tests/org/intellij/erlang/highlighting/ErlangHighlightingTest.java index dce487f80..80c38d8b1 100644 --- a/tests/org/intellij/erlang/highlighting/ErlangHighlightingTest.java +++ b/tests/org/intellij/erlang/highlighting/ErlangHighlightingTest.java @@ -77,6 +77,21 @@ public class ErlangHighlightingTest extends ErlangHighlightingTestBase { public void testNoAutoImport4() { doTest(); } public void testNoAutoImport5() { doTest(); } + private void doTestWithInclude() { + myFixture.configureByText("incl.erl", + "-module(incl).\n" + + "-export([crc32/1, abs/1, dt_get_tag/0, bar/0, abs/0]).\n" + + "\n" + + "crc32(Data) -> Data.\n" + + "abs(D) -> D.\n" + + "abs() -> zero.\n" + + "dt_get_tag() -> ok.\n" + + "bar() -> ok."); + doTest(); + } + + public void testImportAutoimported() { doTestWithInclude(); } + public void testErlang17SyntaxError() { enableErlang17SyntaxInspection(); doTest(); diff --git a/tests/org/intellij/erlang/highlighting/ErlangHighlightingTestBase.java b/tests/org/intellij/erlang/highlighting/ErlangHighlightingTestBase.java index 192f65204..4eaf108e8 100644 --- a/tests/org/intellij/erlang/highlighting/ErlangHighlightingTestBase.java +++ b/tests/org/intellij/erlang/highlighting/ErlangHighlightingTestBase.java @@ -82,7 +82,8 @@ public static void setUpInspections(@NotNull CodeInsightTestFixture fixture) { ErlangIoFormatInspection.class, ErlangDuplicateFunctionExportInspection.class, ErlangDefiningImportedFunctionInspection.class, - ErlangAmbiguousCallOfAutoimportedFunctionInspection.class + ErlangAmbiguousCallOfAutoimportedFunctionInspection.class, + ErlangImportDirectiveOverridesAutoimportedBifInspection.class ); } diff --git a/tests/org/intellij/erlang/quickfixes/ErlangImportFixTest.java b/tests/org/intellij/erlang/quickfixes/ErlangImportFixTest.java index 87c087e11..e29d11764 100644 --- a/tests/org/intellij/erlang/quickfixes/ErlangImportFixTest.java +++ b/tests/org/intellij/erlang/quickfixes/ErlangImportFixTest.java @@ -17,13 +17,17 @@ package org.intellij.erlang.quickfixes; import org.intellij.erlang.inspection.ErlangDefiningImportedFunctionInspection; +import org.intellij.erlang.inspection.ErlangImportDirectiveOverridesAutoimportedBifInspection; public class ErlangImportFixTest extends ErlangQuickFixTestBase { @Override protected void setUp() throws Exception { super.setUp(); //noinspection unchecked - myFixture.enableInspections(ErlangDefiningImportedFunctionInspection.class); + myFixture.enableInspections( + ErlangDefiningImportedFunctionInspection.class, + ErlangImportDirectiveOverridesAutoimportedBifInspection.class + ); } @Override