Skip to content

Commit

Permalink
Remove dependency on SampleParserDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
yegorpetrov committed Feb 18, 2016
1 parent 0f4e207 commit 57db94a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/org/antlr/jetbrains/adaptor/psi/IdentifierDefSubtree.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.intellij.psi.PsiNamedElement;
import com.intellij.util.IncorrectOperationException;
import org.antlr.jetbrains.adaptor.psi.ANTLRPsiNode;
import org.antlr.jetbrains.sample.SampleParserDefinition;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -22,8 +21,15 @@
* for more details.
*/
public abstract class IdentifierDefSubtree extends ANTLRPsiNode implements PsiNameIdentifierOwner {
public IdentifierDefSubtree(@NotNull ASTNode node) {
/**
* Gets the {@link IElementType} of the ID/Identifier rule for
* use in {@link #getNameIdentifier}
*/
private final IElementType idElementType;

public IdentifierDefSubtree(@NotNull ASTNode node, @NotNull IElementType idElementType) {
super(node);
this.idElementType = idElementType;
}

@Override
Expand All @@ -35,7 +41,7 @@ public String getName() {
@Nullable
@Override
public PsiElement getNameIdentifier() {
ASTNode idNode = getNode().findChildByType(SampleParserDefinition.ID);
ASTNode idNode = getNode().findChildByType(idElementType);
if (idNode != null) {
return idNode.getPsi();
}
Expand Down

2 comments on commit 57db94a

@MichaelSnowden
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe replacing the old constructor broke the sample code here: https://github.com/antlr/jetbrains-plugin-sample

@yegorpetrov
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did. The immediate descendants of IdentifierPSINode in the dependent project should provide the idElementType argument from now on.

Please sign in to comment.