private void checkOpenMembers(ClassDescriptorWithResolutionScopes classDescriptor) {
    if (classCanHaveOpenMembers(classDescriptor)) return;

    for (CallableMemberDescriptor memberDescriptor : classDescriptor.getDeclaredCallableMembers()) {
      if (memberDescriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) continue;
      JetNamedDeclaration member =
          (JetNamedDeclaration) DescriptorToSourceUtils.descriptorToDeclaration(memberDescriptor);
      if (member != null && member.hasModifier(JetTokens.OPEN_KEYWORD)) {
        trace.report(NON_FINAL_MEMBER_IN_FINAL_CLASS.on(member));
      }
    }
  }
Exemple #2
0
  @Nullable
  public static JetElement getEnclosingElementForLocalDeclaration(
      @Nullable JetNamedDeclaration declaration) {
    if (declaration instanceof JetTypeParameter) {
      declaration = PsiTreeUtil.getParentOfType(declaration, JetNamedDeclaration.class);
    } else if (declaration instanceof JetParameter) {
      PsiElement parent = declaration.getParent();
      if (parent != null && parent.getParent() instanceof JetNamedFunction) {
        declaration = (JetNamedFunction) parent.getParent();
      }
    }

    //noinspection unchecked
    JetElement container =
        PsiTreeUtil.getParentOfType(
            declaration,
            JetBlockExpression.class,
            JetClassInitializer.class,
            JetProperty.class,
            JetFunction.class,
            JetParameter.class);
    if (container == null) return null;

    return (container instanceof JetClassInitializer)
        ? ((JetClassInitializer) container).getBody()
        : container;
  }
 @NotNull
 public static DeclarationDescriptor getEnclosingDescriptor(
     @NotNull BindingContext context, @NotNull JetElement element) {
   JetNamedDeclaration declaration =
       PsiTreeUtil.getParentOfType(element, JetNamedDeclaration.class);
   if (declaration instanceof JetFunctionLiteral) {
     return getEnclosingDescriptor(context, declaration);
   }
   DeclarationDescriptor descriptor = context.get(DECLARATION_TO_DESCRIPTOR, declaration);
   assert descriptor != null
       : "No descriptor for named declaration: "
           + declaration.getText()
           + "\n(of type "
           + declaration.getClass()
           + ")";
   return descriptor;
 }
Exemple #4
0
  @Nullable
  public static FqName getFQName(@NotNull JetNamedDeclaration namedDeclaration) {
    Name name = namedDeclaration.getNameAsName();
    if (name == null) {
      return null;
    }

    PsiElement parent = namedDeclaration.getParent();
    if (parent instanceof JetClassBody) {
      // One nesting to JetClassBody doesn't affect to qualified name
      parent = parent.getParent();
    }

    FqName firstPart = null;
    if (parent instanceof JetFile) {
      firstPart = getFQName((JetFile) parent);
    } else if (parent instanceof JetNamedFunction || parent instanceof JetClass) {
      firstPart = getFQName((JetNamedDeclaration) parent);
    } else if (namedDeclaration instanceof JetParameter) {
      JetClass constructorClass = getClassIfParameterIsProperty((JetParameter) namedDeclaration);
      if (constructorClass != null) {
        firstPart = getFQName(constructorClass);
      }
    } else if (parent instanceof JetObjectDeclaration) {
      if (parent.getParent() instanceof JetClassObject) {
        JetClassOrObject classOrObject =
            PsiTreeUtil.getParentOfType(parent, JetClassOrObject.class);
        if (classOrObject != null) {
          firstPart = getFQName(classOrObject);
        }
      } else {
        firstPart = getFQName((JetNamedDeclaration) parent);
      }
    }

    if (firstPart == null) {
      return null;
    }

    return firstPart.child(name);
  }