private void computeStructureProposals()

in org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/completion/IvyCodeCompletionProcessor.java [156:209]


    private void computeStructureProposals(IvyFile ivyfile, List<CodeCompletionProposal> propList, int caretOffset) {
        String parent = ivyfile.getParentTagName();
        String qualifier = ivyfile.getQualifier();
        int qlen = qualifier.length();
        if (parent != null
                && ivyfile.getOffset() >= 2 + qualifier.length()
                && ivyfile.getString(ivyfile.getOffset() - 2 - qualifier.length(),
                    ivyfile.getOffset()).startsWith("</")) {
            // closing tag (already started)
            String text = "</" + parent + ">";
            CodeCompletionProposal proposal = new CodeCompletionProposal(
                text, ivyfile.getOffset() - qlen - 2, qlen + 2 + caretOffset, text.length());
            propList.add(proposal);
        } else {
            if (parent != null && qualifier.length() == 0) {
                String text = "</" + parent + ">";
                int closingIndex = ivyfile.getStringIndexForward(text);
                int openingIndex = ivyfile.getStringIndexForward("<" + parent);
                if (closingIndex == -1 || (openingIndex != -1 && closingIndex > openingIndex)) {
                    // suggest closing tag if tag not yet closed
                    CodeCompletionProposal proposal = new CodeCompletionProposal(
                        text, ivyfile.getOffset(), caretOffset, text.length());
                    propList.add(proposal);
                }
            }

            List<IvyTag> childs = null;

            if (parent != null) {
                String parentParent = ivyfile.getParentTagName(ivyfile.getStringIndexBackward("<"
                        + parent));
                IvyTag root = model.getIvyTag(parent, parentParent);
                if (root == null) {
                    errorMessage = "parent tag :" + parent + " not found in model:";
                    return;
                }
                childs = root.getChilds();
            } else {
                childs = Collections.singletonList(model.getRootIvyTag());
            }
            errorMessage = null;
            for (IvyTag child : childs) {
                // Check if proposal matches qualifier
                if (child.getStartTag().startsWith(qualifier)) {
                    for (Proposal prop : child.getProposals()) {
                        // Construct proposal and add to result list
                        propList.add(new CodeCompletionProposal(
                                prop.getProposal(), ivyfile.getOffset() - qlen, qlen + caretOffset,
                                prop.getCursor(), null, prop.getDoc()));
                    }
                }
            }
        }
    }