/**
  * Perform a sanity check on the existing index to verify that it's valid. If the index is
  * corrupt, we'll force a rebuild of it.
  *
  * @return
  */
 protected boolean indexCorrupt() {
   Index index = getIndex();
   if (index == null) {
     return true;
   }
   List<String> categories = index.getCategories();
   return categories == null || categories.isEmpty();
 };
Example #2
0
  /**
   * writeElement
   *
   * @param index
   * @param element
   */
  public void writeElement(Index index, ElementElement element, URI location) {
    String[] columns =
        new String[] { //
          element.getName(), //
          element.getDisplayName(), //
          StringUtil.join(XMLIndexConstants.SUB_DELIMITER, element.getAttributes()), //
          element.getDescription() //
        };
    String key = StringUtil.join(XMLIndexConstants.DELIMITER, columns);

    index.addEntry(this._keyProvider.getElementKey(), key, location);
  }
Example #3
0
  /**
   * writeAttribute
   *
   * @param index
   * @param attribute
   */
  public void writeAttribute(Index index, AttributeElement attribute, URI location) {
    String[] columns =
        new String[] { //
          attribute.getName(), //
          attribute.getElement(), //
          attribute.getDescription(), //
          "" // values //$NON-NLS-1$
        };
    String key = StringUtil.join(XMLIndexConstants.DELIMITER, columns);

    index.addEntry(this._keyProvider.getAttributeKey(), key, location);
  }
Example #4
0
 protected IProject getProject() {
   URI root = _index.getRoot();
   IPath containerPath = org.eclipse.core.filesystem.URIUtil.toPath(root);
   if (containerPath == null) {
     return null;
   }
   IContainer container =
       ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(containerPath);
   if (container == null) {
     return null;
   }
   return container.getProject();
 }
 private void addIndex(String category, String word) {
   index.addEntry(category, word, documentPath);
 }
Example #6
0
  /*
   * (non-Javadoc)
   * @see com.aptana.editor.js.parsing.ast.JSTreeWalker#visit(com.aptana.editor.js.parsing.ast.JSInvokeNode)
   */
  @Override
  public void visit(JSInvokeNode node) {
    IParseNode child = node.getExpression();

    if (child instanceof JSNode) {
      // TODO hang the "require" string as a constant somewhere!
      if (child instanceof JSIdentifierNode
          && "require".equals(child.getNameNode().getName())) // $NON-NLS-1$
      {
        // it's a requires!
        JSArgumentsNode args = (JSArgumentsNode) node.getArguments();
        IParseNode[] children = args.getChildren();
        for (IParseNode arg : children) {
          if (arg instanceof JSStringNode) {
            JSStringNode string = (JSStringNode) arg;
            String text = string.getText();
            // strip quotes TODO Use util method to strip quotes!
            if (text.startsWith("'") || text.startsWith("\"")) // $NON-NLS-1$ //$NON-NLS-2$
            {
              text = text.substring(1, text.length() - 1);
            }

            // Handle resolving absolute versus relative module ids!
            URI resolved = _location.resolve(text);
            URI relative = _index.getRelativeDocumentPath(resolved);
            this.addType(relative.getPath() + ".exports"); // $NON-NLS-1$
          }
        }
      }

      List<String> types = this.getTypes(child);

      // NOTE: This is a special case for functions used as a RHS of assignments or as part of a
      // property chain.
      // If the invocation returns undefined, we change that to Object.
      // TODO: As a refinement, we want to check that the function being called is not defined in
      // the current
      // scope
      if (types.isEmpty()) {
        IParseNode parent = node.getParent();

        if (parent != null) {
          switch (parent.getNodeType()) {
            case IJSNodeTypes.ASSIGN:
              if (node.getIndex() == 1) {
                this.addType(JSTypeConstants.OBJECT_TYPE);
              }
              break;

            case IJSNodeTypes.GET_PROPERTY:
              this.addType(JSTypeConstants.OBJECT_TYPE);
              break;

            default:
              break;
          }
        }
      }

      for (String typeName : types) {
        if (JSTypeUtil.isFunctionPrefix(typeName)) {
          List<String> returnTypes = JSTypeUtil.getFunctionSignatureReturnTypeNames(typeName);
          for (String returnTypeName : returnTypes) {
            this.addType(returnTypeName);
          }
        }
      }
    }
  }