use of org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl 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 org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl in project intellij-community by JetBrains.
the class GroovyLineMarkerProvider method getGroovyCategory.
private static int getGroovyCategory(@NotNull PsiElement element, @NotNull CharSequence documentChars) {
if (element instanceof GrVariableDeclarationImpl) {
GrVariable[] variables = ((GrVariableDeclarationImpl) element).getVariables();
if (variables.length == 1 && variables[0] instanceof GrField && variables[0].getInitializerGroovy() instanceof GrClosableBlock) {
return 2;
}
}
if (element instanceof GrField || element instanceof GrTypeParameter)
return 1;
if (element instanceof GrTypeDefinition || element instanceof GrClassInitializer)
return 2;
if (element instanceof GrMethod) {
if (((GrMethod) element).hasModifierProperty(PsiModifier.ABSTRACT) && !(((GrMethod) element).getBlock() != null && GrTraitUtil.isTrait(((GrMethod) element).getContainingClass()))) {
return 1;
}
TextRange textRange = element.getTextRange();
int start = textRange.getStartOffset();
int end = Math.min(documentChars.length(), textRange.getEndOffset());
int crlf = StringUtil.getLineBreakCount(documentChars.subSequence(start, end));
return crlf == 0 ? 1 : 2;
}
return 0;
}
Aggregations