Search in sources :

Example 1 with ElixirFile

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);
}
Also used : ElixirFile(org.elixir_lang.psi.ElixirFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ElixirFile

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;
}
Also used : StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) BeamFileImpl(org.elixir_lang.beam.psi.BeamFileImpl) PsiFile(com.intellij.psi.PsiFile) ElixirFile(org.elixir_lang.psi.ElixirFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ElixirFile

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;
}
Also used : TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) Editor(com.intellij.openapi.editor.Editor) ElixirFile(org.elixir_lang.psi.ElixirFile) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ElixirFile

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;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) EditorEx(com.intellij.openapi.editor.ex.EditorEx) ElixirFile(org.elixir_lang.psi.ElixirFile) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 5 with ElixirFile

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;
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) Properties(java.util.Properties) ElixirFile(org.elixir_lang.psi.ElixirFile) PsiElement(com.intellij.psi.PsiElement) InvocationTargetException(java.lang.reflect.InvocationTargetException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ElixirFile (org.elixir_lang.psi.ElixirFile)9 Nullable (org.jetbrains.annotations.Nullable)5 PsiElement (com.intellij.psi.PsiElement)3 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)2 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)1 FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)1 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)1 TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 Application (com.intellij.openapi.application.Application)1 Editor (com.intellij.openapi.editor.Editor)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)1 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1