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;
}
}
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;
}
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;
}
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);
}
});
}
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;
}
Aggregations