Comparable (@NotNull LookupElement element, @NotNull CompletionLocation location) { final PsiElement position = location.getCompletionParameters().getPosition(); if (!(position.getContainingFile() instanceof GroovyFileBase)) return null; Object o = element.getObject(); if (o instanceof ResolveResult) { o = ((ResolveResult)o).getElement(); } final PsiElement parent = position.getParent(); final PsiElement qualifier = parent instanceof GrReferenceElement ? ((GrReferenceElement<?>)parent).getQualifier() : null; if (qualifier == null) { if (o instanceof NamedArgumentDescriptor descriptor) { return switch (descriptor.getPriority()) { case ALWAYS_ON_TOP -> NotQualifiedKind.onTop; case AS_LOCAL_VARIABLE -> NotQualifiedKind.local; default -> NotQualifiedKind.unknown; }; } if (o instanceof PsiVariable && !(o instanceof PsiField)) { return NotQualifiedKind.local; } PsiTypeLookupItem item = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY); if (item != null && item.getBracketsCount() > 0) { return NotQualifiedKind.arrayType; } if (isPriorityKeyword(o)) return NotQualifiedKind.local; if (isLightElement(o)) return NotQualifiedKind.unknown; if (o instanceof PsiClass cls) { if (cls.isAnnotationType() && GrMainCompletionProvider.AFTER_AT.accepts(position)) { final GrAnnotation annotation = PsiTreeUtil.getParentOfType(position, GrAnnotation.class); if (annotation != null) { PsiElement annoParent = annotation.getParent(); PsiElement ownerToUse = annoParent instanceof PsiModifierList ? annoParent.getParent() : annoParent; PsiAnnotation.TargetType[] elementTypeFields = GrAnnotationImpl.getApplicableElementTypeFields(ownerToUse); if (AnnotationTargetUtil.findAnnotationTarget(cls, elementTypeFields) != null) { return NotQualifiedKind.restrictedClass; } } } if (GrMainCompletionProvider.IN_CATCH_TYPE.accepts(position) && InheritanceUtil.isInheritor(cls, CommonClassNames.JAVA_LANG_THROWABLE)) { return NotQualifiedKind.restrictedClass; } } if (o instanceof PsiMember member) { final PsiClass containingClass = member.getContainingClass(); if (isAccessor(member)) return NotQualifiedKind.accessor; if (o instanceof PsiClass cls && cls.getContainingClass() == null || o instanceof PsiPackage) return NotQualifiedKind.unknown; if (o instanceof PsiClass) return NotQualifiedKind.innerClass; if (PsiTreeUtil.isContextAncestor(containingClass, position, false)) return NotQualifiedKind.currentClassMember; return NotQualifiedKind.member; } return NotQualifiedKind.unknown; } else { if (o instanceof PsiEnumConstant) return QualifiedKind.enumConstant; if (isLightElement(o)) return QualifiedKind.unknown; if (o instanceof PsiMember) { if (isTrashMethod((PsiMember)o)) return QualifiedKind.unknown; if (isAccessor((PsiMember)o)) return QualifiedKind.accessor; if (isQualifierClassMember((PsiMember)o, qualifier)) { return QualifiedKind.currentClassMember; } if (o instanceof PsiClass && ((PsiClass)o).getContainingClass() == null || o instanceof PsiPackage) return QualifiedKind.unknown; if (o instanceof PsiClass) return QualifiedKind.innerClass; return QualifiedKind.member; } return QualifiedKind.unknown; } }