use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class SpellCheckerDictionaryGenerator method processLeafsNames.
protected void processLeafsNames(@NotNull final PsiElement leafElement, @NotNull final HashSet<String> seenNames) {
final Language language = leafElement.getLanguage();
SpellCheckingInspection.tokenize(leafElement, language, new TokenConsumer() {
@Override
public void consumeToken(PsiElement element, final String text, boolean useRename, int offset, TextRange rangeToCheck, Splitter splitter) {
splitter.split(text, rangeToCheck, textRange -> {
final String word = textRange.substring(text);
addSeenWord(seenNames, word, language);
});
}
});
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class XPathEvalAction method execute.
private void execute(Editor editor) {
final Project project = editor.getProject();
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null) {
return;
}
InputExpressionDialog.Context input;
XmlElement contextNode = null;
final Config cfg = XPathAppComponent.getInstance().getConfig();
do {
RangeHighlighter contextHighlighter = null;
if (cfg.isUseContextAtCursor()) {
// find out current context node
contextNode = MyPsiUtil.findContextNode(psiFile, editor);
if (contextNode != null) {
contextHighlighter = HighlighterUtil.highlightNode(editor, contextNode, cfg.getContextAttributes(), cfg);
}
}
if (contextNode == null) {
// in XPath data model, / is the document itself, including comments, PIs and the root element
contextNode = ((XmlFile) psiFile).getDocument();
if (contextNode == null) {
FileViewProvider fileViewProvider = psiFile.getViewProvider();
if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
Language dataLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage();
PsiFile templateDataFile = fileViewProvider.getPsi(dataLanguage);
if (templateDataFile instanceof XmlFile)
contextNode = ((XmlFile) templateDataFile).getDocument();
}
}
}
input = inputXPathExpression(project, contextNode);
if (contextHighlighter != null) {
contextHighlighter.dispose();
}
if (input == null) {
return;
}
HighlighterUtil.clearHighlighters(editor);
} while (contextNode != null && evaluateExpression(input, contextNode, editor, cfg));
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class PythonRegexpInjector method injectRegexpLanguage.
private static void injectRegexpLanguage(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context, boolean verbose) {
final Language language = verbose ? PythonVerboseRegexpLanguage.INSTANCE : PythonRegexpLanguage.INSTANCE;
registrar.startInjecting(language);
final PyInjectionUtil.InjectionResult result = PyInjectionUtil.registerStringLiteralInjection(context, registrar);
if (result.isInjected()) {
registrar.doneInjecting();
if (!result.isStrict()) {
final PsiFile file = getInjectedFile(registrar);
if (file != null) {
file.putUserData(InjectedLanguageUtil.FRANKENSTEIN_INJECTION, Boolean.TRUE);
}
}
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class XmlUnwrapDescriptor method collectUnwrappers.
@Override
public List<Pair<PsiElement, Unwrapper>> collectUnwrappers(Project project, Editor editor, PsiFile file) {
int offset = editor.getCaretModel().getOffset();
PsiElement e1 = file.findElementAt(offset);
if (e1 != null) {
Language language = e1.getParent().getLanguage();
if (language != file.getLanguage()) {
UnwrapDescriptor unwrapDescriptor = LanguageUnwrappers.INSTANCE.forLanguage(language);
if (unwrapDescriptor != null && !(unwrapDescriptor instanceof XmlUnwrapDescriptor)) {
return unwrapDescriptor.collectUnwrappers(project, editor, file);
}
}
}
List<Pair<PsiElement, Unwrapper>> result = new ArrayList<>();
FileViewProvider viewProvider = file.getViewProvider();
for (Language language : viewProvider.getLanguages()) {
UnwrapDescriptor unwrapDescriptor = LanguageUnwrappers.INSTANCE.forLanguage(language);
if (unwrapDescriptor instanceof XmlUnwrapDescriptor) {
PsiElement e = viewProvider.findElementAt(offset, language);
PsiElement tag = PsiTreeUtil.getParentOfType(e, XmlTag.class);
while (tag != null) {
if (XmlChildRole.START_TAG_NAME_FINDER.findChild(tag.getNode()) != null) {
// Exclude implicit tags suck as 'jsp:root'
result.add(new Pair<>(tag, new XmlEnclosingTagUnwrapper()));
}
tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class);
}
}
}
Collections.sort(result, (o1, o2) -> o2.first.getTextOffset() - o1.first.getTextOffset());
return result;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class BreadcrumbsXmlWrapper method findFirstBreadcrumbedElement.
@Nullable
private static PsiElement findFirstBreadcrumbedElement(final int offset, final VirtualFile file, final Project project, final BreadcrumbsInfoProvider defaultInfoProvider) {
if (file == null || !file.isValid())
return null;
PriorityQueue<PsiElement> leafs = new PriorityQueue<>(3, (o1, o2) -> {
TextRange range1 = o1.getTextRange();
if (range1 == null) {
LOG.error(o1 + " returned null range");
return 1;
}
TextRange range2 = o2.getTextRange();
if (range2 == null) {
LOG.error(o2 + " returned null range");
return -1;
}
return range2.getStartOffset() - range1.getStartOffset();
});
FileViewProvider viewProvider = findViewProvider(file, project);
if (viewProvider == null)
return null;
for (final Language language : viewProvider.getLanguages()) {
ContainerUtil.addIfNotNull(leafs, viewProvider.findElementAt(offset, language));
}
while (!leafs.isEmpty()) {
final PsiElement element = leafs.remove();
if (!element.isValid())
continue;
BreadcrumbsInfoProvider provider = findProviderForElement(element, defaultInfoProvider);
if (provider != null && provider.acceptElement(element)) {
return element;
}
if (!(element instanceof PsiFile)) {
ContainerUtil.addIfNotNull(leafs, getParent(element, provider));
}
}
return null;
}
Aggregations