Search in sources :

Example 6 with PsiFile

use of com.intellij.psi.PsiFile in project buck by facebook.

the class BuckAutoDepsContributor method getVirtualFileFromClassname.

@Nullable
public VirtualFile getVirtualFileFromClassname(String classname) {
    GlobalSearchScope scope = GlobalSearchScope.allScope(mProject);
    PsiClass psiClass = JavaPsiFacade.getInstance(mProject).findClass(classname, scope);
    if (psiClass == null) {
        return null;
    }
    PsiFile psiFile = psiClass.getContainingFile();
    if (psiFile == null) {
        return null;
    }
    return psiFile.getVirtualFile();
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) Nullable(javax.annotation.Nullable)

Example 7 with PsiFile

use of com.intellij.psi.PsiFile in project android-parcelable-intellij-plugin by mcharmas.

the class ParcelableAction method getPsiClassFromContext.

private PsiClass getPsiClassFromContext(AnActionEvent e) {
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (psiFile == null || editor == null) {
        return null;
    }
    int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);
    return PsiTreeUtil.getParentOfType(element, PsiClass.class);
}
Also used : PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PsiFile

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

the class FreelineUtil method checkInstall.

/**
     * 检查是否需要载入Freeline
     *
     * @param project
     * @return
     */
public static boolean checkInstall(@NotNull final Project project) {
    final FreelineStatus status = getFreelineStatus(project);
    if (GradleUtil.isSyncInProgress(project)) {
        NotificationUtils.errorMsgDialog("Waiting for sync project to complete");
        return false;
    }
    if (status.hasInitFreeline()) {
        return true;
    }
    if (status.getGradleBuildFiles().size() < 1) {
        NotificationUtils.errorMsgDialog("It's not an Android Gradle project Currently?");
        return false;
    }
    if (status.isExistClasspath() && status.isExistPlugin() && !status.isExistFreelineCore()) {
        NotificationUtils.errorNotification("Execute task initFreeline and download freeline dependencies...");
        initFreeline(project);
        return false;
    }
    if (DialogUtil.createDialog("Detected that you did not installFreeline Freeline, Whether installFreeline Automatically?", "Install Freeline Automatically", "Cancel")) {
        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()));
            }
        }
        // 多个app模块的情况
        if (selectModulesList.size() > 1) {
            final DialogBuilder builder = new DialogBuilder();
            builder.setTitle("Install Freeline");
            builder.resizable(false);
            builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the module to be installed Freeline.", 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);
                        installFreeline(project, status, pair.getSecond());
                    }
                });
            }
            if (builder.show() > -1) {
                return false;
            }
        } else if (selectModulesList.size() == 1) {
            installFreeline(project, status, selectModulesList.get(0).getSecond());
        } else {
            NotificationUtils.errorMsgDialog("Can not found Application Module! Please Sync Project.");
            return false;
        }
    }
    return false;
}
Also used : GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) ActionEvent(java.awt.event.ActionEvent) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) Pair(com.intellij.openapi.util.Pair)

Example 9 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 10 with PsiFile

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

the class GoStubTest method doTest.

private void doTest(boolean checkErrors) throws IOException {
    String fileName = getTestName(true) + ".go";
    String text = FileUtil.loadFile(new File(getTestDataPath(), fileName));
    PsiFile file = myFixture.addFileToProject(fileName, text);
    String s = buildStubTreeText(getProject(), file.getVirtualFile(), text, checkErrors);
    ParsingTestCase.doCheckResult(getTestDataPath(), getTestName(true) + ".txt", s);
}
Also used : PsiFile(com.intellij.psi.PsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Aggregations

PsiFile (com.intellij.psi.PsiFile)1776 VirtualFile (com.intellij.openapi.vfs.VirtualFile)490 PsiElement (com.intellij.psi.PsiElement)466 Nullable (org.jetbrains.annotations.Nullable)267 Project (com.intellij.openapi.project.Project)266 NotNull (org.jetbrains.annotations.NotNull)248 Document (com.intellij.openapi.editor.Document)181 Editor (com.intellij.openapi.editor.Editor)166 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)106 TextRange (com.intellij.openapi.util.TextRange)88 ArrayList (java.util.ArrayList)81 XmlTag (com.intellij.psi.xml.XmlTag)68 File (java.io.File)58 PsiManager (com.intellij.psi.PsiManager)56 PsiClass (com.intellij.psi.PsiClass)50 List (java.util.List)46 Language (com.intellij.lang.Language)45