Package com.google.java.contract.core.model

Examples of com.google.java.contract.core.model.ContractMethodModel


    String name = kind.getNameSpace() + getContractName(kind, contracted);
    if (nameSuffix != null) {
      name += nameSuffix;
    }
    ContractMethodModel contract =
        new ContractMethodModel(kind, name, new TypeName("void"), contracted);

    contract.addModifier(ElementModifier.PRIVATE);
    type.addMember(contract);

    return contract;
  }
View Full Code Here


  static MethodModel createBlankContractHelper(
      ContractKind kind, ContractAnnotationModel annotation,
      String nameSuffix) {
    TypeModel type = Elements.getTypeOf(annotation);
    MethodModel method = null;
    ContractMethodModel contract = null;

    MethodModel contracted = null;
    if (kind.isMethodContract()) {
      contracted = (MethodModel) annotation.getEnclosingElement();
    }

    TypeName returnType = new TypeName("void");
    String name = getHelperName(kind, annotation.getOwner(), contracted);
    if (nameSuffix != null) {
      name += nameSuffix;
    }
    if (annotation.isPrimary()) {
      contract = new ContractMethodModel(ContractKind.HELPER, name,
                                         returnType, contracted);

      contract.setSourceInfo(annotation.getSourceInfo());

      if (!annotation.isVirtual()) {
        for (TypeName typeParam : type.getTypeParameters()) {
          contract.addTypeParameter(typeParam);
        }
      }

      method = contract;
    } else {
View Full Code Here

    if (annotation.isPrimary()) {
      method.setSourceInfo(annotation.getSourceInfo());
    }

    if (method.getKind() == ElementKind.CONTRACT_METHOD) {
      ContractMethodModel contract = (ContractMethodModel) method;

      Elements.copyParameters(contract, trait.getInitialParameters());
      Elements.copyParameters(contract, trait.getExtraParameters());

      addContractClauses(contract, trait, annotation);
      if (kind.getVariance() == ContractVariance.CONTRAVARIANT) {
        contract.setEpilogue("return null;");
      }

      if (annotation.isPrimary()) {
        contract.setLineNumbers(annotation.getLineNumbers());
      }
    } else {
      Elements.copyParameters(method, trait.getInitialMockParameters());
      Elements.copyParameters(method, trait.getExtraMockParameters());
    }
View Full Code Here

        ContractCreation.createBlankContractHelper(kind, annotation,
                                                   "$" + Integer.toString(pos));
    helper.setReturnType(new ClassName("java/lang/Object"));

    if (helper.getKind() == ElementKind.CONTRACT_METHOD) {
      ContractMethodModel helperContract = (ContractMethodModel) helper;
      if (lineNumber != null) {
        helperContract.setLineNumbers(Collections.singletonList(lineNumber));
      }
      String code = expr;
      if (!annotation.isVirtual()) {
        code = ContractCreation
            .rebaseLocalCalls(expr, JavaUtils.THAT_VARIABLE, null);
      }
      helperContract.addStatement("return " + code + ";");
    }

    ContractMethodModel contract =
        ContractCreation.createBlankContractMethod(kind, annotation, "$" + id);
    contract.setReturnType(new ClassName("java/lang/Object"));
    contract.setId(id);

    contract.addStatement("return "
        + ContractCreation.getHelperCallCode(helper, annotation) + ";");
  }
View Full Code Here

TOP

Related Classes of com.google.java.contract.core.model.ContractMethodModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.