@NotNull @Override public FileViewProvider createFileViewProvider(@NotNull VirtualFile virtualFile, @NotNull Language language, @NotNull PsiManager psiManager, boolean eventSystemEnabled) { assert language.isKindOf(org.elixir_lang.eex.Language.INSTANCE); return new ViewProvider(psiManager, virtualFile, eventSystemEnabled, language); } }
@Nullable private ParserDefinition getDefinition(@NotNull com.intellij.lang.Language language) { com.intellij.lang.Language baseLanguage = getBaseLanguage(); if (language.isKindOf(baseLanguage)) { language = baseLanguage; } return LanguageParserDefinitions.INSTANCE.forLanguage(language); }
@Override public boolean isInContext(@NotNull PsiFile psiFile, int offset) { if (!PsiUtilCore.getLanguageAtOffset(psiFile, offset).isKindOf(ElixirLanguage.INSTANCE)) return false; PsiElement element = psiFile.findElementAt(offset); return !(element instanceof PsiWhiteSpace) && element != null; } }
@Override public boolean isInContext(@NotNull PsiFile file, int offset) { if (PsiUtilCore.getLanguageAtOffset(file, offset).isKindOf(BallerinaLanguage.INSTANCE)) { PsiElement element = file.findElementAt(offset); return !(element instanceof PsiWhiteSpace) && element != null && isInContext(element); } return false; }
/** * Searches for the matching language in {@link FileViewProvider}. * * @param baseLanguage language to look for * @param viewProvider current {@link FileViewProvider} * @return matched {@link Language} */ private static Language findLanguage(Language baseLanguage, FileViewProvider viewProvider) { final Set<Language> languages = viewProvider.getLanguages(); for (final Language actualLanguage : languages) { if (actualLanguage.isKindOf(baseLanguage)) { return actualLanguage; } } for (final Language actualLanguage : languages) { if (actualLanguage instanceof IgnoreLanguage) { return actualLanguage; } } throw new AssertionError("Language " + baseLanguage + " doesn't participate in view provider " + viewProvider + ": " + ContainerUtil.newArrayList(languages)); }
@Override public boolean isInContext(@NotNull PsiFile file, int offset) { if (PsiUtilCore.getLanguageAtOffset(file, offset).isKindOf(GoLanguage.INSTANCE)) { PsiElement psiElement = ObjectUtils.notNull(file.findElementAt(offset), file); if (!acceptLeaf()) { psiElement = getFirstCompositeElement(psiElement); } return psiElement != null && isInContext(psiElement); } return false; }
@Nullable @Override protected PsiFile createFile(@NotNull com.intellij.lang.Language language) { ParserDefinition parserDefinition = getDefinition(language); PsiFileImpl psiFileImpl; if (parserDefinition == null) { psiFileImpl = null; } else if (language.isKindOf(getBaseLanguage())) { psiFileImpl = (PsiFileImpl) parserDefinition.createFile(this); } else { psiFileImpl = (PsiFileImpl) parserDefinition.createFile(this); psiFileImpl.setContentElementType(elementType(language)); } return psiFileImpl; }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, @Nullable PsiElement element) { return element != null && element.getContainingFile().getLanguage().isKindOf(CsvLanguage.INSTANCE); } }
@Override public Comparable weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) { if (PsiUtilCore.findLanguageFromElement(location.getCompletionParameters().getPosition()).isKindOf(PerlLanguage.INSTANCE)) { Integer weight = element.getUserData(WEIGHT); return weight == null ? 0 : weight; } return 0; } }
@Nullable @Override public String getElementDescription(@NotNull PsiElement element, @NotNull ElementDescriptionLocation location) { if (element.getLanguage().isKindOf(PodLanguage.INSTANCE)) { if (element instanceof PodCompositeElement) { if (location == UsageViewShortNameLocation.INSTANCE) { return ((PodCompositeElement)element).getUsageViewShortNameLocation(); } else if (location == UsageViewLongNameLocation.INSTANCE) { return ((PodCompositeElement)element).getUsageViewLongNameLocation(); } else if (location == UsageViewTypeLocation.INSTANCE) { return ((PodCompositeElement)element).getUsageViewTypeLocation(); } } System.err.println("Unresolved " + element + " in " + location); } return null; } }
@Override public boolean isInContext(@NotNull PsiFile file, int offset) { // offset is where cursor or insertion point is I guess if ( !PsiUtilBase.getLanguageAtOffset(file, offset).isKindOf(ANTLRv4Language.INSTANCE) ) { return false; } if ( offset==file.getTextLength() ) { // allow at EOF offset--; } PsiElement element = file.findElementAt(offset); // String trace = DebugUtil.currentStackTrace(); // System.out.println("isInContext: element " + element +", text="+element.getText()); // System.out.println(trace); if ( element==null ) { return false; } return isInContext(file, element, offset); } }
@Override public boolean value(PsiElement element) { return !(element instanceof OuterLanguageElementImpl) || !element.getContainingFile().getViewProvider().getBaseLanguage().isKindOf(PerlLanguage.INSTANCE); } }
public boolean isInContext(@NotNull PsiFile file, int offset) { if (PsiUtilBase.getLanguageAtOffset(file, offset).isKindOf(MathematicaFileType.INSTANCE.getLanguage())) { PsiElement element = PsiUtilBase.getElementAtOffset(file, offset); return !(element instanceof PsiComment) && PsiTreeUtil.getParentOfType(element, PsiComment.class, MString.class) == null; } return false; }
public static boolean isCsvFile(VirtualFile file) { return file.getFileType() instanceof LanguageFileType && ((LanguageFileType) file.getFileType()).getLanguage().isKindOf(CsvLanguage.INSTANCE); }
@Override public boolean isInContext(@NotNull PsiFile psiFile, int fileOffset) { if (!PsiUtilCore.getLanguageAtOffset(psiFile, fileOffset).isKindOf(PerlLanguage.INSTANCE)) { return false; } PsiElement element = psiFile.findElementAt(fileOffset); if (element == null) { element = psiFile.findElementAt(fileOffset - 1); } if (element == null) { return false; } IElementType tokenType = PsiUtilCore.getElementType(element); return !(element instanceof PsiWhiteSpace || element instanceof PerlStringContentElementImpl || element instanceof PsiComment || tokenType == PerlElementTypes.REGEX_TOKEN) && isInContext(element); }
/** * Traversing up from {@code element perl element}, skipping comments and whitespaces, looking for a POD block * * @return POD block or null if not found */ @Nullable @Contract("null -> null") public static PsiElement findPrependingPodBlock(@Nullable PsiElement element) { if (element == null || element instanceof PsiFile || !element.getLanguage().isKindOf(PerlLanguage.INSTANCE)) { return null; } while (true) { PsiElement prevElement = element.getPrevSibling(); if (prevElement == null) { return findPrependingPodBlock(element.getParent()); } element = prevElement; IElementType elementType = PsiUtilCore.getElementType(element); if (elementType == POD) { return element; } else if (elementType != TokenType.WHITE_SPACE && elementType != COMMENT_LINE) { return null; } } }
private void processDocReference(String currentBaseName, String newName, PsiReference reference, Map<PsiElement, String> allRenames) { PsiElement sourceElement = reference.getElement(); if (sourceElement.getLanguage().isKindOf(PodLanguage.INSTANCE)) { PsiNameIdentifierOwner identifierOwner = PsiTreeUtil.getParentOfType(sourceElement, PsiNameIdentifierOwner.class); if (identifierOwner != null) { PsiElement nameIdentifier = identifierOwner.getNameIdentifier(); if (nameIdentifier != null && nameIdentifier.getTextRange().contains(sourceElement.getTextRange())) { String currentName = identifierOwner.getName(); if (currentName != null) { String newSectionName = currentName.replace(currentBaseName, newName); allRenames.put(identifierOwner, newSectionName); } } } } }
@Override public boolean isInContext(@NotNull PsiFile file, int offset) { Language language = PsiUtilCore.getLanguageAtOffset(file, offset); if (language.isKindOf(BashFileType.BASH_LANGUAGE)) { PsiElement element = file.findElementAt(offset); if (element == null) { //if a user edits at the end of a comment at the end of a file then findElementAt returns null //(for yet unknown reasons) element = file.findElementAt(offset - 1); } return !BashPsiUtils.hasParentOfType(element, PsiComment.class, 3) && !BashPsiUtils.hasParentOfType(element, BashShebang.class, 3) && !BashPsiUtils.hasParentOfType(element, BashHereDoc.class, 1) && !BashPsiUtils.isCommandParameterWord(element); } return false; } }
@Override public void visitElement(PsiElement element) { if (element == null || !holder.getFile().getLanguage().isKindOf(CsvLanguage.INSTANCE)) { return; } IElementType elementType = CsvHelper.getElementType(element); PsiElement firstChild = element.getFirstChild(); PsiElement nextSibling = element.getNextSibling(); if (elementType == TokenType.ERROR_ELEMENT && CsvHelper.getElementType(firstChild) == TokenType.BAD_CHARACTER) { CsvValidationInspection.this.registerError(holder, element, UNESCAPED_SEQUENCE, fixUnescapedSequence); if (!"\"".equals(firstChild.getText())) { CsvValidationInspection.this.registerError(holder, element, SEPARATOR_MISSING, fixSeparatorMissing); } } else if ((elementType == CsvTypes.TEXT || elementType == CsvTypes.ESCAPED_TEXT) && CsvHelper.getElementType(nextSibling) == TokenType.ERROR_ELEMENT && nextSibling.getFirstChild() == null) { CsvValidationInspection.this.registerError(holder, element, CLOSING_QUOTE_MISSING, fixClosingQuoteMissing); } } };