Example #1
0
  /**
   * Adds a child to this item's child node list. It first asks the new item whether it's allowed to
   * belong to this item, for example <cfelse> tags must only be a child of an <cfif>
   * tag.
   *
   * @param newItem The new document item to add.
   * @return true - child added, false - error with child.
   */
  public boolean addChild(DocItem newItem) {
    boolean addOkay = true;

    if (!newItem.validChildAddition(this)) {
      parseMessages.addMessage(
          new ParseError(
              newItem.getLineNumber(),
              newItem.getStartPosition(),
              newItem.getEndPosition(),
              newItem.getItemData(),
              "Invalid child "
                  + newItem.getClass().getName()
                  + ":\'"
                  + newItem.getName()
                  + "\' for parent \'"
                  + getName()
                  + "\'"));
      addOkay = false;
    }
    //
    // Set the item's parent & sibling
    newItem.setParent(this);
    if (docNodes.size() == 0) newItem.setPrevSibling(null);
    else newItem.setPrevSibling((DocItem) docNodes.get(docNodes.size() - 1));

    docNodes.add(newItem);

    return addOkay;
  }
  /* (non-Javadoc)
   * @see org.cfeclipse.cfml.editors.contentassist.IAssistContributor#getTagProposals(org.cfeclipse.cfml.editors.contentassist.IAssistState)
   */
  public ICompletionProposal[] getTagProposals(IAssistState state) {

    /*
     * Only show content assist if the trigger was ( or ,
     * We should probably find a better way than this, but the
     * content assist is getting in the way right now.
     */
    if (state.getTriggerData() != ',' && state.getTriggerData() != '(') {
      return null;
    }

    if (state.getTriggerData() == ' ' || state.getTriggerData() == '\t') {
      return null;
    }
    if (!checkContext(state)) return null;
    else {
      // int length = this.functionName.length();

      Set params = ((ISyntaxDictionary) this.sourceDict).getFunctionParams(this.functionName);
      String helpText = ((ISyntaxDictionary) this.sourceDict).getFunctionHelp(this.functionName);

      /*
       * here begins denny's attempt at in-page function argument proposals
       */
      if (params == null) {
        params = new LinkedHashSet();
        CFDocument doc = ((ICFDocument) state.getIDocument()).getCFDocument();
        DocItem rootItem = doc.getDocumentRoot();
        Matcher matcher;
        Pattern pattern;
        String name = "", type = "", required = "", defaultvalue = "";
        pattern =
            Pattern.compile(
                "(\\w+)[\\s=]+(((\\x22|\\x27)((?!\\4).|\\4{2})*\\4))", Pattern.CASE_INSENSITIVE);

        // nodes = rootItem.selectNodes("//function[#startpos>=0 and #endpos < 200]");
        nodes = rootItem.selectNodes("//cffunction");
        Iterator i = nodes.iterator();
        while (i.hasNext()) {
          DocItem currItem = (DocItem) i.next();

          if (currItem.getItemData().indexOf(this.functionName) > 0) {
            // Function newFunk = new Function(this.functionName);
            // System.out.println(currItem.getItemData());
            if (currItem.getFirstChild().getName().equals("cfargument")) {
              CFNodeList childNodes = currItem.getChildNodes();
              int x = 0;
              DocItem childNode = (DocItem) childNodes.get(x);
              while (childNode.getName().equals("cfargument")) {
                matcher = pattern.matcher(childNode.getItemData());
                while (matcher.find()) {
                  String value = matcher.group(2).replaceAll("'", "").replaceAll("\"", "");
                  if (matcher.group(1).toLowerCase().equals("name")) {
                    name = value;
                  }
                  if (matcher.group(1).toLowerCase().equals("type")) {
                    type = value;
                  }
                  if (matcher.group(1).toLowerCase().equals("required")) {
                    required = value;
                  }
                  if (matcher.group(1).toLowerCase().equals("default")) {
                    defaultvalue = value;
                  }
                }
                Parameter newParam =
                    new Parameter(name, type, Boolean.valueOf(required), defaultvalue);
                // Parameter newParam = new Parameter(name,type);
                params.add(newParam);
                System.out.println(currItem.getFirstChild().getItemData());
                childNode = (DocItem) nodes.get(x);
                x++;
              }
            }
          }
        }
        /*
         * here endss denny's attempt at in-page function argument proposals
         */
        if (params == null) {
          return null;
        }
      }

      Parameter[] filteredParams = getFilteredParams(params);

      int x = 0;
      String extraInfo = paramIndent + "<b>" + functionName + "</b> (\n";
      // CompletionProposal proposal = null;
      // String usage = "";
      Parameter activeParam = null;

      int paramCount = filteredParams.length;

      while (x < paramCount) {
        Parameter p = filteredParams[x];

        String delimiter = "";
        if (x + 1 < paramCount) {
          delimiter = " ,";
        }
        extraInfo += paramIndent + paramIndent;
        if (x == this.paramsSoFar) {
          activeParam = p;
          extraInfo += "<b>";
        }
        extraInfo += p.toString() + delimiter;

        if (x == this.paramsSoFar) {
          extraInfo += "</b>";
        }
        extraInfo += "\n";

        x++;
      }

      if (this.paramsSoFar == paramCount) {
        // System.out.println("End of params");
        return null;
      }

      extraInfo += paramIndent + ") \n\n";
      extraInfo += helpText;

      return getParamProposals(activeParam, extraInfo, state.getOffset(), paramCount);
    }
  }