Esempio n. 1
0
  @Test
  public void testFunctionParameterWithConstantValues() {
    String typeName = "MyClass";
    String eventName = "event";
    String propertyName = "eventProperty";

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

    EventElement ee = new EventElement();
    ee.setName(eventName);
    EventPropertyElement epe = new EventPropertyElement();
    epe.fromJSON(
        CollectionsUtil.newTypedMap(
            String.class,
            Object.class,
            IHasPredefinedValues.CONSTANTS_PROPERTY,
            CollectionsUtil.newList("Titanium.UI.FILL", "Titanium.UI.ALIGN")));
    epe.setName(propertyName);
    ee.addProperty(epe);

    type.addEvent(ee);

    // 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());

    EventElement retrievedEvent = retrievedType.getEvent(eventName);
    assertNotNull(retrievedEvent);

    List<EventPropertyElement> retrievedProps = retrievedEvent.getProperties();
    assertNotNull(retrievedProps);
    assertEquals(1, retrievedProps.size());

    // make sure the name is correct
    EventPropertyElement retrievedProperty = retrievedProps.get(0);
    assertEquals(propertyName, retrievedProperty.getName());
    // Check constants
    List<String> constants = retrievedProperty.getConstants();
    assertEquals(2, constants.size());
    assertTrue(constants.contains("Titanium.UI.FILL"));
    assertTrue(constants.contains("Titanium.UI.ALIGN"));
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
   */
  public Object[] getChildren(Object parentElement) {
    List<? extends Object> result = Collections.emptyList();

    if (parentElement instanceof JSElement) {
      JSElement root = (JSElement) parentElement;

      // @formatter:off
      result =
          CollectionsUtil.newList(
              new ClassGroupElement(
                  Messages.JSIndexViewContentProvider_WorkspaceGroupLabel,
                  JSIndexQueryHelper.getJSCoreIndex()),
              new ClassGroupElement(
                  Messages.JSIndexViewContentProvider_ProjectGroupLabel, root.getIndex()));
      // @formatter:on
    } else if (parentElement instanceof ClassGroupElement) {
      ClassGroupElement group = (ClassGroupElement) parentElement;

      result = group.getClasses();
    } else if (parentElement instanceof ClassElement) {
      TypeElement type = (ClassElement) parentElement;
      // NOTE: have to do this "temp" acrobatics to make the compiler happy, due to use of generics
      // and differing
      // return types when grabbing properties vs events
      List<Object> temp = new ArrayList<Object>();

      temp.addAll(type.getProperties());
      temp.addAll(type.getEvents());

      result = temp;
    } else if (parentElement instanceof EventElement) {
      EventElement event = (EventElement) parentElement;

      result = event.getProperties();
    }

    return result.toArray(new Object[result.size()]);
  }