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

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

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

    PsiReference reference = ReferenceUtilKt.getMainReference(referenceExpression);
    PsiElement target = reference.resolve();
    if (target instanceof JetClass) {
      annotationClass = (JetClass) target;
      return QuickFixUtil.canModifyElement(annotationClass);
    }

    return false;
  }
  private void checkModifiersAndAnnotationsInPackageDirective(JetFile file) {
    JetPackageDirective packageDirective = file.getPackageDirective();
    if (packageDirective == null) return;

    JetModifierList modifierList = packageDirective.getModifierList();
    if (modifierList == null) return;

    for (JetAnnotationEntry annotationEntry : modifierList.getAnnotationEntries()) {
      JetConstructorCalleeExpression calleeExpression = annotationEntry.getCalleeExpression();
      if (calleeExpression != null) {
        JetReferenceExpression reference = calleeExpression.getConstructorReferenceExpression();
        if (reference != null) {
          trace.report(UNRESOLVED_REFERENCE.on(reference, reference));
        }
      }
    }
    AnnotationTargetChecker.INSTANCE$.check(packageDirective, trace);

    ModifiersChecker.reportIllegalModifiers(
        modifierList, Arrays.asList(JetTokens.MODIFIER_KEYWORDS_ARRAY), trace);
  }