Esempio n. 1
0
  public void process(@NotNull BodiesResolveContext bodiesResolveContext) {
    for (JetFile file : bodiesResolveContext.getFiles()) {
      checkModifiersAndAnnotationsInPackageDirective(file);
      AnnotationTargetChecker.INSTANCE$.check(file, trace);
    }

    Map<JetClassOrObject, ClassDescriptorWithResolutionScopes> classes =
        bodiesResolveContext.getDeclaredClasses();
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        classes.entrySet()) {
      JetClassOrObject classOrObject = entry.getKey();
      ClassDescriptorWithResolutionScopes classDescriptor = entry.getValue();

      checkSupertypesForConsistency(classDescriptor);
      checkTypesInClassHeader(classOrObject);

      if (classOrObject instanceof JetClass) {
        JetClass jetClass = (JetClass) classOrObject;
        checkClass(bodiesResolveContext, jetClass, classDescriptor);
        descriptorResolver.checkNamesInConstraints(
            jetClass, classDescriptor, classDescriptor.getScopeForClassHeaderResolution(), trace);
      } else if (classOrObject instanceof JetObjectDeclaration) {
        checkObject((JetObjectDeclaration) classOrObject, classDescriptor);
      }

      checkPrimaryConstructor(classOrObject, classDescriptor);

      modifiersChecker.checkModifiersForDeclaration(classOrObject, classDescriptor);
    }

    Map<JetNamedFunction, SimpleFunctionDescriptor> functions = bodiesResolveContext.getFunctions();
    for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry : functions.entrySet()) {
      JetNamedFunction function = entry.getKey();
      SimpleFunctionDescriptor functionDescriptor = entry.getValue();

      checkFunction(function, functionDescriptor);
      modifiersChecker.checkModifiersForDeclaration(function, functionDescriptor);
    }

    Map<JetProperty, PropertyDescriptor> properties = bodiesResolveContext.getProperties();
    for (Map.Entry<JetProperty, PropertyDescriptor> entry : properties.entrySet()) {
      JetProperty property = entry.getKey();
      PropertyDescriptor propertyDescriptor = entry.getValue();

      checkProperty(property, propertyDescriptor);
      modifiersChecker.checkModifiersForDeclaration(property, propertyDescriptor);
    }

    for (Map.Entry<JetSecondaryConstructor, ConstructorDescriptor> entry :
        bodiesResolveContext.getSecondaryConstructors().entrySet()) {
      ConstructorDescriptor constructorDescriptor = entry.getValue();
      JetSecondaryConstructor declaration = entry.getKey();
      checkConstructorDeclaration(constructorDescriptor, declaration);
    }
  }
Esempio n. 2
0
 private void checkAccessors(
     @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
   for (JetPropertyAccessor accessor : property.getAccessors()) {
     PropertyAccessorDescriptor propertyAccessorDescriptor =
         accessor.isGetter() ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter();
     assert propertyAccessorDescriptor != null
         : "No property accessor descriptor for " + property.getText();
     modifiersChecker.checkModifiersForDeclaration(accessor, propertyAccessorDescriptor);
     modifiersChecker.reportIllegalModalityModifiers(accessor);
   }
   JetPropertyAccessor getter = property.getGetter();
   PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
   JetModifierList getterModifierList = getter != null ? getter.getModifierList() : null;
   if (getterModifierList != null && getterDescriptor != null) {
     Map<JetModifierKeywordToken, ASTNode> nodes =
         ModifiersChecker.getNodesCorrespondingToModifiers(
             getterModifierList,
             Sets.newHashSet(
                 JetTokens.PUBLIC_KEYWORD,
                 JetTokens.PROTECTED_KEYWORD,
                 JetTokens.PRIVATE_KEYWORD,
                 JetTokens.INTERNAL_KEYWORD));
     if (getterDescriptor.getVisibility() != propertyDescriptor.getVisibility()) {
       for (ASTNode node : nodes.values()) {
         trace.report(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY.on(node.getPsi()));
       }
     } else {
       for (ASTNode node : nodes.values()) {
         trace.report(Errors.REDUNDANT_MODIFIER_IN_GETTER.on(node.getPsi()));
       }
     }
   }
 }
Esempio n. 3
0
  private void checkPrimaryConstructor(
      JetClassOrObject classOrObject, ClassDescriptor classDescriptor) {
    ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
    JetPrimaryConstructor declaration = classOrObject.getPrimaryConstructor();
    if (primaryConstructor == null || declaration == null) return;

    for (JetParameter parameter : declaration.getValueParameters()) {
      PropertyDescriptor propertyDescriptor =
          trace.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
      if (propertyDescriptor != null) {
        modifiersChecker.checkModifiersForDeclaration(parameter, propertyDescriptor);
      }
    }

    if (declaration.getModifierList() != null && !declaration.hasConstructorKeyword()) {
      trace.report(MISSING_CONSTRUCTOR_KEYWORD.on(declaration.getModifierList()));
    }

    if (!(classOrObject instanceof JetClass)) {
      trace.report(CONSTRUCTOR_IN_OBJECT.on(declaration));
    }

    checkConstructorDeclaration(primaryConstructor, declaration);
  }
Esempio n. 4
0
 private void checkConstructorDeclaration(
     ConstructorDescriptor constructorDescriptor, JetDeclaration declaration) {
   modifiersChecker.reportIllegalModalityModifiers(declaration);
   reportErrorIfHasIllegalModifier(declaration);
   modifiersChecker.checkModifiersForDeclaration(declaration, constructorDescriptor);
 }