Search in sources :

Example 91 with PsiFile

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

the class PyEditingTest method doTestTyping.

private String doTestTyping(final String text, final int offset, final char character) {
    final PsiFile file = myFixture.configureByText(PythonFileType.INSTANCE, text);
    myFixture.getEditor().getCaretModel().moveToOffset(offset);
    myFixture.type(character);
    return myFixture.getDocument(file).getText();
}
Also used : PsiFile(com.intellij.psi.PsiFile)

Example 92 with PsiFile

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

the class PyFormatterTest method doTest.

private void doTest(final boolean reformatText) {
    myFixture.configureByFile("formatter/" + getTestName(true) + ".py");
    WriteCommandAction.runWriteCommandAction(null, () -> {
        CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myFixture.getProject());
        PsiFile file = myFixture.getFile();
        if (reformatText) {
            codeStyleManager.reformatText(file, 0, file.getTextLength());
        } else {
            codeStyleManager.reformat(file);
        }
    });
    myFixture.checkResultByFile("formatter/" + getTestName(true) + "_after.py");
}
Also used : CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) PsiFile(com.intellij.psi.PsiFile)

Example 93 with PsiFile

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

the class PyRegexpTest method getElementAtCaret.

@NotNull
private PsiElement getElementAtCaret() {
    final Editor editor = myFixture.getEditor();
    final Document document = editor.getDocument();
    final PsiFile file = PsiDocumentManager.getInstance(myFixture.getProject()).getPsiFile(document);
    assertNotNull(file);
    final PsiElement element = file.findElementAt(myFixture.getCaretOffset());
    assertNotNull(element);
    return element;
}
Also used : PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 94 with PsiFile

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

the class DomServiceImpl method getFileElements.

@Override
public <T extends DomElement> List<DomFileElement<T>> getFileElements(final Class<T> clazz, final Project project, @Nullable final GlobalSearchScope scope) {
    final Collection<VirtualFile> list = getDomFileCandidates(clazz, project, scope != null ? scope : GlobalSearchScope.allScope(project));
    final ArrayList<DomFileElement<T>> result = new ArrayList<>(list.size());
    for (VirtualFile file : list) {
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        if (psiFile instanceof XmlFile) {
            final DomFileElement<T> element = DomManager.getDomManager(project).getFileElement((XmlFile) psiFile, clazz);
            if (element != null) {
                result.add(element);
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile)

Example 95 with PsiFile

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

the class XmlNamespaceIndex method guessDtd.

@Nullable
public static XmlFile guessDtd(String dtdUri, @NotNull PsiFile baseFile) {
    if (!dtdUri.endsWith(".dtd") || DumbService.isDumb(baseFile.getProject()) || XmlUtil.isStubBuilding())
        return null;
    String dtdFileName = new File(dtdUri).getName();
    List<IndexedRelevantResource<String, XsdNamespaceBuilder>> list = getResourcesByNamespace(dtdFileName, baseFile.getProject(), ModuleUtilCore.findModuleForPsiElement(baseFile));
    if (list.isEmpty()) {
        return null;
    }
    IndexedRelevantResource<String, XsdNamespaceBuilder> resource;
    if (list.size() > 1) {
        final String[] split = dtdUri.split("/");
        resource = Collections.max(list, new Comparator<IndexedRelevantResource<String, XsdNamespaceBuilder>>() {

            @Override
            public int compare(IndexedRelevantResource<String, XsdNamespaceBuilder> o1, IndexedRelevantResource<String, XsdNamespaceBuilder> o2) {
                return weight(o1) - weight(o2);
            }

            int weight(IndexedRelevantResource<String, XsdNamespaceBuilder> o1) {
                VirtualFile file = o1.getFile();
                for (int i = split.length - 1; i >= 0 && file != null; i--) {
                    String s = split[i];
                    if (!s.equals(file.getName())) {
                        return split.length - i;
                    }
                    file = file.getParent();
                }
                return 0;
            }
        });
    } else {
        resource = list.get(0);
    }
    return findSchemaFile(resource.getFile(), baseFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

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