Exemplo n.º 1
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);
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  /*
   * (non-Javadoc)
   * @see com.aptana.editor.js.parsing.ast.JSTreeWalker#visit(com.aptana.editor.js.parsing.ast.JSGetPropertyNode)
   */
  @Override
  public void visit(JSGetPropertyNode node) {
    IParseNode lhs = node.getLeftHandSide();

    if (lhs instanceof JSNode) {
      IParseNode rhs = node.getRightHandSide();
      String memberName = rhs.getText();

      for (String typeName : this.getTypes(lhs)) {
        // Fix up type names as might be necessary
        typeName = JSTypeMapper.getInstance().getMappedType(typeName);
        // TODO Combine with similar code from ParseUtil.getParentObjectTypes
        if (JSTypeConstants.FUNCTION_JQUERY.equals(typeName)
            && lhs instanceof JSIdentifierNode
            && (JSTypeConstants.DOLLAR.equals(lhs.getText())
                || JSTypeConstants.JQUERY.equals(lhs.getText()))) {
          typeName = JSTypeConstants.CLASS_JQUERY;
        }

        // lookup up rhs name in type and add that value's type here
        Collection<PropertyElement> properties =
            this._queryHelper.getTypeMembers(this._index, typeName, memberName);

        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);
              }
            }
          }
        }
      }
    }
  }