From 12ff79efeb1f6330b7b893b6c3071aef3a52b06e Mon Sep 17 00:00:00 2001 From: david_williams Date: Wed, 13 Apr 2005 13:59:30 +0000 Subject: continuing internalization --- .../ui/StructuredTextViewerConfigurationXML.java | 14 +- .../wst/xml/ui/XMLSourceEditingTextTools.java | 136 ++ .../AbstractContentAssistProcessor.java | 2241 -------------------- .../AbstractContentModelGenerator.java | 86 - .../contentassist/AttributeContextInformation.java | 113 - .../AttributeContextInformationPresenter.java | 112 - .../AttributeContextInformationProvider.java | 208 -- .../xml/ui/contentassist/ContentAssistRequest.java | 269 --- .../xml/ui/contentassist/ContextInfoModelUtil.java | 65 - .../ui/contentassist/CustomTemplateProposal.java | 40 - .../NoRegionContentAssistProcessor.java | 263 --- .../NonValidatingModelQueryAction.java | 159 -- .../xml/ui/contentassist/ProposalComparator.java | 48 - .../contentassist/SimpleCMElementDeclaration.java | 170 -- .../ui/contentassist/SourceEditorImageHelper.java | 48 - .../contentassist/XMLContentAssistProcessor.java | 145 -- .../contentassist/XMLContentAssistUtilities.java | 492 ----- .../ui/contentassist/XMLContentModelGenerator.java | 135 -- .../ui/contentassist/XMLRelevanceConstants.java | 51 - .../XMLTemplateCompletionProcessor.java | 80 - .../eclipse/wst/xml/ui/dnd/DragNodeCommand.java | 228 -- .../wst/xml/ui/dnd/XMLDragAndDropManager.java | 48 - .../xml/ui/doubleclick/XMLDoubleClickStrategy.java | 285 --- .../extension/IDesignViewerSelectionManager.java | 33 - .../ui/extensions/XMLSourceEditingTextTools.java | 136 -- .../AbstractContentAssistProcessor.java | 2241 ++++++++++++++++++++ .../AbstractContentModelGenerator.java | 86 + .../contentassist/AttributeContextInformation.java | 113 + .../AttributeContextInformationPresenter.java | 112 + .../AttributeContextInformationProvider.java | 208 ++ .../contentassist/ContentAssistRequest.java | 269 +++ .../contentassist/ContextInfoModelUtil.java | 65 + .../contentassist/CustomTemplateProposal.java | 40 + .../NoRegionContentAssistProcessor.java | 263 +++ .../NonValidatingModelQueryAction.java | 159 ++ .../internal/contentassist/ProposalComparator.java | 48 + .../contentassist/SimpleCMElementDeclaration.java | 170 ++ .../contentassist/SourceEditorImageHelper.java | 48 + .../contentassist/XMLContentAssistProcessor.java | 145 ++ .../contentassist/XMLContentAssistUtilities.java | 492 +++++ .../contentassist/XMLContentModelGenerator.java | 135 ++ .../contentassist/XMLRelevanceConstants.java | 51 + .../XMLTemplateCompletionProcessor.java | 80 + .../wst/xml/ui/internal/dnd/DragNodeCommand.java | 228 ++ .../xml/ui/internal/dnd/XMLDragAndDropManager.java | 48 + .../doubleclick/XMLDoubleClickStrategy.java | 285 +++ .../ui/internal/preferences/EncodingSettings.java | 356 ++++ .../WorkbenchDefaultEncodingSettings.java | 137 ++ .../xml/ui/internal/preferences/XMLColorPage.java | 223 ++ .../preferences/XMLFilesPreferencePage.java | 195 ++ .../preferences/XMLSourcePreferencePage.java | 245 +++ .../preferences/XMLTemplatePreferencePage.java | 67 + .../preferences/XMLUIPreferenceInitializer.java | 2 +- .../AdapterFactoryProviderForEmbeddedXML.java | 40 + .../registry/AdapterFactoryProviderForXML.java | 103 + .../xml/ui/internal/style/IStyleConstantsXML.java | 41 + .../ui/internal/style/LineStyleProviderForXML.java | 173 ++ .../ui/internal/taginfo/MarkupTagInfoProvider.java | 174 ++ .../taginfo/XMLBestMatchHoverProcessor.java | 39 + .../internal/taginfo/XMLInformationProvider.java | 64 + .../internal/taginfo/XMLTagInfoHoverProcessor.java | 334 +++ .../text/XMLDocumentRegionEdgeMatcher.java | 25 + .../wst/xml/ui/openon/DefaultOpenOnXML.java | 361 ---- .../wst/xml/ui/preferences/EncodingSettings.java | 356 ---- .../WorkbenchDefaultEncodingSettings.java | 137 -- .../wst/xml/ui/preferences/XMLColorPage.java | 223 -- .../xml/ui/preferences/XMLFilesPreferencePage.java | 195 -- .../ui/preferences/XMLSourcePreferencePage.java | 246 --- .../ui/preferences/XMLTemplatePreferencePage.java | 67 - .../AdapterFactoryProviderForEmbeddedXML.java | 40 - .../ui/registry/AdapterFactoryProviderForXML.java | 103 - .../wst/xml/ui/style/IStyleConstantsXML.java | 41 - .../wst/xml/ui/style/LineStyleProviderForXML.java | 173 -- .../wst/xml/ui/taginfo/MarkupTagInfoProvider.java | 174 -- .../xml/ui/taginfo/XMLBestMatchHoverProcessor.java | 39 - .../wst/xml/ui/taginfo/XMLInformationProvider.java | 64 - .../xml/ui/taginfo/XMLTagInfoHoverProcessor.java | 334 --- .../xml/ui/text/XMLDocumentRegionEdgeMatcher.java | 25 - .../XMLContentOutlineConfiguration.java | 2 +- 79 files changed, 7647 insertions(+), 8042 deletions(-) create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLSourceEditingTextTools.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentAssistProcessor.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentModelGenerator.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformation.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationPresenter.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationProvider.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContentAssistRequest.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContextInfoModelUtil.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/CustomTemplateProposal.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NoRegionContentAssistProcessor.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NonValidatingModelQueryAction.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ProposalComparator.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SimpleCMElementDeclaration.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SourceEditorImageHelper.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistProcessor.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistUtilities.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentModelGenerator.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLRelevanceConstants.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLTemplateCompletionProcessor.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dnd/DragNodeCommand.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/dnd/XMLDragAndDropManager.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/doubleclick/XMLDoubleClickStrategy.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extension/IDesignViewerSelectionManager.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/extensions/XMLSourceEditingTextTools.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentModelGenerator.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformation.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationPresenter.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AttributeContextInformationProvider.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContentAssistRequest.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ContextInfoModelUtil.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/CustomTemplateProposal.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NoRegionContentAssistProcessor.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/NonValidatingModelQueryAction.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/ProposalComparator.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SimpleCMElementDeclaration.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/SourceEditorImageHelper.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistProcessor.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentAssistUtilities.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLContentModelGenerator.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLTemplateCompletionProcessor.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dnd/DragNodeCommand.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dnd/XMLDragAndDropManager.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/doubleclick/XMLDoubleClickStrategy.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EncodingSettings.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/WorkbenchDefaultEncodingSettings.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLColorPage.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLFilesPreferencePage.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTemplatePreferencePage.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/registry/AdapterFactoryProviderForEmbeddedXML.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/registry/AdapterFactoryProviderForXML.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/style/IStyleConstantsXML.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/style/LineStyleProviderForXML.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/MarkupTagInfoProvider.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLBestMatchHoverProcessor.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLInformationProvider.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/taginfo/XMLTagInfoHoverProcessor.java create mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/text/XMLDocumentRegionEdgeMatcher.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/openon/DefaultOpenOnXML.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/EncodingSettings.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/WorkbenchDefaultEncodingSettings.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLColorPage.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLFilesPreferencePage.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLSourcePreferencePage.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/preferences/XMLTemplatePreferencePage.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/registry/AdapterFactoryProviderForEmbeddedXML.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/registry/AdapterFactoryProviderForXML.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/style/IStyleConstantsXML.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/style/LineStyleProviderForXML.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/MarkupTagInfoProvider.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLBestMatchHoverProcessor.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLInformationProvider.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/taginfo/XMLTagInfoHoverProcessor.java delete mode 100644 bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/text/XMLDocumentRegionEdgeMatcher.java (limited to 'bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml') diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java index 86afb19da1..e44ea102ef 100644 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java @@ -51,17 +51,17 @@ import org.eclipse.wst.sse.ui.util.EditorUtility; import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML; import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML; import org.eclipse.wst.xml.core.text.IXMLPartitions; -import org.eclipse.wst.xml.ui.contentassist.NoRegionContentAssistProcessor; -import org.eclipse.wst.xml.ui.contentassist.XMLContentAssistProcessor; -import org.eclipse.wst.xml.ui.doubleclick.XMLDoubleClickStrategy; import org.eclipse.wst.xml.ui.internal.autoedit.StructuredAutoEditStrategyXML; +import org.eclipse.wst.xml.ui.internal.contentassist.NoRegionContentAssistProcessor; +import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor; import org.eclipse.wst.xml.ui.internal.correction.CorrectionProcessorXML; +import org.eclipse.wst.xml.ui.internal.doubleclick.XMLDoubleClickStrategy; import org.eclipse.wst.xml.ui.internal.hyperlink.XMLHyperlinkDetector; +import org.eclipse.wst.xml.ui.internal.style.LineStyleProviderForXML; +import org.eclipse.wst.xml.ui.internal.taginfo.XMLBestMatchHoverProcessor; +import org.eclipse.wst.xml.ui.internal.taginfo.XMLInformationProvider; +import org.eclipse.wst.xml.ui.internal.taginfo.XMLTagInfoHoverProcessor; import org.eclipse.wst.xml.ui.reconcile.StructuredTextReconcilingStrategyForMarkup; -import org.eclipse.wst.xml.ui.style.LineStyleProviderForXML; -import org.eclipse.wst.xml.ui.taginfo.XMLBestMatchHoverProcessor; -import org.eclipse.wst.xml.ui.taginfo.XMLInformationProvider; -import org.eclipse.wst.xml.ui.taginfo.XMLTagInfoHoverProcessor; /** * This class provides diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLSourceEditingTextTools.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLSourceEditingTextTools.java new file mode 100644 index 0000000000..d03a6c793f --- /dev/null +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/XMLSourceEditingTextTools.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2001, 2004 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; + + + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.wst.sse.core.IModelManager; +import org.eclipse.wst.sse.core.INodeAdapter; +import org.eclipse.wst.sse.core.INodeNotifier; +import org.eclipse.wst.sse.core.IStructuredModel; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; +import org.eclipse.wst.sse.ui.extensions.breakpoint.NodeLocation; +import org.eclipse.wst.sse.ui.extensions.breakpoint.SourceEditingTextTools; +import org.eclipse.wst.xml.core.document.IDOMModel; +import org.eclipse.wst.xml.core.document.IDOMNode; +import org.eclipse.wst.xml.core.document.IDOMText; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + + +/** + * Implements SourceEditingTextTools interface + */ +public class XMLSourceEditingTextTools implements SourceEditingTextTools, INodeAdapter { + + protected class NodeLocationImpl implements NodeLocation { + private IDOMNode node; + + public NodeLocationImpl(IDOMNode xmlnode) { + super(); + node = xmlnode; + } + + public int getEndTagEndOffset() { + if (node.getEndStructuredDocumentRegion() != null) + return node.getEndStructuredDocumentRegion().getEndOffset(); + return -1; + } + + public int getEndTagStartOffset() { + if (node.getEndStructuredDocumentRegion() != null) + return node.getEndStructuredDocumentRegion().getStartOffset(); + return -1; + } + + public int getStartTagEndOffset() { + if (node.getStartStructuredDocumentRegion() != null) + return node.getStartStructuredDocumentRegion().getEndOffset(); + return -1; + } + + public int getStartTagStartOffset() { + if (node.getStartStructuredDocumentRegion() != null) + return node.getStartStructuredDocumentRegion().getStartOffset(); + return -1; + } + } + + + public Document getDOMDocument(IMarker marker) { + if (marker == null) + return null; + + IResource res = marker.getResource(); + if (res == null || !(res instanceof IFile)) + return null; + + IModelManager mm = StructuredModelManager.getModelManager(); + IStructuredModel model = null; + try { + model = mm.getExistingModelForRead((IFile) res); + if (model == null || !(model instanceof IDOMModel)) + return null; + + return ((IDOMModel) model).getDocument(); + } finally { + if (model != null) + model.releaseFromRead(); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.sse.ui.extensions.SourceEditingTextTools#getNodeLocation(org.w3c.dom.Node) + */ + public NodeLocation getNodeLocation(Node node) { + if (node.getNodeType() == Node.ELEMENT_NODE && node instanceof IDOMNode) + return new NodeLocationImpl((IDOMNode) node); + return null; + } + + public String getPageLanguage(Node node) { + return ""; //$NON-NLS-1$ + } + + public int getStartOffset(Node node) { + if (node == null || !(node instanceof IDOMText)) + return -1; + + IStructuredDocumentRegion fnode = ((IDOMText) node).getFirstStructuredDocumentRegion(); + return fnode.getStartOffset(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.sse.core.core.INodeAdapter#isAdapterForType(java.lang.Object) + */ + public boolean isAdapterForType(Object type) { + return SourceEditingTextTools.class.equals(type); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.wst.sse.core.core.INodeAdapter#notifyChanged(org.eclipse.wst.sse.core.core.INodeNotifier, + * int, java.lang.Object, java.lang.Object, java.lang.Object, int) + */ + public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { + } +} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentAssistProcessor.java deleted file mode 100644 index 9074d82c4e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentAssistProcessor.java +++ /dev/null @@ -1,2241 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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.IStructuredModel; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences; -import org.eclipse.wst.sse.core.internal.util.Debug; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.text.ITextRegionList; -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.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.core.document.IDOMDocument; -import org.eclipse.wst.xml.core.document.IDOMElement; -import org.eclipse.wst.xml.core.document.IDOMModel; -import org.eclipse.wst.xml.core.document.IDOMNode; -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.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.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.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() { - super(); - 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); - // CMVC 246618 - 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); // CMVC - // 269884 - } - // 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("'"))) //$NON-NLS-2$//$NON-NLS-1$ - 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)) { - CustomCompletionProposal proposal = new CustomCompletionProposal("\"" + possibleValue + "\"", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), possibleValue.length() + 1, image, possibleValue, 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) { - CustomCompletionProposal proposal = new CustomCompletionProposal("\"" + value + "\"", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), value.length() + 1, image, value, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - if (currentValue.length() > 0 && !value.equals(currentValue)) { - proposal = new CustomCompletionProposal("\"" + currentValue + "\"", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), currentValue.length() + 1, image, currentValue, 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) { - proposal = new CustomCompletionProposal("\"" + currentValue + "\"", //$NON-NLS-2$//$NON-NLS-1$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 1, image, "\"" + currentValue + "\"", //$NON-NLS-2$//$NON-NLS-1$ - 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 = ""; //$NON-NLS-1$ //$NON-NLS-2$ - ICompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 10, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_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) { - addXMLProposal(contentAssistRequest); - } - - /** - * 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(""; //$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:
- * |
- * < |
- * "; //$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) { - // fix for CMVC 261790 - // //////////////////////////////////////////////////////////////////////////////////// - IStructuredDocument sDoc = (IStructuredDocument) fTextViewer.getDocument(); - IStructuredDocumentRegion xmlEndTagOpen = sDoc.getRegionAtCharacterOffset(contentAssistRequest.getReplacementBeginPosition()); - // skip backward to "<", " - // <% String test = "test"; %> - // | - if (needsEndTag(xmlEndTagOpen)) { - String tagName = getTagName(xmlEndTagOpen); - xmlEndTagOpen.getTextEndOffset(); - replaceLength = 0; - replaceText = ""; //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$ - // replaceText = ""; - // //$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: - // 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: < | - 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; - } - } - // fix for CMVC 261790 - // //////////////////////////////////////////////////////////////////////////////////// - // fix for CMVC 263163, sometimes the node is not null, but - // getNodeValue() is null, put in a null check - else if (node.getNodeValue() != null && node.getNodeValue().indexOf(" "; //$NON-NLS-1$ - cursorOffset = replaceText.length(); - displayString = NLS.bind(XMLUIMessages.End_with__, (new Object[]{parent.getNodeName()})); - setErrorMessage(null); - addProposal = true; - } - } - // end fix for CMVC 261790 - // //////////////////////////////////////////////////////////////////////////////////// - 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("", //$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... - // CMVC 242943 - // CMVC 245532 - 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)) { - } - // check if theres a node inbetween XMLPI and cursor position - if (child != null && child instanceof IDOMNode) { - // CMVC 257486 - if (contentAssistRequest.getReplacementBeginPosition() >= ((IDOMNode) child).getEndOffset() || !xmlpiIsFirstElement) { - insertDoctype = false; - } - } - break; - } - } - - if (!xmlpiFound) { - addXMLProposal(contentAssistRequest); - } - else if (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) { - // FIX FOR CMVC 247482 - // make sure tag name is actually what it thinks it - // is...(eg. <%@ vs. ", //$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(); - List validActions = null; - String error = null; - - // CMVC #242943 shouldn't have proposals before XMLPI - // (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; - - // CMVC 248081 - // 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 = (IDOMNode) 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 children - validActions = getAvailableChildrenAtIndex((Element) parent, childPosition); - cmnodes = getValidCMNodes(childPosition, ModelQueryAction.INSERT, validActions); - 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$ - //$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); - Image image = CMImageUtil.getImage(elementDecl); - if (image == null) { - image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); - } - // Account for the < and >. If attributes were - // added, the cursor will be placed - // at the offset before of the first character of the - // first attribute name. - int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, elementDecl); - if (beginsWith(tagname, matchString)) { - String proposedText = getRequiredText(parent, elementDecl); - String proposedInfo = getAdditionalInfo(parentDecl, elementDecl); - CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION); - 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 (!xmlpiFound && contentAssistRequest.getReplacementBeginPosition() < minimumOffset) { - addXMLProposal(contentAssistRequest); - } - - 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 < and > - 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(); - List validActions = null; - String error = null; - String matchString = contentAssistRequest.getMatchString(); - if (parent.getNodeType() == Node.ELEMENT_NODE) { - // retrieve the list of children - validActions = getAvailableChildrenAtIndex((Element) parent, childPosition); - cmnodes = getValidCMNodes(childPosition, ModelQueryAction.INSERT, validActions); - 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$ - //$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 { - cursorAdjustment = proposedText.length() + 1; - proposedText += ">"; //$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; - proposedText = getRequiredName(parent, ed); - if (!beginsWith(proposedText, matchString)) - continue; - if ((node != null && node.getAttributes() != null && node.getAttributes().getLength() > 0) || ((node.getNodeType() != Node.TEXT_NODE) && node.getFirstStructuredDocumentRegion().isEnded())) { - cursorAdjustment = proposedText.length(); - } - else { - cursorAdjustment = proposedText.length(); - if (ed instanceof CMElementDeclaration) { - CMElementDeclaration elementDecl = (CMElementDeclaration) ed; - if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) { - proposedText += getContentGenerator().getStartTagClose(parent, elementDecl); - cursorAdjustment = proposedText.length(); - } - else { - cursorAdjustment = proposedText.length() + 1; - proposedText += ">"; //$NON-NLS-2$//$NON-NLS-1$ - } - } - } - 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); - } - } - } - - protected void addXMLProposal(ContentAssistRequest contentAssistRequest) { - String proposedText = ""; //$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) 221190 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((StructuredTextViewer) 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(); - } - 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 - * null 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.getFullText().trim().equals("&")) { //$NON-NLS-1$ - completionRegion = prev; - 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); //$NON-NLS-1$ - } - } - } - 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 " 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) { - contentAssistRequest = newContentAssistRequest(node, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), 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 "<= 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. - * null 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) { - 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; - int vc = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.VALIDITY_STRICT : ModelQuery.VALIDITY_NONE; - modelQuery.getInsertActions(parent, parentDecl, index, ic, vc, 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 - * null 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 - * null 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 null if - * the processor is incapable of computing context information. - * - * a context information validator, or null 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 null 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((StructuredTextViewer) 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; - } - - protected List getValidCMNodes(int childPosition, int kindOfAction, List modelQueryActions) { - 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, null); - } - - 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/contentassist/AbstractContentModelGenerator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentModelGenerator.java deleted file mode 100644 index fabd84c1cc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AbstractContentModelGenerator.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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/contentassist/AttributeContextInformation.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformation.java deleted file mode 100644 index f2c29631b9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformation.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.contentassist; - -import java.util.HashMap; - -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.ui.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 { - 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; - - /** - * 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 null - */ - public AttributeContextInformation(Image image, String contextDisplayString, String informationDisplayString, HashMap attr2RangeMap) { - Assert.isNotNull(informationDisplayString); - - 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/contentassist/AttributeContextInformationPresenter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationPresenter.java deleted file mode 100644 index 16e4f40ec4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationPresenter.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.xml.core.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; - - /** - * @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... - IStructuredDocumentRegion startRegion = fModelUtil.getXMLNode(fDocumentPosition).getStartStructuredDocumentRegion(); - int start = startRegion.getStartOffset(); - int end = startRegion.getEndOffset(); - return documentPosition < end && documentPosition > start + 1; - } - - /** - * @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/contentassist/AttributeContextInformationProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationProvider.java deleted file mode 100644 index ae09a649d4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/AttributeContextInformationProvider.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.xml.core.document.IDOMNode; -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.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 | - * 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("")) //$NON-NLS-1$ - 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("")) //$NON-NLS-1$ - 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/contentassist/ContentAssistRequest.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContentAssistRequest.java deleted file mode 100644 index 94ac8bf532..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContentAssistRequest.java +++ /dev/null @@ -1,269 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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.util.StringUtils; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionCollection; -import org.eclipse.wst.sse.ui.preferences.PreferenceManager; -import org.w3c.dom.Node; - - -public class ContentAssistRequest { - protected IStructuredDocumentRegion documentRegion = null; - - - protected PreferenceManager fPreferenceManager = 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, PreferenceManager preferencesManager) { - super(); - setNode(node); - setParent(parent); - setDocumentRegion(documentRegion); - setRegion(completionRegion); - setMatchString(filter); - setReplacementBeginPosition(begin); - setReplacementLength(length); - fPreferenceManager = preferencesManager; - } - - 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; - } - - /** - * - * @return com.ibm.sed.structuredDocument.core.IStructuredDocumentRegion - */ - 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; - } - - /** - * - * @return com.ibm.sed.structuredDocument.core.ITextRegion - */ - 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 - * com.ibm.sed.structuredDocument.ITextRegion - */ - 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/contentassist/ContextInfoModelUtil.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContextInfoModelUtil.java deleted file mode 100644 index aee6a9855b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ContextInfoModelUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.contentassist; - -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.xml.core.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; - - -/** - * @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 { - xmlModel.releaseFromRead(); - } - return xmlNode; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/CustomTemplateProposal.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/CustomTemplateProposal.java deleted file mode 100644 index da2ff19895..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/CustomTemplateProposal.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.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.internal.util.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/contentassist/NoRegionContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NoRegionContentAssistProcessor.java deleted file mode 100644 index f3fb8c999d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NoRegionContentAssistProcessor.java +++ /dev/null @@ -1,263 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.contentassist; - - - -import java.util.HashMap; -import java.util.Iterator; - -import org.eclipse.core.resources.IResource; -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.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.sse.ui.internal.contentassist.IResourceDependentProcessor; -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, IResourceDependentProcessor, IReleasable { - - protected char completionProposalAutoActivationCharacters[] = null; - protected char contextInformationAutoActivationCharacters[] = null; - - private final ICompletionProposal[] EMPTY_PROPOSAL_SET = new ICompletionProposal[0]; - protected String fErrorMessage = null; - protected HashMap fNameToProcessorMap = null; - protected HashMap fPartitionToProcessorMap = null; - protected IResource fResource = null; - - public NoRegionContentAssistProcessor() { - super(); - fPartitionToProcessorMap = new HashMap(); - fNameToProcessorMap = new HashMap(); - initNameToProcessorMap(); - initPartitionToProcessorMap(); - - } - - /** - * 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; - } - - /** - * 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((StructuredTextViewer) 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) { - String prevRegionType = sdPrev.getType(); - //System.out.println("previous region type is >> " + - // prevRegionType); - } - } - } - // 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) fPartitionToProcessorMap.get(prevPartitionType); - } - return p; - } - - /** - * Necessary for certain content assist processors (such as - * JSPJavaContentAssistProcessor). This gets set in - * StructuredTextViewerConfiguration. - * - */ - public void initialize(IResource resource) { - fResource = resource; - setResourceOnProcessors(resource); - } - - /** - * Inits map for extra ContentAssistProcessors (useBean, get/setProperty) - */ - protected void initNameToProcessorMap() { - } - - /** - * Adds all relevent ContentAssistProcessors to the partition to processor - * map (just XML here) - */ - protected void initPartitionToProcessorMap() { - XMLContentAssistProcessor xmlProcessor = new XMLContentAssistProcessor(); - fPartitionToProcessorMap.put(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); - } - - private void setResourceOnMap(IResource resource, HashMap map) { - if (!map.isEmpty()) { - Iterator keys = map.keySet().iterator(); - Object o = null; - while (keys.hasNext()) { - o = fPartitionToProcessorMap.get(keys.next()); - if (o instanceof IResourceDependentProcessor) - ((IResourceDependentProcessor) o).initialize(resource); - } - } - } - - /** - * @param resource - */ - private void setResourceOnProcessors(IResource resource) { - setResourceOnMap(resource, fPartitionToProcessorMap); - setResourceOnMap(resource, fNameToProcessorMap); - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NonValidatingModelQueryAction.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NonValidatingModelQueryAction.java deleted file mode 100644 index 7b1c46d0d9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/NonValidatingModelQueryAction.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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/contentassist/ProposalComparator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ProposalComparator.java deleted file mode 100644 index 11048a226c..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/ProposalComparator.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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 = java.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/contentassist/SimpleCMElementDeclaration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SimpleCMElementDeclaration.java deleted file mode 100644 index 4642576f89..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SimpleCMElementDeclaration.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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/contentassist/SourceEditorImageHelper.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SourceEditorImageHelper.java deleted file mode 100644 index bd9306b2ef..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/SourceEditorImageHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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/contentassist/XMLContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistProcessor.java deleted file mode 100644 index bdb110be59..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistProcessor.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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.text.ITextRegion; -import org.eclipse.wst.xml.core.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) { - 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, contentAssistRequest.getReplacementBeginPosition()); - 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); - addTemplates(request, TemplateContextTypeIdsXML.ALL); - 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/contentassist/XMLContentAssistUtilities.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistUtilities.java deleted file mode 100644 index 167f95cd38..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/contentassist/XMLContentAssistUtilities.java +++ /dev/null @@ -1,492 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 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.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.IndexedRegion; -import org.eclipse.wst.sse.core.internal.util.ScriptLanguageKeys; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionContainer; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.document.IDOMElement; -import org.eclipse.wst.xml.core.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 path in realation to com.ibm.sed. - * structured. contentassist. xmlSourceEditorImageHelper - * @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 = proposedText = "= documentPosition && viewerText.length() >= 2 && documentPosition >= 2) { - String last2chars = viewerText.substring(documentPosition - 2, documentPosition); - if (last2chars.endsWith("", //$NON-NLS-1$ - documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), //$NON-NLS-1$ - 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 = 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("<%")) //$NON-NLS-1$ - 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), //$NON-NLS-1$ - 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 image path in realation to com.ibm.sed. - * structured. contentassist. xmlSourceEditorImageHelper - * @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 = proposedText = "= documentPosition && viewerText.length() >= 2 && documentPosition >= 2) { - String last2chars = viewerText.substring(documentPosition - 2, documentPosition); - if (last2chars.endsWith("", //$NON-NLS-1$ - documentPosition, 0, proposedText.length() + 1, XMLEditorPluginImageHelper.getInstance().getImage(imagePath), //$NON-NLS-1$ - 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 , , or - * 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")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - 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