Java Code Examples for com.intellij.psi.util.PsiUtilCore#getTemplateLanguageFile()
The following examples show how to use
com.intellij.psi.util.PsiUtilCore#getTemplateLanguageFile() .
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: ErrorFilter.java From intellij-latte with MIT License | 6 votes |
public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement element) { PsiFile templateLanguageFile = PsiUtilCore.getTemplateLanguageFile(element.getContainingFile()); if (templateLanguageFile == null) { return true; } Language language = templateLanguageFile.getLanguage(); if (language != LatteLanguage.INSTANCE) { return true; } if (element.getParent() instanceof XmlElement || element.getParent() instanceof CssElement) { return false; } if (element.getParent().getLanguage() == LatteLanguage.INSTANCE) { return true; } PsiElement nextSibling; for (nextSibling = PsiTreeUtil.nextLeaf(element); nextSibling instanceof PsiWhiteSpace; nextSibling = nextSibling.getNextSibling()); PsiElement psiElement = nextSibling == null ? null : PsiTreeUtil.findCommonParent(nextSibling, element); boolean nextIsOuterLanguageElement = nextSibling instanceof OuterLanguageElement || nextSibling instanceof LatteMacroClassic; return !nextIsOuterLanguageElement || psiElement == null || psiElement instanceof PsiFile; }
Example 2
Source File: SurroundWithAction.java From consulo with Apache License 2.0 | 6 votes |
@Override protected boolean isValidForFile(@Nonnull Project project, @Nonnull Editor editor, @Nonnull final PsiFile file) { final Language language = file.getLanguage(); if (!LanguageSurrounders.INSTANCE.allForLanguage(language).isEmpty()) { return true; } final PsiFile baseFile = PsiUtilCore.getTemplateLanguageFile(file); if (baseFile != null && baseFile != file && !LanguageSurrounders.INSTANCE.allForLanguage(baseFile.getLanguage()).isEmpty()) { return true; } if (!TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, true).isEmpty()) { return true; } return false; }
Example 3
Source File: InjectionRegistrarImpl.java From consulo with Apache License 2.0 | 5 votes |
InjectionRegistrarImpl(@Nonnull Project project, @Nonnull PsiFile hostPsiFile, @Nonnull PsiElement contextElement, @Nonnull PsiDocumentManager docManager) { myProject = project; myContextElement = contextElement; myHostPsiFile = PsiUtilCore.getTemplateLanguageFile(hostPsiFile); FileViewProvider viewProvider = myHostPsiFile.getViewProvider(); if (viewProvider instanceof InjectedFileViewProvider) throw new IllegalArgumentException(viewProvider + " must not be injected"); myHostVirtualFile = viewProvider.getVirtualFile(); myDocumentManagerBase = (PsiDocumentManagerBase)docManager; myHostDocument = (DocumentEx)viewProvider.getDocument(); }
Example 4
Source File: CodeStyleManagerRunnable.java From consulo with Apache License 2.0 | 4 votes |
public T perform(PsiFile file, int offset, @Nullable TextRange range, T defaultValue) { if (file instanceof PsiCompiledFile) { file = ((PsiCompiledFile)file).getDecompiledPsiFile(); } PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myCodeStyleManager.getProject()); Document document = documentManager.getDocument(file); if (document instanceof DocumentWindow) { final DocumentWindow documentWindow = (DocumentWindow)document; final PsiFile topLevelFile = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file); if (!file.equals(topLevelFile)) { if (range != null) { range = documentWindow.injectedToHost(range); } if (offset != -1) { offset = documentWindow.injectedToHost(offset); } return adjustResultForInjected(perform(topLevelFile, offset, range, defaultValue), documentWindow); } } final PsiFile templateFile = PsiUtilCore.getTemplateLanguageFile(file); if (templateFile != null) { file = templateFile; document = documentManager.getDocument(templateFile); } PsiElement element = null; if (offset != -1) { element = CodeStyleManagerImpl.findElementInTreeWithFormatterEnabled(file, offset); if (element == null && offset != file.getTextLength()) { return defaultValue; } if (isInsidePlainComment(offset, element)) { return computeValueInsidePlainComment(file, offset, defaultValue); } } final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(file); FormattingModelBuilder elementBuilder = element != null ? LanguageFormatting.INSTANCE.forContext(element) : builder; if (builder != null && elementBuilder != null) { mySettings = CodeStyle.getSettings(file); mySignificantRange = offset != -1 ? getSignificantRange(file, offset) : null; myIndentOptions = mySettings.getIndentOptionsByFile(file, mySignificantRange); FormattingMode currentMode = myCodeStyleManager.getCurrentFormattingMode(); myCodeStyleManager.setCurrentFormattingMode(myMode); try { myModel = buildModel(builder, file, document); T result = doPerform(offset, range); if (result != null) { return result; } } finally { myCodeStyleManager.setCurrentFormattingMode(currentMode); } } return defaultValue; }