private RecursiveMethodCallMarkerInfo(@NotNull PsiElement methodCall) { super(methodCall, methodCall.getTextRange(), AllIcons.Gutter.RecursiveMethod, Pass.UPDATE_OVERRIDDEN_MARKERS, FunctionUtil.constant("Recursive call"), null, GutterIconRenderer.Alignment.RIGHT ); } }
private static void fold(@NotNull PsiElement e, @Nullable PsiElement l, @Nullable PsiElement r, @NotNull String placeholderText, @NotNull List<FoldingDescriptor> result) { if (l != null && r != null) { result.add(new NamedFoldingDescriptor(e, l.getTextRange().getStartOffset(), r.getTextRange().getEndOffset(), null, placeholderText)); } }
private BallerinaImplementingFunctionMarkerInfo(@NotNull PsiElement implementation, @NotNull PsiElement definition) { super(implementation, implementation.getTextRange(), AllIcons.Gutter.ImplementingMethod, Pass.LINE_MARKERS, FunctionUtil.constant("Implementing function"), (e, elt) -> navigateToOverridingMethod(e, ((NavigatablePsiElement) definition)), GutterIconRenderer.Alignment.RIGHT ); } }
private BallerinaImplementedFunctionMarkerInfo(@NotNull PsiElement definition, @NotNull PsiElement implementation) { super(definition, definition.getTextRange(), AllIcons.Gutter.ImplementedMethod, Pass.LINE_MARKERS, FunctionUtil.constant("Implemented function"), (e, elt) -> navigateToOverridingMethod(e, ((NavigatablePsiElement) implementation)), GutterIconRenderer.Alignment.RIGHT ); } }
private void highlight(@NotNull final PsiElement element, @NotNull AnnotationHolder annotationHolder, @NotNull final TextAttributesKey textAttributesKey) { highlight(element.getTextRange(), annotationHolder, textAttributesKey); }
@NotNull private static TextRange getTextRange(@NotNull PsiElement o) { return ObjectUtils.notNull(PsiTreeUtil.getParentOfType(o, GoTopLevelDeclaration.class), o).getTextRange(); } }
@Nullable private static PsiElement findNotWhiteSpaceElementAtOffset(@NotNull GoFile file, int offset, boolean forward) { PsiElement element = file.findElementAt(offset); while (element instanceof PsiWhiteSpace) { element = file.findElementAt(forward ? element.getTextRange().getEndOffset() : element.getTextRange().getStartOffset() - 1); } return element; } }
protected int getOffsetLBraceOfBlock(@Nullable GoBlock block) { return block != null ? block.getLbrace().getTextRange().getStartOffset() : -1; } }
@Nullable private static GoExpression getLastExpressionAfter(@NotNull List<GoExpression> list, @Nullable PsiElement anchor) { if (anchor == null) return null; GoExpression last = ContainerUtil.getLastItem(list); return last != null && last.getTextRange().getStartOffset() >= anchor.getTextRange().getEndOffset() ? last : null; }
@NotNull private static List<GoExpression> getExpressionsInRange(@NotNull List<GoExpression> list, @Nullable PsiElement start, @Nullable PsiElement end) { if (start == null && end == null) { return list; } return ContainerUtil.filter(list, expression -> (end == null || expression.getTextRange().getEndOffset() <= end.getTextRange().getStartOffset()) && (start == null || expression.getTextRange().getStartOffset() >= start.getTextRange().getEndOffset())); }
@NotNull private static List<TextRange> extend(@NotNull CharSequence editorText, @NotNull List<? extends PsiElement> list, boolean expand) { PsiElement first = ContainerUtil.getFirstItem(list); PsiElement last = ContainerUtil.getLastItem(list); if (first != null && last != null) { TextRange range = TextRange.create(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset()); if (!expand) return ContainerUtil.newSmartList(range); return expandToWholeLine(editorText, range); } return ContainerUtil.emptyList(); } }
private void annotateKeyword(@NotNull PsiElement element, @NotNull AnnotationHolder holder, @NotNull TextAttributesKey textAttributesKey, boolean excludeEndChar) { TextRange textRange = element.getTextRange(); TextRange newTextRange = new TextRange(textRange.getStartOffset(), textRange.getEndOffset() - (excludeEndChar ? 1 : 0)); Annotation annotation = holder.createInfoAnnotation(newTextRange, null); annotation.setTextAttributes(textAttributesKey); }
private void annotateTemplateStart(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { TextRange textRange = element.getTextRange(); TextRange newTextRange = new TextRange(textRange.getEndOffset() - 1, textRange.getEndOffset()); Annotation annotation = holder.createInfoAnnotation(newTextRange, null); annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.STRING); }
private void annotateKeyword(@NotNull PsiElement element, @NotNull AnnotationHolder holder, boolean excludeEndChar) { TextRange textRange = element.getTextRange(); TextRange newTextRange = new TextRange(textRange.getStartOffset(), textRange.getEndOffset() - (excludeEndChar ? 1 : 0)); Annotation annotation = holder.createInfoAnnotation(newTextRange, null); annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.KEYWORD); }
private CompletionResultSet adjustMatcher(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result, @NotNull PsiElement parent) { int startOffset = parent.getTextRange().getStartOffset(); String newPrefix = parameters.getEditor().getDocument().getText(TextRange.create(startOffset, parameters.getOffset())); return result.withPrefixMatcher(createPrefixMatcher(newPrefix)); } });
@Nullable protected TextRange surroundExpressionWithIfElse(@NotNull PsiElement[] elements, boolean withElse) { GoExpression expression = getExpression(elements); if (expression == null) return null; String condition = expression.getText(); GoIfStatement ifStatement = GoElementFactory.createIfStatement(expression.getProject(), condition, "", withElse ? "" : null); PsiElement replace = expression.replace(ifStatement); int offset = replace.getTextRange().getEndOffset(); return TextRange.create(offset, offset); } }
@Nullable protected TextRange surroundWithParenthesis(@NotNull PsiElement[] elements, boolean withNot) { GoExpression expression = getExpression(elements); if (expression == null) return null; String text = (withNot ? "!" : "") + "(" + expression.getText() + ")"; GoExpression parenthExprNode = GoElementFactory.createExpression(expression.getProject(), text); PsiElement replace = expression.replace(parenthExprNode); int endOffset = replace.getTextRange().getEndOffset(); return TextRange.create(endOffset, endOffset); }
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (!(file instanceof GoFile) || editor == null || !(startElement instanceof GoBlock)) return; PsiElement brace = ((GoBlock)startElement).getRbrace(); if (brace == null) return; Template template = TemplateSettings.getInstance().getTemplateById("go_lang_add_return"); if (template == null) return; int start = brace.getTextRange().getStartOffset(); editor.getCaretModel().moveToOffset(start); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); template.setToReformat(true); TemplateManager.getInstance(project).startTemplate(editor, template, true, Collections.emptyMap(), null); } }
@Override public boolean doEnter(PsiElement psiElement, PsiFile file, @NotNull Editor editor, boolean modified) { GoBlock block = findBlock(psiElement); if (block != null) { editor.getCaretModel().moveToOffset(block.getLbrace().getTextRange().getEndOffset()); } plainEnter(editor); return true; } }
private void annotateExpressionTemplateStart(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { TextRange textRange = element.getTextRange(); TextRange newTextRange = new TextRange(textRange.getEndOffset() - 2, textRange.getEndOffset()); Annotation annotation = holder.createInfoAnnotation(newTextRange, null); annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.TEMPLATE_LANGUAGE_COLOR); if (textRange.getEndOffset() - 2 > textRange.getStartOffset()) { newTextRange = new TextRange(textRange.getStartOffset(), textRange.getEndOffset() - 2); annotation = holder.createInfoAnnotation(newTextRange, null); annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.STRING); } }