コード例 #1
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
  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);
    }
  }
コード例 #2
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
 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);
   }
 }
コード例 #3
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
 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);
   }
 }
コード例 #4
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
  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());
    }
  }
コード例 #5
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
  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);
      }
    }
  }
コード例 #6
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
  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);
      }
    }
  }
コード例 #7
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
  private void checkSupertypeList(
      @NotNull ClassDescriptor supertypeOwner,
      @NotNull Map<JetTypeReference, JetType> supertypes,
      @NotNull JetClassOrObject jetClass) {
    Set<TypeConstructor> allowedFinalSupertypes =
        getAllowedFinalSupertypes(supertypeOwner, jetClass);
    Set<TypeConstructor> typeConstructors = Sets.newHashSet();
    boolean classAppeared = false;
    for (Map.Entry<JetTypeReference, JetType> entry : supertypes.entrySet()) {
      JetTypeReference typeReference = entry.getKey();
      JetType supertype = entry.getValue();

      boolean addSupertype = true;

      ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
      if (classDescriptor != null) {
        if (ErrorUtils.isError(classDescriptor)) continue;

        if (classDescriptor.getKind() != ClassKind.INTERFACE) {
          if (supertypeOwner.getKind() == ClassKind.ENUM_CLASS) {
            trace.report(CLASS_IN_SUPERTYPE_FOR_ENUM.on(typeReference));
            addSupertype = false;
          } else if (supertypeOwner.getKind() == ClassKind.INTERFACE
              && !classAppeared
              && !TypesPackage.isDynamic(supertype) /* avoid duplicate diagnostics */) {
            trace.report(TRAIT_WITH_SUPERCLASS.on(typeReference));
            addSupertype = false;
          }

          if (classAppeared) {
            trace.report(MANY_CLASSES_IN_SUPERTYPE_LIST.on(typeReference));
          } else {
            classAppeared = true;
          }
        }
      } else {
        trace.report(SUPERTYPE_NOT_A_CLASS_OR_TRAIT.on(typeReference));
      }

      TypeConstructor constructor = supertype.getConstructor();
      if (addSupertype && !typeConstructors.add(constructor)) {
        trace.report(SUPERTYPE_APPEARS_TWICE.on(typeReference));
      }

      if (DescriptorUtils.isSingleton(classDescriptor)) {
        trace.report(SINGLETON_IN_SUPERTYPE.on(typeReference));
      } else if (constructor.isFinal() && !allowedFinalSupertypes.contains(constructor)) {
        if (classDescriptor.getModality() == Modality.SEALED) {
          DeclarationDescriptor containingDescriptor = supertypeOwner.getContainingDeclaration();
          while (containingDescriptor != null && containingDescriptor != classDescriptor) {
            containingDescriptor = containingDescriptor.getContainingDeclaration();
          }
          if (containingDescriptor == null) {
            trace.report(SEALED_SUPERTYPE.on(typeReference));
          } else {
            trace.report(SEALED_SUPERTYPE_IN_LOCAL_CLASS.on(typeReference));
          }
        } else {
          trace.report(FINAL_SUPERTYPE.on(typeReference));
        }
      }
    }
  }