Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist')
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java2427
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentModelGenerator.java90
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformation.java115
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationPresenter.java122
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationProvider.java218
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContentAssistRequest.java260
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContextInfoModelUtil.java66
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/CustomTemplateProposal.java40
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NoRegionContentAssistProcessor.java274
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NonValidatingModelQueryAction.java159
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ProposalComparator.java49
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java104
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SimpleCMElementDeclaration.java170
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SourceEditorImageHelper.java48
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java166
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistUtilities.java516
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentModelGenerator.java144
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java52
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java172
19 files changed, 0 insertions, 5192 deletions
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java
deleted file mode 100644
index ee417bcd95..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java
+++ /dev/null
@@ -1,2427 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.Vector;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.sse.core.internal.util.Debug;
-import org.eclipse.wst.sse.ui.internal.IReleasable;
-import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
-import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMContent;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper;
-import org.eclipse.wst.xml.core.internal.document.AttrImpl;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.eclipse.wst.xml.ui.internal.Logger;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
-import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames;
-import org.eclipse.wst.xml.ui.internal.taginfo.MarkupTagInfoProvider;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-abstract public class AbstractContentAssistProcessor implements IContentAssistProcessor, IReleasable {
- /**
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- private class DOMJSPRegionContextsPrivateCopy {
- private static final String JSP_CLOSE = "JSP_CLOSE"; //$NON-NLS-1$
- private static final String JSP_COMMENT_CLOSE = "JSP_COMMENT_CLOSE"; //$NON-NLS-1$
-
- private static final String JSP_COMMENT_OPEN = "JSP_COMMENT_OPEN"; //$NON-NLS-1$
- private static final String JSP_DECLARATION_OPEN = "JSP_DECLARATION_OPEN"; //$NON-NLS-1$
- private static final String JSP_DIRECTIVE_CLOSE = "JSP_DIRECTIVE_CLOSE"; //$NON-NLS-1$
- private static final String JSP_DIRECTIVE_NAME = "JSP_DIRECTIVE_NAME"; //$NON-NLS-1$
-
- private static final String JSP_DIRECTIVE_OPEN = "JSP_DIRECTIVE_OPEN"; //$NON-NLS-1$
- private static final String JSP_EXPRESSION_OPEN = "JSP_EXPRESSION_OPEN"; //$NON-NLS-1$
-
- private static final String JSP_ROOT_TAG_NAME = "JSP_ROOT_TAG_NAME"; //$NON-NLS-1$
-
- private static final String JSP_SCRIPTLET_OPEN = "JSP_SCRIPTLET_OPEN"; //$NON-NLS-1$
-
- }
-
- protected static final String INTERNALERROR = XMLUIMessages.SEVERE_internal_error_occu_UI_;
- protected static final String UNKNOWN_ATTR = XMLUIMessages.No_known_attribute__UI_;
- protected static final String UNKNOWN_CONTEXT = XMLUIMessages.Content_Assist_not_availab_UI_;
- protected char completionProposalAutoActivationCharacters[] = null;
- protected char contextInformationAutoActivationCharacters[] = null;
- private AttributeContextInformationProvider fAttributeInfoProvider = null;
- private AttributeContextInformationPresenter fContextInformationPresenter = null;
-
- protected String fErrorMessage = null;
- protected XMLContentModelGenerator fGenerator;
- // protected IResource resource = null;
- protected MarkupTagInfoProvider fInfoProvider = null;
- protected ITextViewer fTextViewer = null;
-
- private final boolean showValues = true;
-
- public AbstractContentAssistProcessor() {
- init();
- }
-
- protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) {
- IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
- IStructuredDocumentRegion sdRegion = contentAssistRequest.getDocumentRegion();
- // retrieve the list of attributes
- CMElementDeclaration elementDecl = getCMElementDeclaration(node);
- if (elementDecl != null) {
- CMNamedNodeMap attributes = elementDecl.getAttributes();
- String matchString = contentAssistRequest.getMatchString();
-
- // check whether an attribute really exists for the replacement
- // offsets AND if it possesses a value
- boolean attrAtLocationHasValue = false;
- NamedNodeMap attrs = node.getAttributes();
- for (int i = 0; i < attrs.getLength(); i++) {
- AttrImpl existingAttr = (AttrImpl) attrs.item(i);
- ITextRegion name = existingAttr.getNameRegion();
-
- if ((sdRegion.getStartOffset(name) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(name) + name.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength()) && (existingAttr.getValueRegion() != null)) {
- attrAtLocationHasValue = true;
- break;
- }
- }
-
- // only add proposals for the attributes whose names begin with
- // the matchstring
- if (attributes != null) {
- for (int i = 0; i < attributes.getLength(); i++) {
- CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributes.item(i);
-
- int isRequired = 0;
- if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) {
- isRequired = XMLRelevanceConstants.R_REQUIRED;
- }
-
- boolean showAttribute = true;
- showAttribute = showAttribute && beginsWith(getRequiredName(node, attrDecl), matchString.trim());
- AttrImpl attr = (AttrImpl) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
- ITextRegion nameRegion = attr != null ? attr.getNameRegion() : null;
- // nameRegion.getEndOffset() + 1 is required to allow for
- // matches against the full name of an existing Attr
- showAttribute = showAttribute && ((attr == null) || ((nameRegion != null) && (sdRegion.getStartOffset(nameRegion) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(nameRegion) + nameRegion.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength())));
- if (showAttribute) {
- Image attrImage = CMImageUtil.getImage(attrDecl);
- if (attrImage == null) {
- if (isRequired > 0) {
- attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ);
- }
- else {
- attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
- }
- }
-
- String proposedText = null;
- String proposedInfo = getAdditionalInfo(elementDecl, attrDecl);
- CustomCompletionProposal proposal = null;
- // attribute is at this location and already exists
- if (attrAtLocationHasValue) {
- // only propose the name
- proposedText = getRequiredName(node, attrDecl);
- proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), attrImage, proposedText, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired, true);
- }
- // no attribute exists or is elsewhere, generate
- // minimally
- else {
- Attr existingAttrNode = (Attr) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
- String value = null;
- if (existingAttrNode != null) {
- value = existingAttrNode.getNodeValue();
- }
- if ((value != null) && (value.length() > 0)) {
- proposedText = getRequiredName(node, attrDecl);
- }
- else {
- proposedText = getRequiredText(node, attrDecl);
- }
- proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), attrDecl.getNodeName().length() + 2, attrImage,
- // if the value isn't empty (no empty set of
- // quotes), show it
- (showValues && (proposedText.indexOf("\"\"") < 0)) ? proposedText : getRequiredName(node, attrDecl), //$NON-NLS-1$
- null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired);
- }
- contentAssistRequest.addProposal(proposal);
- }
- }
- }
- }
- else {
- setErrorMessage(NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[]{node.getNodeName()})));
- }
- }
-
- 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;
-
- // No CMElementDeclaration means no attribute metadata, but
- // retrieve the
- // declaration for the attribute otherwise
- if (elementDecl != null) {
- CMNamedNodeMap attributes = elementDecl.getAttributes();
- 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);
- if (possibleValues.size() > 0) {
- // ENUMERATED VALUES
- String matchString = contentAssistRequest.getMatchString();
- if (matchString == null) {
- matchString = ""; //$NON-NLS-1$
- }
- 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) {
- for (Iterator j = possibleValues.iterator(); j.hasNext();) {
- String possibleValue = (String) j.next();
- currentValid = currentValid || possibleValue.equals(currentValue);
- if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
-
- String rString = "\"" + possibleValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
- int rOffset = contentAssistRequest.getReplacementBeginPosition();
- int rLength = contentAssistRequest.getReplacementLength();
- int cursorAfter = possibleValue.length() + 1;
- String displayString = "\"" + possibleValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
-
- CustomCompletionProposal proposal = new CustomCompletionProposal(rString, rOffset, rLength, cursorAfter, image, displayString, 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)) {
- String rValue = "\"" + value + "\"";//$NON-NLS-2$//$NON-NLS-1$
- 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)) {
- rValue = "\"" + currentValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
- 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)) {
- String rValue = "\"" + currentValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
- 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);
- }
- }
-
- protected void addCommentProposal(ContentAssistRequest contentAssistRequest) {
- contentAssistRequest.addProposal(new CustomCompletionProposal("<!-- -->", //$NON-NLS-1$
- contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 5, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_COMMENT), NLS.bind(XMLUIMessages.Comment__, (new Object[]{" <!-- -->"})), //$NON-NLS-1$
- null, null, XMLRelevanceConstants.R_COMMENT));
- }
-
- /**
- * Add all of the element declarations int the CMContent object into one
- * big list.
- */
- protected void addContent(List contentList, CMContent content) {
- if (content == null) {
- return;
- }
- if (content instanceof CMGroup) {
- CMNodeList children = ((CMGroup) content).getChildNodes();
- if (children == null) {
- return;
- }
- for (int i = 0; i < children.getLength(); i++) {
- CMNode child = children.item(i);
- if (child.getNodeType() == CMNode.ELEMENT_DECLARATION) {
- contentList.add(child);
- }
- else {
- if (child.getNodeType() == CMNode.GROUP) {
- addContent(contentList, (CMContent) child);
- }
- else {
- throw new IllegalArgumentException("Unknown content child: " + child); //$NON-NLS-1$
- }
- }
- }
- }
- else {
- contentList.add(content);
- }
- }
-
- protected void addDocTypeProposal(ContentAssistRequest contentAssistRequest) {
- // if a DocumentElement exists, use that for the root Element name
- String rootname = "unspecified"; //$NON-NLS-1$
- if (contentAssistRequest.getNode().getOwnerDocument().getDocumentElement() != null) {
- rootname = contentAssistRequest.getNode().getOwnerDocument().getDocumentElement().getNodeName();
- }
-
- String proposedText = "<!DOCTYPE " + rootname + " PUBLIC \"//UNKNOWN/\" \"unknown.dtd\">"; //$NON-NLS-1$ //$NON-NLS-2$
- ICompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 10, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DOCTYPE), "<!DOCTYPE ... >", //$NON-NLS-1$
- null, null, XMLRelevanceConstants.R_DOCTYPE);
- // TODO provide special documentation on doc type
- contentAssistRequest.addProposal(proposal);
- }
-
- /**
- * Add the proposals for a completely empty document
- */
- protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) {
- // nothing
- }
-
- /**
- * Add the proposals for the name in an end tag
- */
- protected void addEndTagNameProposals(ContentAssistRequest contentAssistRequest) {
-
- if (contentAssistRequest.getStartOffset() + contentAssistRequest.getRegion().getTextLength() < contentAssistRequest.getReplacementBeginPosition()) {
- CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$
- contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$
- null, null, XMLRelevanceConstants.R_END_TAG_NAME);
- contentAssistRequest.addProposal(proposal);
- }
- else {
- IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
- Node aNode = contentAssistRequest.getNode();
- String matchString = contentAssistRequest.getMatchString();
- if (matchString.startsWith("</")) {
- matchString = matchString.substring(2);
- }
- while (aNode != null) {
- if (aNode.getNodeType() == Node.ELEMENT_NODE) {
- if (aNode.getNodeName().startsWith(matchString)) {
- IDOMNode aXMLNode = (IDOMNode) aNode;
- CMElementDeclaration ed = modelQuery.getCMElementDeclaration((Element) aNode);
- if ((aXMLNode.getEndStructuredDocumentRegion() == null) && ((ed == null) || (ed.getContentType() != CMElementDeclaration.EMPTY))) {
- String proposedText = aNode.getNodeName();
- String proposedInfo = (ed != null) ? getAdditionalInfo(null, ed) : null;
- if ((node.getNodeType() == Node.TEXT_NODE) && !contentAssistRequest.getDocumentRegion().isEnded()) {
- proposedText += ">"; //$NON-NLS-1$
- }
- CustomCompletionProposal proposal = null;
- // double check to see if the region acted upon is
- // a tag name; replace it if so
- Image image = CMImageUtil.getImage(ed);
- if (image == null) {
- image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
- }
- if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_NAME) {
- proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getStartOffset(), contentAssistRequest.getRegion().getTextLength(), proposedText.length(), image, proposedText, null, proposedInfo, XMLRelevanceConstants.R_END_TAG_NAME);
- }
- else {
- proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{"'" + proposedText + "'"})), //$NON-NLS-1$ //$NON-NLS-2$
- null, proposedInfo, XMLRelevanceConstants.R_END_TAG_NAME);
- }
- contentAssistRequest.addProposal(proposal);
- }
- }
- }
- aNode = aNode.getParentNode();
- }
- }
- }
-
- /**
- * Prompt for end tags to a non-empty Node that hasn't ended Handles these
- * cases: <br>
- * <tagOpen>| <br>
- * <tagOpen>< |<br>
- * <tagOpen></ |
- *
- * @param contentAssistRequest
- */
- protected void addEndTagProposals(ContentAssistRequest contentAssistRequest) {
- IDOMNode node = (IDOMNode) contentAssistRequest.getParent();
-
- if (isCommentNode(node)) {
- // loop and find non comment node parent
- while ((node != null) && isCommentNode(node)) {
- node = (IDOMNode) node.getParentNode();
- }
- }
-
- // node is already closed
- if (node.isClosed()) {
- // loop and find non comment unclose node parent
- while ((node != null) && node.isClosed()) {
- node = (IDOMNode) node.getParentNode();
- }
- }
- // there were no unclosed tags
- if (node == null) {
- return;
- }
-
- // data to create a CustomCompletionProposal
- String replaceText = node.getNodeName() + ">"; //$NON-NLS-1$
- int replaceBegin = contentAssistRequest.getReplacementBeginPosition();
- int replaceLength = contentAssistRequest.getReplacementLength();
- int cursorOffset = node.getNodeName().length() + 1;
- String displayString = ""; //$NON-NLS-1$
- String proposedInfo = ""; //$NON-NLS-1$
- Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
-
- setErrorMessage(null);
- boolean addProposal = false;
-
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- // ////////////////////////////////////////////////////////////////////////////////////
- IStructuredDocument sDoc = (IStructuredDocument) fTextViewer.getDocument();
- IStructuredDocumentRegion xmlEndTagOpen = sDoc.getRegionAtCharacterOffset(contentAssistRequest.getReplacementBeginPosition());
- // skip backward to "<", "</", or the (unclosed) start tag, null
- // if not found
- String type = ""; //$NON-NLS-1$
- while ((xmlEndTagOpen != null) && ((type = xmlEndTagOpen.getType()) != DOMRegionContext.XML_END_TAG_OPEN) && (type != DOMRegionContext.XML_TAG_CLOSE) && !needsEndTag(xmlEndTagOpen) && (type != DOMRegionContext.XML_TAG_OPEN)) {
- xmlEndTagOpen = xmlEndTagOpen.getPrevious();
- }
-
- if (xmlEndTagOpen == null) {
- return;
- }
-
- node = (IDOMNode) node.getModel().getIndexedRegion(xmlEndTagOpen.getStartOffset());
- node = (IDOMNode) node.getParentNode();
-
- if (isStartTag(xmlEndTagOpen)) {
- // this is the case for a start tag w/out end tag
- // eg:
- // <p>
- // <% String test = "test"; %>
- // |
- if (needsEndTag(xmlEndTagOpen)) {
- String tagName = getTagName(xmlEndTagOpen);
- xmlEndTagOpen.getTextEndOffset();
- replaceLength = 0;
- replaceText = "</" + tagName + ">"; //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
- // replaceText = "</" + node.getNodeName() + ">";
- // //$NON-NLS-1$ $NON-NLS-2$
- cursorOffset = tagName.length() + 3;
- displayString = NLS.bind(XMLUIMessages.End_with__, (new Object[]{tagName}));
- addProposal = true;
- }
- }
- else if (type == DOMRegionContext.XML_END_TAG_OPEN) {
- // this is the case for: <tag> </ |
- // possibly <tag> </ |<anotherTag>
- // should only be replacing white space...
- replaceLength = (replaceBegin > xmlEndTagOpen.getTextEndOffset()) ? replaceBegin - xmlEndTagOpen.getTextEndOffset() : 0;
- replaceText = node.getNodeName() + ">"; //$NON-NLS-1$
- cursorOffset = replaceText.length();
- replaceBegin = xmlEndTagOpen.getTextEndOffset();
- displayString = NLS.bind(XMLUIMessages.End_with_, (new Object[]{node.getNodeName()}));
- addProposal = true;
- }
- else if (type == DOMRegionContext.XML_TAG_OPEN) {
- // this is the case for: <tag> < |
- replaceText = "/" + node.getNodeName() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
- cursorOffset = replaceText.length();
- // replaceText = "/" + node.getNodeName() + ">"; //$NON-NLS-1$
- // $NON-NLS-2$
- // should only be replacing white space...
- replaceLength = (replaceBegin > xmlEndTagOpen.getTextEndOffset()) ? replaceBegin - xmlEndTagOpen.getTextEndOffset() : 0;
- replaceBegin = xmlEndTagOpen.getTextEndOffset();
- displayString = NLS.bind(XMLUIMessages.End_with_, (new Object[]{"/" + node.getNodeName()})); //$NON-NLS-1$
- addProposal = true;
- }
- }
- // ////////////////////////////////////////////////////////////////////////////////////
- // sometimes the node is not null, but
- // getNodeValue() is null, put in a null check
- else if ((node.getNodeValue() != null) && (node.getNodeValue().indexOf("</") != -1)) { //$NON-NLS-1$
- // the case where "</" is started, but the nodes comes in as a
- // text node (instead of element)
- // like this: <tag> </|
- Node parent = node.getParentNode();
- if ((parent != null) && (parent.getNodeType() != Node.DOCUMENT_NODE)) {
- replaceText = parent.getNodeName() + ">"; //$NON-NLS-1$
- cursorOffset = replaceText.length();
- displayString = NLS.bind(XMLUIMessages.End_with__, (new Object[]{parent.getNodeName()}));
- setErrorMessage(null);
- addProposal = true;
- }
- }
- // ////////////////////////////////////////////////////////////////////////////////////
- else if (node.getNodeType() == Node.DOCUMENT_NODE) {
- setErrorMessage(UNKNOWN_CONTEXT);
- }
- if (addProposal == true) {
- CustomCompletionProposal proposal = new CustomCompletionProposal(replaceText, replaceBegin, replaceLength, cursorOffset, image, displayString, null, proposedInfo, XMLRelevanceConstants.R_END_TAG);
- contentAssistRequest.addProposal(proposal);
- }
- }
-
- protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) {
- ICompletionProposal[] eps = computeEntityReferenceProposals(documentPosition, completionRegion, treeNode);
- for (int i = 0; (eps != null) && (i < eps.length); i++) {
- contentAssistRequest.addProposal(eps[i]);
- }
- }
-
- protected void addEntityProposals(Vector proposals, Properties map, String key, int nodeOffset, IStructuredDocumentRegion sdRegion, ITextRegion completionRegion) {
- if (map == null) {
- return;
- }
- String entityName = ""; //$NON-NLS-1$
- String entityValue = ""; //$NON-NLS-1$
- Image entityIcon = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENTITY_REFERENCE);
- String replacementText = ""; //$NON-NLS-1$
- String displayString = ""; //$NON-NLS-1$
- Enumeration keys = map.keys();
-
- while ((keys != null) && keys.hasMoreElements()) {
- entityName = (String) keys.nextElement();
- entityValue = map.getProperty(entityName);
- // filter based on partial entity string...
- if (entityName.toLowerCase().startsWith(key.toLowerCase()) || key.trim().equals("")) //$NON-NLS-1$
- {
- // figure out selection...if text is selected, add it to
- // selection length
- int selectionLength = nodeOffset;
- if (fTextViewer != null) {
- selectionLength += fTextViewer.getSelectedRange().y;
- }
- // create a new proposal for entity string...
- replacementText = "&" + entityName + ";"; //$NON-NLS-1$ //$NON-NLS-2$
- displayString = "&" + entityName + "; (" + entityValue + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ICompletionProposal cp = new CustomCompletionProposal(replacementText, sdRegion.getStartOffset(completionRegion), selectionLength, replacementText.length(), entityIcon, displayString, null, null, XMLRelevanceConstants.R_ENTITY);
- if (cp != null) {
- proposals.add(cp);
- }
- }
- }
- }
-
- protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest) {
- CustomCompletionProposal proposal = new CustomCompletionProposal("<![CDATA[]]>", //$NON-NLS-1$
- contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 9, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_CDATASECTION), "CDATA Section", //$NON-NLS-1$
- null, null, XMLRelevanceConstants.R_CDATA);
- contentAssistRequest.addProposal(proposal);
-
- proposal = new CustomCompletionProposal(nodeName, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), nodeName.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TXTEXT), "#PCDATA", //$NON-NLS-1$
- null, null, XMLRelevanceConstants.R_CDATA);
- contentAssistRequest.addProposal(proposal);
- }
-
- protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) {
- Node aNode = contentAssistRequest.getNode();
- boolean xmlpiFound = false;
- Document owningDocument = aNode.getOwnerDocument();
- // ==> // int xmlpiNodePosition = -1;
-
- // make sure xmlpi is root element
- // don't want doctype proposal if XMLPI isn't first element...
- Node first = owningDocument.getFirstChild();
- boolean xmlpiIsFirstElement = ((first != null) && (first.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE));
- boolean insertDoctype = xmlpiIsFirstElement;
-
- for (Node child = owningDocument.getFirstChild(); child != null; child = child.getNextSibling()) {
- boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml")); //$NON-NLS-1$
- xmlpiFound = xmlpiFound || xmlpi;
- if (xmlpiFound) {
- if (child instanceof IDOMNode) {
- // ==> // int xmlpiNodePosition =
- // ((XMLNode)child).getEndOffset();
- }
- // skip white space and text
- while (((child = child.getNextSibling()) != null) && (child.getNodeType() == Node.TEXT_NODE)) {
- // just skipping
- }
- // check if theres a node inbetween XMLPI and cursor position
- if ((child != null) && (child instanceof IDOMNode)) {
- if ((contentAssistRequest.getReplacementBeginPosition() >= ((IDOMNode) child).getEndOffset()) || !xmlpiIsFirstElement) {
- insertDoctype = false;
- }
- }
- break;
- }
- }
-
- if (xmlpiFound && (owningDocument.getDoctype() == null) && isCursorAfterXMLPI(contentAssistRequest) && insertDoctype) {
- addDocTypeProposal(contentAssistRequest);
- }
- }
-
- /**
- * Close an unclosed start tag
- */
- protected void addTagCloseProposals(ContentAssistRequest contentAssistRequest) {
- IDOMNode node = (IDOMNode) contentAssistRequest.getParent();
- if (node.getNodeType() == Node.ELEMENT_NODE) {
-
- CMElementDeclaration elementDecl = getCMElementDeclaration(node);
- String proposedInfo = (elementDecl != null) ? getAdditionalInfo(null, elementDecl) : null;
- int contentType = (elementDecl != null) ? elementDecl.getContentType() : CMElementDeclaration.ANY;
- // if it's XML and content doesn't HAVE to be element, add "/>"
- // proposal.
- boolean endWithSlashBracket = (getXML(node) && (contentType != CMElementDeclaration.ELEMENT));
-
- Image image = CMImageUtil.getImage(elementDecl);
- if (image == null) {
- image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
- }
-
- // is the start tag ended properly?
- if ((contentAssistRequest.getDocumentRegion() == node.getFirstStructuredDocumentRegion()) && !(node.getFirstStructuredDocumentRegion()).isEnded()) {
- setErrorMessage(null);
- // Is this supposed to be an empty tag? Note that if we can't
- // tell, we assume it's not.
- if ((elementDecl != null) && (elementDecl.getContentType() == CMElementDeclaration.EMPTY)) {
- // prompt with a self-closing end character if needed
- CustomCompletionProposal proposal = new CustomCompletionProposal(getContentGenerator().getStartTagClose(node, elementDecl), contentAssistRequest.getReplacementBeginPosition(),
- // this is one of the few times to ignore the length --
- // always insert
- // contentAssistRequest.getReplacementLength(),
- 0, getContentGenerator().getStartTagClose(node, elementDecl).length(), image, NLS.bind(XMLUIMessages.Close_with___, (new Object[]{getContentGenerator().getStartTagClose(node, elementDecl)})), null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG);
- contentAssistRequest.addProposal(proposal);
- }
- else {
- // prompt with a close for the start tag
- CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$
- contentAssistRequest.getReplacementBeginPosition(),
- // this is one of the few times to ignore the
- // length -- always insert
- // contentAssistRequest.getReplacementLength(),
- 0, 1, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$
- null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG);
- contentAssistRequest.addProposal(proposal);
-
- // prompt with the closer for the start tag and an end tag
- // if one is not present
- if (node.getEndStructuredDocumentRegion() == null) {
- // make sure tag name is actually what it thinks it
- // is...(eg. <%@ vs. <jsp:directive)
- IStructuredDocumentRegion sdr = contentAssistRequest.getDocumentRegion();
- String openingTagText = (sdr != null) ? sdr.getFullText() : ""; //$NON-NLS-1$
- if ((openingTagText != null) && (openingTagText.indexOf(node.getNodeName()) != -1)) {
- proposal = new CustomCompletionProposal("></" + node.getNodeName() + ">", //$NON-NLS-2$//$NON-NLS-1$
- contentAssistRequest.getReplacementBeginPosition(),
- // this is one of the few times to
- // ignore the length -- always insert
- // contentAssistRequest.getReplacementLength(),
- 0, 1, image, NLS.bind(XMLUIMessages.Close_with____, (new Object[]{node.getNodeName()})), null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG);
- contentAssistRequest.addProposal(proposal);
- }
- }
- // prompt with slash bracket "/>" incase if it's a self
- // ending tag
- if (endWithSlashBracket) {
- proposal = new CustomCompletionProposal("/>", //$NON-NLS-1$
- contentAssistRequest.getReplacementBeginPosition(),
- // this is one of the few times to ignore
- // the length -- always insert
- // contentAssistRequest.getReplacementLength(),
- 0, 2, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" \"/>\""})), //$NON-NLS-1$
- null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG + 1); // +1
- // to
- // bring
- // to
- // top
- // of
- // list
- contentAssistRequest.addProposal(proposal);
- }
- }
- }
- else if ((contentAssistRequest.getDocumentRegion() == node.getLastStructuredDocumentRegion()) && !node.getLastStructuredDocumentRegion().isEnded()) {
- setErrorMessage(null);
- // prompt with a closing end character for the end tag
- CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$
- contentAssistRequest.getReplacementBeginPosition(),
- // this is one of the few times to ignore the
- // length -- always insert
- // contentAssistRequest.getReplacementLength(),
- 0, 1, image, NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$
- null, proposedInfo, XMLRelevanceConstants.R_CLOSE_TAG);
- contentAssistRequest.addProposal(proposal);
- }
- }
- else if (node.getNodeType() == Node.DOCUMENT_NODE) {
- setErrorMessage(UNKNOWN_CONTEXT);
- }
- }
-
- protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) {
- List cmnodes = null;
- Node parent = contentAssistRequest.getParent();
- String error = null;
-
- // (nsd) This is only valid at the document element level
- // only valid if it's XML (check added 2/17/2004)
- if ((parent != null) && (parent.getNodeType() == Node.DOCUMENT_NODE) && ((IDOMDocument) parent).isXMLType() && !isCursorAfterXMLPI(contentAssistRequest)) {
- return;
- }
- // only want proposals if cursor is after doctype...
- if (!isCursorAfterDoctype(contentAssistRequest)) {
- return;
- }
-
- // fix for meta-info comment nodes.. they currently "hide" other
- // proposals because the don't
- // have a content model (so can't propose any children..)
- if ((parent != null) && (parent instanceof IDOMNode) && isCommentNode((IDOMNode) parent)) {
- // loop and find non comment node?
- while ((parent != null) && isCommentNode((IDOMNode) parent)) {
- parent = parent.getParentNode();
- }
- }
-
- if (parent.getNodeType() == Node.ELEMENT_NODE) {
- CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
- if (parentDecl != null) {
- // XSD-specific ability - no filtering
- CMDataType childType = parentDecl.getDataType();
- if (childType != null) {
- String[] childStrings = childType.getEnumeratedValues();
- if (childStrings != null) {
- // the content string is the sole valid child...so
- // replace the rest
- int begin = contentAssistRequest.getReplacementBeginPosition();
- int length = contentAssistRequest.getReplacementLength();
- if (parent instanceof IDOMNode) {
- if (((IDOMNode) parent).getLastStructuredDocumentRegion() != ((IDOMNode) parent).getFirstStructuredDocumentRegion()) {
- begin = ((IDOMNode) parent).getFirstStructuredDocumentRegion().getEndOffset();
- length = ((IDOMNode) parent).getLastStructuredDocumentRegion().getStartOffset() - begin;
- }
- }
- String proposedInfo = getAdditionalInfo(parentDecl, childType);
- for (int i = 0; i < childStrings.length; i++) {
- CustomCompletionProposal textProposal = new CustomCompletionProposal(childStrings[i], begin, length, childStrings[i].length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM), childStrings[i], null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
- contentAssistRequest.addProposal(textProposal);
- }
- }
- }
- }
- if ((parentDecl != null) && (parentDecl.getContentType() == CMElementDeclaration.PCDATA)) {
- addPCDATAProposal(parentDecl.getNodeName(), contentAssistRequest);
- }
- else {
- // retrieve the list of all possible children within this
- // parent context
- cmnodes = getAvailableChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT);
-
- // retrieve the list of the possible children within this
- // parent context and at this index
- List strictCMNodeSuggestions = null;
- if (XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT.equals(XMLUIPlugin.getInstance().getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY))) {
- strictCMNodeSuggestions = getValidChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT);
- }
- Iterator nodeIterator = cmnodes.iterator();
- if (!nodeIterator.hasNext()) {
- if (getCMElementDeclaration(parent) != null) {
- error = NLS.bind(XMLUIMessages._Has_no_available_child, (new Object[]{parent.getNodeName()}));
- }
- else {
- error = NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[]{parent.getNodeName()}));
- }
- }
- String matchString = contentAssistRequest.getMatchString();
- // chop off any leading <'s and whitespace from the
- // matchstring
- while ((matchString.length() > 0) && (Character.isWhitespace(matchString.charAt(0)) || beginsWith(matchString, "<"))) {
- //$NON-NLS-1$
- matchString = matchString.substring(1);
- }
- while (nodeIterator.hasNext()) {
- Object o = nodeIterator.next();
- if (o instanceof CMElementDeclaration) {
- CMElementDeclaration elementDecl = (CMElementDeclaration) o;
- // only add proposals for the child element's that
- // begin with the matchstring
- String tagname = getRequiredName(parent, elementDecl);
- boolean isStrictCMNodeSuggestion = strictCMNodeSuggestions != null ? strictCMNodeSuggestions.contains(elementDecl) : false;
-
- Image image = CMImageUtil.getImage(elementDecl);
-
- if (image == null) {
- if (strictCMNodeSuggestions != null) {
- image = isStrictCMNodeSuggestion ? XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC_EMPHASIZED) : XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC_DEEMPHASIZED);
- }
- else {
- image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
- }
-
- }
-
- // int markupAdjustment =
- // getContentGenerator().getMinimalStartTagLength(parent,
- // elementDecl);
- if (beginsWith(tagname, matchString)) {
- String proposedText = getRequiredText(parent, elementDecl);
-
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811
- // place cursor in first empty quotes
- int markupAdjustment = getCursorPositionForProposedText(proposedText);
-
- String proposedInfo = getAdditionalInfo(parentDecl, elementDecl);
- int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION;
- CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, relevance);
- contentAssistRequest.addProposal(proposal);
- }
- }
- }
- if (contentAssistRequest.getProposals().size() == 0) {
- if (error != null) {
- setErrorMessage(error);
- }
- else if ((contentAssistRequest.getMatchString() != null) && (contentAssistRequest.getMatchString().length() > 0)) {
- setErrorMessage(NLS.bind(XMLUIMessages.No_known_child_tag, (new Object[]{parent.getNodeName(), contentAssistRequest.getMatchString()})));
- //$NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\"."
- }
- else {
- setErrorMessage(NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[]{parent.getNodeName()})));
- }
- }
- }
- }
- else if (parent.getNodeType() == Node.DOCUMENT_NODE) {
- // Can only prompt with elements if the cursor position is past
- // the XML processing
- // instruction and DOCTYPE declaration
- boolean xmlpiFound = false;
- boolean doctypeFound = false;
- int minimumOffset = -1;
-
- for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
-
- boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml")); //$NON-NLS-1$
- boolean doctype = child.getNodeType() == Node.DOCUMENT_TYPE_NODE;
- if (xmlpi || (doctype && (minimumOffset < 0))) {
- minimumOffset = ((IDOMNode) child).getFirstStructuredDocumentRegion().getStartOffset() + ((IDOMNode) child).getFirstStructuredDocumentRegion().getTextLength();
- }
- xmlpiFound = xmlpiFound || xmlpi;
- doctypeFound = doctypeFound || doctype;
- }
-
- if (contentAssistRequest.getReplacementBeginPosition() >= minimumOffset) {
- List childDecls = getAvailableRootChildren((Document) parent, childPosition);
- for (int i = 0; i < childDecls.size(); i++) {
- CMElementDeclaration ed = (CMElementDeclaration) childDecls.get(i);
- if (ed != null) {
- Image image = CMImageUtil.getImage(ed);
- if (image == null) {
- image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
- }
- String proposedText = getRequiredText(parent, ed);
- String tagname = getRequiredName(parent, ed);
- // account for the &lt; and &gt;
- int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, ed);
- String proposedInfo = getAdditionalInfo(null, ed);
- CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
- contentAssistRequest.addProposal(proposal);
- }
- }
- }
- }
- }
-
- protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int childPosition) {
- List cmnodes = null;
- Node parent = contentAssistRequest.getParent();
- IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
- String error = null;
- String matchString = contentAssistRequest.getMatchString();
- if (parent.getNodeType() == Node.ELEMENT_NODE) {
- // retrieve the list of children
- // validActions = getAvailableChildrenAtIndex((Element) parent,
- // childPosition);
- cmnodes = getAvailableChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT);
- Iterator nodeIterator = cmnodes.iterator();
- // chop off any leading <'s and whitespace from the matchstring
- while ((matchString.length() > 0) && (Character.isWhitespace(matchString.charAt(0)) || beginsWith(matchString, "<"))) {
- //$NON-NLS-1$
- matchString = matchString.substring(1);
- }
- if (!nodeIterator.hasNext()) {
- error = NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[]{parent.getNodeName()}));
- }
- while (nodeIterator.hasNext()) {
- CMNode elementDecl = (CMNode) nodeIterator.next();
- if (elementDecl != null) {
- // only add proposals for the child element's that begin
- // with the matchstring
- String proposedText = null;
- int cursorAdjustment = 0;
-
- // do a check to see if partial attributes of partial tag
- // names are in list
- if (((node != null) && (node.getAttributes() != null) && (node.getAttributes().getLength() > 0) && attributeInList(node, parent, elementDecl)) || ((node.getNodeType() != Node.TEXT_NODE) && node.getFirstStructuredDocumentRegion().isEnded())) {
-
- proposedText = getRequiredName(parent, elementDecl);
- cursorAdjustment = proposedText.length();
- }
- else {
- proposedText = getRequiredName(parent, elementDecl);
- cursorAdjustment = proposedText.length();
- if (elementDecl instanceof CMElementDeclaration) {
- CMElementDeclaration ed = (CMElementDeclaration) elementDecl;
- if (ed.getContentType() == CMElementDeclaration.EMPTY) {
- proposedText += getContentGenerator().getStartTagClose(parent, ed);
- cursorAdjustment = proposedText.length();
- }
- else {
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811
- StringBuffer sb = new StringBuffer();
- getContentGenerator().generateTag(parent, ed, sb);
- // since it's a name proposal, assume '<' is
- // already there
- // only return the rest of the tag
- proposedText = sb.toString().substring(1);
- cursorAdjustment = getCursorPositionForProposedText(proposedText);
-
- // cursorAdjustment = proposedText.length() +
- // 1;
- // proposedText += "></" +
- // getRequiredName(parent, elementDecl) + ">";
- // //$NON-NLS-2$//$NON-NLS-1$
- }
- }
- }
- if (beginsWith(proposedText, matchString)) {
- Image image = CMImageUtil.getImage(elementDecl);
- if (image == null) {
- image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
- }
- String proposedInfo = getAdditionalInfo(getCMElementDeclaration(parent), elementDecl);
- CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, image, getRequiredName(parent, elementDecl), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME);
- contentAssistRequest.addProposal(proposal);
- }
- }
- }
- if (contentAssistRequest.getProposals().size() == 0) {
- if (error != null) {
- setErrorMessage(error);
- }
- else if ((contentAssistRequest.getMatchString() != null) && (contentAssistRequest.getMatchString().length() > 0)) {
- setErrorMessage(NLS.bind(XMLUIMessages.No_known_child_tag_names, (new Object[]{parent.getNodeName(), contentAssistRequest.getMatchString()})));
- //$NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\""
- }
- else {
- setErrorMessage(NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[]{parent.getNodeName()})));
- }
- }
- }
- else if (parent.getNodeType() == Node.DOCUMENT_NODE) {
- List childElements = getAvailableRootChildren((Document) parent, childPosition);
- for (int i = 0; i < childElements.size(); i++) {
- CMNode ed = (CMNode) childElements.get(i);
- if (ed == null) {
- continue;
- }
- String proposedText = null;
- int cursorAdjustment = 0;
- if (ed instanceof CMElementDeclaration) {
- // proposedText = getRequiredName(parent, ed);
- StringBuffer sb = new StringBuffer();
- getContentGenerator().generateTag(parent, (CMElementDeclaration) ed, sb);
- // tag starts w/ '<', but we want to compare to name
- proposedText = sb.toString().substring(1);
-
- if (!beginsWith(proposedText, matchString)) {
- continue;
- }
-
- cursorAdjustment = getCursorPositionForProposedText(proposedText);
-
- if (ed instanceof CMElementDeclaration) {
- CMElementDeclaration elementDecl = (CMElementDeclaration) ed;
- if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) {
- proposedText += getContentGenerator().getStartTagClose(parent, elementDecl);
- cursorAdjustment = proposedText.length();
- }
- }
-
- String proposedInfo = getAdditionalInfo(null, ed);
- Image image = CMImageUtil.getImage(ed);
- if (image == null) {
- image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
- }
- CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, image, getRequiredName(parent, ed), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME);
- contentAssistRequest.addProposal(proposal);
- }
- }
- }
- }
-
- /**
- * this is the position the cursor should be in after the proposal is
- * applied
- *
- * @param proposedText
- * @return the position the cursor should be in after the proposal is
- * applied
- */
- private int getCursorPositionForProposedText(String proposedText) {
- int cursorAdjustment;
- cursorAdjustment = proposedText.indexOf("\"\"") + 1; //$NON-NLS-1$
- // otherwise, after the first tag
- if (cursorAdjustment == 0) {
- cursorAdjustment = proposedText.indexOf('>') + 1;
- }
- if (cursorAdjustment == 0) {
- cursorAdjustment = proposedText.length() + 1;
- }
-
- return cursorAdjustment;
- }
-
- /**
- * @deprecated XML proposal is added via xml declaration template instead
- */
- protected void addXMLProposal(ContentAssistRequest contentAssistRequest) {
- String proposedText = "<?xml version=\"1.0\" encoding=\"" + ContentTypeEncodingPreferences.getUserPreferredCharsetName(ContentTypeIdForXML.ContentTypeID_XML) + "\"?>"; //$NON-NLS-2$//$NON-NLS-1$
- ICompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION), proposedText, null, null, XMLRelevanceConstants.R_XML_DECLARATION);
- // TODO add special XML proposal info
- contentAssistRequest.addProposal(proposal);
- }
-
- /**
- * This method determines if any of the attributes in the proposed XMLNode
- * node, are possible values of attributes from possible Elements at this
- * point in the document according to the Content Model.
- *
- * @param node
- * the element with attributes that you would like to test if
- * are possible for possible Elements at this point
- * @param cmnode
- * possible element at this point in the document (depending on
- * what 'node' is) true if any attributes of 'node' match any
- * possible attributes from 'cmnodes' list.
- */
- protected boolean attributeInList(IDOMNode node, Node parent, CMNode cmnode) {
- if ((node == null) || (parent == null) || (cmnode == null)) {
- return false;
- }
- String elementMatchString = node.getNodeName();
- String cmnodeName = getRequiredName(parent, cmnode);// cmnode.getNodeName();
- if (node instanceof Element) {
- NamedNodeMap map = ((Element) node).getAttributes();
- String attrMatchString = ""; //$NON-NLS-1$
- CMNamedNodeMap cmattrMap = null;
- // iterate attribute possibilities for partially started node
- for (int i = 0; (map != null) && (i < map.getLength()); i++) {
- attrMatchString = map.item(i).getNodeName();
- // filter on whatever user typed for element name already
- if (beginsWith(cmnodeName, elementMatchString)) {
- if (cmnode.getNodeType() == CMNode.ELEMENT_DECLARATION) {
- cmattrMap = ((CMElementDeclaration) cmnode).getAttributes();
- // iterate possible attributes from a cmnode in
- // proposal list
- for (int k = 0; (cmattrMap != null) && (k < cmattrMap.getLength()); k++) {
- // check if name matches
- if (cmattrMap.item(k).getNodeName().equals(attrMatchString)) {
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
-
- protected boolean beginsWith(String aString, String prefix) {
- if ((aString == null) || (prefix == null)) {
- return true;
- }
- // (pa) matching independent of case to be consistant with Java
- // editor CA
- return aString.toLowerCase().startsWith(prefix.toLowerCase());
- }
-
- protected ContentAssistRequest computeAttributeProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- ContentAssistRequest contentAssistRequest = null;
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
- if (documentPosition < sdRegion.getStartOffset(completionRegion)) {
- // setup to insert new attributes
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
- }
- else {
- // Setup to replace an existing attribute name
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
- }
- addAttributeNameProposals(contentAssistRequest);
- contentAssistRequest.setReplacementBeginPosition(documentPosition);
- contentAssistRequest.setReplacementLength(0);
- if ((node.getFirstStructuredDocumentRegion() != null) && (!node.getFirstStructuredDocumentRegion().isEnded())) {
- addTagCloseProposals(contentAssistRequest);
- }
- return contentAssistRequest;
- }
-
- protected ContentAssistRequest computeAttributeValueProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- 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 = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString);
- addAttributeNameProposals(contentAssistRequest);
- if ((actualNode.getFirstStructuredDocumentRegion() != null) && !actualNode.getFirstStructuredDocumentRegion().isEnded()) {
- addTagCloseProposals(contentAssistRequest);
- }
- }
- 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 = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
- addAttributeNameProposals(contentAssistRequest);
- }
- else {
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
- addAttributeValueProposals(contentAssistRequest);
- }
- }
- return contentAssistRequest;
- }
-
- protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) {
- ContentAssistRequest contentAssistRequest = null;
- String regionType = completionRegion.getType();
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
-
- // Handle the most common and best supported cases
- if ((xmlnode.getNodeType() == Node.ELEMENT_NODE) || (xmlnode.getNodeType() == Node.DOCUMENT_NODE)) {
- if (regionType == DOMRegionContext.XML_TAG_OPEN) {
- contentAssistRequest = computeTagOpenProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- }
- else if (regionType == DOMRegionContext.XML_TAG_NAME) {
- contentAssistRequest = computeTagNameProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
- contentAssistRequest = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
- contentAssistRequest = computeEqualsProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- }
- else if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (documentPosition == sdRegion.getTextEndOffset()) && (sdRegion.getText(completionRegion).endsWith("\"") || sdRegion.getText(completionRegion).endsWith("\'"))) //$NON-NLS-1$ //$NON-NLS-2$
- {
- // this is for when the cursor is at the end of the closing
- // quote for an attribute..
- IDOMNode actualNode = (IDOMNode) xmlnode.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
- contentAssistRequest = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString);
- addTagCloseProposals(contentAssistRequest);
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
- contentAssistRequest = computeAttributeValueProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- }
- else if ((regionType == DOMRegionContext.XML_TAG_CLOSE) || (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE) || (regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_CLOSE))) {
- contentAssistRequest = computeTagCloseProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- }
- else if (regionType == DOMRegionContext.XML_END_TAG_OPEN) {
- contentAssistRequest = computeEndTagOpenProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- }
- else if ((regionType == DOMRegionContext.XML_CONTENT) || (regionType == DOMRegionContext.XML_CHAR_REFERENCE) || (regionType == DOMRegionContext.XML_ENTITY_REFERENCE) || (regionType == DOMRegionContext.XML_PE_REFERENCE)) {
- contentAssistRequest = computeContentProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- }
-
- // These ITextRegion types begin DOM Elements as well and although
- // internally harder to assist,
- // text insertions directly before them can be made
- else if ((documentPosition == sdRegion.getStartOffset(completionRegion)) && (regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_COMMENT_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DECLARATION_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_EXPRESSION_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_SCRIPTLET_OPEN) || (regionType == DOMRegionContext.XML_DECLARATION_OPEN) || (regionType == DOMRegionContext.XML_PI_OPEN) || (regionType == DOMRegionContext.XML_COMMENT_OPEN) || (regionType == DOMRegionContext.XML_CDATA_OPEN))) {
- contentAssistRequest = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
- addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode));
- addStartDocumentProposals(contentAssistRequest);
- }
- }
- // Not a Document or Element? (odd cases go here for now)
- else if (isCloseRegion(completionRegion)) {
- contentAssistRequest = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion) + completionRegion.getLength(), 0, matchString);
- addStartDocumentProposals(contentAssistRequest);
- if (documentPosition >= sdRegion.getTextEndOffset(completionRegion)) {
- addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode) + 1);
- }
- }
- else if ((documentPosition == sdRegion.getStartOffset(completionRegion)) && (regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_COMMENT_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DECLARATION_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_EXPRESSION_OPEN) || regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_SCRIPTLET_OPEN) || (regionType == DOMRegionContext.XML_DECLARATION_OPEN) || (regionType == DOMRegionContext.XML_PI_OPEN) || (regionType == DOMRegionContext.XML_COMMENT_OPEN) || (regionType == DOMRegionContext.XML_CDATA_OPEN))) {
- contentAssistRequest = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
- addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode));
- addStartDocumentProposals(contentAssistRequest);
- }
- return contentAssistRequest;
- }
-
- /**
- * CONTENT ASSIST STARTS HERE
- *
- * Return a list of proposed code completions based on the specified
- * location within the document that corresponds to the current cursor
- * position within the text-editor control.
- *
- * @param textViewer
- * @param documentPosition -
- * the cursor location within the document
- *
- * an array of ICompletionProposals
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer textViewer, int documentPosition) {
-
- setErrorMessage(null);
-
- fTextViewer = textViewer;
-
- IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition);
-
- Node node = (Node) treeNode;
- while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) {
- node = node.getParentNode();
- }
- IDOMNode xmlnode = (IDOMNode) node;
-
- ContentAssistRequest contentAssistRequest = null;
-
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
- ITextRegion completionRegion = getCompletionRegion(documentPosition, node);
-
- String matchString = getMatchString(sdRegion, completionRegion, documentPosition);
-
- // Handle empty Documents
- if (completionRegion == null) {
- if (((treeNode == null) || (((Node) treeNode).getNodeType() == Node.DOCUMENT_NODE)) && (completionRegion == null) && ((xmlnode == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
- IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(textViewer.getDocument());
- try {
- if (sModel != null) {
- IDOMDocument docNode = ((IDOMModel) sModel).getDocument();
- contentAssistRequest = newContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition, 0, null);
- addEmptyDocumentProposals(contentAssistRequest);
- }
- }
- finally {
- if (sModel != null) {
- sModel.releaseFromRead();
- }
- }
- if (contentAssistRequest == null) {
- Logger.logException(new IllegalStateException("problem getting model")); //$NON-NLS-1$
- return new ICompletionProposal[0];
- }
- return contentAssistRequest.getCompletionProposals();
- }
- // MASSIVE ERROR CONDITION
- Logger.logException(new IllegalStateException("completion region was null")); //$NON-NLS-1$
- setErrorMessage(INTERNALERROR);
- contentAssistRequest = newContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$
- return contentAssistRequest.getCompletionProposals();
- }
-
-
- // catch documents where no region can be determined
- if ((xmlnode.getNodeType() == Node.DOCUMENT_NODE) && ((completionRegion == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
- contentAssistRequest = computeStartDocumentProposals(documentPosition, matchString, completionRegion, (IDOMNode) treeNode, xmlnode);
- return contentAssistRequest.getCompletionProposals();
- }
-
- // compute normal proposals
- contentAssistRequest = computeCompletionProposals(documentPosition, matchString, completionRegion, (IDOMNode) treeNode, xmlnode);
- if (contentAssistRequest == null) {
- contentAssistRequest = newContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$
- if (Debug.displayWarnings) {
- System.out.println(UNKNOWN_CONTEXT + " " + completionRegion.getType() + "@" + documentPosition); //$NON-NLS-2$//$NON-NLS-1$
- }
- setErrorMessage(UNKNOWN_CONTEXT);
- }
-
- if (contentAssistRequest.getProposals().size() == 0) {
- setErrorMessage(UNKNOWN_CONTEXT);
- }
-
- return contentAssistRequest.getCompletionProposals();
- }
-
- protected ContentAssistRequest computeContentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- ContentAssistRequest contentAssistRequest = null;
-
- // setup to add children at the content node's position
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition, 0, matchString);
- if ((node != null) && (node.getNodeType() == Node.DOCUMENT_NODE) && (((Document) node).getDoctype() == null)) {
- addStartDocumentProposals(contentAssistRequest);
- }
- addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset));
- if (node.getNodeType() != Node.DOCUMENT_NODE) {
- addEndTagProposals(contentAssistRequest);
- }
- // entities?
- addEntityProposals(contentAssistRequest, documentPosition, completionRegion, node);
- // addEntityProposals(contentAssistRequest);
- return contentAssistRequest;
- }
-
- /**
- * Returns information about possible contexts based on the specified
- * location within the document that corresponds to the current cursor
- * position within the text viewer.
- *
- * @param viewer
- * the viewer whose document is used to compute the possible
- * contexts an array of context information objects or
- * <code>null</code> if no context could be found
- */
- public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
- if (fAttributeInfoProvider == null) {
- fAttributeInfoProvider = new AttributeContextInformationProvider((IStructuredDocument) viewer.getDocument(), (AttributeContextInformationPresenter) getContextInformationValidator());
- }
- return fAttributeInfoProvider.getAttributeInformation(documentOffset);
- }
-
- protected ContentAssistRequest computeEndTagOpenProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- ContentAssistRequest contentAssistRequest = null;
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
- int completionRegionStart = sdRegion.getStartOffset(completionRegion);
- int completionRegionLength = completionRegion.getLength();
- IStructuredDocumentRegion sdRegionAtCompletionOffset = node.getStructuredDocument().getRegionAtCharacterOffset(completionRegionStart + completionRegionLength);
- ITextRegion regionAtEndOfCompletion = sdRegionAtCompletionOffset.getRegionAtCharacterOffset(completionRegionStart + completionRegionLength);
-
- if ((documentPosition != completionRegionStart) && (regionAtEndOfCompletion != null) && (regionAtEndOfCompletion.getType() == DOMRegionContext.XML_TAG_NAME)) {
- ITextRegion nameRegion = regionAtEndOfCompletion;
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, nodeAtOffset.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(nameRegion), nameRegion.getTextLength(), matchString);
- }
- else {
- if (nodeAtOffset.getFirstStructuredDocumentRegion() == sdRegion) {
- // abnormal case, this unmatched end tag will be a sibling
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, nodeAtOffset.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
- }
- else {
- // normal case, this end tag is the parent
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, nodeAtOffset, sdRegion, completionRegion, documentPosition, 0, matchString);
- }
- }
- // if (documentPosition >= sdRegion.getStartOffset(completionRegion) +
- // completionRegion.getTextLength())
- addEndTagProposals(contentAssistRequest);
- // else
- if (completionRegionStart == documentPosition) {
- // positioned at start of end tag
- addTagInsertionProposals(contentAssistRequest, node.getChildNodes().getLength());
- }
- return contentAssistRequest;
- }
-
- /**
- * return all possible EntityReferenceProposals (according to current
- * position in doc)
- */
- protected ICompletionProposal[] computeEntityReferenceProposals(int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) {
- // only handle XML content for now
- Vector proposals = new Vector(); // ICompletionProposals
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
- if ((completionRegion != null) && (completionRegion.getType() == DOMRegionContext.XML_CONTENT)) {
- int nodeOffset = documentPosition - sdRegion.getStartOffset(completionRegion);
- String regionText = sdRegion.getFullText(completionRegion);
-
- // if directly to the right of a &, region will be null, need to
- // move to
- // the previous region...there might be a better way to do this
- if ((regionText != null) && regionText.trim().equals("") && (documentPosition > 0)) { //$NON-NLS-1$
- IStructuredDocumentRegion prev = treeNode.getStructuredDocument().getRegionAtCharacterOffset(documentPosition - 1);
- if ((prev != null) && prev.getText().equals("&")) { //$NON-NLS-1$
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=206680
- // examine previous region
- sdRegion = prev;
- completionRegion = prev.getLastRegion();
- regionText = prev.getFullText();
- nodeOffset = 1;
- }
- }
-
- // string must start w/ &
- if ((regionText != null) && regionText.startsWith("&")) { //$NON-NLS-1$
- String key = (nodeOffset > 0) ? regionText.substring(1, nodeOffset) : ""; //$NON-NLS-1$
-
- // get entity proposals, passing in the appropriate start
- // string
- ModelQuery mq = ModelQueryUtil.getModelQuery(((Node) treeNode).getOwnerDocument());
- if (mq != null) {
- CMDocument xmlDoc = mq.getCorrespondingCMDocument(treeNode);
- CMNamedNodeMap cmmap = null;
- Properties entities = null;
- if (xmlDoc != null) {
- cmmap = xmlDoc.getEntities();
- }
- if (cmmap != null) {
- entities = mapToProperties(cmmap);
- }
- else // 224787 in absence of content model, just use
- // minimal 5 entities
- {
- entities = new Properties();
- entities.put("quot", "\""); //$NON-NLS-1$ //$NON-NLS-2$
- entities.put("apos", "'"); //$NON-NLS-1$ //$NON-NLS-2$
- entities.put("amp", "&"); //$NON-NLS-1$ //$NON-NLS-2$
- entities.put("lt", "<"); //$NON-NLS-1$ //$NON-NLS-2$
- entities.put("gt", ">"); //$NON-NLS-1$ //$NON-NLS-2$
- entities.put("nbsp", " "); //$NON-NLS-1$ //$NON-NLS-2$
- }
- addEntityProposals(proposals, entities, key, nodeOffset, sdRegion, completionRegion);
- }
- }
- }
- return (ICompletionProposal[]) ((proposals.size() > 0) ? proposals.toArray(new ICompletionProposal[proposals.size()]) : null);
- }
-
- protected ContentAssistRequest computeEqualsProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- ContentAssistRequest contentAssistRequest = null;
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
- ITextRegion valueRegion = node.getStartStructuredDocumentRegion().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) + completionRegion.getLength());
- if ((valueRegion != null) && (valueRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (sdRegion.getStartOffset(valueRegion) <= documentPosition)) {
- // replace the adjacent attribute value
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, valueRegion, sdRegion.getStartOffset(valueRegion), valueRegion.getTextLength(), matchString);
- }
- else {
- // append an attribute value after the '='
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
- }
- addAttributeValueProposals(contentAssistRequest);
- return contentAssistRequest;
- }
-
- protected ContentAssistRequest computeStartDocumentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- // setup for a non-empty document, but one that hasn't been formally
- // started
- ContentAssistRequest contentAssistRequest = null;
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition, 0, matchString);
- addStartDocumentProposals(contentAssistRequest);
- return contentAssistRequest;
- }
-
- protected ContentAssistRequest computeTagCloseProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- ContentAssistRequest contentAssistRequest = null;
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
-
- if ((node.getNodeType() == Node.DOCUMENT_NODE) || (documentPosition >= sdRegion.getEndOffset())) {
- // this is a content request as the documentPosition is AFTER the
- // end of the closing region
- if ((node == nodeAtOffset) && (node.getParentNode() != null)) {
- node = (IDOMNode) node.getParentNode();
- }
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
- addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset));
- if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() == null)) {
- addEndTagProposals(contentAssistRequest);
- }
- }
- else {
- // at the start of the tag's close or within it
- ITextRegion closeRegion = sdRegion.getLastRegion();
- boolean insideTag = !sdRegion.isEnded() || (documentPosition <= sdRegion.getStartOffset(closeRegion));
- if (insideTag) {
- // this is a request for completions within a tag
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString);
- if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() != null)) {
- addTagCloseProposals(contentAssistRequest);
- }
- if (sdRegion == nodeAtOffset.getFirstStructuredDocumentRegion()) {
- contentAssistRequest.setReplacementBeginPosition(documentPosition);
- contentAssistRequest.setReplacementLength(0);
- addAttributeNameProposals(contentAssistRequest);
- }
- }
- }
- return contentAssistRequest;
- }
-
- protected ContentAssistRequest computeTagNameProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- ContentAssistRequest contentAssistRequest = null;
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
-
- if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion()) {
- // completing the *first* tag in "<tagname1 |<tagname2"
- IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
- if (actualNode != null) {
- if (actualNode.getFirstStructuredDocumentRegion() == sdRegion) {
- // start tag
- if (documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()) {
- // it's attributes
- contentAssistRequest = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString);
- if (node.getStructuredDocument().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) - 1).getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) - 1).getType() == DOMRegionContext.XML_TAG_OPEN) {
- addAttributeNameProposals(contentAssistRequest);
- }
- addTagCloseProposals(contentAssistRequest);
- }
- else {
- // it's name
- contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString);
- addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(actualNode));
- }
- }
- else {
- if (documentPosition >= sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()) {
- // insert name
- contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
- }
- else {
- // replace name
- contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
- }
- addEndTagNameProposals(contentAssistRequest);
- }
- }
- }
- else {
- if (documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) {
- // unclosed tag with only a name; should prompt for attributes
- // and a close instead
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString);
- addAttributeNameProposals(contentAssistRequest);
- addTagCloseProposals(contentAssistRequest);
- }
- else {
- if (sdRegion.getRegions().get(0).getType() != DOMRegionContext.XML_END_TAG_OPEN) {
- int replaceLength = documentPosition - sdRegion.getStartOffset(completionRegion);
- contentAssistRequest = newContentAssistRequest(node, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), replaceLength, matchString);
- addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset));
- }
- else {
- IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(documentPosition);
- if (actualNode != null) {
- if (documentPosition >= sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) {
- contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
- }
- else {
- contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
- }
- addEndTagNameProposals(contentAssistRequest);
- }
- }
- }
- }
- return contentAssistRequest;
- }
-
- protected ContentAssistRequest computeTagOpenProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
- ContentAssistRequest contentAssistRequest = null;
- IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
- if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion()) {
- // completing the *first* XML_TAG_OPEN in "<<tagname"
- IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
- if (actualNode != null) {
- contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
- addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(actualNode));
- addEndTagProposals(contentAssistRequest); // (pa) 220850
- }
- }
- else {
- if (documentPosition == sdRegion.getStartOffset(completionRegion)) {
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- // at the start of an existing tag, right before the '<'
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
- addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset));
- addEndTagProposals(contentAssistRequest);
- }
- else if (node.getNodeType() == Node.DOCUMENT_NODE) {
- // at the opening of the VERY first tag with a '<'
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
- addStartDocumentProposals(contentAssistRequest);
- }
- }
- else {
- // within the white space
- ITextRegion name = getNameRegion(node.getStartStructuredDocumentRegion());
- // (pa) ITextRegion refactor
- // if (name != null && name.containsOffset(documentPosition))
- // {
- if ((name != null) && ((sdRegion.getStartOffset(name) <= documentPosition) && (sdRegion.getEndOffset(name) >= documentPosition))) {
- // replace the existing name
- contentAssistRequest = newContentAssistRequest(node, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(name), name.getTextLength(), matchString);
- }
- else {
- // insert a valid new name, or possibly an end tag
- contentAssistRequest = newContentAssistRequest(nodeAtOffset, ((Node) nodeAtOffset).getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
- addEndTagProposals(contentAssistRequest);
- contentAssistRequest.setReplacementBeginPosition(documentPosition);
- contentAssistRequest.setReplacementLength(0);
- }
- addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset));
- }
- }
- return contentAssistRequest;
- }
-
- /**
- * Retreives cmnode's documentation to display in the completion
- * proposal's additional info. If no documentation exists for cmnode, try
- * displaying parentOrOwner's documentation
- *
- * String any documentation information to display for cmnode.
- * <code>null</code> if there is nothing to display.
- */
- protected String getAdditionalInfo(CMNode parentOrOwner, CMNode cmnode) {
- String addlInfo = null;
-
- if (cmnode == null) {
- if (Debug.displayWarnings) {
- new IllegalArgumentException("Null declaration!").printStackTrace(); //$NON-NLS-1$
- }
- return null;
- }
-
- addlInfo = getInfoProvider().getInfo(cmnode);
- if ((addlInfo == null) && (parentOrOwner != null)) {
- addlInfo = getInfoProvider().getInfo(parentOrOwner);
- }
- return addlInfo;
- }
-
- // returns a list of ModelQueryActions
- protected List getAvailableChildrenAtIndex(Element parent, int index, int validityChecking) {
- List list = new ArrayList();
- CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
- if (parentDecl != null) {
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
- // taken from ActionManagers
- // int editMode = modelQuery.getEditMode();
- int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED;
- int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES | ModelQuery.INCLUDE_SEQUENCE_GROUPS : ModelQuery.INCLUDE_CHILD_NODES;
- modelQuery.getInsertActions(parent, parentDecl, index, ic, validityChecking, list);
- }
- return list;
- }
-
- // returns a list of CMElementDeclarations
- protected List getAvailableRootChildren(Document document, int childIndex) {
- List list = null;
-
- // extract the valid 'root' node name from the DocumentType Node
- DocumentType docType = document.getDoctype();
- String rootName = null;
- if (docType != null) {
- rootName = docType.getNodeName();
- }
- if (rootName == null) {
- return new ArrayList(0);
- }
-
- for (Node child = document.getFirstChild(); child != null; child = child.getNextSibling()) {
- // make sure the "root" Element isn't already present
- // is it required to be an Element?
- if ((child.getNodeType() == Node.ELEMENT_NODE) && stringsEqual(child.getNodeName(), rootName)) {
- // if the node is missing either the start or end tag, don't
- // count it as present
- if ((child instanceof IDOMNode) && ((((IDOMNode) child).getStartStructuredDocumentRegion() == null) || (((IDOMNode) child).getEndStructuredDocumentRegion() == null))) {
- continue;
- }
- if (Debug.displayInfo) {
- System.out.println(rootName + " already present!"); //$NON-NLS-1$
- }
- setErrorMessage(NLS.bind(XMLUIMessages.The_document_element__, (new Object[]{rootName})));
- return new ArrayList(0);
- }
- }
-
- list = new ArrayList(1);
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
- if (modelQuery != null) {
- CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
- if (cmdoc != null) {
- if (rootName != null) {
- CMElementDeclaration rootDecl = (CMElementDeclaration) cmdoc.getElements().getNamedItem(rootName);
- if (rootDecl != null) {
- list.add(rootDecl);
- }
- else {
- // supply the given document name anyway, even if it
- // is an error
- list.add(new SimpleCMElementDeclaration(rootName));
- if (Debug.displayInfo || Debug.displayWarnings) {
- System.out.println("No definition found for " + rootName + " in " + docType.getPublicId() + "/" + docType.getSystemId()); //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- }
- String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- if (location.length() > 0) {
- setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for_in, (new Object[]{rootName, location})));
- }
- else {
- setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for, (new Object[]{rootName})));
- }
- }
- }
- }
- else {
- if (Debug.displayInfo || Debug.displayWarnings) {
- System.out.println("No content model found."); //$NON-NLS-1$
- }
- //$NON-NLS-1$
- //$NON-NLS-1$
- String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- if (location.length() > 0) {
- setErrorMessage(NLS.bind(XMLUIMessages.No_content_model_for, (new Object[]{location})));
- }
- else {
- setErrorMessage(XMLUIMessages.No_content_model_found_UI_);
- }
- }
- }
-
- return list;
- }
-
- protected CMElementDeclaration getCMElementDeclaration(Node node) {
- CMElementDeclaration result = null;
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
- if (modelQuery != null) {
- result = modelQuery.getCMElementDeclaration((Element) node);
- }
- }
- return result;
- }
-
- /**
- * Returns the characters which when entered by the user should
- * automatically trigger the presentation of possible completions.
- *
- * the auto activation characters for completion proposal or
- * <code>null</code> if no auto activation is desired
- */
- public char[] getCompletionProposalAutoActivationCharacters() {
- return completionProposalAutoActivationCharacters;
- }
-
- protected ITextRegion getCompletionRegion(int offset, IStructuredDocumentRegion sdRegion) {
- ITextRegion region = sdRegion.getRegionAtCharacterOffset(offset);
- if (region == null) {
- return null;
- }
-
- if (sdRegion.getStartOffset(region) == offset) {
- // The offset is at the beginning of the region
- if ((sdRegion.getStartOffset(region) == sdRegion.getStartOffset()) && (sdRegion.getPrevious() != null) && (!sdRegion.getPrevious().isEnded())) {
- // Is the region also the start of the node? If so, the
- // previous IStructuredDocumentRegion is
- // where to look for a useful region.
- region = sdRegion.getPrevious().getRegionAtCharacterOffset(offset - 1);
- }
- else {
- // Is there no separating whitespace from the previous region?
- // If not,
- // then that region is the important one
- ITextRegion previousRegion = sdRegion.getRegionAtCharacterOffset(offset - 1);
- if ((previousRegion != null) && (previousRegion != region) && (previousRegion.getTextLength() == previousRegion.getLength())) {
- region = previousRegion;
- }
- }
- }
- else {
- // The offset is NOT at the beginning of the region
- if (offset > sdRegion.getStartOffset(region) + region.getTextLength()) {
- // Is the offset within the whitespace after the text in this
- // region?
- // If so, use the next region
- ITextRegion nextRegion = sdRegion.getRegionAtCharacterOffset(sdRegion.getStartOffset(region) + region.getLength());
- if (nextRegion != null) {
- region = nextRegion;
- }
- }
- else {
- // Is the offset within the important text for this region?
- // If so, then we've already got the right one.
- }
- }
-
- // valid WHITE_SPACE region handler (#179924)
- if ((region != null) && (region.getType() == DOMRegionContext.WHITE_SPACE)) {
- ITextRegion previousRegion = sdRegion.getRegionAtCharacterOffset(sdRegion.getStartOffset(region) - 1);
- if (previousRegion != null) {
- region = previousRegion;
- }
- }
-
- return region;
- }
-
- /**
- * Return the region whose content's require completion. This is something
- * of a misnomer as sometimes the user wants to be prompted for contents
- * of a non-existant ITextRegion, such as for enumerated attribute values
- * following an '=' sign.
- */
- protected ITextRegion getCompletionRegion(int documentPosition, Node domnode) {
- if (domnode == null) {
- return null;
- }
-
- ITextRegion region = null;
- int offset = documentPosition;
- IStructuredDocumentRegion flatNode = null;
- IDOMNode node = (IDOMNode) domnode;
-
- if (node.getNodeType() == Node.DOCUMENT_NODE) {
- if (node.getStructuredDocument().getLength() == 0) {
- return null;
- }
- ITextRegion result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
- while (result == null) {
- offset--;
- result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
- }
- return result;
- }
-
- IStructuredDocumentRegion startTag = node.getStartStructuredDocumentRegion();
- IStructuredDocumentRegion endTag = node.getEndStructuredDocumentRegion();
-
- // Determine if the offset is within the start
- // IStructuredDocumentRegion, end IStructuredDocumentRegion, or
- // somewhere within the Node's XML content.
- if ((startTag != null) && (startTag.getStartOffset() <= offset) && (offset < startTag.getStartOffset() + startTag.getLength())) {
- flatNode = startTag;
- }
- else if ((endTag != null) && (endTag.getStartOffset() <= offset) && (offset < endTag.getStartOffset() + endTag.getLength())) {
- flatNode = endTag;
- }
-
- if (flatNode != null) {
- // the offset is definitely within the start or end tag, continue
- // on and find the region
- region = getCompletionRegion(offset, flatNode);
- }
- else {
- // the docPosition is neither within the start nor the end, so it
- // must be content
- flatNode = node.getStructuredDocument().getRegionAtCharacterOffset(offset);
- // (pa) ITextRegion refactor
- // if (flatNode.contains(documentPosition)) {
- if ((flatNode.getStartOffset() <= documentPosition) && (flatNode.getEndOffset() >= documentPosition)) {
- // we're interesting in completing/extending the previous
- // IStructuredDocumentRegion if the current
- // IStructuredDocumentRegion isn't plain content or if it's
- // preceded by an orphan '<'
- if ((offset == flatNode.getStartOffset()) && (flatNode.getPrevious() != null) && (((flatNode.getRegionAtCharacterOffset(documentPosition) != null) && (flatNode.getRegionAtCharacterOffset(documentPosition).getType() != DOMRegionContext.XML_CONTENT)) || (flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_TAG_OPEN) || (flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_END_TAG_OPEN))) {
- // Is the region also the start of the node? If so, the
- // previous IStructuredDocumentRegion is
- // where to look for a useful region.
- region = flatNode.getPrevious().getLastRegion();
- }
- else if (flatNode.getEndOffset() == documentPosition) {
- region = flatNode.getLastRegion();
- }
- else {
- region = flatNode.getFirstRegion();
- }
- }
- else {
- // catch end of document positions where the docPosition isn't
- // in a IStructuredDocumentRegion
- region = flatNode.getLastRegion();
- }
- }
-
- return region;
- }
-
- /**
- * Provided by default. Subclasses may override with their own
- * implementations.
- *
- * @see AbstractContentAssistProcessor#getContentGenerator()
- */
- public XMLContentModelGenerator getContentGenerator() {
- if (fGenerator == null) {
- fGenerator = new XMLContentModelGenerator();
- }
- return fGenerator;
- }
-
- /**
- * Returns the characters which when entered by the user should
- * automatically trigger the presentation of context information.
- *
- * the auto activation characters for presenting context information or
- * <code>null</code> if no auto activation is desired
- */
- public char[] getContextInformationAutoActivationCharacters() {
- return contextInformationAutoActivationCharacters;
- }
-
- /**
- * Returns a validator used to determine when displayed context
- * information should be dismissed. May only return <code>null</code> if
- * the processor is incapable of computing context information.
- *
- * a context information validator, or <code>null</code> if the
- * processor is incapable of computing context information
- */
- public IContextInformationValidator getContextInformationValidator() {
- if (fContextInformationPresenter == null) {
- fContextInformationPresenter = new AttributeContextInformationPresenter();
- }
- return fContextInformationPresenter;
- }
-
- protected int getElementPosition(Node child) {
- Node parent = child.getParentNode();
- if (parent == null) {
- return 0;
- }
-
- NodeList children = parent.getChildNodes();
- if (children == null) {
- return 0;
- }
- int count = 0;
-
- for (int i = 0; i < children.getLength(); i++) {
- if (children.item(i) == child) {
- return count;
- }
- else {
- // if (children.item(i).getNodeType() == Node.ELEMENT_NODE)
- count++;
- }
- }
- return 0;
- }
-
- private int getElementPositionForModelQuery(Node child) {
- return getElementPosition(child);
- // return -1;
- }
-
- /**
- * Return the reason why computeProposals was not able to find any
- * completions.
- *
- * an error message or null if no error occurred
- */
- public String getErrorMessage() {
- return fErrorMessage;
- }
-
- /**
- * @param iResource
- */
- // public void initialize(IResource iResource) {
- // this.resource = iResource;
- // }
- /**
- * Gets the infoProvider.
- *
- * fInfoProvider and if fInfoProvider was <code>null</code> create a new
- * instance
- */
- public MarkupTagInfoProvider getInfoProvider() {
- if (fInfoProvider == null) {
- fInfoProvider = new MarkupTagInfoProvider();
- }
- return fInfoProvider;
- }
-
- protected String getMatchString(IStructuredDocumentRegion parent, ITextRegion aRegion, int offset) {
- if ((aRegion == null) || isCloseRegion(aRegion)) {
- return ""; //$NON-NLS-1$
- }
- String matchString = null;
- String regionType = aRegion.getType();
- if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (regionType == DOMRegionContext.XML_TAG_OPEN) || (offset > parent.getStartOffset(aRegion) + aRegion.getTextLength())) {
- matchString = ""; //$NON-NLS-1$
- }
- else if (regionType == DOMRegionContext.XML_CONTENT) {
- matchString = ""; //$NON-NLS-1$
- }
- else {
- if ((parent.getText(aRegion).length() > 0) && (parent.getStartOffset(aRegion) < offset)) {
- matchString = parent.getText(aRegion).substring(0, offset - parent.getStartOffset(aRegion));
- }
- else {
- matchString = ""; //$NON-NLS-1$
- }
- }
- return matchString;
- }
-
- protected ITextRegion getNameRegion(IStructuredDocumentRegion flatNode) {
- if (flatNode == null) {
- return null;
- }
- Iterator regionList = flatNode.getRegions().iterator();
- while (regionList.hasNext()) {
- ITextRegion region = (ITextRegion) regionList.next();
- if (isNameRegion(region)) {
- return region;
- }
- }
- return null;
- }
-
- /**
- * Retrieves all of the possible valid values for this attribute
- * declaration
- */
- protected List getPossibleDataTypeValues(Node node, CMAttributeDeclaration ad) {
- List list = null;
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element) node;
- String[] dataTypeValues = null;
- // The ModelQuery may not be available if the corresponding
- // adapter
- // is absent
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
- if (modelQuery != null) {
- dataTypeValues = modelQuery.getPossibleDataTypeValues(element, ad);
- }
- else {
- if (ad.getAttrType() != null) {
- dataTypeValues = ad.getAttrType().getEnumeratedValues();
- }
- }
- if (dataTypeValues != null) {
- list = new ArrayList(dataTypeValues.length);
- for (int i = 0; i < dataTypeValues.length; i++) {
- list.add(dataTypeValues[i]);
- }
- }
- }
- if (list == null) {
- list = new ArrayList(0);
- }
- return list;
- }
-
- protected String getRequiredName(Node parentOrOwner, CMNode cmnode) {
- if ((cmnode == null) || (parentOrOwner == null)) {
- if (Debug.displayWarnings) {
- new IllegalArgumentException("Null declaration!").printStackTrace(); //$NON-NLS-1$
- }
- return ""; //$NON-NLS-1$
- }
- return getContentGenerator().getRequiredName(parentOrOwner, cmnode);
- }
-
- protected String getRequiredText(Node parentOrOwner, CMAttributeDeclaration attrDecl) {
- if (attrDecl == null) {
- if (Debug.displayWarnings) {
- new IllegalArgumentException("Null attribute declaration!").printStackTrace(); //$NON-NLS-1$
- }
- return ""; //$NON-NLS-1$
- }
- StringBuffer buff = new StringBuffer();
- getContentGenerator().generateRequiredAttribute(parentOrOwner, attrDecl, buff);
- return buff.toString();
- }
-
- protected String getRequiredText(Node parentOrOwner, CMElementDeclaration elementDecl) {
- if (elementDecl == null) {
- if (Debug.displayWarnings) {
- new IllegalArgumentException("Null attribute declaration!").printStackTrace(); //$NON-NLS-1$
- }
- return ""; //$NON-NLS-1$
- }
- StringBuffer buff = new StringBuffer();
- getContentGenerator().generateTag(parentOrOwner, elementDecl, buff);
- return buff.toString();
- }
-
- /**
- * StructuredTextViewer must be set before using this.
- */
- public IStructuredDocumentRegion getStructuredDocumentRegion(int pos) {
- // (pa) ITextRegion refactor defect 245190
- // return
- // (IStructuredDocumentRegion)ContentAssistUtils.getNodeAt((StructuredTextViewer)fTextViewer,
- // pos);
- return ContentAssistUtils.getStructuredDocumentRegion(fTextViewer, pos);
- }
-
- private String getTagName(IStructuredDocumentRegion sdRegion) {
- ITextRegionList regions = sdRegion.getRegions();
- ITextRegion region = null;
- String name = ""; //$NON-NLS-1$
- for (int i = 0; i < regions.size(); i++) {
- region = regions.get(i);
- if (region.getType() == DOMRegionContext.XML_TAG_NAME) {
- name = sdRegion.getText(region);
- break;
- }
- }
- return name;
- }
-
- // returns a list of CMNodes that are available within this parent context
- // Given the grammar shown below and a snippet of XML code (where the '|'
- // indicated the cursor position)
- // the list would return all of the element declarations that are
- // potential child elements of Foo.
- //
- // grammar : Foo -> (A, B, C)
- // snippet : <Foo><A>|
- // result : {A, B, C}
- //
- // TODO cs... do we need to pass in the 'kindOfAction'? Seems to me we
- // could assume it's always an insert.
- protected List getAvailableChildElementDeclarations(Element parent, int childPosition, int kindOfAction) {
- List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_NONE);
- Iterator iterator = modelQueryActions.iterator();
- List cmnodes = new Vector();
- while (iterator.hasNext()) {
- ModelQueryAction action = (ModelQueryAction) iterator.next();
- if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) {
- CMNode actionCMNode = action.getCMNode();
- if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
- cmnodes.add(actionCMNode);
- }
- }
- }
- return cmnodes;
- }
-
- // returns a list of CMNodes that can be validly inserted at this
- // childPosition
- // Given the grammar shown below and a snippet of XML code (where the '|'
- // indicated the cursor position)
- // the list would return only the element declarations can be inserted
- // while maintaing validity of the content.
- //
- // grammar : Foo -> (A, B, C)
- // snippet : <Foo><A>|
- // result : {B}
- //
- protected List getValidChildElementDeclarations(Element parent, int childPosition, int kindOfAction) {
- List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_STRICT);
- Iterator iterator = modelQueryActions.iterator();
- List cmnodes = new Vector();
- while (iterator.hasNext()) {
- ModelQueryAction action = (ModelQueryAction) iterator.next();
- if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) {
- CMNode actionCMNode = action.getCMNode();
- if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
- cmnodes.add(actionCMNode);
- }
- }
- }
- return cmnodes;
- }
-
- /**
- * Similar to the call in HTMLContentAssistProcessor. Pass in a node, it
- * tells you if the document is XML type.
- *
- * @param node
- *
- */
- protected boolean getXML(Node node) {
- if (node == null) {
- return false;
- }
-
- Document doc = null;
- doc = (node.getNodeType() != Node.DOCUMENT_NODE) ? node.getOwnerDocument() : ((Document) node);
-
- return (doc instanceof IDOMDocument) && ((IDOMDocument) doc).isXMLType();
- }
-
- // Initialize local settings
- protected void init() {
- // implement in subclasses
- }
-
- protected boolean isCloseRegion(ITextRegion region) {
- String type = region.getType();
- return ((type == DOMRegionContext.XML_PI_CLOSE) || (type == DOMRegionContext.XML_TAG_CLOSE) || (type == DOMRegionContext.XML_EMPTY_TAG_CLOSE) || (type == DOMRegionContext.XML_CDATA_CLOSE) || (type == DOMRegionContext.XML_COMMENT_CLOSE) || (type == DOMRegionContext.XML_ATTLIST_DECL_CLOSE) || (type == DOMRegionContext.XML_ELEMENT_DECL_CLOSE) || (type == DOMRegionContext.XML_DOCTYPE_DECLARATION_CLOSE) || (type == DOMJSPRegionContextsPrivateCopy.JSP_CLOSE) || (type == DOMJSPRegionContextsPrivateCopy.JSP_COMMENT_CLOSE) || (type.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_CLOSE)) || (type == DOMRegionContext.XML_DECLARATION_CLOSE));
- }
-
- /*
- * This is to determine if a tag is a special meta-info comment tag that
- * shows up as an ELEMENT
- */
- private boolean isCommentNode(IDOMNode node) {
- return ((node != null) && (node instanceof IDOMElement) && ((IDOMElement) node).isCommentTag());
- }
-
- /**
- * Checks if cursor position is after doctype tag...
- *
- * @param car
- *
- */
- protected boolean isCursorAfterDoctype(ContentAssistRequest car) {
- Node aNode = car.getNode();
- Document parent = aNode.getOwnerDocument();
- int xmldoctypeNodePosition = -1;
- boolean isAfterDoctype = true;
-
- if (parent == null) {
- return true; // blank document case
- }
-
- for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child instanceof IDOMNode) {
- if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
- xmldoctypeNodePosition = ((IDOMNode) child).getEndOffset();
- isAfterDoctype = (car.getReplacementBeginPosition() >= xmldoctypeNodePosition);
- break;
- }
- }
- }
- return isAfterDoctype;
- }
-
- /**
- * This method can check if the cursor is after the XMLPI
- *
- * @param car
- *
- */
- protected boolean isCursorAfterXMLPI(ContentAssistRequest car) {
- Node aNode = car.getNode();
- boolean xmlpiFound = false;
- Document parent = aNode.getOwnerDocument();
- int xmlpiNodePosition = -1;
- boolean isAfterXMLPI = false;
-
- if (parent == null) {
- return true; // blank document case
- }
-
- for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
- boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml")); //$NON-NLS-1$
- xmlpiFound = xmlpiFound || xmlpi;
- if (xmlpiFound) {
- if (child instanceof IDOMNode) {
- xmlpiNodePosition = ((IDOMNode) child).getEndOffset();
- isAfterXMLPI = (car.getReplacementBeginPosition() >= xmlpiNodePosition);
- }
- break;
- }
- }
- return isAfterXMLPI;
- }
-
- protected boolean isNameRegion(ITextRegion region) {
- String type = region.getType();
- return ((type == DOMRegionContext.XML_TAG_NAME) || (type == DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_NAME) || (type == DOMRegionContext.XML_ELEMENT_DECL_NAME) || (type == DOMRegionContext.XML_DOCTYPE_NAME) || (type == DOMRegionContext.XML_ATTLIST_DECL_NAME) || (type == DOMJSPRegionContextsPrivateCopy.JSP_ROOT_TAG_NAME) || type.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_NAME));
- }
-
- protected boolean isQuote(String string) {
- String trimmed = string.trim();
- if (trimmed.length() > 0) {
- return (trimmed.charAt(0) == '\'') || (trimmed.charAt(0) == '"');
- }
- return false;
- }
-
- private boolean isSelfClosed(IStructuredDocumentRegion startTag) {
- ITextRegionList regions = startTag.getRegions();
- return regions.get(regions.size() - 1).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE;
- }
-
- private boolean isStartTag(IStructuredDocumentRegion sdRegion) {
- boolean result = false;
- if (sdRegion.getRegions().size() > 0) {
- ITextRegion r = sdRegion.getRegions().get(0);
- result = (r.getType() == DOMRegionContext.XML_TAG_OPEN) && sdRegion.isEnded();
- }
- return result;
- }
-
- protected Properties mapToProperties(CMNamedNodeMap map) {
- Properties p = new Properties();
- for (int i = 0; i < map.getLength(); i++) {
- CMEntityDeclaration decl = (CMEntityDeclaration) map.item(i);
- p.put(decl.getName(), decl.getValue());
- }
- return p;
- }
-
- /**
- * Gets the corresponding XMLNode, and checks if it's closed.
- *
- * @param startTag
- *
- */
- private boolean needsEndTag(IStructuredDocumentRegion startTag) {
- boolean result = false;
- IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fTextViewer.getDocument());
- try {
- if (sModel != null) {
- IDOMNode xmlNode = (IDOMNode) sModel.getIndexedRegion(startTag.getStart());
- if (!isStartTag(startTag)) {
- result = false;
- }
- else if (isSelfClosed(startTag)) {
- result = false;
- }
- else if (!xmlNode.isContainer()) {
- result = false;
- }
- else {
- result = xmlNode.getEndStructuredDocumentRegion() == null;
- }
- }
- }
- finally {
- if (sModel != null) {
- sModel.releaseFromRead();
- }
- }
- return result;
- }
-
- protected ContentAssistRequest newContentAssistRequest(Node node, Node possibleParent, IStructuredDocumentRegion documentRegion, ITextRegion completionRegion, int begin, int length, String filter) {
- return new ContentAssistRequest(node, possibleParent, documentRegion, completionRegion, begin, length, filter);
- }
-
- public void release() {
- fGenerator = null;
- }
-
- /**
- * Set the reason why computeProposals was not able to find any
- * completions.
- */
- public void setErrorMessage(String errorMessage) {
- fErrorMessage = errorMessage;
- }
-
- /**
- * Set the reason why computeProposals was not able to find any
- * completions.
- */
- protected void setErrorMessage(String errorMessage, String append) {
- setErrorMessage(errorMessage + append);
- }
-
- /**
- * Set the reason why computeProposals was not able to find any
- * completions.
- */
- protected void setErrorMessage(String errorMessage, String prepend, String append) {
- setErrorMessage(prepend + errorMessage + append);
- }
-
- protected boolean stringsEqual(String a, String b) {
- // (pa) 221190 matching independent of case to be consistant with Java
- // editor CA
- return a.equalsIgnoreCase(b);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentModelGenerator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentModelGenerator.java
deleted file mode 100644
index 7884482852..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentModelGenerator.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper;
-import org.w3c.dom.Node;
-
-
-public abstract class AbstractContentModelGenerator {
-
- public static boolean generateChildren = false;
-
- public AbstractContentModelGenerator() {
- super();
- }
-
- public abstract void generateAttribute(CMAttributeDeclaration attrDecl, StringBuffer buffer);
-
- protected void generateAttributes(CMElementDeclaration elementDecl, StringBuffer buffer) {
- CMNamedNodeMap attributes = elementDecl.getAttributes();
- if (attributes == null) {
- return;
- }
- for (int i = 0; i < attributes.getLength(); i++) {
- generateAttribute((CMAttributeDeclaration) attributes.item(i), buffer);
- }
- return;
- }
-
- protected abstract void generateEndTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer);
-
- public void generateRequiredChildren(Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) {
- if (generateChildren) {
- }
- return;
- }
-
- protected abstract void generateStartTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer);
-
- public void generateTag(Node parent, CMElementDeclaration elementDecl, StringBuffer buffer) {
- if ((elementDecl == null) || (buffer == null)) {
- return;
- }
-
- String tagName = getRequiredName(parent, elementDecl);
-
- generateStartTag(tagName, parent, elementDecl, buffer);
- generateRequiredChildren(parent, elementDecl, buffer);
- generateEndTag(tagName, parent, elementDecl, buffer);
- return;
- }
-
- public abstract int getMinimalStartTagLength(Node node, CMElementDeclaration elementDecl);
-
- public String getRequiredName(Node ownerNode, CMNode cmnode) {
- if (ownerNode != null) {
- return DOMNamespaceHelper.computeName(cmnode, ownerNode, null);
- }
- return cmnode.getNodeName();
- }
-
- public abstract String getStartTagClose(Node parentNode, CMElementDeclaration elementDecl);
-
- protected boolean requiresAttributes(CMElementDeclaration ed) {
- CMNamedNodeMap attributes = ed.getAttributes();
- if (attributes == null) {
- return false;
- }
- for (int i = 0; i < attributes.getLength(); i++) {
- if (((CMAttributeDeclaration) attributes.item(i)).getUsage() == CMAttributeDeclaration.REQUIRED) {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformation.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformation.java
deleted file mode 100644
index 66e514ae24..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformation.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import java.util.HashMap;
-
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationExtension;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.wst.sse.ui.internal.util.Assert;
-
-
-/**
- * Implementation of IContextInformation. Adds knowledge about the information
- * display string such as required attributes for this context.
- *
- * @author pavery
- */
-public class AttributeContextInformation implements IContextInformation, IContextInformationExtension {
- private HashMap fAttr2RangeMap;
- /** The name of the context */
- private String fContextDisplayString;
- /** The image to be displayed */
- private Image fImage;
- /** The information to be displayed */
- private String fInformationDisplayString;
- private int fPosition = -1;
-
- /**
- * Creates a new context information with an image.
- *
- * @param image
- * the image to display when presenting the context information
- * @param contextDisplayString
- * the string to be used when presenting the context
- * @param informationDisplayString
- * the string to be displayed when presenting the context
- * information, may not be <code>null</code>
- */
- public AttributeContextInformation(Image image, String contextDisplayString, String informationDisplayString, HashMap attr2RangeMap) {
- Assert.isNotNull(informationDisplayString, "illegal argument: informationDisplayString can not be null"); //$NON-NLS-1$
-
- fImage = image;
- fContextDisplayString = contextDisplayString;
- fInformationDisplayString = informationDisplayString;
- fAttr2RangeMap = attr2RangeMap;
- }
-
- /**
- * Creates a new context information without an image.
- *
- * @param contextDisplayString
- * the string to be used when presenting the context
- * @param informationDisplayString
- * the string to be displayed when presenting the context
- * information
- */
- public AttributeContextInformation(String contextDisplayString, String informationDisplayString, HashMap attr2RangeMap) {
- this(null, contextDisplayString, informationDisplayString, attr2RangeMap);
- }
-
- /**
- * Maps (String -> Position). The attribute name to the Text position.
- *
- *
- */
- public HashMap getAttr2RangeMap() {
- return fAttr2RangeMap;
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.IContextInformation#getContextDisplayString()
- */
- public String getContextDisplayString() {
- if (fContextDisplayString != null) {
- return fContextDisplayString;
- }
- return fInformationDisplayString;
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.IContextInformationExtension#getContextInformationPosition()
- */
- public int getContextInformationPosition() {
- return fPosition;
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.IContextInformation#getImage()
- */
- public Image getImage() {
- return fImage;
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.IContextInformation#getInformationDisplayString()
- */
- public String getInformationDisplayString() {
- return fInformationDisplayString;
- }
-
- public void setContextInformationPosition(int position) {
- fPosition = position;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationPresenter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationPresenter.java
deleted file mode 100644
index acd660bb20..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationPresenter.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import java.util.HashMap;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-/**
- * Responsible for the presentation of the context info popup. This includes
- * text style, and when the window should close.
- *
- * @author pavery
- */
-public class AttributeContextInformationPresenter implements IContextInformationPresenter, IContextInformationValidator {
- private int fDocumentPosition = -1;
-
- private IContextInformation fInfo = null;
- private ContextInfoModelUtil fModelUtil = null;
- private ITextViewer fViewer = null;
-
- public AttributeContextInformationPresenter() {
- super();
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.IContextInformationValidator#install(org.eclipse.jface.text.contentassist.IContextInformation,
- * org.eclipse.jface.text.ITextViewer, int)
- */
- public void install(IContextInformation info, ITextViewer viewer, int documentPosition) {
- fInfo = info;
- fViewer = viewer;
- fDocumentPosition = documentPosition;
- fModelUtil = new ContextInfoModelUtil((IStructuredDocument) fViewer.getDocument());
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.IContextInformationValidator#isContextInformationValid(int)
- */
- public boolean isContextInformationValid(int documentPosition) {
- // determine whether or not this context info should still be
- // showing...
- // if cursor still within the element it's valid...
- boolean result = false;
- if (fModelUtil != null) {
- IStructuredDocumentRegion startRegion = fModelUtil.getXMLNode(fDocumentPosition).getStartStructuredDocumentRegion();
- int start = startRegion.getStartOffset();
- int end = startRegion.getEndOffset();
- result = (documentPosition < end) && (documentPosition > start + 1);
- }
- return result;
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int,
- * org.eclipse.jface.text.TextPresentation)
- */
- public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
- presentation.clear();
-
- if (!(fInfo instanceof AttributeContextInformation)) {
- return false;
- }
-
- // iterate existing attributes from current node
- IDOMNode xmlNode = fModelUtil.getXMLNode(documentPosition);
- IStructuredDocumentRegion sdRegion = xmlNode.getFirstStructuredDocumentRegion();
- ITextRegionList regions = sdRegion.getRegions();
- ITextRegion r = null;
- String attrName = ""; //$NON-NLS-1$
- Object temp = null;
- Position p = null;
- HashMap map = ((AttributeContextInformation) fInfo).getAttr2RangeMap();
-
- // so we can add ranges in order
- StyleRange[] sorted = new StyleRange[fInfo.getInformationDisplayString().length()];
- for (int i = 0; i < regions.size(); i++) {
- r = regions.get(i);
- if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
- attrName = sdRegion.getText(r);
- temp = map.get(attrName);
- if (temp != null) {
- p = (Position) temp;
- sorted[p.offset] = new StyleRange(p.offset, p.length, null, null, SWT.BOLD);
- }
- }
- }
- // style ranges need to be added in order
- StyleRange sr = null;
- for (int i = 0; i < sorted.length; i++) {
- sr = sorted[i];
- if (sr != null) {
- presentation.addStyleRange(sr);
- }
- }
- return true;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationProvider.java
deleted file mode 100644
index b005237ed9..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationProvider.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.contentassist.ContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMContent;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-/**
- * Calculates attribute context information based on a StructuedDocument and
- * document position.
- *
- * @author pavery
- */
-class AttributeContextInformationProvider {
- private final IContextInformation[] EMPTY_CONTEXT_INFO = new IContextInformation[0];
- private Comparator fComparator;
-
- private IStructuredDocument fDocument = null;
- private ContextInfoModelUtil fModelUtil = null;
-
- public AttributeContextInformationProvider(IStructuredDocument doc, AttributeContextInformationPresenter presenter) {
- fDocument = doc;
- fModelUtil = new ContextInfoModelUtil(fDocument);
- }
-
- /**
- * @param sdRegion
- *
- */
- private boolean canProposeInfo(IStructuredDocumentRegion sdRegion) {
- if ((sdRegion != null) && isEndTag(sdRegion)) {
- return false;
- }
- else {
- return true;
- }
- }
-
- public IContextInformation[] getAttributeInformation(int offset) {
- /*
- * need to take care of special cases w/ ambiguous regions <tag>|
- * </tag> also end tags..
- */
- IContextInformation[] results = EMPTY_CONTEXT_INFO;
-
- IStructuredDocumentRegion sdRegion = fModelUtil.getDocument().getRegionAtCharacterOffset(offset);
- if (!canProposeInfo(sdRegion)) {
- return EMPTY_CONTEXT_INFO;
- }
-
- IDOMNode node = fModelUtil.getXMLNode(offset);
- if (node != null) {
- switch (node.getNodeType()) {
- case Node.ELEMENT_NODE :
- results = getInfoForElement(node);
- break;
- // future...
- // case Node.TEXT_NODE :
- // results = getInfoForText(node);
- // break;
- }
- }
- return results;
- }
-
- /**
- * Returns a comparator that compares CMAttributeDeclaration names.
- *
- * the comparator
- */
- private Comparator getCMAttributeComparator() {
- if (fComparator == null) {
- fComparator = new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((CMAttributeDeclaration) o1).getAttrName().compareTo(((CMAttributeDeclaration) o2).getAttrName());
- }
- };
- }
- return fComparator;
- }
-
- /**
- * @param node
- *
- */
- private IContextInformation[] getInfoForElement(IDOMNode node) {
- IContextInformation[] results = EMPTY_CONTEXT_INFO;
- CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) node);
- if (decl != null) {
- CMNamedNodeMap attributes = decl.getAttributes();
-
- String attrContextString = node.getNodeName();
- StringBuffer attrInfo = new StringBuffer(" "); //$NON-NLS-1$
- String name = ""; //$NON-NLS-1$
- HashMap attrPosMap = new HashMap();
- int pos = 0;
- int length = 0;
- int numPerLine = 8;
-
- CMAttributeDeclaration[] sortedAttrs = getSortedAttributes(attributes);
-
- for (int i = 0; i < sortedAttrs.length; i++) {
- name = sortedAttrs[i].getAttrName();
- length = name.length();
- pos = attrInfo.length();
-
- attrInfo.append(name);
-
- if (sortedAttrs[i].getUsage() == CMAttributeDeclaration.REQUIRED) {
- attrInfo.append("*"); //$NON-NLS-1$
- length++;
- }
- if (i < attributes.getLength() - 1) {
- attrInfo.append(" "); //$NON-NLS-1$
- if ((i != 0) && (i % numPerLine == 0)) {
- attrInfo.append("\n "); //$NON-NLS-1$
- }
- }
- attrPosMap.put(name, new Position(pos, length));
- }
- if (!attrInfo.toString().trim().equals("")) {
- return new IContextInformation[]{new AttributeContextInformation(attrContextString, attrInfo.toString(), attrPosMap)};
- }
- }
- return results;
- }
-
- /**
- * @param node
- *
- */
- IContextInformation[] getInfoForText(IDOMNode node) {
- Node parent = node.getParentNode();
- String contextString = node.getNodeName();
- StringBuffer info = new StringBuffer(" "); //$NON-NLS-1$
- if ((parent != null) && (parent.getNodeType() == Node.ELEMENT_NODE)) {
- CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) parent);
- CMContent content = decl.getContent();
- if (content instanceof CMGroup) {
- CMGroup cmGroup = (CMGroup) content;
- CMNodeList children = cmGroup.getChildNodes();
- CMNode cmNode = null;
- for (int i = 0; i < children.getLength(); i++) {
- cmNode = children.item(i);
- contextString = cmNode.getNodeName();
- if (contextString != null) {
- info.append("<" + cmNode.getNodeName() + ">"); //$NON-NLS-1$ //$NON-NLS-2$
- if (i < children.getLength() - 1) {
- info.append(" "); //$NON-NLS-1$
- }
- }
- }
- }
- }
- if (!info.toString().trim().equals("")) {
- return new IContextInformation[]{new ContextInformation(contextString, info.toString())};
- }
- else {
- return EMPTY_CONTEXT_INFO;
- }
- }
-
- /**
- * Returns sorted array of CMAttributeDeclarations.
- *
- * @param attributes
- *
- */
- private CMAttributeDeclaration[] getSortedAttributes(CMNamedNodeMap attributes) {
- List sorted = new ArrayList();
- for (int i = 0; i < attributes.getLength(); i++) {
- sorted.add(attributes.item(i));
- }
- Collections.sort(sorted, getCMAttributeComparator());
- return (CMAttributeDeclaration[]) sorted.toArray(new CMAttributeDeclaration[sorted.size()]);
- }
-
- /**
- * @param sdRegion
- *
- */
- private boolean isEndTag(IStructuredDocumentRegion sdRegion) {
- ITextRegionList regions = sdRegion.getRegions();
- return regions.get(0).getType() == DOMRegionContext.XML_END_TAG_OPEN;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContentAssistRequest.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContentAssistRequest.java
deleted file mode 100644
index 6a1d3af534..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContentAssistRequest.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection;
-import org.eclipse.wst.sse.core.utils.StringUtils;
-import org.w3c.dom.Node;
-
-
-public class ContentAssistRequest {
- protected IStructuredDocumentRegion documentRegion = null;
- protected List macros = new ArrayList();
- protected String matchString;
- protected Node node = null;
- protected Node parent = null;
- protected List proposals = new ArrayList();
- protected ITextRegion region = null;
- protected int replacementBeginPosition;
- protected int replacementLength;
-
- // private Boolean separate = null; // (pa) not used
- // private Boolean sort = null; // (pa) not used
- /**
- * XMLContentAssistRequest constructor comment.
- */
- public ContentAssistRequest(Node node, Node parent, IStructuredDocumentRegion documentRegion, ITextRegion completionRegion, int begin, int length, String filter) {
- super();
- setNode(node);
- setParent(parent);
- setDocumentRegion(documentRegion);
- setRegion(completionRegion);
- setMatchString(filter);
- setReplacementBeginPosition(begin);
- setReplacementLength(length);
- }
-
- public void addMacro(ICompletionProposal newProposal) {
- macros.add(newProposal);
- }
-
- public void addProposal(ICompletionProposal newProposal) {
- proposals.add(newProposal);
- }
-
- public ICompletionProposal[] getCompletionProposals() {
- ICompletionProposal results[] = null;
- if ((getProposals().size() > 0) || (getMacros().size() > 0)) {
- List allProposals = new ArrayList();
- if (!shouldSeparate()) {
- allProposals.addAll(getProposals());
- // should be empty, as all macros should have gone into the
- // proposal list
- allProposals.addAll(getMacros());
- allProposals = sortProposals(allProposals);
- }
- else {
- allProposals.addAll(sortProposals(getProposals()));
- allProposals.addAll(sortProposals(getMacros()));
- }
-
- results = new ICompletionProposal[allProposals.size()];
- for (int i = 0; i < allProposals.size(); i++) {
- results[i] = (ICompletionProposal) allProposals.get(i);
- }
- }
- return results;
- }
-
-
- public IStructuredDocumentRegion getDocumentRegion() {
- return documentRegion;
- }
-
- /**
- *
- * @return java.util.List
- */
- public java.util.List getMacros() {
- return macros;
- }
-
- /**
- *
- * @return java.lang.String
- */
- public java.lang.String getMatchString() {
- return matchString;
- }
-
- /**
- *
- * @return org.w3c.dom.Node
- */
- public org.w3c.dom.Node getNode() {
- return node;
- }
-
- /**
- *
- * @return org.w3c.dom.Node
- */
- public org.w3c.dom.Node getParent() {
- return parent;
- }
-
- /**
- *
- * @return java.util.List
- */
- public java.util.List getProposals() {
- return proposals;
- }
-
- public ITextRegion getRegion() {
- return region;
- }
-
- /**
- *
- * @return int
- */
- public int getReplacementBeginPosition() {
- return replacementBeginPosition;
- }
-
- /**
- * @return int
- */
- public int getReplacementLength() {
- return replacementLength;
- }
-
- public int getStartOffset() {
- if ((getDocumentRegion() != null) && (getRegion() != null)) {
- return ((ITextRegionCollection) getDocumentRegion()).getStartOffset(getRegion());
- }
- return -1;
- }
-
- public String getText() {
- if ((getDocumentRegion() != null) && (getRegion() != null)) {
- return ((ITextRegionCollection) getDocumentRegion()).getText(getRegion());
- }
- return ""; //$NON-NLS-1$
- }
-
- public int getTextEndOffset() {
- if ((getDocumentRegion() != null) && (getRegion() != null)) {
- return ((ITextRegionCollection) getDocumentRegion()).getTextEndOffset(getRegion());
- }
- return -1;
- }
-
- /**
- * @param region
- */
- public void setDocumentRegion(IStructuredDocumentRegion region) {
- documentRegion = region;
- }
-
- /**
- *
- * @param newMatchString
- * java.lang.String
- */
- public void setMatchString(java.lang.String newMatchString) {
- matchString = newMatchString;
- }
-
- /**
- *
- * @param newNode
- * org.w3c.dom.Node
- */
- public void setNode(org.w3c.dom.Node newNode) {
- node = newNode;
- }
-
- /**
- *
- * @param newParent
- * org.w3c.dom.Node
- */
- public void setParent(org.w3c.dom.Node newParent) {
- parent = newParent;
- }
-
- /**
- *
- * @param newRegion
- */
- public void setRegion(ITextRegion newRegion) {
- region = newRegion;
- }
-
- /**
- *
- * @param newReplacementBeginPosition
- * int
- */
- public void setReplacementBeginPosition(int newReplacementBeginPosition) {
- replacementBeginPosition = newReplacementBeginPosition;
- }
-
-
- public void setReplacementLength(int newReplacementLength) {
- replacementLength = newReplacementLength;
- }
-
- public boolean shouldSeparate() {
- /*
- * if (separate == null) { PreferenceManager manager =
- * getPreferenceManager(); if(manager == null) { separate =
- * Boolean.FALSE; } else { Element caSettings =
- * manager.getElement(PreferenceNames.CONTENT_ASSIST); separate = new
- * Boolean(caSettings.getAttribute(PreferenceNames.SEPARATE).equals(PreferenceNames.TRUE)); } }
- * return separate.booleanValue();
- */
- return false;
- }
-
- protected List sortProposals(List proposalsIn) {
- Collections.sort(proposalsIn, new ProposalComparator());
- return proposalsIn;
-
- }
-
- /**
- *
- * @return java.lang.String
- */
- public java.lang.String toString() {
- return "Node: " + getNode() //$NON-NLS-1$
- + "\nParent: " + getParent() //$NON-NLS-1$
- + "\nStructuredDocumentRegion: " + StringUtils.escape(getDocumentRegion().toString()) //$NON-NLS-1$
- + "\nRegion: " + getRegion() //$NON-NLS-1$
- + "\nMatch string: '" + StringUtils.escape(getMatchString()) + "'" //$NON-NLS-2$//$NON-NLS-1$
- + "\nOffsets: [" + getReplacementBeginPosition() + "-" + (getReplacementBeginPosition() + getReplacementLength()) + "]\n"; //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContextInfoModelUtil.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContextInfoModelUtil.java
deleted file mode 100644
index a48e75337b..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContextInfoModelUtil.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-
-
-/**
- * @author pavery
- */
-public class ContextInfoModelUtil {
- IStructuredDocument fDocument = null;
-
- ContextInfoModelUtil(IStructuredDocument doc) {
- fDocument = doc;
- }
-
- public IStructuredDocument getDocument() {
- return fDocument;
- }
-
- public ModelQuery getModelQuery() {
- ModelQuery mq = null;
-
- IStructuredModel xmlModel = null;
- try {
- xmlModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
- mq = ModelQueryUtil.getModelQuery(xmlModel);
- }
- finally {
- if (xmlModel != null) {
- xmlModel.releaseFromRead();
- }
- }
- return mq;
- }
-
- public IDOMNode getXMLNode(int offset) {
- IStructuredModel xmlModel = null;
- IDOMNode xmlNode = null;
- try {
- xmlModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
- xmlNode = (IDOMNode) xmlModel.getIndexedRegion(offset);
- }
- finally {
- if (xmlModel != null)
- xmlModel.releaseFromRead();
- }
- return xmlNode;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/CustomTemplateProposal.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/CustomTemplateProposal.java
deleted file mode 100644
index f19dd90858..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/CustomTemplateProposal.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.templates.Template;
-import org.eclipse.jface.text.templates.TemplateContext;
-import org.eclipse.jface.text.templates.TemplateProposal;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.wst.sse.core.utils.StringUtils;
-import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal;
-
-/**
- * Purpose of this class is to make the additional proposal info into content
- * fit for an HTML viewer (by escaping characters)
- */
-class CustomTemplateProposal extends TemplateProposal implements IRelevanceCompletionProposal {
- // copies of this class exist in:
- // org.eclipse.jst.jsp.ui.internal.contentassist
- // org.eclipse.wst.html.ui.internal.contentassist
- // org.eclipse.wst.xml.ui.internal.contentassist
-
- public CustomTemplateProposal(Template template, TemplateContext context, IRegion region, Image image, int relevance) {
- super(template, context, region, image, relevance);
- }
-
- public String getAdditionalProposalInfo() {
- String additionalInfo = super.getAdditionalProposalInfo();
- return StringUtils.convertToHTMLContent(additionalInfo);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NoRegionContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NoRegionContentAssistProcessor.java
deleted file mode 100644
index 57744f39bd..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NoRegionContentAssistProcessor.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-
-
-import java.util.HashMap;
-import java.util.Iterator;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.ui.internal.IReleasable;
-import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
-import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.eclipse.wst.xml.core.text.IXMLPartitions;
-
-
-/**
- * ContentAssistProcessor to handle special cases in content assist where the
- * partitioner cannot determine a partition type at the current cursor
- * position (usually at EOF).
- *
- * @author pavery
- */
-public class NoRegionContentAssistProcessor implements IContentAssistProcessor, IReleasable {
-
- private static final boolean DEBUG = false;
- protected char completionProposalAutoActivationCharacters[] = null;
- protected char contextInformationAutoActivationCharacters[] = null;
-
- private final ICompletionProposal[] EMPTY_PROPOSAL_SET = new ICompletionProposal[0];
- protected String fErrorMessage = null;
- private HashMap fNameToProcessorMap = null;
- private HashMap fPartitionToProcessorMap = null;
-
- public NoRegionContentAssistProcessor() {
- super();
- }
-
- protected void addPartitionProcessor(String key, IContentAssistProcessor processor) {
- addProcessor(getPartitionToProcessorMap(), key, processor);
- }
-
- protected void addNameProcessor(String key, IContentAssistProcessor processor) {
- addProcessor(getNameToProcessorMap(), key, processor);
- }
-
- protected IContentAssistProcessor getPartitionProcessor(String key) {
- return (IContentAssistProcessor) getPartitionToProcessorMap().get(key);
- }
-
- /**
- * Ensures release if it's a duplicate partition type.
- *
- * @param map
- * @param key
- * @param processor
- */
- private void addProcessor(HashMap map, String key, IContentAssistProcessor processor) {
- Object o = map.remove(key);
- if (o != null) {
- if (o instanceof IReleasable) {
- ((IReleasable) o).release();
- }
- }
- map.put(key, processor);
- }
-
- /**
- * Figures out what the correct ICompletionProposalProcessor is and
- * computesCompletionProposals on that.
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
- * int)
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
- IContentAssistProcessor p = null;
- ICompletionProposal[] results = EMPTY_PROPOSAL_SET;
-
- p = guessContentAssistProcessor(viewer, documentOffset);
- if (p != null) {
- results = p.computeCompletionProposals(viewer, documentOffset);
- }
-
- return (results != null) ? results : EMPTY_PROPOSAL_SET;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer,
- * int)
- */
- public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
- // get context info from processor that we end up using...
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
- */
- public char[] getCompletionProposalAutoActivationCharacters() {
- return completionProposalAutoActivationCharacters;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
- */
- public char[] getContextInformationAutoActivationCharacters() {
- return contextInformationAutoActivationCharacters;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
- */
- public IContextInformationValidator getContextInformationValidator() {
- // return the validator for the content assist processor that we
- // used...
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
- */
- public String getErrorMessage() {
- return fErrorMessage;
- }
-
- private HashMap getNameToProcessorMap() {
- if (fNameToProcessorMap == null) {
- fNameToProcessorMap = new HashMap();
- initNameToProcessorMap();
- }
- return fNameToProcessorMap;
- }
-
- private HashMap getPartitionToProcessorMap() {
- if (fPartitionToProcessorMap == null) {
- fPartitionToProcessorMap = new HashMap();
- initPartitionToProcessorMap();
- }
- return fPartitionToProcessorMap;
- }
-
- /**
- * Gives you the document partition type (String) for the given
- * StructuredTextViewer and documentPosition.
- *
- * @param viewer
- * @param documentPosition
- * @return String
- */
- protected String getPartitionType(StructuredTextViewer viewer, int documentPosition) {
- IDocument document = viewer.getDocument();
- String partitionType = null;
- ITypedRegion partition = null;
- try {
- partition = document.getPartition(documentPosition);
- partitionType = partition.getType();
- }
- catch (BadLocationException e) {
- partitionType = null;
- }
- return partitionType;
- }
-
- /**
- * Guesses a ContentAssistProcessor based on the TextViewer and
- * documentOffset.
- *
- * @param viewer
- * @param documentOffset
- */
- protected IContentAssistProcessor guessContentAssistProcessor(ITextViewer viewer, int documentOffset) {
- // mapping logic here...
- // look @ previous region
- // look @ previous doc partition type
- // look @ page language
- IContentAssistProcessor p = null;
- IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(viewer, documentOffset);
- if (sdRegion != null) {
- String currentRegionType = sdRegion.getType();
- // System.out.println("current region type is >> " +
- // currentRegionType);
- if (currentRegionType == DOMRegionContext.UNDEFINED) {
- IStructuredDocumentRegion sdPrev = sdRegion.getPrevious();
- if (sdPrev != null) {
- if (DEBUG) {
- String prevRegionType = sdPrev.getType();
- System.out.println("previous region type is >> " + prevRegionType); //$NON-NLS-1$
- }
- }
- }
- }
- // working w/ viewer & document partition
- if ((p == null) && (viewer.getDocument().getLength() > 0)) {
- String prevPartitionType = getPartitionType((StructuredTextViewer) viewer, documentOffset - 1);
- // System.out.println("previous partition type is > " +
- // prevPartitionType);
- p = (IContentAssistProcessor) getPartitionToProcessorMap().get(prevPartitionType);
- }
- return p;
- }
-
- /**
- * Inits map for extra ContentAssistProcessors (useBean, get/setProperty)
- */
- protected void initNameToProcessorMap() {
- // nothing to do in this case
- }
-
- /**
- * Adds all relevent ContentAssistProcessors to the partition to processor
- * map (just XML here)
- */
- protected void initPartitionToProcessorMap() {
- XMLContentAssistProcessor xmlProcessor = new XMLContentAssistProcessor();
- addProcessor(getPartitionToProcessorMap(), IXMLPartitions.XML_DEFAULT, xmlProcessor);
- }
-
- public void release() {
- releasePartitionToProcessorMap();
- releaseNameToProcessorMap();
- }
-
- protected void releaseMap(HashMap map) {
- if ((map != null) && !map.isEmpty()) {
- Iterator it = map.keySet().iterator();
- Object key = null;
- while (it.hasNext()) {
- key = it.next();
- if (map.get(key) instanceof IReleasable) {
- ((IReleasable) map.get(key)).release();
- }
- }
- map.clear();
- map = null;
- }
- }
-
- protected void releaseNameToProcessorMap() {
- releaseMap(fNameToProcessorMap);
- }
-
- protected void releasePartitionToProcessorMap() {
- releaseMap(fPartitionToProcessorMap);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NonValidatingModelQueryAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NonValidatingModelQueryAction.java
deleted file mode 100644
index 24a397dcf6..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NonValidatingModelQueryAction.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-
-public class NonValidatingModelQueryAction implements org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction {
-
- protected CMNode cmnode = null;
- protected int endIndex = 0;
- protected int kind = INSERT;
- protected int startIndex = 0;
- protected Object userData = null;
-
- /**
- * NonValidatingModelQueryAction constructor comment.
- */
- protected NonValidatingModelQueryAction() {
- super();
- }
-
- /**
- * NonValidatingModelQueryAction constructor comment.
- */
- public NonValidatingModelQueryAction(CMNode newChild, int newKind, int newStart, int newEnd, Object newUserData) {
- super();
- cmnode = newChild;
- kind = newKind;
- startIndex = newStart;
- endIndex = newEnd;
- userData = newUserData;
- }
-
- /**
- * getCMNode method comment.
- */
- public org.eclipse.wst.xml.core.internal.contentmodel.CMNode getCMNode() {
- return cmnode;
- }
-
- /**
- *
- * @return int
- */
- public int getEndIndex() {
- return endIndex;
- }
-
- /**
- *
- * @return int
- */
- public int getKind() {
- return kind;
- }
-
- /**
- * getParent method comment.
- */
- public org.w3c.dom.Node getParent() {
- return null;
- }
-
- /**
- *
- * @return int
- */
- public int getStartIndex() {
- return startIndex;
- }
-
- /**
- * getUserData method comment.
- */
- public Object getUserData() {
- return null;
- }
-
- /**
- * performAction method comment.
- */
- public void performAction() {
- }
-
- /**
- * setCMNode method comment.
- */
- protected void setCMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode newNode) {
- cmnode = newNode;
- }
-
- /**
- *
- * @param newEndIndex
- * int
- */
- protected void setEndIndex(int newEndIndex) {
- endIndex = newEndIndex;
- }
-
- /**
- *
- * @param newKind
- * int
- */
- protected void setKind(int newKind) {
- kind = newKind;
- }
-
- /**
- *
- * @param newStartIndex
- * int
- */
- protected void setStartIndex(int newStartIndex) {
- startIndex = newStartIndex;
- }
-
- /**
- * setUserData method comment.
- */
- public void setUserData(Object object) {
- }
-
- /**
- *
- * @return java.lang.String
- */
- public String toString() {
- String actionName = null;
- switch (kind) {
- case INSERT :
- actionName = "INSERT";//$NON-NLS-1$
- break;
- case REMOVE :
- actionName = "REMOVE";//$NON-NLS-1$
- break;
- case REPLACE :
- actionName = "REPLACE";//$NON-NLS-1$
- break;
- default :
- actionName = "UNKNOWN ACTION ";//$NON-NLS-1$
- }
- String nodeName = (cmnode != null) ? getCMNode().getNodeName() : "(unknown)";//$NON-NLS-1$
- return actionName + "=" + nodeName + "(" + startIndex + "..." + endIndex + ")";//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ProposalComparator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ProposalComparator.java
deleted file mode 100644
index ee6e8e8a66..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ProposalComparator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-
-
-import java.util.Comparator;
-
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal;
-
-
-public class ProposalComparator implements Comparator {
-
-
- public int compare(Object o1, Object o2) {
- int relevance = 0;
- if ((o1 instanceof IRelevanceCompletionProposal) && (o2 instanceof IRelevanceCompletionProposal)) {
- // sort based on relevance
- IRelevanceCompletionProposal cp1 = (IRelevanceCompletionProposal) o1;
- IRelevanceCompletionProposal cp2 = (IRelevanceCompletionProposal) o2;
-
- relevance = cp2.getRelevance() - cp1.getRelevance();
-
- // if same relevance, secondary sort (lexigraphically)
- if ((relevance == 0) && (o1 instanceof ICompletionProposal) && (o2 instanceof ICompletionProposal)) {
- String displayString1 = ((ICompletionProposal) o1).getDisplayString();
- String displayString2 = ((ICompletionProposal) o2).getDisplayString();
- if ((displayString1 != null) && (displayString2 != null)) {
- // relevance = displayString1.compareTo(displayString2);
- // // this didn't mix caps w/ lowercase
- relevance = com.ibm.icu.text.Collator.getInstance().compare(displayString1, displayString2);
- }
- }
- }
- // otherwise if it's not ISEDRelevanceCompletionProposal, don't sort
- return relevance;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java
deleted file mode 100644
index c371494694..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ReplaceNameTemplateContext.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.templates.DocumentTemplateContext;
-import org.eclipse.jface.text.templates.Template;
-import org.eclipse.jface.text.templates.TemplateBuffer;
-import org.eclipse.jface.text.templates.TemplateContextType;
-import org.eclipse.jface.text.templates.TemplateException;
-
-/**
- * Just like DocumentTemplateContext except if an insert offset is passed in,
- * during evaluation, the "prefix" before the template will be checked to see
- * if it matches the template name. If so, overwrite the template name.
- * Otherwise, just insert the template at the insert offset location (by not
- * overwriting the prefix text)
- */
-public class ReplaceNameTemplateContext extends DocumentTemplateContext {
- private int fInsertOffset = -1;
-
- /**
- * Creates a document template context.
- *
- * @param type
- * the context type
- * @param document
- * the document this context applies to
- * @param offset
- * the offset of the document region
- * @param length
- * the length of the document region
- */
- public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, int offset, int length) {
- this(type, document, new Position(offset, length));
- }
-
- /**
- * Creates a document template context. The supplied <code>Position</code>
- * will be queried to compute the <code>getStart</code> and
- * <code>getEnd</code> methods, which will therefore answer updated
- * position data if it is registered with the document.
- *
- * @param type
- * the context type
- * @param document
- * the document this context applies to
- * @param position
- * the position describing the area of the document which forms
- * the template context
- * @since 3.1
- */
- public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, Position position) {
- super(type, document, position);
- }
-
- /**
- * Creates a document template context.
- *
- * @param type
- * the context type
- * @param document
- * the document this context applies to
- * @param offset
- * the offset of the document region
- * @param length
- * the length of the document region
- * @param insertOffset
- * the offset of the document region where insert was
- * originally requested
- */
- public ReplaceNameTemplateContext(TemplateContextType type, IDocument document, int offset, int length, int insertOffset) {
- this(type, document, new Position(offset, length));
- fInsertOffset = insertOffset;
- }
-
- /*
- * @see org.eclipse.jface.text.templates.TemplateContext#evaluate(org.eclipse.jface.text.templates.Template)
- */
- public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
- TemplateBuffer buffer = super.evaluate(template);
- if (buffer != null) {
- if ((fInsertOffset > -1) && (fInsertOffset > getStart())) {
- String prefix = getDocument().get(getStart(), fInsertOffset - getStart());
- if (!template.getName().startsWith(prefix)) {
- // generate a new buffer that actually contains the
- // text that was going to be overwritten
- buffer = new TemplateBuffer(prefix + buffer.getString(), buffer.getVariables());
- }
- }
- }
- return buffer;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SimpleCMElementDeclaration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SimpleCMElementDeclaration.java
deleted file mode 100644
index 41a607aa0e..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SimpleCMElementDeclaration.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-
-
-public class SimpleCMElementDeclaration implements org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration {
-
- String fNodeName;
-
- /**
- * SimpleCMELementDeclaration constructor comment.
- */
- public SimpleCMElementDeclaration() {
- super();
- }
-
- public SimpleCMElementDeclaration(String nodeName) {
- super();
- setNodeName(nodeName);
- }
-
- /**
- * getAttributes method
- *
- * @return CMNamedNodeMap
- *
- * Returns CMNamedNodeMap of AttributeDeclaration
- */
- public org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap getAttributes() {
- return null;
- }
-
- /**
- * getCMContent method
- *
- * @return CMContent
- *
- * Returns the root node of this element's content model. This can be an
- * CMElementDeclaration or a CMGroup
- */
- public org.eclipse.wst.xml.core.internal.contentmodel.CMContent getContent() {
- return null;
- }
-
- /**
- * getContentType method
- *
- * @return int
- *
- * Returns one of : ANY, EMPTY, ELEMENT, MIXED, PCDATA, CDATA.
- */
- public int getContentType() {
- return 0;
- }
-
- /**
- * getDataType method
- *
- * @return java.lang.String
- */
- public org.eclipse.wst.xml.core.internal.contentmodel.CMDataType getDataType() {
- return null;
- }
-
- /**
- * getElementName method
- *
- * @return java.lang.String
- */
- public String getElementName() {
- return null;
- }
-
- /**
- * getLocalElements method
- *
- * @return CMNamedNodeMap
- *
- * Returns a list of locally defined elements.
- */
- public org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap getLocalElements() {
- return null;
- }
-
- /**
- * getMaxOccur method
- *
- * @return int
- *
- * If -1, it's UNBOUNDED.
- */
- public int getMaxOccur() {
- return 0;
- }
-
- /**
- * getMinOccur method
- *
- * @return int
- *
- * If 0, it's OPTIONAL. If 1, it's REQUIRED.
- */
- public int getMinOccur() {
- return 0;
- }
-
- /**
- *
- * @return java.lang.String
- */
- public java.lang.String getNodeName() {
- return fNodeName;
- }
-
- /**
- * getNodeType method
- *
- * @return int
- *
- * Returns one of :
- *
- */
- public int getNodeType() {
- return 0;
- }
-
- /**
- * getProperty method
- *
- * @return java.lang.Object
- *
- * Returns the object property desciped by the propertyName
- *
- */
- public Object getProperty(String propertyName) {
- return null;
- }
-
- /**
- *
- * @param newNodeName
- * java.lang.String
- */
- public void setNodeName(java.lang.String newNodeName) {
- fNodeName = newNodeName;
- }
-
- /**
- * supports method
- *
- * @return boolean
- *
- * Returns true if the CMNode supports a specified property
- *
- */
- public boolean supports(String propertyName) {
- return false;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SourceEditorImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SourceEditorImageHelper.java
deleted file mode 100644
index fe16777023..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SourceEditorImageHelper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-
-
-/**
- * @deprecated use internal XMLEditorPluginImageHelper or external
- * SharedXMLEditorPluginImageHelper instead
- */
-public class SourceEditorImageHelper {
-
- public SourceEditorImageHelper() {
- super();
- }
-
- public Image createImage(String resource) {
- ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(XMLUIPlugin.ID, resource);
- Image image = desc.createImage();
- JFaceResources.getImageRegistry().put(resource, image);
- return image;
- }
-
- public Image getImage(String resource) {
- Image image = JFaceResources.getImageRegistry().get(resource);
- if (image == null) {
- image = createImage(resource);
- }
- return image;
- }
-
-
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java
deleted file mode 100644
index 252c04c5fb..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames;
-import org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeIdsXML;
-
-public class XMLContentAssistProcessor extends AbstractContentAssistProcessor implements IPropertyChangeListener {
-
- protected IPreferenceStore fPreferenceStore = null;
- protected IResource fResource = null;
- private XMLTemplateCompletionProcessor fTemplateProcessor = null;
- private List fTemplateContexts = new ArrayList();
-
- public XMLContentAssistProcessor() {
- super();
- }
-
- protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) {
- addTemplates(contentAssistRequest, TemplateContextTypeIdsXML.ATTRIBUTE);
- super.addAttributeNameProposals(contentAssistRequest);
- }
-
- protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) {
- addTemplates(contentAssistRequest, TemplateContextTypeIdsXML.ATTRIBUTE_VALUE);
- super.addAttributeValueProposals(contentAssistRequest);
- }
-
- protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) {
- addTemplates(contentAssistRequest, TemplateContextTypeIdsXML.NEW);
- super.addEmptyDocumentProposals(contentAssistRequest);
- }
-
- protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) {
- addTemplates(contentAssistRequest, TemplateContextTypeIdsXML.TAG);
- super.addTagInsertionProposals(contentAssistRequest, childPosition);
- }
-
- /**
- * Adds templates to the list of proposals
- *
- * @param contentAssistRequest
- * @param context
- */
- private void addTemplates(ContentAssistRequest contentAssistRequest, String context) {
- addTemplates(contentAssistRequest, context, contentAssistRequest.getReplacementBeginPosition());
- }
-
- /**
- * Adds templates to the list of proposals
- *
- * @param contentAssistRequest
- * @param context
- * @param startOffset
- */
- private void addTemplates(ContentAssistRequest contentAssistRequest, String context, int startOffset) {
- if (contentAssistRequest == null) {
- return;
- }
-
- // if already adding template proposals for a certain context type, do
- // not add again
- if (!fTemplateContexts.contains(context)) {
- fTemplateContexts.add(context);
- boolean useProposalList = !contentAssistRequest.shouldSeparate();
-
- if (getTemplateCompletionProcessor() != null) {
- getTemplateCompletionProcessor().setContextType(context);
- ICompletionProposal[] proposals = getTemplateCompletionProcessor().computeCompletionProposals(fTextViewer, startOffset);
- for (int i = 0; i < proposals.length; ++i) {
- if (useProposalList) {
- contentAssistRequest.addProposal(proposals[i]);
- }
- else {
- contentAssistRequest.addMacro(proposals[i]);
- }
- }
- }
- }
- }
-
- protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) {
- ContentAssistRequest request = super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
- // bug115927 use original document position for all/any region
- // templates
- addTemplates(request, TemplateContextTypeIdsXML.ALL, documentPosition);
- return request;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.xml.ui.contentassist.AbstractContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
- * int)
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer textViewer, int documentPosition) {
- fTemplateContexts.clear();
- return super.computeCompletionProposals(textViewer, documentPosition);
- }
-
- protected IPreferenceStore getPreferenceStore() {
- if (fPreferenceStore == null) {
- fPreferenceStore = XMLUIPlugin.getDefault().getPreferenceStore();
- }
- return fPreferenceStore;
- }
-
- private XMLTemplateCompletionProcessor getTemplateCompletionProcessor() {
- if (fTemplateProcessor == null) {
- fTemplateProcessor = new XMLTemplateCompletionProcessor();
- }
- return fTemplateProcessor;
- }
-
- protected void init() {
- getPreferenceStore().addPropertyChangeListener(this);
- reinit();
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- String property = event.getProperty();
-
- if ((property.compareTo(XMLUIPreferenceNames.AUTO_PROPOSE) == 0) || (property.compareTo(XMLUIPreferenceNames.AUTO_PROPOSE_CODE) == 0)) {
- reinit();
- }
- }
-
- protected void reinit() {
- String key = XMLUIPreferenceNames.AUTO_PROPOSE;
- boolean doAuto = getPreferenceStore().getBoolean(key);
- if (doAuto) {
- key = XMLUIPreferenceNames.AUTO_PROPOSE_CODE;
- completionProposalAutoActivationCharacters = getPreferenceStore().getString(key).toCharArray();
- }
- else {
- completionProposalAutoActivationCharacters = null;
- }
- }
-
- public void release() {
- super.release();
- getPreferenceStore().removePropertyChangeListener(this);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistUtilities.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistUtilities.java
deleted file mode 100644
index 4aa4b346c8..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistUtilities.java
+++ /dev/null
@@ -1,516 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-import org.eclipse.wst.sse.core.internal.util.ScriptLanguageKeys;
-import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
-import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-/**
- * @author pavery
- */
-public class XMLContentAssistUtilities extends ContentAssistUtils {
-
- /**
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- private class DOMJSPRegionContextsPrivateCopy {
- private static final String JSP_CLOSE = "JSP_CLOSE"; //$NON-NLS-1$
- private static final String JSP_DECLARATION_OPEN = "JSP_DECLARATION_OPEN"; //$NON-NLS-1$
- private static final String JSP_SCRIPTLET_OPEN = "JSP_SCRIPTLET_OPEN"; //$NON-NLS-1$
- private static final String JSP_EXPRESSION_OPEN = "JSP_EXPRESSION_OPEN"; //$NON-NLS-1$
-
- }
-
-
- public static final String CONTENT = "Content"; //$NON-NLS-1$
- public static final String CONTENT_SCRIPT_TYPE = "Content-Script-Type"; //$NON-NLS-1$
- public static final String HEAD = "HEAD"; //$NON-NLS-1$
- public static final String HTML = "HTML"; //$NON-NLS-1$
- public static final String HTTP_EQUIV = "HTTP-EQUIV"; //$NON-NLS-1$
- public static final String META = "META"; //$NON-NLS-1$
-
- /**
- * A convenience method for getting the closing proposal given the
- * contents (IndexedRegion) of a tag that is started, but possibly not
- * ended
- *
- * @param viewer
- * the text viewer
- * @param documentPosition
- * the cursor position in the viewer
- * @param indexedNode
- * the contents of the tag that is started but possibly not
- * ended
- * @param parentTagName
- * the tag on which you are checkin for an ending tag
- * @param imagePath
- * content assist image relative path
- * @return ICompletionProposal
- */
- public static ICompletionProposal computeJSPEndTagProposal(ITextViewer viewer, int documentPosition, IndexedRegion indexedNode, String parentTagName, String imagePath) {
- ICompletionProposal p = null;
-
- // check if tag is closed
- boolean hasEndTag = true;
- boolean isJSPTag = false;
- IDOMNode xnode = null;
- String tagName = ""; //$NON-NLS-1$
- if (indexedNode instanceof IDOMNode) {
- xnode = ((IDOMNode) indexedNode);
- // it's ended already...
- if (xnode.getEndStructuredDocumentRegion() != null) {
- return null;
- }
- IDOMNode openNode = null;
- if (!xnode.getNodeName().equalsIgnoreCase(parentTagName)) {
- openNode = (IDOMNode) xnode.getParentNode();
- }
- if (openNode != null) {
- if (openNode instanceof IDOMElement) {
- isJSPTag = ((IDOMElement) openNode).isJSPTag();
- }
- tagName = openNode.getNodeName();
- hasEndTag = (openNode.getEndStructuredDocumentRegion() != null);
- }
- }
-
- // it's closed, don't add close tag proposal
- if (!hasEndTag && !isJSPTag) {
-
- // create appropriate close tag text
- String proposedText = "</" + tagName; //$NON-NLS-1$
- String viewerText = viewer.getTextWidget().getText();
- if ((viewerText.length() >= documentPosition) && (viewerText.length() >= 2) && (documentPosition >= 2)) {
- String last2chars = viewerText.substring(documentPosition - 2, documentPosition);
- if (last2chars.endsWith("</")) {
- proposedText = tagName;
- }
- else if (last2chars.endsWith("<")) {
- proposedText = "/" + tagName; //$NON-NLS-1$
- }
- }
-
- // create proposal
- p = new CustomCompletionProposal(proposedText + ">", //$NON-NLS-1$
- documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), NLS.bind(XMLUIMessages.End_with_, (new Object[]{proposedText})), null, null, XMLRelevanceConstants.R_END_TAG);
- }
- else if (!hasEndTag && isJSPTag) {
-
- // create appropriate close tag text
- String proposedText = "%"; //$NON-NLS-1$
- String viewerText = viewer.getTextWidget().getText();
-
- // TODO (pa) make it smarter to add "%>" or just ">" if % is
- // already there...
- if ((viewerText.length() >= documentPosition) && (viewerText.length() >= 2)) {
- String last2chars = viewerText.substring(documentPosition - 2, documentPosition);
- String lastchar = viewerText.substring(documentPosition - 1, documentPosition);
- if (lastchar.equals("%")) //$NON-NLS-1$
- {
- if (last2chars.endsWith("<%")) {
- proposedText = "%"; //$NON-NLS-1$
- }
- else {
- proposedText = ""; //$NON-NLS-1$
- }
- }
- }
-
- // create proposal
- p = new CustomCompletionProposal(proposedText + ">", //$NON-NLS-1$
- documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), NLS.bind(XMLUIMessages.End_with_, (new Object[]{proposedText})), null, null, XMLRelevanceConstants.R_END_TAG);
- }
-
- return p;
- }
-
-
- /**
- * A convenience method for getting the closing proposal given the
- * contents (IndexedRegion) of a tag that is started, but possibly not
- * ended
- *
- * @param viewer
- * the text viewer
- * @param documentPosition
- * the cursor position in the viewer
- * @param indexedNode
- * the contents of the tag that is started but possibly not
- * ended
- * @param parentTagName
- * the tag on which you are checkin for an ending tag
- * @param imagePath
- * content assist relative image path
- * @return ICompletionProposal
- */
- public static ICompletionProposal computeXMLEndTagProposal(ITextViewer viewer, int documentPosition, IndexedRegion indexedNode, String parentTagName, String imagePath) {
- ICompletionProposal p = null;
-
- // check if tag is closed
- boolean hasEndTag = true;
- IDOMNode xnode = null;
- String tagName = ""; //$NON-NLS-1$
- if (indexedNode instanceof IDOMNode) {
- xnode = ((IDOMNode) indexedNode);
- // it's ended already...
- if (xnode.getEndStructuredDocumentRegion() != null) {
- return null;
- }
- IDOMNode styleNode = null;
- if (!xnode.getNodeName().equalsIgnoreCase(parentTagName)) {
- styleNode = (IDOMNode) xnode.getParentNode();
- }
- if (styleNode != null) {
- tagName = styleNode.getNodeName();
- hasEndTag = (styleNode.getEndStructuredDocumentRegion() != null);
- }
- }
-
- // it's closed, don't add close tag proposal
- if (!hasEndTag) {
-
- // create appropriate close tag text
- String proposedText = "</" + tagName; //$NON-NLS-1$
- String viewerText = viewer.getTextWidget().getText();
- if ((viewerText.length() >= documentPosition) && (viewerText.length() >= 2) && (documentPosition >= 2)) {
- String last2chars = viewerText.substring(documentPosition - 2, documentPosition);
- if (last2chars.endsWith("</")) {
- proposedText = tagName;
- }
- else if (last2chars.endsWith("<")) {
- proposedText = "/" + tagName; //$NON-NLS-1$
- }
- }
-
- // create proposal
- p = new CustomCompletionProposal(proposedText + ">", //$NON-NLS-1$
- documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), NLS.bind(XMLUIMessages.End_with_, (new Object[]{proposedText})), null, null, XMLRelevanceConstants.R_END_TAG);
- }
- return p;
- }
-
- private static String getMetaScriptType(Document doc) {
- // Can not just do a Document.getElementsByTagName(String) as this
- // needs
- // to be relatively fast.
- List metas = new ArrayList();
- // check for META tags under the Document
- Node html = null;
- Node head = null;
- Node child = null;
- // ----------------------------------------------------------------------
- // (pa) 20021217
- // cmvc defect 235554
- // performance enhancement: using child.getNextSibling() rather than
- // nodeList(item) for O(n) vs. O(n*n)
- // ----------------------------------------------------------------------
-
- for (child = doc.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- }
- if (child.getNodeName().equalsIgnoreCase(META)) {
- metas.add(child);
- }
- else if (child.getNodeName().equalsIgnoreCase(HTML)) {
- html = child;
- }
- }
- // NodeList children = doc.getChildNodes();
- // for(int i = 0; i < children.getLength(); i++) {
- // child = children.item(i);
- // if(child.getNodeType() != Node.ELEMENT_NODE)
- // continue;
- // if(child.getNodeName().equalsIgnoreCase(META))
- // metas.add(child);
- // else if(child.getNodeName().equalsIgnoreCase(HTML))
- // html = child;
- // }
-
- // check for META tags under HEAD
- if (html != null) {
- for (child = html.getFirstChild(); (child != null) && (head == null); child = child.getNextSibling()) {
- if (child.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- }
- if (child.getNodeName().equalsIgnoreCase(HEAD)) {
- head = child;
- }
- }
- // children = html.getChildNodes();
- // for(int i = 0; i < children.getLength() && head == null; i++) {
- // child = children.item(i);
- // if(child.getNodeType() != Node.ELEMENT_NODE)
- // continue;
- // if(child.getNodeName().equalsIgnoreCase(HEAD))
- // head = child;
- // }
- }
-
- if (head != null) {
- for (head.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- }
- if (child.getNodeName().equalsIgnoreCase(META)) {
- metas.add(child);
- }
- }
- // children = head.getChildNodes();
- // for(int i = 0 ; i < children.getLength(); i++) {
- // child = children.item(i);
- // if(child.getNodeType() != Node.ELEMENT_NODE)
- // continue;
- // if(child.getNodeName().equalsIgnoreCase(META))
- // metas.add(child);
- // }
- }
-
- return getMetaScriptType(metas);
- }
-
- private static String getMetaScriptType(List metaNodeList) {
- Node meta = null;
- NamedNodeMap attributes = null;
- boolean httpEquiv = false;
- String contentScriptType = null;
-
- for (int i = metaNodeList.size() - 1; i >= 0; i--) {
- meta = (Node) metaNodeList.get(i);
- attributes = meta.getAttributes();
- httpEquiv = false;
- contentScriptType = null;
- for (int j = 0; j < attributes.getLength(); j++) {
- if (attributes.item(j).getNodeName().equalsIgnoreCase(HTTP_EQUIV)) {
- httpEquiv = attributes.item(j).getNodeValue().equalsIgnoreCase(CONTENT_SCRIPT_TYPE);
- }
- else if (attributes.item(j).getNodeName().equalsIgnoreCase(CONTENT)) {
- contentScriptType = attributes.item(j).getNodeValue();
- }
- }
- if (httpEquiv && (contentScriptType != null)) {
- return contentScriptType;
- }
- }
- return null;
- }
-
- /**
- * Returns the scripting language the scriptNode is in Currently returns
- * javascript unless some unknown type or language is specified. Then the
- * unknown type/language is returned
- *
- * @param scriptNode
- */
- public static String getScriptLanguage(Node scriptNode) {
- Node attr = null;
-
- boolean specified = false;
- // try to find a scripting adapter for 'type'
- if ((scriptNode == null) || (scriptNode.getAttributes() == null)) {
- return null;
- }
-
- attr = scriptNode.getAttributes().getNamedItem("type");//$NON-NLS-1$
- if (attr != null) {
- specified = true;
- String type = attr.getNodeValue();
- return lookupScriptType(type);
- }
- // now try to find a scripting adapter for 'language' (deprecated by
- // HTML specifications)
- attr = scriptNode.getAttributes().getNamedItem("language");//$NON-NLS-1$
- if (attr != null) {
- specified = true;
- String language = attr.getNodeValue();
- return lookupScriptLanguage(language);
- }
- // check if one is specified by a META tag at the root level or inside
- // of HEAD
- String type = null;
- if (!specified) {
- type = getMetaScriptType(scriptNode.getOwnerDocument());
- }
- if (type != null) {
- specified = true;
- return lookupScriptType(type);
- }
- // return default
- if (!specified) {
- return ScriptLanguageKeys.JAVASCRIPT;
- }
- return null;
- }
-
- /**
- * Tells you if the flatnode is the %> delimiter
- *
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- public static boolean isJSPCloseDelimiter(IStructuredDocumentRegion fn) {
- if (fn == null) {
- return false;
- }
- return isJSPCloseDelimiter(fn.getType());
- }
-
- /**
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- public static boolean isJSPCloseDelimiter(String type) {
- if (type == null) {
- return false;
- }
- return (type.equals(DOMJSPRegionContextsPrivateCopy.JSP_CLOSE) || type.equals(DOMRegionContext.XML_TAG_CLOSE));
- }
-
- /**
- * Tells you if the flatnode is the JSP region <%%>, <%=%>, <%!%>
- *
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- public static boolean isJSPDelimiter(IStructuredDocumentRegion fn) {
- boolean isDelimiter = false;
- String type = fn.getType();
- if (type != null) {
- isDelimiter = isJSPDelimiter(type);
- }
- return isDelimiter;
- }
-
- /**
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- public static boolean isJSPDelimiter(String type) {
- if (type == null) {
- return false;
- }
- return (isJSPOpenDelimiter(type) || isJSPCloseDelimiter(type));
- }
-
- /**
- * Tells you if the flatnode is <%, <%=, or <%! ISSUE: this is a bit of
- * hidden JSP knowledge that was implemented this way for expedency.
- * Should be evolved in future to depend on "nestedContext".
- */
- public static boolean isJSPOpenDelimiter(IStructuredDocumentRegion fn) {
- if (fn == null) {
- return false;
- }
- return isJSPOpenDelimiter(fn.getType());
- }
-
- /**
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- public static boolean isJSPOpenDelimiter(String type) {
- if (type == null) {
- return false;
- }
- return (type.equals(DOMJSPRegionContextsPrivateCopy.JSP_SCRIPTLET_OPEN) || type.equals(DOMJSPRegionContextsPrivateCopy.JSP_DECLARATION_OPEN) || type.equals(DOMJSPRegionContextsPrivateCopy.JSP_EXPRESSION_OPEN));
- }
-
- /**
- * Tells you if the flatnode is the <jsp:scriptlet>, <jsp:expression>, or
- * <jsp:declaration>tag
- *
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- public static boolean isXMLJSPDelimiter(IStructuredDocumentRegion fn) {
- boolean isDelimiter = false;
- if ((fn != null) && (fn instanceof ITextRegionContainer)) {
- Object[] regions = ((ITextRegionContainer) fn).getRegions().toArray();
- ITextRegion temp = null;
- String regionText = ""; //$NON-NLS-1$
- for (int i = 0; i < regions.length; i++) {
- temp = (ITextRegion) regions[i];
- if (temp.getType() == DOMRegionContext.XML_TAG_NAME) {
- regionText = fn.getText(temp);
- if (regionText.equalsIgnoreCase("jsp:scriptlet") || regionText.equalsIgnoreCase("jsp:expression") || regionText.equalsIgnoreCase("jsp:declaration")) {
- isDelimiter = true;
- }
- }
- }
- }
- return isDelimiter;
- }
-
- /**
- * Returns "javascript" if language attribute is some form of javascript,
- * "java" if language attribute is some form of java. Otherwise, just
- * returns type.
- *
- * @param language
- */
- public static String lookupScriptLanguage(String language) {
- for (int i = 0; i < ScriptLanguageKeys.JAVASCRIPT_LANGUAGE_KEYS.length; i++) {
- if (ScriptLanguageKeys.JAVASCRIPT_LANGUAGE_KEYS[i].equalsIgnoreCase(language)) {
- return ScriptLanguageKeys.JAVASCRIPT;
- }
- }
- for (int i = 0; i < ScriptLanguageKeys.JAVA_LANGUAGE_KEYS.length; i++) {
- if (ScriptLanguageKeys.JAVA_LANGUAGE_KEYS[i].equalsIgnoreCase(language)) {
- return ScriptLanguageKeys.JAVA;
- }
- }
- return language;
- }
-
- /**
- * Returns "javascript" if type (used in <script type="xxx"> is actually
- * javascript type. Otherwise, just returns type
- *
- * @param type
- */
- public static String lookupScriptType(String type) {
- for (int i = 0; i < ScriptLanguageKeys.JAVASCRIPT_MIME_TYPE_KEYS.length; i++) {
- if (ScriptLanguageKeys.JAVASCRIPT_MIME_TYPE_KEYS[i].equalsIgnoreCase(type)) {
- return ScriptLanguageKeys.JAVASCRIPT;
- }
- }
- return type;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentModelGenerator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentModelGenerator.java
deleted file mode 100644
index 0c4698a7b8..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentModelGenerator.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Node;
-
-
-public class XMLContentModelGenerator extends AbstractContentModelGenerator {
-
- /**
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- private class DOMJSPRegionContextsPrivateCopy {
- private static final String JSP_DIRECTIVE_OPEN = "JSP_DIRECTIVE_OPEN"; //$NON-NLS-1$
- }
-
- /**
- * XMLContentModelGenerator constructor comment.
- */
- public XMLContentModelGenerator() {
- super();
- }
-
- public void generateAttribute(CMAttributeDeclaration attrDecl, StringBuffer buffer) {
- if ((attrDecl == null) || (buffer == null)) {
- return;
- }
- int usage = attrDecl.getUsage();
- if (usage == CMAttributeDeclaration.REQUIRED) {
- buffer.append(" "); //$NON-NLS-1$
- generateRequiredAttribute(null, attrDecl, buffer); // todo pass
- // ownerNode as
- // 1st param
- }
- return;
- }
-
- protected void generateEndTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) {
- if (elementDecl == null) {
- return;
- }
- if (elementDecl.getContentType() != CMElementDeclaration.EMPTY) {
- buffer.append("</" + tagName + ">");//$NON-NLS-2$//$NON-NLS-1$
- }
- return;
- }
-
- public void generateRequiredAttribute(Node ownerNode, CMAttributeDeclaration attrDecl, StringBuffer buffer) {
- if ((attrDecl == null) || (buffer == null)) {
- return;
- }
-
- // attribute name
- String attributeName = getRequiredName(ownerNode, attrDecl);
- CMDataType attrType = attrDecl.getAttrType();
- // = sign
- buffer.append(attributeName + "=\""); //$NON-NLS-1$
- // attribute value
- if (attrType != null) {
- // insert any value that is implied
- if ((attrType.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && (attrType.getImpliedValue() != null)) {
- buffer.append(attrType.getImpliedValue());
- }
- // otherwise, if an enumerated list of values exists, use the
- // first value
- else if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) {
- buffer.append(attrType.getEnumeratedValues()[0]);
- }
- }
- buffer.append("\""); //$NON-NLS-1$
- return;
- }
-
- protected void generateStartTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) {
- if ((elementDecl == null) || (buffer == null)) {
- return;
- }
- buffer.append("<" + tagName);//$NON-NLS-1$
- generateAttributes(elementDecl, buffer);
- buffer.append(getStartTagClose(parentNode, elementDecl));
- return;
- }
-
- public int getMinimalStartTagLength(Node node, CMElementDeclaration elementDecl) {
- if (elementDecl == null) {
- return 0;
- }
- if (requiresAttributes(elementDecl)) {
- return getRequiredName(node, elementDecl).length() + 2; // < +
- // name +
- // space
- }
- else {
- return 1 + getRequiredName(node, elementDecl).length() + getStartTagClose(node, elementDecl).length(); // < +
- // name
- // +
- // appropriate
- // close
- }
- }
-
- protected String getOtherClose(Node notATagNode) {
- if (notATagNode instanceof IDOMNode) {
- IStructuredDocumentRegion node = ((IDOMNode) notATagNode).getStartStructuredDocumentRegion();
- if ((node != null) && (node.getNumberOfRegions() > 1) && node.getRegions().get(0).getType().equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN)) {
- return "%>"; //$NON-NLS-1$
- }
- }
- return null;
- }
-
- public String getStartTagClose(Node parentNode, CMElementDeclaration elementDecl) {
- String other = getOtherClose(parentNode);
- if (other != null) {
- return other;
- }
- if (elementDecl == null) {
- return ">";//$NON-NLS-1$
- }
- if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) {
- return "/>"; //$NON-NLS-1$
- }
- return ">"; //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java
deleted file mode 100644
index 4a99070ae6..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceConstants;
-
-
-
-/**
- * some relevance constants for content assist higher relevance means it shows
- * up higher on the list
- */
-public interface XMLRelevanceConstants extends IRelevanceConstants {
-
- int R_CDATA = 400;
- int R_CLOSE_TAG = 1500;
-
- int R_COMMENT = 100;
-
- // moved this above macros
- int R_DOCTYPE = 600;
- int R_END_TAG = 1400;
- int R_END_TAG_NAME = 1100;
- int R_ENTITY = 1000;
- int R_JSP = 500;
-
- int R_JSP_ATTRIBUTE_VALUE = 700;
-
- // (pa) make these the same relevance so proposals are same order for V501
- int R_MACRO = 500;
-
- // add this onto "required" attrs, elements, etc to bubble them up on
- // sorting...
- // CMVC 246618
- int R_REQUIRED = 10;
- int R_TAG_INSERTION = 500;
- int R_STRICTLY_VALID_TAG_INSERTION = 600;
- int R_TAG_NAME = 1200;
- int R_XML_ATTRIBUTE_NAME = 900;
- int R_XML_ATTRIBUTE_VALUE = 800;
- int R_XML_DECLARATION = 1300;
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java
deleted file mode 100644
index 29f9ad2f46..0000000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentassist;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.templates.ContextTypeRegistry;
-import org.eclipse.jface.text.templates.Template;
-import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
-import org.eclipse.jface.text.templates.TemplateContext;
-import org.eclipse.jface.text.templates.TemplateContextType;
-import org.eclipse.jface.text.templates.TemplateException;
-import org.eclipse.jface.text.templates.TemplateProposal;
-import org.eclipse.jface.text.templates.persistence.TemplateStore;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
-
-
-/**
- * Completion processor for XML Templates. Most of the work is already done by
- * the XML Content Assist processor, so by the time the
- * XMLTemplateCompletionProcessor is asked for content assist proposals, the
- * XML content assist processor has already set the context type for
- * templates.
- */
-class XMLTemplateCompletionProcessor extends TemplateCompletionProcessor {
- private static final class ProposalComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- return ((TemplateProposal) o2).getRelevance() - ((TemplateProposal) o1).getRelevance();
- }
- }
-
- private static final Comparator fgProposalComparator = new ProposalComparator();
- private String fContextTypeId = null;
-
- /*
- * Copied from super class except instead of calling createContext(viewer,
- * region) call createContext(viewer, region, offset) instead
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
-
- ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
-
- // adjust offset to end of normalized selection
- if (selection.getOffset() == offset) {
- offset = selection.getOffset() + selection.getLength();
- }
-
- String prefix = extractPrefix(viewer, offset);
- Region region = new Region(offset - prefix.length(), prefix.length());
- TemplateContext context = createContext(viewer, region, offset);
- if (context == null) {
- return new ICompletionProposal[0];
- }
-
- // name of the selection variables {line, word}_selection
- context.setVariable("selection", selection.getText()); //$NON-NLS-1$
-
- Template[] templates = getTemplates(context.getContextType().getId());
-
- List matches = new ArrayList();
- for (int i = 0; i < templates.length; i++) {
- Template template = templates[i];
- try {
- context.getContextType().validate(template.getPattern());
- }
- catch (TemplateException e) {
- continue;
- }
- if (template.matches(prefix, context.getContextType().getId())) {
- matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
- }
- }
-
- Collections.sort(matches, fgProposalComparator);
-
- return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
- }
-
- /**
- * Creates a concrete template context for the given region in the
- * document. This involves finding out which context type is valid at the
- * given location, and then creating a context of this type. The default
- * implementation returns a <code>SmartReplaceTemplateContext</code> for
- * the context type at the given location. This takes the offset at which
- * content assist was invoked into consideration.
- *
- * @param viewer
- * the viewer for which the context is created
- * @param region
- * the region into <code>document</code> for which the
- * context is created
- * @param offset
- * the original offset where content assist was invoked
- * @return a template context that can handle template insertion at the
- * given location, or <code>null</code>
- */
- private TemplateContext createContext(ITextViewer viewer, IRegion region, int offset) {
- // pretty much same code as super.createContext except create
- // SmartReplaceTemplateContext
- TemplateContextType contextType = getContextType(viewer, region);
- if (contextType != null) {
- IDocument document = viewer.getDocument();
- return new ReplaceNameTemplateContext(contextType, document, region.getOffset(), region.getLength(), offset);
- }
- return null;
- }
-
- protected ICompletionProposal createProposal(Template template, TemplateContext context, IRegion region, int relevance) {
- return new CustomTemplateProposal(template, context, region, getImage(template), relevance);
- }
-
- protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
- TemplateContextType type = null;
-
- ContextTypeRegistry registry = getTemplateContextRegistry();
- if (registry != null) {
- type = registry.getContextType(fContextTypeId);
- }
-
- return type;
- }
-
- protected Image getImage(Template template) {
- // just return the same image for now
- return XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_MACRO);
- }
-
- private ContextTypeRegistry getTemplateContextRegistry() {
- return XMLUIPlugin.getDefault().getTemplateContextRegistry();
- }
-
- protected Template[] getTemplates(String contextTypeId) {
- Template templates[] = null;
-
- TemplateStore store = getTemplateStore();
- if (store != null) {
- templates = store.getTemplates(contextTypeId);
- }
-
- return templates;
- }
-
- private TemplateStore getTemplateStore() {
- return XMLUIPlugin.getDefault().getTemplateStore();
- }
-
- void setContextType(String contextTypeId) {
- fContextTypeId = contextTypeId;
- }
-}

Back to the top