use of org.elixir_lang.psi.ElixirFile in project intellij-elixir by KronicDeth.
the class TypedHandler method charTyped.
/*
* Instance Methods
*/
/**
* Called after the specified character typed by the user has been inserted in the editor.
*
* @param charTyped the character that was typed
* @param project the project in which the {@code file} exists
* @param editor the editor that has the {@code file} open
* @param file the file into which the {@code charTyped} was typed
*/
@Override
public Result charTyped(char charTyped, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
Result result = Result.CONTINUE;
if (file instanceof ElixirFile) {
if (charTyped == ' ') {
int caret = editor.getCaretModel().getOffset();
if (caret > 2) {
// "(do|fn)<space><caret>"
final EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(caret - 2);
IElementType tokenType = iterator.getTokenType();
if (tokenType == ElixirTypes.DO || tokenType == ElixirTypes.FN) {
editor.getDocument().insertString(caret, " end");
result = Result.STOP;
}
}
} else if (charTyped == '<') {
int caret = editor.getCaretModel().getOffset();
if (caret > 2) {
// "~<sigil_name><"
final EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(caret - 1);
IElementType tokenType = iterator.getTokenType();
if (SIGIL_PROMOTERS.contains(tokenType)) {
editor.getDocument().insertString(caret, ">");
result = Result.STOP;
}
}
if (result == Result.CONTINUE && caret > 1) {
// "<<"
final EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(caret - 2);
if (iterator.getTokenType() == ElixirTypes.OPENING_BIT) {
editor.getDocument().insertString(caret, ">>");
result = Result.STOP;
}
}
} else if (charTyped == '/' || charTyped == '|') {
int caret = editor.getCaretModel().getOffset();
if (caret > 2) {
// "~<sigil_name>(/|\|)"
final EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(caret - 1);
IElementType tokenType = iterator.getTokenType();
if (SIGIL_PROMOTERS.contains(tokenType)) {
editor.getDocument().insertString(caret, String.valueOf(charTyped));
result = Result.STOP;
}
}
}
}
return result;
}
use of org.elixir_lang.psi.ElixirFile in project intellij-elixir by KronicDeth.
the class CreateElixirModuleAction method createModuleFromTemplate.
/**
* @link com.intellij.ide.acitons.CreateTemplateInPackageAction#doCreate
* @link com.intellij.ide.actions.CreateClassAction
* @link com.intellij.psi.impl.file.JavaDirectoryServiceImpl.createClassFromTemplate
*/
@Nullable
private static ElixirFile createModuleFromTemplate(@NotNull PsiDirectory directory, @NotNull String basename, @NotNull String moduleName, @NotNull String templateName) {
FileTemplateManager fileTemplateManager = FileTemplateManager.getDefaultInstance();
FileTemplate template = fileTemplateManager.getInternalTemplate(templateName);
Properties defaultProperties = fileTemplateManager.getDefaultProperties();
Properties properties = new Properties(defaultProperties);
properties.setProperty(FileTemplate.ATTRIBUTE_NAME, moduleName);
PsiElement element;
try {
element = FileTemplateUtil.createFromTemplate(template, basename, properties, directory);
} catch (Exception exception) {
LOG.error(exception);
return null;
}
if (element == null) {
return null;
}
return (ElixirFile) element;
}
use of org.elixir_lang.psi.ElixirFile in project intellij-elixir by KronicDeth.
the class CreateElixirModuleActionTest method checkModuleFile.
private void checkModuleFile(final String moduleName, String path) throws IOException {
ActionManager actionManager = ActionManager.getInstance();
final CreateElixirModuleAction elixirNewFileAction = (CreateElixirModuleAction) actionManager.getAction("Elixir.NewFile");
// @see https://devnet.jetbrains.com/message/5539349#5539349
VirtualFile directoryVirtualFile = myFixture.getTempDirFixture().findOrCreateDir("");
final PsiDirectory directory = myFixture.getPsiManager().findDirectory(directoryVirtualFile);
Application application = ApplicationManager.getApplication();
application.runWriteAction(new Runnable() {
@Override
public void run() {
ElixirFile file = elixirNewFileAction.createFile(moduleName, TEMPLATE_NAME, directory);
assertNotNull("Expected CreateElixirModuleAction.createFile to create an ElixirFile", file);
}
});
boolean ignoreTrailingWhitespaces = true;
myFixture.checkResultByFile(path, path, ignoreTrailingWhitespaces);
}
use of org.elixir_lang.psi.ElixirFile in project intellij-elixir by KronicDeth.
the class BeamFileImpl method setMirror.
@Override
public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
PsiElement mirrorElement = SourceTreeToPsiMap.treeToPsiNotNull(element);
if (!(mirrorElement instanceof ElixirFile)) {
throw new InvalidMirrorException("Unexpected mirror file: " + mirrorElement);
}
ElixirFile mirrorFile = (ElixirFile) mirrorElement;
setMirrors(modulars(), mirrorFile.modulars());
}
Aggregations