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

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


  protected void dumpSources(List<TypeModel> types,
                             List<SyntheticJavaFile> sources) {
    Iterator<TypeModel> itType = types.iterator();
    Iterator<SyntheticJavaFile> itFile = sources.iterator();
    while (itType.hasNext() && itFile.hasNext()) {
      TypeModel type = itType.next();
      SyntheticJavaFile file = itFile.next();
      DebugUtils.dump(type.getName().getBinaryName(),
                      file.getCharContent(true).toString().getBytes(),
                      Kind.SOURCE);
    }
  }
View Full Code Here


     * prevents name clashes due to erasure.
     */
    ArrayList<TypeModel> undecoratedTypes =
        new ArrayList<TypeModel>(roots.size());
    for (TypeElement r : roots) {
      TypeModel type = factory.createType(r, diagnosticManager);
      ElementScanner annotator =
          new ElementScanner() {
            @Override
            public void visitContractAnnotation(
                ContractAnnotationModel annotation) {
              if (annotation.isVirtual()
                  && knownTypeNames.contains(
                      annotation.getOwner().getQualifiedName())) {
                annotation.setWeakVirtual(true);
              }
            }
          };
      type.accept(annotator);
      undecoratedTypes.add(type);
    }
    /*
     * Decorate the type models with contract methods and create
     * helper types.
     */
    ArrayList<TypeModel> types =
        new ArrayList<TypeModel>(undecoratedTypes.size());
    for (TypeModel type : undecoratedTypes) {
      ClassContractCreator creator =
          new ClassContractCreator(diagnosticManager);
      type.accept(creator);
      TypeModel helper = creator.getHelperType();
      types.add(type);
      if (helper != null) {
        types.add(helper);
      }
    }
View Full Code Here

  @Requires({
    "method != null",
    "method.isConstructor()"
  })
  private void appendConstructorCode(MethodModel method) {
    TypeModel parent = Elements.getTypeOf(method);
    List<? extends TypeName> superArguments = parent.getSuperArguments();
    if (!superArguments.isEmpty()) {
      append("super(");
      Iterator<? extends TypeName> it = superArguments.iterator();
      for (;;) {
        append(getDefaultValue(it.next()));
View Full Code Here

  })
  @Ensures("result != null")
  static ContractMethodModel createBlankContractMethod(
      ContractKind kind, ContractAnnotationModel annotation,
      String nameSuffix) {
    TypeModel type = Elements.getTypeOf(annotation);

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

    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

  })
  @Ensures("result != null")
  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 {
      method = new MethodModel(ElementKind.CONTRACT_MOCK, name, returnType);
      if (contracted != null) {
        Elements.copyParameters(method, contracted.getParameters());
      }
    }

    if (!annotation.isVirtual()) {
      method.addParameter(
          new VariableModel(ElementKind.PARAMETER,
                            JavaUtils.THAT_VARIABLE, annotation.getOwner()));
    }

    if (!annotation.isVirtual()) {
      method.addModifier(ElementModifier.PUBLIC);
      method.addModifier(ElementModifier.STATIC);
    } else {
      method.addModifier(ElementModifier.PROTECTED);
    }

    if (annotation.isPrimary()
        || annotation.isVirtual() && !annotation.isWeakVirtual()) {
      type.addMember(method);
    }

    return method;
  }
View Full Code Here

        kind = ElementKind.ANNOTATION_TYPE;
        break;
      default:
        return null;
    }
    type = new TypeModel(kind, utils.getClassNameForType(e.asType()));
    utils.copyModifiers(e, type);
    if (kind == ElementKind.ENUM) {
      type.removeModifier(ElementModifier.FINAL);
    }
View Full Code Here

TOP

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

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.