Search in sources :

Example 26 with ITextRegionContainer

use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.

the class AttrImpl method hasNestedValue.

/**
 * Check if Attr has JSP in value
 */
public boolean hasNestedValue() {
    if (this.fValueRegion == null)
        return false;
    if (!(this.fValueRegion instanceof ITextRegionContainer))
        return false;
    ITextRegionList regions = ((ITextRegionContainer) this.fValueRegion).getRegions();
    if (regions == null)
        return false;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
        ITextRegion region = (ITextRegion) e.next();
        if (region == null)
            continue;
        String regionType = region.getType();
        if (regionType == DOMRegionContext.XML_TAG_OPEN || isNestedLanguageOpening(regionType))
            return true;
    }
    return false;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)

Example 27 with ITextRegionContainer

use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.

the class XSLSourceParser method parseNodes.

@Override
protected IStructuredDocumentRegion parseNodes() {
    // regions are initially reported as complete offsets within the
    // scanned input
    // they are adjusted here to be indexes from the currentNode's start
    // offset
    IStructuredDocumentRegion headNode = null;
    IStructuredDocumentRegion lastNode = null;
    ITextRegion region = null;
    IStructuredDocumentRegion currentNode = null;
    String type = null;
    while ((region = getNextRegion()) != null) {
        type = region.getType();
        if (type == DOMRegionContext.BLOCK_TEXT) {
            if (currentNode != null && currentNode.getLastRegion().getType() == DOMRegionContext.BLOCK_TEXT) {
                // multiple block texts indicated embedded containers; no
                // new IStructuredDocumentRegion
                currentNode.addRegion(region);
                currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
                region.adjustStart(-currentNode.getStart());
            // DW 4/16/2003 regions no longer have parents
            // region.setParent(currentNode);
            } else {
                // not continuing a IStructuredDocumentRegion
                if (currentNode != null) {
                    // terminated
                    if (!currentNode.isEnded()) {
                        currentNode.setLength(region.getStart() - currentNode.getStart());
                    // fCurrentNode.setTextLength(region.getStart() -
                    // fCurrentNode.getStart());
                    }
                    lastNode = currentNode;
                }
                fireNodeParsed(currentNode);
                currentNode = createStructuredDocumentRegion(type);
                if (lastNode != null) {
                    lastNode.setNext(currentNode);
                }
                currentNode.setPrevious(lastNode);
                currentNode.setStart(region.getStart());
                currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
                currentNode.setEnded(true);
                region.adjustStart(-currentNode.getStart());
                currentNode.addRegion(region);
            // DW 4/16/2003 regions no longer have parents
            // region.setParent(currentNode);
            }
        } else // the following contexts OPEN new StructuredDocumentRegions
        if ((currentNode != null && currentNode.isEnded()) || (type == DOMRegionContext.XML_CONTENT) || (type == DOMRegionContext.XML_CHAR_REFERENCE) || (type == DOMRegionContext.XML_ENTITY_REFERENCE) || (type == DOMRegionContext.XML_PI_OPEN) || (type == DOMRegionContext.XML_TAG_OPEN) || (type == DOMRegionContext.XML_END_TAG_OPEN) || (type == DOMRegionContext.XML_COMMENT_OPEN) || (type == DOMRegionContext.XML_CDATA_OPEN) || (type == DOMRegionContext.XML_DECLARATION_OPEN)) {
            if (currentNode != null) {
                // ensure that any existing node is at least terminated
                if (!currentNode.isEnded()) {
                    currentNode.setLength(region.getStart() - currentNode.getStart());
                // fCurrentNode.setTextLength(region.getStart() -
                // fCurrentNode.getStart());
                }
                lastNode = currentNode;
            }
            fireNodeParsed(currentNode);
            currentNode = createStructuredDocumentRegion(type);
            if (lastNode != null) {
                lastNode.setNext(currentNode);
            }
            currentNode.setPrevious(lastNode);
            currentNode.setStart(region.getStart());
            currentNode.addRegion(region);
            currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
            region.adjustStart(-currentNode.getStart());
        // DW 4/16/2003 regions no longer have parents
        // region.setParent(currentNode);
        } else // StructuredDocumentRegions; just add to them
        if ((type == DOMRegionContext.XML_TAG_NAME) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) || (type == DOMRegionContext.XML_COMMENT_TEXT) || (type == DOMRegionContext.XML_PI_CONTENT) || (type == DOMRegionContext.XML_DOCTYPE_INTERNAL_SUBSET)) {
            currentNode.addRegion(region);
            currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
            region.adjustStart(-currentNode.getStart());
        // DW 4/16/2003 regions no longer have parents
        // region.setParent(currentNode);
        } else // cleanly
        if ((type == DOMRegionContext.XML_PI_CLOSE) || (type == DOMRegionContext.XML_TAG_CLOSE) || (type == DOMRegionContext.XML_EMPTY_TAG_CLOSE) || (type == DOMRegionContext.XML_COMMENT_CLOSE) || (type == DOMRegionContext.XML_DECLARATION_CLOSE) || (type == DOMRegionContext.XML_CDATA_CLOSE)) {
            currentNode.setEnded(true);
            currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
            currentNode.addRegion(region);
            region.adjustStart(-currentNode.getStart());
        // DW 4/16/2003 regions no longer have parents
        // region.setParent(currentNode);
        } else // this is extremely rare, but valid
        if (type == DOMRegionContext.WHITE_SPACE) {
            ITextRegion lastRegion = currentNode.getLastRegion();
            // pack the embedded container with this region
            if (lastRegion instanceof ITextRegionContainer) {
                ITextRegionContainer container = (ITextRegionContainer) lastRegion;
                container.getRegions().add(region);
                // containers must have parent set ...
                // setting for EACH subregion is redundent, but not sure
                // where else to do, so will do here for now.
                container.setParent(currentNode);
                // DW 4/16/2003 regions no longer have parents
                // region.setParent(container);
                region.adjustStart(container.getLength() - region.getStart());
            }
            currentNode.getLastRegion().adjustLength(region.getLength());
            currentNode.adjustLength(region.getLength());
        } else if (type == DOMRegionContext.UNDEFINED && currentNode != null) {
            // combine with previous if also undefined
            if (currentNode.getLastRegion() != null && currentNode.getLastRegion().getType() == DOMRegionContext.UNDEFINED) {
                currentNode.getLastRegion().adjustLength(region.getLength());
                currentNode.adjustLength(region.getLength());
            } else // previous wasn't undefined
            {
                currentNode.addRegion(region);
                currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
                region.adjustStart(-currentNode.getStart());
            }
        } else {
            // ensure that a node exists
            if (currentNode == null) {
                currentNode = createStructuredDocumentRegion(type);
                currentNode.setStart(region.getStart());
            }
            currentNode.addRegion(region);
            currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
            region.adjustStart(-currentNode.getStart());
            // region.setParent(currentNode);
            if (Debug.debugTokenizer)
                // $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
                System.out.println(getClass().getName() + " found region of not specifically handled type " + region.getType() + " @ " + region.getStart() + "[" + region.getLength() + "]");
        // $NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
        }
        // ensures that they open StructuredDocumentRegions the same way
        if ((type == DOMRegionContext.XML_CONTENT) || (type == DOMRegionContext.XML_CHAR_REFERENCE) || (type == DOMRegionContext.XML_ENTITY_REFERENCE)) {
            currentNode.setEnded(true);
        }
        if (headNode == null && currentNode != null) {
            headNode = currentNode;
        }
    }
    if (currentNode != null) {
        fireNodeParsed(currentNode);
        currentNode.setPrevious(lastNode);
    }
    // fStringInput = null;
    primReset();
    return headNode;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)

Example 28 with ITextRegionContainer

use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method addAttributeValueProposals.

protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) {
    IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
    // Find the attribute region and name for which this position should
    // have a value proposed
    IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion();
    ITextRegionList openRegions = open.getRegions();
    int i = openRegions.indexOf(contentAssistRequest.getRegion());
    if (i < 0) {
        return;
    }
    ITextRegion nameRegion = null;
    while (i >= 0) {
        nameRegion = openRegions.get(i--);
        if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
            break;
        }
    }
    // the name region is REQUIRED to do anything useful
    if (nameRegion != null) {
        // Retrieve the declaration
        CMElementDeclaration elementDecl = getCMElementDeclaration(node);
        // String attributeName = nameRegion.getText();
        String attributeName = open.getText(nameRegion);
        CMAttributeDeclaration attrDecl = null;
        // declaration for the attribute otherwise
        if (elementDecl != null) {
            CMNamedNodeMap attributes = elementDecl.getAttributes();
            CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes) {

                private Map caseInsensitive;

                private Map getCaseInsensitiveMap() {
                    if (caseInsensitive == null)
                        caseInsensitive = new HashMap();
                    return caseInsensitive;
                }

                public CMNode getNamedItem(String name) {
                    CMNode node = super.getNamedItem(name);
                    if (node == null) {
                        node = (CMNode) getCaseInsensitiveMap().get(name.toLowerCase(Locale.US));
                    }
                    return node;
                }

                public void put(CMNode cmNode) {
                    super.put(cmNode);
                    getCaseInsensitiveMap().put(cmNode.getNodeName().toLowerCase(Locale.US), cmNode);
                }
            };
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
                for (int k = 0; k < nodes.size(); k++) {
                    CMNode cmnode = (CMNode) nodes.get(k);
                    if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                        allAttributes.put(cmnode);
                    }
                }
            }
            attributes = allAttributes;
            String noprefixName = DOMNamespaceHelper.getUnprefixedName(attributeName);
            if (attributes != null) {
                attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(noprefixName);
                if (attrDecl == null) {
                    attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(attributeName);
                }
            }
            if (attrDecl == null) {
                setErrorMessage(UNKNOWN_ATTR, attributeName);
            }
        }
        String currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue();
        String proposedInfo = null;
        Image image = CMImageUtil.getImage(attrDecl);
        if (image == null) {
            if ((attrDecl != null) && (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED)) {
                image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ);
            } else {
                image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
            }
        }
        if ((attrDecl != null) && (attrDecl.getAttrType() != null)) {
            // attribute is known, prompt with values from the declaration
            proposedInfo = getAdditionalInfo(elementDecl, attrDecl);
            List possibleValues = getPossibleDataTypeValues(node, attrDecl);
            String defaultValue = attrDecl.getAttrType().getImpliedValue();
            if (possibleValues.size() > 0 || defaultValue != null) {
                // ENUMERATED VALUES
                String matchString = contentAssistRequest.getMatchString();
                if (matchString == null) {
                    // $NON-NLS-1$
                    matchString = "";
                }
                if ((matchString.length() > 0) && (matchString.startsWith("\"") || matchString.startsWith("'"))) {
                    matchString = matchString.substring(1);
                }
                boolean currentValid = false;
                // d210858, if the region's a container, don't suggest the
                // enumerated values as they probably won't help
                boolean existingComplicatedValue = (contentAssistRequest.getRegion() != null) && (contentAssistRequest.getRegion() instanceof ITextRegionContainer);
                if (!existingComplicatedValue) {
                    int rOffset = contentAssistRequest.getReplacementBeginPosition();
                    int rLength = contentAssistRequest.getReplacementLength();
                    for (Iterator j = possibleValues.iterator(); j.hasNext(); ) {
                        String possibleValue = (String) j.next();
                        if (!possibleValue.equals(defaultValue)) {
                            currentValid = currentValid || possibleValue.equals(currentValue);
                            if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
                                // $NON-NLS-2$//$NON-NLS-1$
                                String rString = "\"" + possibleValue + "\"";
                                CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, possibleValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM), rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
                                contentAssistRequest.addProposal(proposal);
                            }
                        }
                    }
                    if (defaultValue != null && ((matchString.length() == 0) || defaultValue.startsWith(matchString))) {
                        // $NON-NLS-2$//$NON-NLS-1$
                        String rString = "\"" + defaultValue + "\"";
                        CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, defaultValue.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT), rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
                        contentAssistRequest.addProposal(proposal);
                    }
                }
            } else if (((attrDecl.getUsage() == CMAttributeDeclaration.FIXED) || (attrDecl.getAttrType().getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)) && (attrDecl.getAttrType().getImpliedValue() != null)) {
                // FIXED values
                String value = attrDecl.getAttrType().getImpliedValue();
                if ((value != null) && (value.length() > 0)) {
                    // $NON-NLS-2$//$NON-NLS-1$
                    String rValue = "\"" + value + "\"";
                    CustomCompletionProposal proposal = new CustomCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), rValue.length() + 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
                    contentAssistRequest.addProposal(proposal);
                    if ((currentValue.length() > 0) && !value.equals(currentValue)) {
                        // $NON-NLS-2$//$NON-NLS-1$
                        rValue = "\"" + currentValue + "\"";
                        proposal = new CustomCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), rValue.length() + 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
                        contentAssistRequest.addProposal(proposal);
                    }
                }
            }
        } else {
            // unknown attribute, so supply nice empty values
            proposedInfo = getAdditionalInfo(null, elementDecl);
            CustomCompletionProposal proposal = null;
            if ((currentValue != null) && (currentValue.length() > 0)) {
                // $NON-NLS-2$//$NON-NLS-1$
                String rValue = "\"" + currentValue + "\"";
                proposal = new CustomCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
                contentAssistRequest.addProposal(proposal);
            }
        }
    } else {
        setErrorMessage(UNKNOWN_CONTEXT);
    }
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) HashMap(java.util.HashMap) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) Image(org.eclipse.swt.graphics.Image) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Map(java.util.Map) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 29 with ITextRegionContainer

use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.

the class MarkupValidator method checkForAttributeValue.

private void checkForAttributeValue(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    // check for attributes without a value
    // track the attribute/equals/value sequence using a state of 0, 1 ,2
    // representing the name, =, and value, respectively
    int attrState = 0;
    ITextRegionList textRegions = structuredDocumentRegion.getRegions();
    // ReconcileAnnotationKey key = createKey(structuredDocumentRegion,
    // getScope());
    int errorCount = 0;
    for (int i = 0; (i < textRegions.size()) && (errorCount < ELEMENT_ERROR_LIMIT); i++) {
        ITextRegion textRegion = textRegions.get(i);
        if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || isTagCloseTextRegion(textRegion)) {
            // dangling name and '='
            if ((attrState == 2) && (i >= 2)) {
                // create annotation
                ITextRegion nameRegion = textRegions.get(i - 2);
                if (!(nameRegion instanceof ITextRegionContainer)) {
                    Object[] args = { structuredDocumentRegion.getText(nameRegion) };
                    String messageText = NLS.bind(XMLCoreMessages.Attribute__is_missing_a_value, args);
                    int start = structuredDocumentRegion.getStartOffset(nameRegion);
                    int end = structuredDocumentRegion.getEndOffset();
                    int lineNo = getLineNumber(start);
                    int textLength = structuredDocumentRegion.getText(nameRegion).trim().length();
                    LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE), messageText);
                    message.setOffset(start);
                    message.setLength(textLength);
                    message.setLineNo(lineNo);
                    // quick fix info
                    ITextRegion equalsRegion = textRegions.get(i - 2 + 1);
                    int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end;
                    Object[] additionalFixInfo = { structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset) };
                    getAnnotationMsg(reporter, ProblemIDsXML.MissingAttrValue, message, additionalFixInfo, textLength);
                    errorCount++;
                }
            } else // name but no '=' (XML only)
            if ((attrState == 1) && (i >= 1)) {
                // create annotation
                ITextRegion previousRegion = textRegions.get(i - 1);
                if (!(previousRegion instanceof ITextRegionContainer)) {
                    Object[] args = { structuredDocumentRegion.getText(previousRegion) };
                    String messageText = NLS.bind(XMLCoreMessages.Attribute__has_no_value, args);
                    int start = structuredDocumentRegion.getStartOffset(previousRegion);
                    int textLength = structuredDocumentRegion.getText(previousRegion).trim().length();
                    int lineNo = getLineNumber(start);
                    LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE), messageText);
                    message.setOffset(start);
                    message.setLength(textLength);
                    message.setLineNo(lineNo);
                    getAnnotationMsg(reporter, ProblemIDsXML.NoAttrValue, message, structuredDocumentRegion.getText(previousRegion), textLength);
                    errorCount++;
                }
            }
            attrState = 1;
        } else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
            attrState = 2;
        } else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
            attrState = 0;
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 30 with ITextRegionContainer

use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer in project webtools.sourceediting by eclipse.

the class AbstractXMLCompletionProposalComputer method computeAttributeValueProposals.

private ContentAssistRequest computeAttributeValueProposals(String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node, CompletionProposalInvocationContext context) {
    int documentPosition = context.getInvocationOffset();
    ContentAssistRequest contentAssistRequest = null;
    IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
    if ((documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) && (sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength() != sdRegion.getStartOffset(completionRegion) + completionRegion.getLength())) {
        // setup to add a new attribute at the documentPosition
        IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
        contentAssistRequest = new ContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString);
        addAttributeNameProposals(contentAssistRequest, context);
        if ((actualNode.getFirstStructuredDocumentRegion() != null) && !actualNode.getFirstStructuredDocumentRegion().isEnded()) {
            addTagCloseProposals(contentAssistRequest, context);
        }
    } else {
        // setup to replace the existing value
        if (!nodeAtOffset.getFirstStructuredDocumentRegion().isEnded() && (documentPosition < sdRegion.getStartOffset(completionRegion))) {
            // if the IStructuredDocumentRegion isn't closed and the
            // cursor is in front of the value, add
            contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
            addAttributeNameProposals(contentAssistRequest, context);
        } else {
            int replaceLength = completionRegion.getTextLength();
            // if container region, be sure replace length is only the attribute value region not the entire container
            if (completionRegion instanceof ITextRegionContainer) {
                ITextRegion openRegion = ((ITextRegionContainer) completionRegion).getFirstRegion();
                ITextRegion closeRegion = ((ITextRegionContainer) completionRegion).getLastRegion();
                /*
					 * check to see if the container is opened the same way its closed.
					 * Such as:
					 * <img src=' '
					 * But not:
					 * <img src='
					 * 
					 * </body>
					 * </html>
					 * In the latter case we only want to replace the opening text of the container
					 * Admittedly crude test, but effective.
					 */
                if (openRegion.getType() != closeRegion.getType()) {
                    replaceLength = openRegion.getTextLength();
                }
            }
            contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), replaceLength, matchString);
            addAttributeValueProposals(contentAssistRequest, context);
        }
    }
    return contentAssistRequest;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)

Aggregations

ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)52 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)39 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)26 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)25 IStructuredDocumentRegionList (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)11 Iterator (java.util.Iterator)10 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)10 List (java.util.List)8 ArrayList (java.util.ArrayList)7 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)4 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)3 ITextViewer (org.eclipse.jface.text.ITextViewer)3 Image (org.eclipse.swt.graphics.Image)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)3 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)3 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)3 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3