use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.
the class SimpleTemplateLanguageFormattingModelBuilder method createModel.
@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
if (element instanceof PsiFile) {
final FileViewProvider viewProvider = ((PsiFile) element).getViewProvider();
if (viewProvider instanceof TemplateLanguageFileViewProvider) {
final Language language = ((TemplateLanguageFileViewProvider) viewProvider).getTemplateDataLanguage();
FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(language);
if (builder != null) {
return builder.createModel(viewProvider.getPsi(language), settings);
}
}
}
final PsiFile file = element.getContainingFile();
return new DocumentBasedFormattingModel(new AbstractBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) {
@Override
protected List<Block> buildChildren() {
return Collections.emptyList();
}
@Override
public Spacing getSpacing(final Block child1, @NotNull final Block child2) {
return Spacing.getReadOnlySpacing();
}
@Override
public boolean isLeaf() {
return true;
}
}, element.getProject(), settings, file.getFileType(), file);
}
use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.
the class TemplateDataElementType method createPsiFileFromSource.
protected PsiFile createPsiFileFromSource(final Language language, CharSequence sourceCode, PsiManager manager) {
@NonNls final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), sourceCode, LocalTimeCounter.currentTime());
FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {
@Override
@NotNull
public Language getBaseLanguage() {
return language;
}
};
// Since we're already inside a template language PSI that was built regardless of the file size (for whatever reason),
// there should also be no file size checks for template data files.
SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
return viewProvider.getPsi(language);
}
use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.
the class XmlTagTreeHighlightingPass method doCollectInformation.
@Override
public void doCollectInformation(@NotNull ProgressIndicator progress) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
if (!WebEditorOptions.getInstance().isTagTreeHighlightingEnabled()) {
return;
}
final int offset = myEditor.getCaretModel().getOffset();
PsiElement[] elements = BreadcrumbsXmlWrapper.getLinePsiElements(offset, myFile.getVirtualFile(), myProject, myInfoProvider);
if (elements == null || elements.length == 0 || !XmlTagTreeHighlightingUtil.containsTagsWithSameName(elements)) {
elements = PsiElement.EMPTY_ARRAY;
final FileViewProvider provider = myFile.getViewProvider();
for (Language language : provider.getLanguages()) {
PsiElement element = provider.findElementAt(offset, language);
if (!isTagStartOrEnd(element)) {
element = null;
}
if (element == null && offset > 0) {
element = provider.findElementAt(offset - 1, language);
if (!isTagStartOrEnd(element))
element = null;
}
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
if (tag != null) {
elements = new PsiElement[] { tag };
}
}
}
for (int i = elements.length - 1; i >= 0; i--) {
if (elements[i] instanceof XmlTag) {
myPairsToHighlight.add(getTagRanges((XmlTag) elements[i]));
}
}
}
use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.
the class CollapseTagIntention method getTag.
private static XmlTag getTag(Editor editor, PsiFile file) {
int offset = editor.getCaretModel().getOffset();
FileViewProvider provider = file.getViewProvider();
for (Language language : provider.getLanguages()) {
PsiElement element = provider.findElementAt(offset, language);
XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
if (tag != null && XmlChildRole.START_TAG_END_FINDER.findChild(tag.getNode()) != null) {
return tag;
}
}
return null;
}
use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.
the class HtmlUtil method isHtmlTagContainingFile.
public static boolean isHtmlTagContainingFile(PsiElement element) {
if (element == null) {
return false;
}
final PsiFile containingFile = element.getContainingFile();
if (containingFile != null) {
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
if (tag instanceof HtmlTag) {
return true;
}
final XmlDocument document = PsiTreeUtil.getParentOfType(element, XmlDocument.class, false);
if (document instanceof HtmlDocumentImpl) {
return true;
}
final FileViewProvider provider = containingFile.getViewProvider();
Language language;
if (provider instanceof TemplateLanguageFileViewProvider) {
language = ((TemplateLanguageFileViewProvider) provider).getTemplateDataLanguage();
} else {
language = provider.getBaseLanguage();
}
return language == XHTMLLanguage.INSTANCE;
}
return false;
}
Aggregations