com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider Java Examples
The following examples show how to use
com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommentByBlockCommentHandler.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public static Commenter getCommenter(final PsiFile file, final Editor editor, final Language lineStartLanguage, final Language lineEndLanguage) { final FileViewProvider viewProvider = file.getViewProvider(); for (MultipleLangCommentProvider provider : MultipleLangCommentProvider.EP_NAME.getExtensions()) { if (provider.canProcess(file, viewProvider)) { return provider.getLineCommenter(file, editor, lineStartLanguage, lineEndLanguage); } } final Language fileLanguage = file.getLanguage(); Language lang = lineStartLanguage == null || LanguageCommenters.INSTANCE.forLanguage(lineStartLanguage) == null || fileLanguage.getBaseLanguage() == lineStartLanguage // file language is a more specific dialect of the line language ? fileLanguage : lineStartLanguage; if (viewProvider instanceof TemplateLanguageFileViewProvider && lang == ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage()) { lang = viewProvider.getBaseLanguage(); } return LanguageCommenters.INSTANCE.forLanguage(lang); }
Example #2
Source File: StructureViewElementWrapper.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private Navigatable getNavigatableInTemplateLanguageFile() { PsiElement element = (PsiElement)myTreeElement.getValue(); if (element == null) return null; int offset = element.getTextRange().getStartOffset(); final Language dataLanguage = ((TemplateLanguageFileViewProvider)myMainFile.getViewProvider()).getTemplateDataLanguage(); final PsiFile dataFile = myMainFile.getViewProvider().getPsi(dataLanguage); if (dataFile == null) return null; PsiElement tlElement = dataFile.findElementAt(offset); while(true) { if (tlElement == null || tlElement.getTextRange().getStartOffset() != offset) break; if (tlElement instanceof Navigatable) { return (Navigatable)tlElement; } tlElement = tlElement.getParent(); } return null; }
Example #3
Source File: TemplateLanguageFormattingModelBuilder.java From consulo with Apache License 2.0 | 6 votes |
protected Block getRootBlock(PsiElement element, FileViewProvider viewProvider, CodeStyleSettings settings) { ASTNode node = element.getNode(); if (node == null) { return createDummyBlock(node); } if (viewProvider instanceof TemplateLanguageFileViewProvider) { final Language dataLanguage = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage(); final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(dataLanguage); if (builder instanceof DelegatingFormattingModelBuilder && ((DelegatingFormattingModelBuilder)builder).dontFormatMyModel()) { return createDummyBlock(node); } if (builder != null) { final FormattingModel model = builder.createModel(viewProvider.getPsi(dataLanguage), settings); List<DataLanguageBlockWrapper> childWrappers = buildChildWrappers(model.getRootBlock()); if (childWrappers.size() == 1) { childWrappers = buildChildWrappers(childWrappers.get(0).getOriginal()); } return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null, filterBlocksByRange(childWrappers, node.getTextRange()), settings); } } return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null, Collections.<DataLanguageBlockWrapper>emptyList(), settings); }
Example #4
Source File: FluidFileIndentOptionsProvider.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Nullable @Override public CommonCodeStyleSettings.IndentOptions getIndentOptions(@NotNull CodeStyleSettings settings, @NotNull PsiFile file) { if (file instanceof FluidFile) { if (file.getViewProvider() instanceof TemplateLanguageFileViewProvider) { Language language = ((TemplateLanguageFileViewProvider) file.getViewProvider()).getTemplateDataLanguage(); return settings.getCommonSettings(language).getIndentOptions(); } } return null; }
Example #5
Source File: InjectedFileViewProvider.java From consulo with Apache License 2.0 | 5 votes |
static InjectedFileViewProvider create(@Nonnull PsiManagerEx manager, @Nonnull VirtualFileWindowImpl file, @Nonnull DocumentWindowImpl window, @Nonnull Language language) { AbstractFileViewProvider original = (AbstractFileViewProvider)manager.getFileManager().createFileViewProvider(file, false); return original instanceof TemplateLanguageFileViewProvider ? new MultipleRootsInjectedFileViewProvider.Template(manager, file, window, language, original) : original instanceof MultiplePsiFilesPerDocumentFileViewProvider ? new MultipleRootsInjectedFileViewProvider(manager, file, window, language, original) : new SingleRootInjectedFileViewProvider(manager, file, window, language); }
Example #6
Source File: TemplateLanguageStructureViewBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static JBIterable<Language> getLanguages(@Nullable PsiFile psiFile) { if (psiFile == null) return JBIterable.empty(); FileViewProvider provider = psiFile.getViewProvider(); Language baseLanguage = provider.getBaseLanguage(); Language dataLanguage = provider instanceof TemplateLanguageFileViewProvider ? ((TemplateLanguageFileViewProvider)provider).getTemplateDataLanguage() : null; return JBIterable.of(baseLanguage).append(dataLanguage).append(JBIterable.from(provider.getLanguages()).filter(o -> o != baseLanguage && o != dataLanguage)); }
Example #7
Source File: SelectInContextImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public Object getSelectorInFile() { if (myPsiFile.getViewProvider() instanceof TemplateLanguageFileViewProvider) { return super.getSelectorInFile(); } final int offset = myEditor.getEditor().getCaretModel().getOffset(); if (offset >= 0 && offset < myPsiFile.getTextLength()) { return myPsiFile.findElementAt(offset); } return super.getSelectorInFile(); }
Example #8
Source File: MultipleRootsInjectedFileViewProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public Language getTemplateDataLanguage() { return ((TemplateLanguageFileViewProvider)myOriginalProvider).getTemplateDataLanguage(); }
Example #9
Source File: MultipleRootsInjectedFileViewProvider.java From consulo with Apache License 2.0 | 4 votes |
@Override public IElementType getContentElementType(@Nonnull Language language) { return ((TemplateLanguageFileViewProvider)myOriginalProvider).getContentElementType(language); }