Beispiel #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;
  }
Beispiel #2
0
  private CFNodeList selectNodes(XPathSearch search) {
    CFNodeList result = new CFNodeList();

    if (docNodes == null) {
      docNodes = new CFNodeList();
    }

    for (int i = 0; i < docNodes.size(); i++) {
      DocItem currItem = (DocItem) docNodes.get(i);
      DocItem endItem = null;
      if (search.searchForEndTag && currItem.getMatchingItem() != null) {
        endItem = currItem.getMatchingItem();
      }

      int matches = 0;
      int endMatches = 0;

      if (search.doChildNodes) result.addAll(currItem.selectNodes(search));

      // r2 added simple * node selection
      if (search.searchForTag
          && (currItem.getName().compareToIgnoreCase(search.tagName) == 0
              || search.tagName.equals("*"))) {
        matches++;
      }
      if (endItem != null
          && search.searchForTag
          && (endItem.getName().compareToIgnoreCase(search.tagName) == 0
              || search.tagName.equals("*"))) {
        endMatches++;
      }

      // System.out.print("DocItem::selectNodes() - Testing \'" + currItem.getName() + "\'");
      if (search.attrSearch.containsKey(XPathSearch.ATTR_STARTPOS)) {
        ComparisonType comp = (ComparisonType) search.attrSearch.get(XPathSearch.ATTR_STARTPOS);
        // System.out.println(XPathSearch.ATTR_STARTPOS + ": ");
        if (comp.performComparison(currItem.startPosition)) {
          matches++;
          // System.out.print(" success ");
        }
        if (endItem != null && comp.performComparison(endItem.startPosition)) {
          endMatches++;
        }
      }
      if (search.attrSearch.containsKey(XPathSearch.ATTR_ENDPOS)) {
        // System.out.print(XPathSearch.ATTR_ENDPOS + ":");
        ComparisonType comp = (ComparisonType) search.attrSearch.get(XPathSearch.ATTR_ENDPOS);
        if (comp.performComparison(currItem.endPosition)) {
          matches++;
          // System.out.print(" success ");
        }
        if (endItem != null && comp.performComparison(endItem.endPosition)) {
          endMatches++;
          // System.out.println(" failed ");
        }
      }

      if (matches == search.getMatchesRequired()) {
        // System.out.println("DocItem::selectNodes(XPathSearch) - Got match for " +
        // currItem.itemName);
        result.add(currItem);
        // System.out.print(" name match success");
      } else if (endItem != null && endMatches == search.getMatchesRequired()) {
        result.add(currItem);
        // System.out.println(" End matched " + endItem.getMatchingItem());
        // System.out.print(" name match failed with ");
      }

      // System.out.println("");
    }

    return result;
  }
Beispiel #3
0
 public DocItem getFirstChild() {
   return (DocItem) docNodes.get(0);
 }
Beispiel #4
0
 public DocItem getLastChild() {
   return (DocItem) docNodes.get(docNodes.size() - 1);
 }
  /* (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);
    }
  }