Exemple #1
0
  private void checkCyclicConstructorDelegationCall(
      @NotNull ConstructorDescriptor constructorDescriptor,
      @NotNull Set<ConstructorDescriptor> visitedConstructors) {
    if (visitedConstructors.contains(constructorDescriptor)) return;

    // if visit constructor that is already in current chain
    // such constructor is on cycle
    Set<ConstructorDescriptor> visitedInCurrentChain = Sets.newHashSet();
    ConstructorDescriptor currentConstructorDescriptor = constructorDescriptor;
    while (true) {
      visitedInCurrentChain.add(currentConstructorDescriptor);
      ConstructorDescriptor delegatedConstructorDescriptor =
          getDelegatedConstructor(currentConstructorDescriptor);
      if (delegatedConstructorDescriptor == null) break;

      // if next delegation call is super or primary constructor or already visited
      if (!constructorDescriptor
              .getContainingDeclaration()
              .equals(delegatedConstructorDescriptor.getContainingDeclaration())
          || delegatedConstructorDescriptor.isPrimary()
          || visitedConstructors.contains(delegatedConstructorDescriptor)) {
        break;
      }

      if (visitedInCurrentChain.contains(delegatedConstructorDescriptor)) {
        reportEachConstructorOnCycle(delegatedConstructorDescriptor);
        break;
      }
      currentConstructorDescriptor = delegatedConstructorDescriptor;
    }
    visitedConstructors.addAll(visitedInCurrentChain);
  }
Exemple #2
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);
      }
    }
  }
Exemple #3
0
  public void resolveConstructorParameterDefaultValuesAndAnnotations(
      @NotNull DataFlowInfo outerDataFlowInfo,
      @NotNull BindingTrace trace,
      @NotNull JetClass klass,
      @NotNull ConstructorDescriptor constructorDescriptor,
      @NotNull LexicalScope declaringScope) {
    List<JetParameter> valueParameters = klass.getPrimaryConstructorParameters();
    List<ValueParameterDescriptor> valueParameterDescriptors =
        constructorDescriptor.getValueParameters();

    LexicalScope scope =
        getPrimaryConstructorParametersScope(declaringScope, constructorDescriptor);

    valueParameterResolver.resolveValueParameters(
        valueParameters, valueParameterDescriptors, scope, outerDataFlowInfo, trace);
  }
Exemple #4
0
  public void resolveSecondaryConstructorBody(
      @NotNull final DataFlowInfo outerDataFlowInfo,
      @NotNull final BindingTrace trace,
      @NotNull final JetSecondaryConstructor constructor,
      @NotNull final ConstructorDescriptor descriptor,
      @NotNull LexicalScope declaringScope) {
    ForceResolveUtil.forceResolveAllContents(descriptor.getAnnotations());

    final CallChecker callChecker = new ConstructorHeaderCallChecker(descriptor);
    resolveFunctionBody(
        outerDataFlowInfo,
        trace,
        constructor,
        descriptor,
        declaringScope,
        new Function1<LexicalScope, DataFlowInfo>() {
          @Override
          public DataFlowInfo invoke(@NotNull LexicalScope headerInnerScope) {
            return resolveSecondaryConstructorDelegationCall(
                outerDataFlowInfo, trace, headerInnerScope, constructor, descriptor, callChecker);
          }
        },
        callChecker);
  }