Example #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);
          }
        }
      }
    }
  }
Example #2
0
  /*
   * (non-Javadoc)
   * @see com.aptana.editor.js.parsing.ast.JSTreeWalker#visit(com.aptana.editor.js.parsing.ast.JSConstructNode)
   */
  @Override
  public void visit(JSConstructNode node) {
    // TODO: Need to handle any property assignments off of "this"
    IParseNode child = node.getExpression();

    if (child instanceof JSNode) {
      List<String> types = this.getTypes(child);
      List<String> returnTypes = new ArrayList<String>();

      for (String typeName : types) {
        if (typeName.startsWith(JSTypeConstants.GENERIC_CLASS_OPEN)) {
          returnTypes.add(JSTypeUtil.getClassType(typeName));
        } else {
          // FIXME If this is a function that returns a type, assume that function is a constructor
          // and we've
          // defined the type as Function<Type>.
          // This is where the properties for that type are going to be hung.
          // That may not be "right". We may want to unwrap the function's return type and use that
          // as the
          // type we're dealing with.
          // in that case, we need to change JSSymbolTypeInferrer#generateType to also unwrap
          // Function<Type>
          // properly.
          returnTypes.add(typeName);
        }
      }

      for (String typeName : returnTypes) {
        Collection<PropertyElement> properties =
            this._queryHelper.getTypeMembers(
                this._index, typeName, JSTypeConstants.PROTOTYPE_PROPERTY);

        if (properties != null) {
          for (PropertyElement property : properties) {
            for (String propertyType : property.getTypeNames()) {
              this.addType(propertyType);
            }
          }
        }
      }
    }
  }
Example #3
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);
              }
            }
          }
        }
      }
    }
  }