/** * 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; }
/** * Inserts the node newChild before existing node refChild. If refChild is null, insert newChild * at end of the list of children. * * @param newChild The new child node to insert * @param refChild The reference node, i.e. the node before which the new node must be inserted. * @throws InvalidChildItemException Raised if <code>newChild</code> being added is not valid for * this node type. * @throws NodeNotFound Raised if the <code>refChild</code> node is not found in the node's * children. */ public void insertBefore(DocItem newChild, DocItem refChild) throws InvalidChildItemException, NodeNotFound { if (!newChild.validChildAddition(this)) throw new InvalidChildItemException( "Child item of type \'" + newChild.getName() + "\' says it is not allowed to belong to this (\'" + itemName + "\') doc item"); int insertPos = docNodes.size(); // // Does the refChild exist and exists in this node's children? if (refChild != null && docNodes.contains(refChild)) insertPos = docNodes.indexOf(refChild); else if (refChild != null) // Isn't null & doesn't belong to this node. Argh! throw new NodeNotFound("Cannot find node \'" + refChild.getName() + "\'"); docNodes.add(insertPos, newChild); }
public Object[] getElements(Object parent) { try { CFDocument doc = document.getCFDocument(); if (doc == null) { // OBT: Added to handle when the parse fatally fails. return EMPTY_ARRAY; } DocItem rootItem = doc.getDocumentRoot(); // nodes = rootItem.selectNodes("//function[#startpos>=0 and #endpos < 200]"); nodes = rootItem.selectNodes("//cffunction"); if (nodes.size() == 0) { nodes = rootItem.selectNodes("//ASTFunctionDeclaration"); } return getMethods(nodes); } catch (Exception e) { System.err.println("CFCMethodsContentProvider has no elements"); e.printStackTrace(); return EMPTY_ARRAY; } }
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; }
/** * Removes the specified child from the list of nodes. * * @param oldChild The node to remove * @return The node removed. * @throws NodeNotFound Raised if the <code>refChild</code> node is not found in the node's * children. */ public DocItem removeChild(DocItem oldChild) throws NodeNotFound { if (!docNodes.remove(oldChild)) throw new NodeNotFound("Cannot find node \'" + oldChild.getName() + "\'"); return oldChild; }
/* (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); } }