Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Intellij GoToDeclarationHandler
public class MyGoToDeclarationHandler extends GotoDeclarationHandlerBase {
@Nullable
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, int offset, Editor editor) {
if (sourceElement.getParent().getParent().getParent() instanceof XmlTag) {
XmlTag tag = (XmlTag)sourceElement.getParent().getParent().getParent();
if (tag.getName().equals("custom:include")) {
VirtualFile currentFile = PsiUtilCore.getVirtualFile(sourceElement);
LinkedList<PsiElement> elements = new LinkedList<PsiElement>();
//this is a silly behavior for demonstration, just take the first file(s) in this directory
elements.add(PsiManager.getInstance(editor.getProject()).findFile(currentFile.getParent().getChildren()[0]));
elements.add(PsiManager.getInstance(editor.getProject()).findFile(currentFile.getParent().getChildren()[1]));
return elements.toArray(new PsiElement[0]);
}
}
return null;
}
@Override
public PsiElement getGotoDeclarationTarget(PsiElement sourceElement, Editor editor) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.