示例#1
0
  @Test
  public void testIdentifier() {
    // @formatter:off
    @SuppressWarnings("unchecked")
    List<List<String>> lists =
        CollectionsUtil.newList(
            CollectionsUtil.newList("_", "$", "a", "A"),
            CollectionsUtil.newList("", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    // @formatter:on

    this.assertListCrossProducts(lists, JSTokenType.IDENTIFIER);
  }
示例#2
0
  @Test
  public void testScientificNotation() {
    // @formatter:off
    @SuppressWarnings("unchecked")
    List<List<String>> lists =
        CollectionsUtil.newList(
            // { "+", "-", "" },	// TODO: apparently the scanner can't differentiate between 5 + 10
            // and 5 + +10?
            CollectionsUtil.newList("1", "1.", ".9", "1.9"),
            CollectionsUtil.newList("e", "E"),
            CollectionsUtil.newList("+", "-", ""),
            CollectionsUtil.newList("10"));
    // @formatter:on

    this.assertListCrossProducts(lists, JSTokenType.NUMBER);
  }
示例#3
0
  @Test
  public void testHex() {
    // @formatter:off
    @SuppressWarnings("unchecked")
    List<List<String>> lists =
        CollectionsUtil.newList(
            // { "+", "-", "" },	// TODO: apparently the scanner can't differentiate between 5 + 10
            // and 5 + +10?
            CollectionsUtil.newList("0"),
            CollectionsUtil.newList("x", "X"),
            CollectionsUtil.newList(
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A",
                "B", "C", "D", "E", "F"),
            CollectionsUtil.newList(
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A",
                "B", "C", "D", "E", "F"));
    // @formatter:on

    this.assertListCrossProducts(lists, JSTokenType.NUMBER);
  }
示例#4
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"));
  }
示例#5
0
    public IStatus call() throws Exception {
      // index vs filesystem
      List<String> args = CollectionsUtil.newList("diff-files", "-z"); // $NON-NLS-1$ //$NON-NLS-2$
      if (!CollectionsUtil.isEmpty(filePaths)) {
        args.add("--"); // $NON-NLS-1$
        args.addAll(filePaths);
      }

      IStatus result =
          repo.execute(GitRepository.ReadWrite.READ, args.toArray(new String[args.size()]));
      if (result != null && result.isOK()) {
        readUnstagedFiles(result.getMessage());
      }
      return Status.OK_STATUS;
    }
示例#6
0
  /*
   * (non-Javadoc)
   * @see com.aptana.editor.js.parsing.ast.JSTreeWalker#visit(com.aptana.editor.js.parsing.ast.JSIdentifierNode)
   */
  @Override
  public void visit(JSIdentifierNode node) {
    String name = node.getText();
    Collection<PropertyElement> properties = null;

    if (this._scope != null && this._scope.hasSymbol(name)) {
      IParseNode parent = node.getParent();

      if (parent != null && parent.getNodeType() == IJSNodeTypes.PARAMETERS) {
        // special handling of parameters to potentially get the type
        // from documentation and to prevent an infinite loop since
        // parameters point to themselves in the symbol table
        this.addParameterTypes(node);
      } else {
        // Check the local scope for type first
        JSSymbolTypeInferrer symbolInferrer =
            new JSSymbolTypeInferrer(this._scope, this._index, this._location);
        PropertyElement property = symbolInferrer.getSymbolPropertyElement(name);
        if (property != null) {
          // We found a match in the local scope
          properties = CollectionsUtil.newList(property);
        } else {
          // No match in the local scope, query the globals in index
          properties = this._queryHelper.getGlobals(this._index, getProject(), getFileName(), name);
        }
      }
    } else {
      // Scope says it doesn't has a symbol with that name, so query the globals in index
      properties = this._queryHelper.getGlobals(this._index, getProject(), getFileName(), name);
    }

    // Hopefully we found at least one match...
    if (properties != null) {
      for (PropertyElement property : properties) {
        if (property instanceof FunctionElement) {
          FunctionElement function = (FunctionElement) property;
          for (String type : function.getSignatureTypes()) {
            this.addType(type);
          }
        } else {
          for (String type : property.getTypeNames()) {
            this.addType(type);
          }
        }
      }
    }
  }
示例#7
0
  @Test
  public void testPropertyWithConstantValues() {
    String typeName = "MyClass";
    String propertyName = "myProperty";

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

    // create property within type
    PropertyElement property =
        createProperty(
            "name",
            propertyName,
            IHasPredefinedValues.CONSTANTS_PROPERTY,
            CollectionsUtil.newList("Titanium.UI.FILL", "Titanium.UI.ALIGN"));
    type.addProperty(property);

    // 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(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"));
  }
示例#8
0
    public IStatus call() throws Exception {
      // index vs working tree (HEAD?)
      List<String> args =
          CollectionsUtil.newList(
              "ls-files",
              "--others", //$NON-NLS-1$ //$NON-NLS-2$
              "--exclude-standard",
              "-z"); //$NON-NLS-1$ //$NON-NLS-2$
      if (!CollectionsUtil.isEmpty(filePaths)) {
        args.add("--"); // $NON-NLS-1$
        args.addAll(filePaths);
      }

      IStatus result =
          repo.execute(GitRepository.ReadWrite.READ, args.toArray(new String[args.size()]));
      if (result != null && result.isOK()) {
        readOtherFiles(result.getMessage());
      }
      return Status.OK_STATUS;
    }
  /*
   * (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()]);
  }
示例#10
0
    private void readOtherFiles(String string) {
      List<String> lines = linesFromNotification(string);
      Map<String, List<String>> dictionary = new HashMap<String, List<String>>(lines.size());
      // Other files are untracked, so we don't have any real index information. Instead, we can
      // just fake it.
      // The line below is not used at all, as for these files the commitBlob isn't set
      List<String> fileStatus =
          CollectionsUtil.newList(
              ":000000", // for new file //$NON-NLS-1$
              "100644", //$NON-NLS-1$
              "0000000000000000000000000000000000000000", // SHA //$NON-NLS-1$
              "0000000000000000000000000000000000000000", //$NON-NLS-1$
              ADD_STATUS, // A for Add, D for delete
              null);
      for (String path : lines) {
        if (path.length() == 0) {
          continue;
        }
        dictionary.put(path, fileStatus);
      }

      addFilesFromDictionary(dictionary, false, false);
    }
示例#11
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));
    }
  }