コード例 #1
0
  private static void checkFieldAnnotation(
      @NotNull JetProperty altProperty, @NotNull JavaFieldImpl field, boolean isVar) {
    if (!ComparatorUtil.equalsNullable(field.getName().asString(), altProperty.getName())) {
      throw new AlternativeSignatureMismatchException(
          "Field name mismatch, original: %s, alternative: %s",
          field.getName().asString(), altProperty.getName());
    }

    if (altProperty.getTypeRef() == null) {
      throw new AlternativeSignatureMismatchException(
          "Field annotation for shouldn't have type reference");
    }

    if (altProperty.getGetter() != null || altProperty.getSetter() != null) {
      throw new AlternativeSignatureMismatchException(
          "Field annotation for shouldn't have getters and setters");
    }

    if (altProperty.isVar() != isVar) {
      throw new AlternativeSignatureMismatchException("Wrong mutability in annotation for field");
    }

    if (altProperty.getInitializer() != null) {
      throw new AlternativeSignatureMismatchException(
          "Default value is not expected in annotation for field");
    }
  }
コード例 #2
0
  public AlternativeFieldSignatureData(
      @NotNull JavaAnnotationResolver annotationResolver,
      @NotNull JavaFieldImpl field,
      @NotNull JetType originalReturnType,
      boolean isVar) {
    String signature = SignaturesUtil.getKotlinSignature(annotationResolver, field);

    if (signature == null) {
      setAnnotated(false);
      return;
    }

    setAnnotated(true);
    Project project = field.getPsi().getProject();
    JetProperty altPropertyDeclaration = JetPsiFactory.createProperty(project, signature);

    try {
      checkForSyntaxErrors(altPropertyDeclaration);
      checkFieldAnnotation(altPropertyDeclaration, field, isVar);
      altReturnType =
          computeReturnType(
              originalReturnType,
              altPropertyDeclaration.getTypeRef(),
              new HashMap<TypeParameterDescriptor, TypeParameterDescriptorImpl>());
    } catch (AlternativeSignatureMismatchException e) {
      setError(e.getMessage());
    }
  }