Search in sources :

Example 81 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class CollapseTagTest method testAvailable.

public void testAvailable() throws Exception {
    PsiFile file = myFixture.configureByText(XmlFileType.INSTANCE, "<a>    <caret>   </a>");
    assertTrue(new CollapseTagIntention().isAvailable(getProject(), myFixture.getEditor(), file));
}
Also used : CollapseTagIntention(com.intellij.xml.util.CollapseTagIntention) PsiFile(com.intellij.psi.PsiFile)

Example 82 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class CollapseTagTest method testAlreadyCollapsed.

public void testAlreadyCollapsed() throws Exception {
    PsiFile file = myFixture.configureByText(XmlFileType.INSTANCE, "<a/>");
    assertFalse(new CollapseTagIntention().isAvailable(getProject(), myFixture.getEditor(), file));
}
Also used : CollapseTagIntention(com.intellij.xml.util.CollapseTagIntention) PsiFile(com.intellij.psi.PsiFile)

Example 83 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class CollapseTagTest method testNotAvailable.

public void testNotAvailable() throws Exception {
    PsiFile file = myFixture.configureByText(XmlFileType.INSTANCE, "<a>    <caret>   <b/> </a>");
    assertFalse(new CollapseTagIntention().isAvailable(getProject(), myFixture.getEditor(), file));
}
Also used : CollapseTagIntention(com.intellij.xml.util.CollapseTagIntention) PsiFile(com.intellij.psi.PsiFile)

Example 84 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-plugins by StepicOrg.

the class ProgrammingLanguageUtils method switchProgrammingLanguage.

public static void switchProgrammingLanguage(@NotNull Project project, @NotNull StepNode targetStepNode, @NotNull SupportedLanguages language) {
    if (!targetStepNode.getSupportedLanguages().contains(language)) {
        return;
    }
    SupportedLanguages currentLang = targetStepNode.getCurrentLang();
    String currentMainFileName = currentLang.getMainFileName();
    String mainFilePath = String.join("/", targetStepNode.getPath(), EduNames.SRC, currentMainFileName);
    VirtualFile mainFile = project.getBaseDir().findFileByRelativePath(mainFilePath);
    boolean mainFileExists = mainFile != null;
    if (currentLang == language && mainFileExists) {
        return;
    }
    if (currentMainFileName.equals(language.getMainFileName()) && mainFileExists) {
        targetStepNode.setCurrentLang(language);
        Metrics.switchLanguage(project, targetStepNode, SUCCESSFUL);
        return;
    }
    PsiDirectory src = getOrCreateSrcPsiDirectory(project, targetStepNode);
    if (src == null) {
        return;
    }
    PsiDirectory hide = getOrCreatePsiDirectory(project, src, EduNames.HIDE);
    if (hide == null) {
        return;
    }
    PsiFile second = findFile(src, language.getMainFileName());
    boolean moveSecond = second == null;
    if (moveSecond) {
        second = getOrCreateMainFile(project, hide.getVirtualFile(), language, targetStepNode);
        if (second == null) {
            logger.error("Can't create Main file: " + language.getMainFileName());
            return;
        }
    }
    PsiFile first = findFile(hide, currentMainFileName);
    boolean moveFirst = first == null;
    if (moveFirst) {
        first = findFile(src, currentMainFileName);
        moveFirst = !second.isEquivalentTo(first);
    }
    targetStepNode.setCurrentLang(language);
    ArrayList<VirtualFile> needClose = closeStepNodeFile(project, targetStepNode);
    PsiFile finalSecond = second;
    PsiFile finalFirst = first;
    boolean finalMoveFirst = moveFirst;
    ApplicationManager.getApplication().invokeAndWait(() -> {
        FileEditorManager.getInstance(project).openFile(finalSecond.getVirtualFile(), true);
        FileEditorManager editorManager = FileEditorManager.getInstance(project);
        needClose.forEach(editorManager::closeFile);
        exchangeFiles(src, hide, finalFirst, finalSecond, finalMoveFirst, moveSecond);
        ProjectView.getInstance(project).selectPsiElement(finalSecond, false);
    });
    Metrics.switchLanguage(project, targetStepNode, SUCCESSFUL);
}
Also used : SupportedLanguages(org.stepik.core.SupportedLanguages) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ProjectFilesUtils.getOrCreateSrcPsiDirectory(org.stepik.core.utils.ProjectFilesUtils.getOrCreateSrcPsiDirectory) ProjectFilesUtils.getOrCreatePsiDirectory(org.stepik.core.utils.ProjectFilesUtils.getOrCreatePsiDirectory) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile)

Example 85 with PsiFile

use of com.intellij.psi.PsiFile in project Main by SpartanRefactoring.

the class ToolboxTest method testCheckExcluded.

public void testCheckExcluded() throws Exception {
    tb.initComponent();
    PsiFile f = createTestFileFromString("class A{}");
    tb.excludeFile(f);
    assertTrue(tb.checkExcluded(f));
    tb.includeFile(f);
    assertFalse(tb.checkExcluded(f));
    tb.disposeComponent();
}
Also used : 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