use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrKindWeigher method weigh.
@Override
public Comparable weigh(@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) {
switch(((NamedArgumentDescriptor) o).getPriority()) {
case ALWAYS_ON_TOP:
return NotQualifiedKind.onTop;
case AS_LOCAL_VARIABLE:
return NotQualifiedKind.local;
default:
return 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) {
if (((PsiClass) o).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((PsiClass) o, elementTypeFields) != null) {
return NotQualifiedKind.restrictedClass;
}
}
}
if (GrMainCompletionProvider.IN_CATCH_TYPE.accepts(position) && InheritanceUtil.isInheritor((PsiClass) o, CommonClassNames.JAVA_LANG_THROWABLE)) {
return NotQualifiedKind.restrictedClass;
}
}
if (o instanceof PsiMember) {
final PsiClass containingClass = ((PsiMember) o).getContainingClass();
if (isAccessor((PsiMember) o))
return NotQualifiedKind.accessor;
if (o instanceof PsiClass && ((PsiClass) o).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;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GroovyAnnotationAttributeInfoHandler method showParameterInfo.
@Override
public void showParameterInfo(@NotNull GrAnnotationArgumentList argumentList, @NotNull CreateParameterInfoContext context) {
final GrAnnotation parent = (GrAnnotation) argumentList.getParent();
final PsiElement resolved = parent.getClassReference().resolve();
if (resolved instanceof PsiClass && ((PsiClass) resolved).isAnnotationType()) {
final PsiAnnotationMethod[] methods = extractAnnotationMethodsFromClass((PsiClass) resolved);
context.setItemsToShow(methods);
context.showHint(argumentList, argumentList.getTextRange().getStartOffset(), this);
final PsiAnnotationMethod currentMethod = findAnnotationMethod(context.getFile(), context.getEditor());
if (currentMethod != null) {
context.setHighlightedElement(currentMethod);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrabDependencies method prepareQueries.
static Map<String, String> prepareQueries(PsiFile file) {
final Set<GrAnnotation> grabs = new LinkedHashSet<>();
final Set<GrAnnotation> excludes = new THashSet<>();
final Set<GrAnnotation> resolvers = new THashSet<>();
file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof GrAnnotation) {
GrAnnotation anno = (GrAnnotation) element;
String qname = anno.getQualifiedName();
if (GrabAnnos.GRAB_ANNO.equals(qname))
grabs.add(anno);
else if (GrabAnnos.GRAB_EXCLUDE_ANNO.equals(qname))
excludes.add(anno);
else if (GrabAnnos.GRAB_RESOLVER_ANNO.equals(qname))
resolvers.add(anno);
}
super.visitElement(element);
}
});
Function<GrAnnotation, String> mapper = grAnnotation -> grAnnotation.getText();
String common = StringUtil.join(excludes, mapper, " ") + " " + StringUtil.join(resolvers, mapper, " ");
LinkedHashMap<String, String> result = new LinkedHashMap<>();
for (GrAnnotation grab : grabs) {
String grabText = grab.getText();
result.put(grabText, (grabText + " " + common).trim());
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrAnnotationAttributeCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
if (parent instanceof GrAnnotationNameValuePair && position == ((GrAnnotationNameValuePair) parent).getNameIdentifierGroovy()) {
GrAnnotation annotation = PsiImplUtil.getAnnotation((GrAnnotationNameValuePair) parent);
if (annotation != null) {
new AnnotationAttributeCompletionResultProcessor(annotation).process(result, PrefixMatcher.ALWAYS_TRUE);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method setupAnnotations.
private static void setupAnnotations(@NotNull GrTypeDefinition aClass, @NotNull PsiMethod method, @NotNull GrMethod result) {
if (OverrideImplementUtil.isInsertOverride(method, aClass)) {
result.getModifierList().addAnnotation(CommonClassNames.JAVA_LANG_OVERRIDE);
}
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(method.getProject());
final PsiParameter[] originalParams = method.getParameterList().getParameters();
GrParameter[] parameters = result.getParameters();
for (int i = 0; i < parameters.length; i++) {
GrParameter parameter = parameters[i];
PsiParameter original = originalParams[i];
for (PsiAnnotation annotation : original.getModifierList().getAnnotations()) {
final GrModifierList modifierList = parameter.getModifierList();
String qname = annotation.getQualifiedName();
if (qname != null && modifierList.findAnnotation(qname) == null) {
if (annotation instanceof GrAnnotation) {
modifierList.add(annotation);
} else {
modifierList.add(factory.createAnnotationFromText(annotation.getText()));
}
}
}
}
}
Aggregations