Esempio n. 1
0
  public void resolvePropertyAccessors(
      @NotNull BodiesResolveContext c,
      @NotNull JetProperty property,
      @NotNull PropertyDescriptor propertyDescriptor) {
    ObservableBindingTrace fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor);

    JetPropertyAccessor getter = property.getGetter();
    PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
    if (getter != null && getterDescriptor != null) {
      LexicalScope accessorScope = makeScopeForPropertyAccessor(c, getter, propertyDescriptor);
      ForceResolveUtil.forceResolveAllContents(getterDescriptor.getAnnotations());
      resolveFunctionBody(
          c.getOuterDataFlowInfo(),
          fieldAccessTrackingTrace,
          getter,
          getterDescriptor,
          accessorScope);
    }

    JetPropertyAccessor setter = property.getSetter();
    PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
    if (setter != null && setterDescriptor != null) {
      LexicalScope accessorScope = makeScopeForPropertyAccessor(c, setter, propertyDescriptor);
      ForceResolveUtil.forceResolveAllContents(setterDescriptor.getAnnotations());
      resolveFunctionBody(
          c.getOuterDataFlowInfo(),
          fieldAccessTrackingTrace,
          setter,
          setterDescriptor,
          accessorScope);
    }
  }
Esempio n. 2
0
  private void resolvePropertyDeclarationBodies(@NotNull BodiesResolveContext c) {

    // Member properties
    Set<JetProperty> processed = Sets.newHashSet();
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      if (!(entry.getKey() instanceof JetClass)) continue;
      JetClass jetClass = (JetClass) entry.getKey();
      ClassDescriptorWithResolutionScopes classDescriptor = entry.getValue();

      for (JetProperty property : jetClass.getProperties()) {
        PropertyDescriptor propertyDescriptor = c.getProperties().get(property);
        assert propertyDescriptor != null;

        resolveProperty(
            c,
            classDescriptor.getScopeForMemberDeclarationResolution(),
            property,
            propertyDescriptor);
        processed.add(property);
      }
    }

    // Top-level properties & properties of objects
    for (Map.Entry<JetProperty, PropertyDescriptor> entry : c.getProperties().entrySet()) {
      JetProperty property = entry.getKey();
      if (processed.contains(property)) continue;

      PropertyDescriptor propertyDescriptor = entry.getValue();

      resolveProperty(c, null, property, propertyDescriptor);
    }
  }
Esempio n. 3
0
  private void resolveProperty(
      @NotNull BodiesResolveContext c,
      @Nullable LexicalScope parentScope,
      @NotNull JetProperty property,
      @NotNull PropertyDescriptor propertyDescriptor) {
    computeDeferredType(propertyDescriptor.getReturnType());

    JetExpression initializer = property.getInitializer();
    LexicalScope propertyScope = getScopeForProperty(c, property);
    if (parentScope == null) {
      parentScope = propertyScope;
    }
    if (initializer != null) {
      resolvePropertyInitializer(
          c.getOuterDataFlowInfo(), property, propertyDescriptor, initializer, propertyScope);
    }

    JetExpression delegateExpression = property.getDelegateExpression();
    if (delegateExpression != null) {
      assert initializer == null
          : "Initializer should be null for delegated property : " + property.getText();
      resolvePropertyDelegate(
          c.getOuterDataFlowInfo(),
          property,
          propertyDescriptor,
          delegateExpression,
          parentScope,
          propertyScope);
    }

    resolvePropertyAccessors(c, property, propertyDescriptor);
  }
Esempio n. 4
0
 private void resolveAnonymousInitializers(@NotNull BodiesResolveContext c) {
   for (Map.Entry<JetClassInitializer, ClassDescriptorWithResolutionScopes> entry :
       c.getAnonymousInitializers().entrySet()) {
     JetClassInitializer initializer = entry.getKey();
     ClassDescriptorWithResolutionScopes descriptor = entry.getValue();
     resolveAnonymousInitializer(c.getOuterDataFlowInfo(), initializer, descriptor);
   }
 }
Esempio n. 5
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. 6
0
 private void resolveSecondaryConstructors(@NotNull BodiesResolveContext c) {
   for (Map.Entry<JetSecondaryConstructor, ConstructorDescriptor> entry :
       c.getSecondaryConstructors().entrySet()) {
     LexicalScope declaringScope = c.getDeclaringScope(entry.getKey());
     assert declaringScope != null : "Declaring scope should be registered before body resolve";
     resolveSecondaryConstructorBody(
         c.getOuterDataFlowInfo(), trace, entry.getKey(), entry.getValue(), declaringScope);
   }
   if (c.getSecondaryConstructors().isEmpty()) return;
   Set<ConstructorDescriptor> visitedConstructors = Sets.newHashSet();
   for (Map.Entry<JetSecondaryConstructor, ConstructorDescriptor> entry :
       c.getSecondaryConstructors().entrySet()) {
     checkCyclicConstructorDelegationCall(entry.getValue(), visitedConstructors);
   }
 }
Esempio n. 7
0
 @NotNull
 private static LexicalScope getScopeForProperty(
     @NotNull BodiesResolveContext c, @NotNull JetProperty property) {
   LexicalScope scope = c.getDeclaringScope(property);
   assert scope != null : "Scope for property " + property.getText() + " should exists";
   return scope;
 }
Esempio n. 8
0
  private void resolveDelegationSpecifierLists(@NotNull BodiesResolveContext c) {
    // TODO : Make sure the same thing is not initialized twice
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      JetClassOrObject classOrObject = entry.getKey();
      ClassDescriptorWithResolutionScopes descriptor = entry.getValue();

      resolveDelegationSpecifierList(
          c.getOuterDataFlowInfo(),
          classOrObject,
          descriptor,
          descriptor.getUnsubstitutedPrimaryConstructor(),
          descriptor.getScopeForClassHeaderResolution(),
          descriptor.getScopeForMemberDeclarationResolution());
    }
  }
Esempio n. 9
0
  private void resolveFunctionBodies(@NotNull BodiesResolveContext c) {
    for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry :
        c.getFunctions().entrySet()) {
      JetNamedFunction declaration = entry.getKey();

      LexicalScope scope = c.getDeclaringScope(declaration);
      assert scope != null
          : "Scope is null: " + PsiUtilPackage.getElementTextWithContext(declaration);

      if (!c.getTopDownAnalysisMode().getIsLocalDeclarations()
          && !(bodyResolveCache instanceof BodyResolveCache.ThrowException)
          && expressionTypingServices.getStatementFilter() != StatementFilter.NONE) {
        bodyResolveCache.resolveFunctionBody(declaration).addOwnDataTo(trace, true);
      } else {
        resolveFunctionBody(c.getOuterDataFlowInfo(), trace, declaration, entry.getValue(), scope);
      }
    }
  }
Esempio n. 10
0
 private LexicalScope makeScopeForPropertyAccessor(
     @NotNull BodiesResolveContext c,
     @NotNull JetPropertyAccessor accessor,
     @NotNull PropertyDescriptor descriptor) {
   LexicalScope accessorDeclaringScope = c.getDeclaringScope(accessor);
   assert accessorDeclaringScope != null
       : "Scope for accessor " + accessor.getText() + " should exists";
   return JetScopeUtils.makeScopeForPropertyAccessor(descriptor, accessorDeclaringScope, trace);
 }
Esempio n. 11
0
  private void resolvePrimaryConstructorParameters(@NotNull BodiesResolveContext c) {
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      JetClassOrObject klass = entry.getKey();
      ClassDescriptorWithResolutionScopes classDescriptor = entry.getValue();
      ConstructorDescriptor unsubstitutedPrimaryConstructor =
          classDescriptor.getUnsubstitutedPrimaryConstructor();
      if (unsubstitutedPrimaryConstructor != null) {
        ForceResolveUtil.forceResolveAllContents(unsubstitutedPrimaryConstructor.getAnnotations());

        LexicalScope parameterScope =
            getPrimaryConstructorParametersScope(
                classDescriptor.getScopeForClassHeaderResolution(),
                unsubstitutedPrimaryConstructor);
        valueParameterResolver.resolveValueParameters(
            klass.getPrimaryConstructorParameters(),
            unsubstitutedPrimaryConstructor.getValueParameters(),
            parameterScope,
            c.getOuterDataFlowInfo(),
            trace);
      }
    }
  }
Esempio n. 12
0
  private void resolveBehaviorDeclarationBodies(@NotNull BodiesResolveContext c) {
    resolveDelegationSpecifierLists(c);

    resolvePropertyDeclarationBodies(c);

    resolveAnonymousInitializers(c);
    resolvePrimaryConstructorParameters(c);
    resolveSecondaryConstructors(c);

    resolveFunctionBodies(c);

    // SCRIPT: resolve script bodies
    scriptBodyResolverResolver.resolveScriptBodies(c);

    if (!c.getTopDownAnalysisMode().getIsLocalDeclarations()) {
      computeDeferredTypes();
    }
  }