use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class BlockSupportImpl method getFileCopy.
@NotNull
public static PsiFileImpl getFileCopy(@NotNull PsiFileImpl originalFile, @NotNull FileViewProvider providerCopy) {
FileViewProvider viewProvider = originalFile.getViewProvider();
Language language = originalFile.getLanguage();
PsiFile file = providerCopy.getPsi(language);
if (file != null && !(file instanceof PsiFileImpl)) {
throw new RuntimeException("View provider " + viewProvider + " refused to provide PsiFileImpl for " + language + details(providerCopy, viewProvider));
}
PsiFileImpl newFile = (PsiFileImpl) file;
if (newFile == null && language == PlainTextLanguage.INSTANCE && originalFile == viewProvider.getPsi(viewProvider.getBaseLanguage())) {
newFile = (PsiFileImpl) providerCopy.getPsi(providerCopy.getBaseLanguage());
}
if (newFile == null) {
throw new RuntimeException("View provider " + viewProvider + " refused to parse text with " + language + details(providerCopy, viewProvider));
}
return newFile;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class LineLayout method distinctTokens.
private static boolean distinctTokens(@Nullable IElementType token1, @Nullable IElementType token2) {
if (token1 == token2)
return false;
if (token1 == null || token2 == null)
return true;
if (StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(token1) || StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(token2))
return false;
if (token1 != TokenType.WHITE_SPACE && token2 != TokenType.WHITE_SPACE && !token1.getLanguage().is(token2.getLanguage()))
return true;
Language language = token1.getLanguage();
if (language == Language.ANY)
language = token2.getLanguage();
BidiRegionsSeparator separator = LanguageBidiRegionsSeparator.INSTANCE.forLanguage(language);
return separator.createBorderBetweenTokens(token1, token2);
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class XmlStructuralSearchProfile method detectFileType.
@NotNull
@Override
public FileType detectFileType(@NotNull PsiElement context) {
PsiFile file = context instanceof PsiFile ? (PsiFile) context : context.getContainingFile();
Language contextLanguage = context instanceof PsiFile ? null : context.getLanguage();
if (file.getLanguage() == StdLanguages.HTML || (file.getFileType() == StdFileTypes.JSP && contextLanguage == StdLanguages.HTML)) {
return StdFileTypes.HTML;
}
return StdFileTypes.XML;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class StructuralSearchProfileBase method compile.
@Override
public void compile(PsiElement[] elements, @NotNull final GlobalCompilingVisitor globalVisitor) {
final PsiElement topElement = elements[0].getParent();
final PsiElement element = elements.length > 1 ? topElement : elements[0];
element.accept(new MyCompilingVisitor(globalVisitor, topElement));
element.accept(new PsiRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
super.visitElement(element);
if (DuplocatorUtil.isIgnoredNode(element)) {
return;
}
CompiledPattern pattern = globalVisitor.getContext().getPattern();
MatchingHandler handler = pattern.getHandler(element);
if (!(handler instanceof SubstitutionHandler) && !(handler instanceof TopLevelMatchingHandler) && !(handler instanceof LightTopLevelMatchingHandler)) {
pattern.setHandler(element, new SkippingHandler(handler));
}
/*
place skipping handler under top-level handler, because when we skip top-level node we can get non top-level handler, so
depth matching won't be done!;
*/
if (handler instanceof LightTopLevelMatchingHandler) {
MatchingHandler delegate = ((LightTopLevelMatchingHandler) handler).getDelegate();
if (!(delegate instanceof SubstitutionHandler)) {
pattern.setHandler(element, new LightTopLevelMatchingHandler(new SkippingHandler(delegate)));
}
}
}
});
final Language baseLanguage = element.getContainingFile().getLanguage();
// todo: try to optimize it: too heavy strategy!
globalVisitor.getContext().getPattern().setStrategy(new MatchingStrategy() {
@Override
public boolean continueMatching(PsiElement start) {
Language language = start.getLanguage();
PsiFile file = start.getContainingFile();
if (file != null) {
Language fileLanguage = file.getLanguage();
if (fileLanguage.isKindOf(language)) {
// dialect
language = fileLanguage;
}
}
return language == baseLanguage;
}
@Override
public boolean shouldSkip(PsiElement element, PsiElement elementToMatchWith) {
return DuplocatorUtil.shouldSkip(element, elementToMatchWith);
}
});
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class MatcherImplUtil method createSourceTreeFromText.
public static PsiElement[] createSourceTreeFromText(String text, PatternTreeContext context, FileType fileType, String extension, Project project, boolean physical) {
if (fileType instanceof LanguageFileType) {
Language language = ((LanguageFileType) fileType).getLanguage();
StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
if (profile != null) {
return profile.createPatternTree(text, context, fileType, null, null, extension, project, physical);
}
}
return PsiElement.EMPTY_ARRAY;
}
Aggregations