Last active
December 3, 2016 18:29
-
-
Save andresdominguez/8811f467eab0bdab7e1c51479a0a17a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InjectTestAction extends AnAction { | |
@Override | |
public void actionPerformed(AnActionEvent e) { | |
PsiFile file = e.getData(PlatformDataKeys.PSI_FILE); | |
Caret caret = e.getData(PlatformDataKeys.CARET); | |
Editor editor = e.getData(PlatformDataKeys.EDITOR); | |
JSParameterList injectParameterList = findInjectParameterList(file); | |
// Subtract 1 because it ends with ). | |
int paramListOffset = injectParameterList.getTextRange().getEndOffset() - 1; | |
// Surround injectable with underscores. | |
String injectableWithUnderscores = "_" + caret.getSelectedText() + "_"; | |
Document document = editor.getDocument(); | |
// Assign the variable <selection> = _<selection>_; | |
document.insertString(caret.getSelectionEnd(), " = " + injectableWithUnderscores + ";"); | |
// Add the dependency parameter list. | |
document.insertString(paramListOffset, injectableWithUnderscores); | |
} | |
JSParameterList findInjectParameterList(...) { ... } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment