use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.
the class GroovyLineMarkerProvider method getLineMarkerInfo.
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
final PsiElement parent = element.getParent();
if (parent instanceof PsiNameIdentifierOwner) {
if (parent instanceof GrField && element == ((GrField) parent).getNameIdentifierGroovy()) {
for (GrAccessorMethod method : GroovyPropertyUtils.getFieldAccessors((GrField) parent)) {
MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (superSignature != null) {
PsiMethod superMethod = superSignature.getMethod();
boolean overrides = method.hasModifierProperty(PsiModifier.ABSTRACT) == superMethod.hasModifierProperty(PsiModifier.ABSTRACT) || superMethod.getBody() != null && GrTraitUtil.isTrait(superMethod.getContainingClass());
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
final MarkerType type = GroovyMarkerTypes.OVERRIDING_PROPERTY_TYPE;
return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
}
}
} else if (parent instanceof GrMethod && element == ((GrMethod) parent).getNameIdentifierGroovy() && hasSuperMethods((GrMethod) element.getParent())) {
final Icon icon = AllIcons.Gutter.OverridingMethod;
final MarkerType type = GroovyMarkerTypes.GR_OVERRIDING_METHOD;
return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
}
}
//need to draw method separator above docComment
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
PsiElement element1 = element;
boolean isMember = false;
while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
element1 = element1.getParent();
if (element1 instanceof PsiMember || element1 instanceof GrVariableDeclarationImpl) {
isMember = true;
break;
}
}
if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) {
PsiFile file = element1.getContainingFile();
Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file);
boolean drawSeparator = false;
if (document != null) {
CharSequence documentChars = document.getCharsSequence();
int category = getGroovyCategory(element1, documentChars);
for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) {
int category1 = getGroovyCategory(child, documentChars);
if (category1 == 0)
continue;
drawSeparator = category != 1 || category1 != 1;
break;
}
}
if (drawSeparator) {
GrDocComment comment = null;
if (element1 instanceof GrDocCommentOwner) {
comment = ((GrDocCommentOwner) element1).getDocComment();
}
LineMarkerInfo info = new LineMarkerInfo<>(element, comment != null ? comment.getTextRange() : element.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
}
}
}
return null;
}
use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.
the class GroovyQuoteHandler method getClosingQuote.
@Override
public CharSequence getClosingQuote(HighlighterIterator iterator, int offset) {
if (offset >= 3) {
Document document = iterator.getDocument();
if (document == null)
return null;
String quote = document.getText(new TextRange(offset - 3, offset));
if ("'''".equals(quote))
return quote;
if ("\"\"\"".equals(quote))
return quote;
}
if (offset >= 2) {
Document document = iterator.getDocument();
if (document == null)
return null;
String quote = document.getText(new TextRange(offset - 2, offset));
if ("$/".equals(quote))
return "/$";
}
return null;
}
use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.
the class FieldInitializerTailTypes method processTail.
@Override
public int processTail(Editor editor, int tailOffset) {
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject());
Document document = editor.getDocument();
CharSequence chars = document.getCharsSequence();
int textLength = chars.length();
if (tailOffset < textLength - 1 && chars.charAt(tailOffset) == ' ' && chars.charAt(tailOffset + 1) == '=') {
return moveCaret(editor, tailOffset, 2);
}
if (tailOffset < textLength && chars.charAt(tailOffset) == '=') {
return moveCaret(editor, tailOffset, 1);
}
if (styleSettings.SPACE_AROUND_ASSIGNMENT_OPERATORS) {
document.insertString(tailOffset, " =");
tailOffset = moveCaret(editor, tailOffset, 2);
} else {
document.insertString(tailOffset, "=");
tailOffset = moveCaret(editor, tailOffset, 1);
}
if (styleSettings.SPACE_AROUND_ASSIGNMENT_OPERATORS) {
tailOffset = insertChar(editor, tailOffset, ' ');
}
document.insertString(tailOffset, myText);
return moveCaret(editor, tailOffset, myPosition);
}
use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.
the class PsiEventsTest method testEditingInDocComment.
public void testEditingInDocComment() throws Exception {
final Ref<Boolean> gotIt = new Ref<>(false);
getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() {
@Override
public void childReplaced(@NotNull PsiTreeChangeEvent event) {
gotIt.set(true);
}
});
GroovyFile file = GroovyPsiElementFactory.getInstance(myProject).createGroovyFile("/** This is doc comment*/class C{}", true, null);
final PsiDocumentManager docManager = PsiDocumentManager.getInstance(myProject);
final Document doc = docManager.getDocument(file);
assertNotNull(doc);
CommandProcessor.getInstance().executeCommand(myProject, () -> ApplicationManager.getApplication().runWriteAction(() -> {
doc.insertString(3, " ");
docManager.commitDocument(doc);
}), "file text set", this);
assertTrue(gotIt.get());
}
use of com.intellij.openapi.editor.Document in project intellij-community by JetBrains.
the class TaskCompletionTest method configureFile.
private void configureFile(String text) {
PsiFile psiFile = myFixture.configureByText("test.txt", text);
Document document = myFixture.getDocument(psiFile);
final Project project = getProject();
TextFieldWithAutoCompletion.installCompletion(document, project, new TaskAutoCompletionListProvider(project), false);
document.putUserData(CommitMessage.DATA_KEY, new CommitMessage(project));
}
Aggregations