use of org.elixir_lang.psi.ElixirFile in project intellij-elixir by KronicDeth.
the class ElixirXDebugProcess method getModuleName.
@Nullable
private String getModuleName(@NotNull ElixirSourcePosition breakpointPosition) {
ElixirFile psiFile = (ElixirFile) PsiManager.getInstance(getRunConfiguration().getProject()).findFile(breakpointPosition.getFile());
if (psiFile == null)
return null;
PsiElement elem = psiFile.findElementAt(breakpointPosition.getSourcePosition().getOffset());
return ElixirPsiImplUtil.getModuleName(elem);
}
use of org.elixir_lang.psi.ElixirFile in project intellij-elixir by KronicDeth.
the class StructureViewBuilderProvider method getStructureViewBuilder.
/**
* Returns the structure view builder for the specified file.
*
* @param fileType file type of the file to provide structure for
* @param virtualFile The file for which the structure view builder is requested.
* @param project The project to which the file belongs.
* @return The structure view builder, or null if no structure view is available for the file.
*/
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(@NotNull FileType fileType, @NotNull VirtualFile virtualFile, @NotNull Project project) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
StructureViewBuilder structureViewBuilder = null;
if (psiFile instanceof BeamFileImpl) {
BeamFileImpl beamFileImpl = (BeamFileImpl) psiFile;
PsiElement mirror = beamFileImpl.getMirror();
if (mirror instanceof ElixirFile) {
structureViewBuilder = Factory.structureViewBuilder((ElixirFile) mirror);
}
}
return structureViewBuilder;
}
use of org.elixir_lang.psi.ElixirFile in project intellij-elixir by KronicDeth.
the class Factory method structureViewBuilder.
@Nullable
public static StructureViewBuilder structureViewBuilder(@NotNull final PsiFile psiFile) {
StructureViewBuilder structureViewBuilder = null;
if (psiFile instanceof ElixirFile) {
final ElixirFile elixirFile = (ElixirFile) psiFile;
structureViewBuilder = new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new Model(elixirFile, editor);
}
@Override
public boolean isRootNodeShown() {
return false;
}
};
}
return structureViewBuilder;
}
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;
}
Aggregations