use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class OverrideMethodsHandler method invoke.
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (!EditorModificationUtil.checkModificationAllowed(editor))
return;
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
return;
}
Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.OVERRIDE_METHOD.forLanguage(language);
if (codeInsightActionHandler != null) {
codeInsightActionHandler.invoke(project, editor, file);
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class FoldingPolicy method isCollapseByDefault.
public static boolean isCollapseByDefault(PsiElement element) {
final Language lang = element.getLanguage();
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
try {
return foldingBuilder != null && foldingBuilder.isCollapsedByDefault(element.getNode());
} catch (IndexNotReadyException e) {
LOG.error(e);
return false;
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class FoldingUpdate method getFoldingsFor.
private static void getFoldingsFor(@NotNull PsiFile file, @NotNull Document document, @NotNull FoldingMap elementsToFoldMap, boolean quick) {
final FileViewProvider viewProvider = file.getViewProvider();
TextRange docRange = TextRange.from(0, document.getTextLength());
for (final Language language : viewProvider.getLanguages()) {
final PsiFile psi = viewProvider.getPsi(language);
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
if (psi != null && foldingBuilder != null) {
for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) {
PsiElement psiElement = descriptor.getElement().getPsi();
if (psiElement == null) {
LOG.error("No PSI for folding descriptor " + descriptor);
continue;
}
if (!docRange.contains(descriptor.getRange())) {
diagnoseIncorrectRange(psi, document, language, foldingBuilder, descriptor, psiElement);
continue;
}
elementsToFoldMap.putValue(psiElement, descriptor);
}
}
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class CommentByBlockCommentHandler method findCommenter.
@Nullable
private static Commenter findCommenter(PsiFile file, Editor editor, Caret caret) {
final FileType fileType = file.getFileType();
if (fileType instanceof AbstractFileType) {
return ((AbstractFileType) fileType).getCommenter();
}
Language lang = PsiUtilBase.getLanguageInEditor(caret, file.getProject());
return getCommenter(file, editor, lang, lang);
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class EnterInStringLiteralHandler method isInStringLiteral.
private static boolean isInStringLiteral(@NotNull Editor editor, @NotNull DataContext dataContext, int offset) {
Language language = EnterHandler.getLanguage(dataContext);
if (offset > 0 && language != null) {
QuoteHandler quoteHandler = TypedHandler.getLanguageQuoteHandler(language);
if (quoteHandler == null) {
FileType fileType = language.getAssociatedFileType();
quoteHandler = fileType != null ? TypedHandler.getQuoteHandlerForType(fileType) : null;
}
if (quoteHandler != null) {
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
return StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(iterator.getTokenType()) || quoteHandler.isInsideLiteral(iterator);
}
}
return false;
}
Aggregations