Example #1
0
 @Nullable
 public static Name getShortName(@NotNull KtAnnotationEntry annotation) {
   KtTypeReference typeReference = annotation.getTypeReference();
   assert typeReference != null : "Annotation entry hasn't typeReference " + annotation.getText();
   KtTypeElement typeElement = typeReference.getTypeElement();
   if (typeElement instanceof KtUserType) {
     KtUserType userType = (KtUserType) typeElement;
     String shortName = userType.getReferencedName();
     if (shortName != null) {
       return Name.identifier(shortName);
     }
   }
   return null;
 }
  @Override
  public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiFile file) {
    if (!super.isAvailable(project, editor, file)) {
      return false;
    }

    KtTypeReference typeReference = annotationEntry.getTypeReference();
    if (typeReference == null) {
      return false;
    }

    KtSimpleNameExpression referenceExpression =
        PsiTreeUtil.findChildOfType(typeReference, KtSimpleNameExpression.class);
    if (referenceExpression == null) {
      return false;
    }

    PsiReference reference = ReferenceUtilKt.getMainReference(referenceExpression);
    PsiElement target = reference.resolve();
    if (target instanceof KtClass) {
      annotationClass = (KtClass) target;
      return JetRefactoringUtilKt.canRefactor(annotationClass);
    }

    return false;
  }