Skip to content

Commit

Permalink
Merge pull request #649 from ris58h/629-do-not-include-declaration-in…
Browse files Browse the repository at this point in the history
…-usages

Don't include declarations in usages (fixes #629).
  • Loading branch information
bjansen authored Sep 14, 2023
2 parents aab6b13 + 9cb8554 commit bcc62fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/antlr/intellij/plugin/psi/LexerRuleRefNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.antlr.intellij.plugin.psi;

import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.tree.IElementType;

Expand All @@ -10,6 +11,16 @@ public LexerRuleRefNode(IElementType type, CharSequence text) {

@Override
public PsiReference getReference() {
if (isDeclaration()) {
return null;
}
return new GrammarElementRef(this, getText());
}

private boolean isDeclaration() {
PsiElement parent = getParent();
return parent instanceof LexerRuleSpecNode
|| parent instanceof TokenSpecNode
|| parent instanceof ChannelSpecNode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ public ParserRuleRefNode(IElementType type, CharSequence text) {

@Override
public PsiReference getReference() {
if (isDeclaration()) {
return null;
}
return new GrammarElementRef(this, getText());
}

private boolean isDeclaration() {
return getParent() instanceof ParserRuleSpecNode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
public class GrammarElementRefTest extends LightPlatformCodeInsightFixtureTestCase {
public void testFindUsagesOfLexerRule() {
Collection<UsageInfo> ruleUsages = myFixture.testFindUsages("SimpleGrammar.g4");
assertEquals(4, ruleUsages.size());
assertEquals(3, ruleUsages.size());
}

public void testFindUsagesOfParserRule() {
Collection<UsageInfo> ruleUsages = myFixture.testFindUsages("SimpleGrammar2.g4");
assertEquals(2, ruleUsages.size());
assertEquals(1, ruleUsages.size());
}

public void testHighlightUsagesOfLexerRule() {
RangeHighlighter[] usages = myFixture.testHighlightUsages("SimpleGrammar.g4");

assertEquals(5, usages.length);
assertEquals(4, usages.length);
}

public void testHighlightUsagesOfParserRule() {
RangeHighlighter[] usages = myFixture.testHighlightUsages("SimpleGrammar2.g4");

assertEquals(3, usages.length);
assertEquals(2, usages.length);
}

public void testReferenceToLexerRule() {
Expand Down

0 comments on commit bcc62fa

Please sign in to comment.