Search in sources :

Example 56 with Language

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;
}
Also used : Language(com.intellij.lang.Language) PlainTextLanguage(com.intellij.openapi.fileTypes.PlainTextLanguage) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with Language

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);
}
Also used : Language(com.intellij.lang.Language) LanguageBidiRegionsSeparator(com.intellij.openapi.editor.bidi.LanguageBidiRegionsSeparator) BidiRegionsSeparator(com.intellij.openapi.editor.bidi.BidiRegionsSeparator)

Example 58 with Language

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;
}
Also used : Language(com.intellij.lang.Language) XMLLanguage(com.intellij.lang.xml.XMLLanguage) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with Language

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);
        }
    });
}
Also used : Language(com.intellij.lang.Language) CompiledPattern(com.intellij.structuralsearch.impl.matcher.CompiledPattern) MatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.MatchingStrategy)

Example 60 with Language

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;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) StructuralSearchProfile(com.intellij.structuralsearch.StructuralSearchProfile)

Aggregations

Language (com.intellij.lang.Language)292 NotNull (org.jetbrains.annotations.NotNull)58 Nullable (org.jetbrains.annotations.Nullable)49 PsiElement (com.intellij.psi.PsiElement)46 PsiFile (com.intellij.psi.PsiFile)45 FileType (com.intellij.openapi.fileTypes.FileType)31 Project (com.intellij.openapi.project.Project)31 TextRange (com.intellij.openapi.util.TextRange)25 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 FileViewProvider (com.intellij.psi.FileViewProvider)21 HbLanguage (com.dmarcotte.handlebars.HbLanguage)20 JavaLanguage (com.intellij.lang.java.JavaLanguage)16 Editor (com.intellij.openapi.editor.Editor)14 XMLLanguage (com.intellij.lang.xml.XMLLanguage)12 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)11 List (java.util.List)11 HTMLLanguage (com.intellij.lang.html.HTMLLanguage)9 JavascriptLanguage (com.intellij.lang.javascript.JavascriptLanguage)9 Document (com.intellij.openapi.editor.Document)9