From 27cd90a9e88cdf057da9383c49587bf6167fa7f7 Mon Sep 17 00:00:00 2001 From: xonix Date: Thu, 18 Apr 2024 01:56:48 +0300 Subject: [PATCH] False positive warning "Function ... is never used" #214 : more tests --- src/main/java/intellij_awk/psi/AwkElementFactory.java | 5 +++++ src/main/java/intellij_awk/psi/AwkStringMixin.java | 2 +- src/test/java/intellij_awk/AwkRenameTests.java | 1 + src/test/testData/rename/funcRef.awk | 8 ++++++++ src/test/testData/rename/funcRefAfter.awk | 8 ++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/test/testData/rename/funcRef.awk create mode 100644 src/test/testData/rename/funcRefAfter.awk diff --git a/src/main/java/intellij_awk/psi/AwkElementFactory.java b/src/main/java/intellij_awk/psi/AwkElementFactory.java index f39a9d59..f52394b1 100644 --- a/src/main/java/intellij_awk/psi/AwkElementFactory.java +++ b/src/main/java/intellij_awk/psi/AwkElementFactory.java @@ -18,6 +18,11 @@ public static AwkFunctionName createFunctionName(Project project, String name) { return createAwkPsiElement(project, "function " + name + "(){}", AwkFunctionName.class); } + public static AwkStr createString(Project project, String str) { + return createAwkPsiElement( + project, "{ a = \"" + str.replace("\"", "\\\"") + "\" }", AwkStr.class); + } + public static AwkItem createFunctionItem(Project project, String name) { return createAwkPsiElement(project, "function " + name + "(){}", AwkItem.class); } diff --git a/src/main/java/intellij_awk/psi/AwkStringMixin.java b/src/main/java/intellij_awk/psi/AwkStringMixin.java index 180b6718..049f978f 100644 --- a/src/main/java/intellij_awk/psi/AwkStringMixin.java +++ b/src/main/java/intellij_awk/psi/AwkStringMixin.java @@ -37,7 +37,7 @@ static boolean canBeFunctionName(String s) { } public PsiElement setName(String newName) { - return replaceNameNode(AwkElementFactory.createFunctionCallName(getProject(), newName)); + return replaceNameNode(AwkElementFactory.createString(getProject(), newName)); } @Override diff --git a/src/test/java/intellij_awk/AwkRenameTests.java b/src/test/java/intellij_awk/AwkRenameTests.java index 40f62158..82d1e795 100644 --- a/src/test/java/intellij_awk/AwkRenameTests.java +++ b/src/test/java/intellij_awk/AwkRenameTests.java @@ -12,6 +12,7 @@ public class AwkRenameTests extends BasePlatformTestCase { public void testVars6() { checkByFile(); } public void testVars7() { checkByFile(); } public void testFunc1() { checkByFile(); } + public void testFuncRef() { checkByFile(); } public void testIndirect1() { checkByFile(); } @Override diff --git a/src/test/testData/rename/funcRef.awk b/src/test/testData/rename/funcRef.awk new file mode 100644 index 00000000..a5408b8b --- /dev/null +++ b/src/test/testData/rename/funcRef.awk @@ -0,0 +1,8 @@ +BEGIN { + a = "fname" + b("fname") + substr("fname") + print "fname" +} +function b() {} +function fname() {} \ No newline at end of file diff --git a/src/test/testData/rename/funcRefAfter.awk b/src/test/testData/rename/funcRefAfter.awk new file mode 100644 index 00000000..69a0b56b --- /dev/null +++ b/src/test/testData/rename/funcRefAfter.awk @@ -0,0 +1,8 @@ +BEGIN { + a = "newName" + b("newName") + substr("fname") + print "fname" +} +function b() {} +function newName() {} \ No newline at end of file