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;
}
}
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;
}
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());
});
}
}
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;
}
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);
}
Aggregations