@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { if (!super.isAvailable(project, editor, file)) { return false; } BindingContext context = KotlinCacheManager.getInstance(project).getDeclarationsFromProject().getBindingContext(); AnnotationDescriptor annotationDescriptor = context.get(BindingContext.ANNOTATION, annotationEntry); if (annotationDescriptor == null) { return false; } annotationType = annotationDescriptor.getType(); DeclarationDescriptor declarationDescriptor = annotationType.getConstructor().getDeclarationDescriptor(); if (declarationDescriptor == null) { return false; } PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, declarationDescriptor); if (declaration instanceof JetClass) { annotationClass = (JetClass) declaration; return annotationClass.isWritable(); } return false; }
private void renderAnnotations(@NotNull Annotated annotated, @NotNull StringBuilder builder) { if (!modifiers.contains(Modifier.ANNOTATIONS)) return; for (AnnotationDescriptor annotation : annotated.getAnnotations()) { ClassDescriptor annotationClass = (ClassDescriptor) annotation.getType().getConstructor().getDeclarationDescriptor(); assert annotationClass != null; if (!excludedAnnotationClasses.contains( DescriptorUtils.getFQName(annotationClass).toSafe())) { builder.append(renderType(annotation.getType())); if (verbose) { builder .append("(") .append( StringUtil.join(DescriptorUtils.getSortedValueArguments(annotation, this), ", ")) .append(")"); } builder.append(" "); } } }
@Nullable private static String getMessageFromAnnotationDescriptor( @NotNull AnnotationDescriptor descriptor) { ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType()); if (classDescriptor != null) { ValueParameterDescriptor parameter = DescriptorResolverUtils.getAnnotationParameterByName( DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor); if (parameter != null) { CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameter); if (valueArgument != null) { Object value = valueArgument.getValue(); if (value instanceof String) { return String.valueOf(value); } } } } return null; }
public void serialize(AnnotationDescriptor annotation) { new TypeSerializer(sb).serialize(annotation.getType()); sb.append("("); serializeCommaSeparated(annotation.getValueArguments()); sb.append(")"); }