/**
   * FunctionElement
   *
   * @param base
   */
  public FunctionElement(FunctionElement base) {
    super(base);

    // NOTE: this is a shallow clone, so references are shared in lists
    this._parameters = new ArrayList<ParameterElement>(base.getParameters());
    this._references = new ArrayList<String>(base.getReferences());
    this._exceptions = new ArrayList<ExceptionElement>(base.getExceptions());
    this._returnTypes = new ArrayList<ReturnTypeElement>(base.getReturnTypes());
    this._isConstructor = base.isConstructor();
    this._isMethod = base.isMethod();
  }
示例#2
0
  @Test
  public void testEventPropertyWithConstantValues() {
    String typeName = "MyClass";
    String functionName = "convertUnits";
    String paramName = "convertToUnits";
    List<String> constants =
        CollectionsUtil.newList(
            "Titanium.UI.UNIT_CM",
            "Titanium.UI.UNIT_MM",
            "Titanium.UI.UNIT_DIP",
            "Titanium.UI.UNIT_IN",
            "Titanium.UI.UNIT_PX");

    // create type
    TypeElement type = new TypeElement();
    type.setName(typeName);

    // create function within type
    FunctionElement function = new FunctionElement();
    function.setName(functionName);

    ParameterElement parameter = new ParameterElement();
    parameter.setName(paramName);
    parameter.fromJSON(
        CollectionsUtil.newTypedMap(
            String.class, Object.class, IHasPredefinedValues.CONSTANTS_PROPERTY, constants));
    function.addParameter(parameter);

    type.addProperty(function);

    // write type to index
    this.writeType(type);

    // then retrieve it
    List<TypeElement> retrievedTypes = this.getType(typeName);
    TypeElement retrievedType = retrievedTypes.get(0);

    assertNotNull(retrievedType);
    assertEquals(typeName, retrievedType.getName());

    // make sure we have one property
    List<PropertyElement> properties = retrievedType.getProperties();
    assertNotNull(properties);
    assertEquals(1, properties.size());

    // make sure the name is correct
    PropertyElement retrievedProperty = properties.get(0);
    assertEquals(functionName, retrievedProperty.getName());
    assertTrue(retrievedProperty instanceof FunctionElement);
    FunctionElement retrievedFunction = (FunctionElement) retrievedProperty;
    List<ParameterElement> retrievedParams = retrievedFunction.getParameters();
    assertNotNull(retrievedParams);
    assertEquals(1, retrievedParams.size());

    ParameterElement retrievedParam = retrievedParams.get(0);

    // Check constants
    List<String> retrievedConstants = retrievedParam.getConstants();
    assertEquals(constants.size(), retrievedConstants.size());
    for (String constant : constants) {
      assertTrue(retrievedConstants.contains(constant));
    }
  }