Search in sources :

Example 1 with ParserDefinition

use of com.intellij.lang.ParserDefinition in project idea-handlebars by dmarcotte.

the class HbFileViewProvider method createFile.

@Override
protected PsiFile createFile(@NotNull Language lang) {
    ParserDefinition parserDefinition = getDefinition(lang);
    if (parserDefinition == null) {
        return null;
    }
    if (lang.is(getTemplateDataLanguage())) {
        PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
        file.setContentElementType(getTemplateDataElementType(getBaseLanguage()));
        return file;
    } else if (lang.isKindOf(getBaseLanguage())) {
        return parserDefinition.createFile(this);
    } else {
        return null;
    }
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl)

Example 2 with ParserDefinition

use of com.intellij.lang.ParserDefinition in project Main by SpartanRefactoring.

the class LeonidasTipper method getPsiTreeFromString.

/**
     * @param name    the name of the tipper
     * @param content the definition file of the tipper
     * @return PsiFile representing the file of the tipper
     */
private PsiJavaFile getPsiTreeFromString(String name, String content) {
    Language language = JavaLanguage.INSTANCE;
    LightVirtualFile virtualFile = new LightVirtualFile(name, language, content);
    SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
    final FileViewProviderFactory factory = LanguageFileViewProviders.INSTANCE.forLanguage(language);
    FileViewProvider viewProvider = factory != null ? factory.createFileViewProvider(virtualFile, language, Utils.getPsiManager(Utils.getProject()), true) : null;
    if (viewProvider == null)
        viewProvider = new SingleRootFileViewProvider(Utils.getPsiManager(ProjectManager.getInstance().getDefaultProject()), virtualFile, true);
    language = viewProvider.getBaseLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (parserDefinition != null) {
        return (PsiJavaFile) viewProvider.getPsi(language);
    }
    return null;
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) Language(com.intellij.lang.Language) JavaLanguage(com.intellij.lang.java.JavaLanguage) LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 3 with ParserDefinition

use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.

the class RestFileViewProvider method createFile.

@Override
protected PsiFile createFile(@NotNull final Language lang) {
    ParserDefinition def = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    if (def == null)
        return null;
    if (lang == getTemplateDataLanguage()) {
        PsiFileImpl file = (PsiFileImpl) def.createFile(this);
        file.setContentElementType(RestPythonElementTypes.PYTHON_BLOCK_DATA);
        return file;
    } else if (lang.getID().equals("DjangoTemplate")) {
        PsiFileImpl file = (PsiFileImpl) def.createFile(this);
        file.setContentElementType(RestPythonElementTypes.DJANGO_BLOCK_DATA);
        return file;
    } else if (lang == RestLanguage.INSTANCE) {
        return def.createFile(this);
    }
    return null;
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl)

Example 4 with ParserDefinition

use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.

the class WordCompletionContributor method addValuesFromOtherStringLiterals.

private static void addValuesFromOtherStringLiterals(CompletionResultSet result, CompletionParameters parameters, final Set<String> realExcludes, PsiElement position) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(position.getLanguage());
    if (definition == null) {
        return;
    }
    final ElementPattern<PsiElement> pattern = psiElement().withElementType(definition.getStringLiteralElements());
    final PsiElement localString = PsiTreeUtil.findFirstParent(position, false, element -> pattern.accepts(element));
    if (localString == null) {
        return;
    }
    ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(localString);
    if (manipulator == null) {
        return;
    }
    int offset = manipulator.getRangeInElement(localString).getStartOffset();
    PsiFile file = position.getContainingFile();
    final CompletionResultSet fullStringResult = result.withPrefixMatcher(file.getText().substring(offset + localString.getTextRange().getStartOffset(), parameters.getOffset()));
    file.accept(new PsiRecursiveElementWalkingVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element == localString) {
                return;
            }
            if (pattern.accepts(element)) {
                element.accept(new PsiRecursiveElementWalkingVisitor() {

                    @Override
                    public void visitElement(PsiElement each) {
                        String valueText = ElementManipulators.getValueText(each);
                        if (StringUtil.isNotEmpty(valueText) && !realExcludes.contains(valueText)) {
                            final LookupElement item = LookupElementBuilder.create(valueText);
                            fullStringResult.addElement(item);
                        }
                    }
                });
                return;
            }
            super.visitElement(element);
        }
    });
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 5 with ParserDefinition

use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.

the class FindManagerImpl method addTokenTypesForLanguage.

private static TokenSet addTokenTypesForLanguage(FindModel model, Language lang, TokenSet tokensOfInterest) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    if (definition != null) {
        tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInCommentsOnly() ? definition.getCommentTokens() : TokenSet.EMPTY);
        tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInStringLiteralsOnly() ? definition.getStringLiteralElements() : TokenSet.EMPTY);
    }
    return tokensOfInterest;
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition)

Aggregations

ParserDefinition (com.intellij.lang.ParserDefinition)23 Language (com.intellij.lang.Language)8 ASTNode (com.intellij.lang.ASTNode)7 TokenSet (com.intellij.psi.tree.TokenSet)6 PsiElement (com.intellij.psi.PsiElement)5 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)4 FileType (com.intellij.openapi.fileTypes.FileType)3 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)3 IElementType (com.intellij.psi.tree.IElementType)3 IFileElementType (com.intellij.psi.tree.IFileElementType)3 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)3 Annotation (com.intellij.lang.annotation.Annotation)2 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)1 VirtualFileWindowImpl (com.intellij.injected.editor.VirtualFileWindowImpl)1 PsiBuilder (com.intellij.lang.PsiBuilder)1