Skip to content

Commit

Permalink
"Import directive overrides auto-imported BIF" inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
smolcoder committed Dec 22, 2014
1 parent bd66d65 commit fd43108
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.PsiReference;
import org.intellij.erlang.bif.ErlangBifDescriptor;
import org.intellij.erlang.bif.ErlangBifTable;
import org.intellij.erlang.psi.ErlangFile;
import org.intellij.erlang.psi.ErlangImportFunction;
import org.intellij.erlang.psi.impl.ErlangFunctionReferenceImpl;
import org.intellij.erlang.psi.impl.ErlangPsiImplUtil;
import org.intellij.erlang.quickfixes.ErlangRemoveFunctionFromImportFixBase;
import org.intellij.erlang.sdk.ErlangSdkRelease;
import org.intellij.erlang.sdk.ErlangSdkType;
Expand All @@ -38,13 +37,13 @@ protected boolean canRunOn(@NotNull ErlangFile file) {

protected void checkFile(@NotNull ErlangFile file, @NotNull ProblemsHolder problemsHolder) {
for (ErlangImportFunction importFunction : file.getImportedFunctions()) {
PsiReference reference = importFunction.getReference();
if (!(reference instanceof ErlangFunctionReferenceImpl) || reference.resolve() == null) continue;
ErlangFunctionReferenceImpl r = (ErlangFunctionReferenceImpl) reference;
ErlangBifDescriptor bifDescriptor = ErlangBifTable.getBif("erlang", r.getName(), r.getArity());
ErlangBifDescriptor bifDescriptor = ErlangBifTable.getBif(
"erlang",
ErlangPsiImplUtil.getName(importFunction.getQAtom()),
ErlangPsiImplUtil.getArity(importFunction.getInteger()));
if (bifDescriptor == null || !bifDescriptor.isAutoImported()) continue;
problemsHolder.registerProblem(importFunction,
"Import directive overrides pre R14 auto-imported BIF '" + r.getSignature() + "'",
"Import directive overrides pre R14 auto-imported BIF '" + ErlangPsiImplUtil.createFunctionPresentation(importFunction) + "'",
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
new ErlangRemoveFunctionFromImportFixBase.ErlangRemoveFunctionFromImportFix());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static class ErlangRemoveFunctionFromImportFix extends ErlangRemoveFuncti
@Override
protected String getSignature(@NotNull PsiElement function) {
ErlangImportFunction f = PsiTreeUtil.getParentOfType(function, ErlangImportFunction.class, false);
return (f != null) ? ErlangPsiImplUtil.createFunctionPresentation(f) : null;
return f != null ? ErlangPsiImplUtil.createFunctionPresentation(f) : null;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class ErlangHighlightingTest extends ErlangHighlightingTestBase {
public void testNoAutoImport4() { doTest(); }
public void testNoAutoImport5() { doTest(); }

private void doTestWithInclude() {
public void testImportAutoimported() {
myFixture.configureByText("incl.erl",
"-module(incl).\n" +
"-export([crc32/1, abs/1, dt_get_tag/0, bar/0, abs/0]).\n" +
Expand All @@ -90,8 +90,6 @@ private void doTestWithInclude() {
doTest();
}

public void testImportAutoimported() {doTestWithInclude(); }

public void testErlang17SyntaxError() {
enableErlang17SyntaxInspection();
doTest();
Expand Down
12 changes: 0 additions & 12 deletions tests/org/intellij/erlang/quickfixes/ErlangImportFixTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,4 @@ private void doTest() {
public void testOneImport() { doTest(); }
public void testDuplicateImport() { doTest(); }
public void testNoImport() { doTest(); }
public void testImportAutoimported() {
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();
}
}

0 comments on commit fd43108

Please sign in to comment.