private VariableDescriptor createLoopParameterDescriptor(
      KtParameter loopParameter,
      KotlinType expectedParameterType,
      ExpressionTypingContext context) {
    components
        .modifiersChecker
        .withTrace(context.trace)
        .checkParameterHasNoValOrVar(loopParameter, VAL_OR_VAR_ON_LOOP_PARAMETER);

    KtTypeReference typeReference = loopParameter.getTypeReference();
    VariableDescriptor variableDescriptor;
    if (typeReference != null) {
      variableDescriptor =
          components.descriptorResolver.resolveLocalVariableDescriptor(
              context.scope, loopParameter, context.trace);
      KotlinType actualParameterType = variableDescriptor.getType();
      if (expectedParameterType != null
          && !KotlinTypeChecker.DEFAULT.isSubtypeOf(expectedParameterType, actualParameterType)) {
        context.trace.report(
            TYPE_MISMATCH_IN_FOR_LOOP.on(
                typeReference, expectedParameterType, actualParameterType));
      }
    } else {
      if (expectedParameterType == null) {
        expectedParameterType = ErrorUtils.createErrorType("Error");
      }
      variableDescriptor =
          components.descriptorResolver.resolveLocalVariableDescriptor(
              loopParameter, expectedParameterType, context.trace, context.scope);
    }

    checkVariableShadowing(context.scope, context.trace, variableDescriptor);

    return variableDescriptor;
  }
示例#2
0
 private void generatePrimaryConstructorProperties() {
   boolean isAnnotation = descriptor.getKind() == ClassKind.ANNOTATION_CLASS;
   for (KtParameter p : getPrimaryConstructorParameters()) {
     if (p.hasValOrVar()) {
       PropertyDescriptor propertyDescriptor =
           bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, p);
       if (propertyDescriptor != null) {
         if (!isAnnotation) {
           propertyCodegen.generatePrimaryConstructorProperty(p, propertyDescriptor);
         } else {
           propertyCodegen.generateConstructorPropertyAsMethodForAnnotationClass(
               p, propertyDescriptor);
         }
       }
     }
   }
 }