Search in sources :

Example 51 with PsiFile

use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoAutoImportInsertHandler method autoImport.

private static void autoImport(@NotNull InsertionContext context, @NotNull GoNamedElement element) {
    PsiFile file = context.getFile();
    boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(ModuleUtilCore.findModuleForPsiElement(file));
    String importPath = element.getContainingFile().getImportPath(vendoringEnabled);
    if (StringUtil.isEmpty(importPath))
        return;
    PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
    PsiReference reference = file.findReferenceAt(context.getStartOffset());
    if (reference != null) {
        PsiElement referenceElement = reference.getElement();
        GoImportPackageQuickFix fix = new GoImportPackageQuickFix(referenceElement, importPath);
        fix.invoke(context.getProject(), file, context.getEditor(), referenceElement, referenceElement);
    }
}
Also used : GoImportPackageQuickFix(com.goide.codeInsight.imports.GoImportPackageQuickFix) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 52 with PsiFile

use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiElement position = parameters.getPosition();
    PsiFile file = parameters.getOriginalFile();
    ASTNode node = position.getNode();
    if (file instanceof GoFile && position.getParent() instanceof GoPackageClause && node.getElementType() == GoTypes.IDENTIFIER) {
        boolean isTestFile = GoTestFinder.isTestFile(file);
        PsiDirectory directory = file.getParent();
        String currentPackageName = ((GoFile) file).getPackageName();
        Collection<String> packagesInDirectory = GoPackageUtil.getAllPackagesInDirectory(directory, null, true);
        for (String packageName : packagesInDirectory) {
            if (!packageName.equals(currentPackageName)) {
                result.addElement(packageLookup(packageName, GoCompletionUtil.PACKAGE_PRIORITY - 1));
            }
            if (isTestFile) {
                result.addElement(packageLookup(packageName + GoConstants.TEST_SUFFIX, GoCompletionUtil.PACKAGE_PRIORITY));
            }
        }
        if (directory != null && ContainerUtil.filter(directory.getFiles(), Conditions.instanceOf(GoFile.class)).size() == 1) {
            String packageFromDirectory = GoPsiImplUtil.getLocalPackageName(directory.getName());
            if (!packageFromDirectory.isEmpty()) {
                result.addElement(packageLookup(packageFromDirectory, GoCompletionUtil.PACKAGE_PRIORITY - 1));
            }
        }
        result.addElement(packageLookup(GoConstants.MAIN, GoCompletionUtil.PACKAGE_PRIORITY - 2));
    }
    super.fillCompletionVariants(parameters, result);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) ASTNode(com.intellij.lang.ASTNode) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 53 with PsiFile

use of com.intellij.psi.PsiFile in project freeline by alibaba.

the class UsingReportAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getProject();
    Module[] modules = ModuleManager.getInstance(project).getModules();
    List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
    for (Module module : modules) {
        GradleBuildFile file = GradleBuildFile.get(module);
        if (file != null && !GradleUtil.isLibrary(file)) {
            selectModulesList.add(Pair.create(module, file.getPsiFile()));
        }
    }
    if (selectModulesList.size() > 1) {
        final DialogBuilder builder = new DialogBuilder();
        builder.setTitle("Freeline Reporter");
        builder.resizable(false);
        builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the exact one.", Messages.getInformationIcon(), SwingConstants.CENTER));
        builder.addOkAction().setText("Cancel");
        for (final Pair<Module, PsiFile> pair : selectModulesList) {
            builder.addAction(new AbstractAction(":" + pair.first.getName()) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
                    report(project, pair.getSecond());
                }
            });
        }
        if (builder.show() > -1) {
        //return false;
        }
    } else if (selectModulesList.size() == 1) {
        report(project, selectModulesList.get(0).getSecond());
    }
}
Also used : GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) Pair(com.intellij.openapi.util.Pair)

Example 54 with PsiFile

use of com.intellij.psi.PsiFile in project idea-handlebars by dmarcotte.

the class HbStructureViewFactory method getStructureViewBuilder.

@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    return new TemplateLanguageStructureViewBuilder(psiFile) {

        @Override
        protected StructureViewComposite.StructureViewDescriptor createMainView(FileEditor fileEditor, PsiFile mainFile) {
            if (!psiFile.isValid())
                return null;
            final StructureViewBuilder builder = new TreeBasedStructureViewBuilder() {

                @NotNull
                @Override
                public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
                    return new HbStructureViewModel((HbPsiFile) psiFile, editor);
                }
            };
            StructureView structureView = builder.createStructureView(fileEditor, psiFile.getProject());
            return new StructureViewComposite.StructureViewDescriptor(HbLanguage.INSTANCE.getDisplayName(), structureView, HbFileType.INSTANCE.getIcon());
        }
    };
}
Also used : TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) TemplateLanguageStructureViewBuilder(com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureView(com.intellij.ide.structureView.StructureView) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) HbPsiFile(com.dmarcotte.handlebars.psi.HbPsiFile) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageStructureViewBuilder(com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable) StructureViewComposite(com.intellij.ide.structureView.impl.StructureViewComposite) Nullable(org.jetbrains.annotations.Nullable)

Example 55 with PsiFile

use of com.intellij.psi.PsiFile in project idea-handlebars by dmarcotte.

the class HbsEmmetTest method testSimpleTagsWithHtmlSubstitutor.

public void testSimpleTagsWithHtmlSubstitutor() {
    HbTestUtils.setOpenHtmlAsHandlebars(true, getProject(), getTestRootDisposable());
    final PsiFile file = myFixture.configureByText("test.html", "div>span<caret>");
    assertInstanceOf(file, HbPsiFile.class);
    TemplateManager.getInstance(getProject()).startTemplate(myFixture.getEditor(), TemplateSettings.TAB_CHAR);
    myFixture.checkResult("<div><span></span></div>");
}
Also used : HbPsiFile(com.dmarcotte.handlebars.psi.HbPsiFile) PsiFile(com.intellij.psi.PsiFile)

Aggregations

PsiFile (com.intellij.psi.PsiFile)1785 VirtualFile (com.intellij.openapi.vfs.VirtualFile)496 PsiElement (com.intellij.psi.PsiElement)468 Project (com.intellij.openapi.project.Project)267 Nullable (org.jetbrains.annotations.Nullable)267 NotNull (org.jetbrains.annotations.NotNull)248 Document (com.intellij.openapi.editor.Document)181 Editor (com.intellij.openapi.editor.Editor)168 XmlFile (com.intellij.psi.xml.XmlFile)126 PsiDirectory (com.intellij.psi.PsiDirectory)114 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)109 Module (com.intellij.openapi.module.Module)108 TextRange (com.intellij.openapi.util.TextRange)88 ArrayList (java.util.ArrayList)84 XmlTag (com.intellij.psi.xml.XmlTag)68 File (java.io.File)58 PsiManager (com.intellij.psi.PsiManager)56 PsiClass (com.intellij.psi.PsiClass)51 List (java.util.List)46 Language (com.intellij.lang.Language)45