Exemplo n.º 1
0
  @Nullable
  public static KtClassOrObject getClassIfParameterIsProperty(@NotNull KtParameter jetParameter) {
    if (jetParameter.hasValOrVar()) {
      PsiElement grandParent = jetParameter.getParent().getParent();
      if (grandParent instanceof KtPrimaryConstructor) {
        return ((KtPrimaryConstructor) grandParent).getContainingClassOrObject();
      }
    }

    return null;
  }
  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;
  }
Exemplo n.º 3
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);
         }
       }
     }
   }
 }