Search in sources :

Example 66 with PsiFile

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

the class YAMLPsiManager method isOutOfCodeBlock.

@Override
protected boolean isOutOfCodeBlock(@NotNull PsiElement element) {
    while (true) {
        if (element instanceof YAMLFile) {
            return true;
        }
        if (element instanceof PsiFile || element instanceof PsiDirectory) {
            return false;
        }
        PsiElement parent = element.getParent();
        if (!(parent instanceof YAMLFile || parent instanceof YAMLKeyValue || parent instanceof YAMLCompoundValue || parent instanceof YAMLDocument)) {
            return false;
        }
        element = parent;
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 67 with PsiFile

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

the class XsltDebuggerEditorsProvider method createDocument.

@NotNull
@Override
public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition sourcePosition, @NotNull EvaluationMode mode) {
    final PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("XPathExpr." + myFileType.getDefaultExtension(), myFileType, text, LocalTimeCounter.currentTime(), true);
    if (sourcePosition instanceof XsltSourcePosition && ((XsltSourcePosition) sourcePosition).getLocation() instanceof Debugger.StyleFrame) {
        final Debugger.Locatable location = ((XsltSourcePosition) sourcePosition).getLocation();
        final EvalContextProvider context = new EvalContextProvider(((Debugger.StyleFrame) location).getVariables());
        context.attachTo(psiFile);
    } else {
        final PsiElement contextElement = XsltBreakpointHandler.findContextElement(project, sourcePosition);
        if (contextElement != null) {
            final BreakpointContext context = new BreakpointContext(contextElement);
            context.attachTo(psiFile);
        }
    }
    final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
    assert document != null;
    return document;
}
Also used : Debugger(org.intellij.plugins.xsltDebugger.rt.engine.Debugger) BreakpointContext(org.intellij.plugins.xsltDebugger.BreakpointContext) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with PsiFile

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

the class YAMLScalarConversionTest method doTest.

private void doTest(Class<? extends YAMLScalar>... unsupportedClasses) {
    final PsiFile file = myFixture.configureByFile("sampleDocument.yml");
    Collection<YAMLScalar> scalars = PsiTreeUtil.collectElementsOfType(file, YAMLScalar.class);
    assertEquals(5, scalars.size());
    final String text;
    try {
        text = FileUtil.loadFile(new File(getTestDataPath() + getTestName(true) + ".txt"), true);
    } catch (IOException e) {
        fail(e.toString());
        return;
    }
    for (YAMLScalar scalar : scalars) {
        boolean isUnsupported = ((Computable<Boolean>) () -> {
            for (Class<? extends YAMLScalar> aClass : unsupportedClasses) {
                if (aClass == scalar.getClass()) {
                    return true;
                }
            }
            return false;
        }).compute();
        final ElementManipulator<YAMLScalar> manipulator = ElementManipulators.getManipulator(scalar);
        assertNotNull(manipulator);
        WriteCommandAction.runWriteCommandAction(getProject(), () -> {
            final YAMLScalar newElement = manipulator.handleContentChange(scalar, text);
            assertEquals(isUnsupported + ";" + newElement.getClass() + ";" + scalar.getClass(), isUnsupported, newElement.getClass() != scalar.getClass());
            assertEquals("Failed at " + scalar.getClass() + " (became " + newElement.getClass() + "): ", text, newElement.getTextValue());
        });
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) YAMLScalar(org.jetbrains.yaml.psi.YAMLScalar) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) Computable(com.intellij.openapi.util.Computable)

Example 69 with PsiFile

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

the class PythonConsoleView method addTextRangeToHistory.

@NotNull
protected String addTextRangeToHistory(@NotNull TextRange textRange, @NotNull EditorEx inputEditor, boolean preserveMarkup) {
    String text;
    EditorHighlighter highlighter;
    if (inputEditor instanceof EditorWindow) {
        PsiFile file = ((EditorWindow) inputEditor).getInjectedFile();
        highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), getProject());
        String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null);
        highlighter.setText(fullText);
        text = textRange.substring(fullText);
    } else {
        text = inputEditor.getDocument().getText(textRange);
        highlighter = inputEditor.getHighlighter();
    }
    SyntaxHighlighter syntax = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter) highlighter).getSyntaxHighlighter() : null;
    doAddPromptToHistory(true);
    if (syntax != null) {
        ConsoleViewUtil.printWithHighlighting(this, text, syntax, () -> doAddPromptToHistory(false));
    } else {
        print(text, ConsoleViewContentType.USER_INPUT);
    }
    print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
    return text;
}
Also used : PsiFile(com.intellij.psi.PsiFile) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) EditorWindow(com.intellij.injected.editor.EditorWindow) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with PsiFile

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

the class PyDebugProcess method getSourcePositionForType.

@Nullable
@Override
public XSourcePosition getSourcePositionForType(String typeName) {
    XSourcePosition currentPosition = getCurrentFrameSourcePosition();
    final PsiFile file = getPsiFile(currentPosition);
    if (file == null || typeName == null || !(file instanceof PyFile))
        return null;
    final PyType pyType = resolveTypeFromString(typeName, file);
    return pyType == null ? null : typeToPosition(pyType);
}
Also used : PyType(com.jetbrains.python.psi.types.PyType) 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