Examples of MethodModel


Examples of com.carrotsearch.randomizedtesting.ClassModel.MethodModel

    Map<Method,MethodModel> annotatedLeafMethods = classModel.getAnnotatedLeafMethods(ann);

    StringBuilder b = new StringBuilder();
    for (Map.Entry<Method,MethodModel> e : annotatedLeafMethods.entrySet()) {
      if (verify(e.getKey())) {
        MethodModel mm = e.getValue();
        if (mm.getDown() != null || mm.getUp() != null) {
          b.append("Methods annotated with @" + ann.getName() + " shadow or override each other:\n");
          while (mm.getUp() != null) {
            mm = mm.getUp();
          }
          while (mm != null) {
            b.append("  - ");
            if (mm.element.isAnnotationPresent(ann)) b.append("@").append(ann.getSimpleName()).append(" ");
            b.append(signature(mm.element)).append("\n");
            mm = mm.getDown();
          }
        }
      }
    }
View Full Code Here

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

    if (id != -1) {
      append(", id = ");
      append(Integer.toString(id));
    }

    MethodModel contracted = contract.getContractedMethod();
    if (contracted != null) {
      append(", target = \"");
      append(contracted.getSimpleName());
      append("\"");
    }

    List<Long> lineNumbers = contract.getLineNumbers();
    if (lineNumbers != null && !lineNumbers.isEmpty()) {
View Full Code Here

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

      ContractCreationTrait trait, ContractMethodModel contract,
      ContractAnnotationModel annotation) {
    if (!trait.visit(annotation)) {
      return null;
    }
    MethodModel helper = createContractHelper(trait, annotation);
    return createContractMethod(trait, contract, annotation, helper);
  }
View Full Code Here

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

  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);
View Full Code Here

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

  @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(
View Full Code Here

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

  })
  @Ensures("result != null")
  static MethodModel createContractHelper(ContractCreationTrait trait,
                                          ContractAnnotationModel annotation) {
    ContractKind kind = getContractKind(annotation);
    MethodModel method = createBlankContractHelper(kind, annotation, null);

    TypeName returnType =
        new TypeName(kind.getVariance() == ContractVariance.CONTRAVARIANT
                     ? trait.getExceptionName()
                     : "void");
    method.setReturnType(returnType);

    if (kind.getVariance() == ContractVariance.CONTRAVARIANT) {
      method.addParameter(
          new VariableModel(ElementKind.PARAMETER,
                            JavaUtils.ERROR_VARIABLE, returnType));
    }

    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());
View Full Code Here

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

    "lineNumber == null || lineNumber >= 1"
  })
  private void createOldMethods(ContractKind kind,
      int pos, int id, String expr, ContractAnnotationModel annotation,
      Long lineNumber) {
    MethodModel helper =
        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;
View Full Code Here

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

    return null;
  }

  @Override
  public Void visitExecutable(ExecutableElement e, ElementModel p) {
    MethodModel exec = null;
    String name = e.getSimpleName().toString();

    /*
     * For enum types, synthesized methods values() and
     * valueOf(String) are reflected by the API but must not be
     * reproduced in the mock.
     */
    if (p.getKind() == ElementKind.ENUM) {
      ExecutableType t = (ExecutableType) e.asType();
      if (name.equals("values")) {
        if (t.getParameterTypes().isEmpty()) {
          return null;
        }
      } else if (name.equals("valueOf")) {
        List<TypeMirror> valueOfParameterTypes =
            Collections.singletonList(
                utils.elementUtils
                .getTypeElement("java.lang.String").asType());
        if (t.getParameterTypes().equals(valueOfParameterTypes)) {
          return null;
        }
      }
    }

    /* Create element; decide if constructor or not. */
    if (name.toString().equals("<init>")) {
      exec = new MethodModel();
    } else {
      exec = new MethodModel(ElementKind.METHOD, name,
                             utils.getTypeNameForType(e.getReturnType()));
    }
    utils.copyModifiers(e, exec);

    /* Add generic signature. */
    List<? extends TypeParameterElement> genericTypes = e.getTypeParameters();
    for (TypeParameterElement tp : genericTypes) {
      exec.addTypeParameter(utils.getGenericTypeName(tp));
    }

    /* Add parameters. */
    scan(e.getParameters(), exec);
    exec.setVariadic(e.isVarArgs());

    /* Add throws list. */
    for (TypeMirror tt : e.getThrownTypes()) {
      exec.addException(utils.getTypeNameForType(tt));
    }

    /* Add annotations. */
    scanAnnotations(e, true, type.getName(), exec);

View Full Code Here

Examples of net.jangaroo.jooc.model.MethodModel

    FieldModel eventNameConstant = new FieldModel("NAME", "String", CompilerUtils.quote(event.name));
    eventNameConstant.setStatic(true);
    eventNameConstant.setAsdoc(MessageFormat.format("This constant defines the value of the <code>type</code> property of the event object\nfor a <code>{0}</code> event.\n   * @eventType {0}", event.name));
    extAsClass.addMember(eventNameConstant);

    MethodModel constructorModel = extAsClass.createConstructor();
    constructorModel.addParam(new ParamModel("arguments", "Array"));
    StringBuilder propertyAssignments = new StringBuilder();
    for (int i = 0; i < event.params.size(); i++) {
      Param param = event.params.get(i);

      // add assignment to constructor body:
      if (i > 0) {
        propertyAssignments.append("\n    ");
      }
      propertyAssignments.append(String.format("this['%s'] = arguments[%d];", convertName(param.name), i));

      // add getter method:
      MethodModel property = new MethodModel(MethodType.GET, convertName(param.name), convertType(param.type));
      property.setAsdoc(toAsDoc(param.doc));
      extAsClass.addMember(property);
    }

    constructorModel.setBody(propertyAssignments.toString());

View Full Code Here

Examples of net.jangaroo.jooc.model.MethodModel

  private static void addMethods(ClassModel classModel, List<Method> methods) {
    for (Method method : methods) {
      if (classModel.getMember(method.name) == null) {
        boolean isConstructor = method.name.equals("constructor");
        MethodModel methodModel = isConstructor
                ? new MethodModel(classModel.getName(), null)
                : new MethodModel(convertName(method.name), convertType(method.return_.type));
        methodModel.setAsdoc(toAsDoc(method.doc));
        methodModel.getReturnModel().setAsdoc(toAsDoc(method.return_.doc));
        setStatic(methodModel, method);
        for (Param param : method.params) {
          ParamModel paramModel = new ParamModel(convertName(param.name), convertType(param.type));
          paramModel.setAsdoc(toAsDoc(param.doc));
          setDefaultValue(paramModel, param);
          paramModel.setRest(param == method.params.get(method.params.size() - 1) && param.type.endsWith("..."));
          methodModel.addParam(paramModel);
        }
        classModel.addMember(methodModel);
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.