Skip to content

Commit

Permalink
False positive warning "Function ... is never used" #214 : more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Apr 16, 2024
1 parent ab07ebb commit aa08fb6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/intellij_awk/psi/AwkStringMixin.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package intellij_awk.psi;

import static com.intellij.openapi.util.text.StringUtil.unquoteString;

import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import intellij_awk.AwkReferenceFunction;
import intellij_awk.AwkUtil;
import java.util.regex.Pattern;
import javax.swing.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.regex.Pattern;

import static com.intellij.openapi.util.text.StringUtil.unquoteString;

public abstract class AwkStringMixin extends AwkNamedElementImpl {
public AwkStringMixin(@NotNull ASTNode node) {
super(node);
Expand All @@ -37,11 +37,15 @@ public PsiElement setName(String newName) {

@Override
public PsiReference getReference() {
return getName() != null
return getName() != null && isRhsOfAssignment()
? new AwkReferenceFunction(this, TextRange.from(1, getTextLength() - 2))
: null;
}

private boolean isRhsOfAssignment() {
return AwkUtil.isType(AwkUtil.getPrevNotWhitespace(getParent()), AwkTypes.ASSIGN);
}

@Override
public @Nullable Icon getIcon(int flags) {
return null;
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/intellij_awk/AwkInspectionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ public void testFuncRefToPreventUnusedFunc2_1() {
checkByFile(unusedFunction);
}

public void testFuncRefToPreventUnusedFunc3() {
checkByFileNoProblemAtCaret(unusedFunction);
}

public void testFuncRefToPreventUnusedFunc3_1() {
checkByFile(unusedFunction);
}

@Override
protected String getTestDataPath() {
return "src/test/testData/inspection";
Expand Down
5 changes: 5 additions & 0 deletions src/test/testData/inspection/funcRefToPreventUnusedFunc3.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN {
print a = "fname"
}

function <caret>fname() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN {
print "fname"
}

function <caret>fname() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BEGIN {
print "fname"
}

0 comments on commit aa08fb6

Please sign in to comment.