use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class CMDataTypeValueHelper method getValue.
public String getValue(CMAttributeDeclaration ad, NamespaceTable namespaceTable) {
String value = null;
if (isXSIType(ad)) {
List list = getQualifiedXSITypes(ad, namespaceTable);
value = list.size() > 0 ? (String) list.get(0) : null;
}
//
if (value == null) {
if (// $NON-NLS-1$
ad.getAttrName().equals("xml:lang")) {
// $NON-NLS-1$
value = "EN";
}
}
if (value == null) {
CMDataType dataType = ad.getAttrType();
if (dataType != null) {
value = getValue(dataType);
}
}
return value;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class CMValidator method getOriginArray.
public void getOriginArray(CMElementDeclaration ed, List elementContent, ElementContentComparator comparator, ElementPathRecordingResult result) {
CMNode[] cmNodeArray = null;
validate(ed, elementContent, comparator, result);
if (result.isValid) {
CMDataType dataType = ed.getDataType();
int size = elementContent.size();
cmNodeArray = new CMNode[size];
Vector originList = result.getElementOriginList();
int originListSize = originList.size();
int originListIndex = 0;
for (int i = 0; i < size; i++) {
Object o = elementContent.get(i);
if (comparator.isElement(o)) {
if (originListIndex < originListSize) {
cmNodeArray[i] = (CMNode) originList.get(originListIndex);
originListIndex++;
}
} else if (comparator.isPCData(o)) {
cmNodeArray[i] = dataType;
}
// else the CMNode at this index is null
}
result.setOriginArray(cmNodeArray);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class MarkupTagInfoProvider method printDefaultInfo.
/**
* Adds the default info (element name, content model, data type) of
* CMNode to the string buffer, sb
*/
protected void printDefaultInfo(CMNode node, StringBuffer sb) {
{
if (node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
CMElementDeclaration ed = (CMElementDeclaration) node;
sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Element____1 + SPACE + BOLD_END);
sb.append(node.getNodeName());
sb.append(PARAGRAPH_END);
printDocumentation(sb, node);
if (ed.getContentType() == CMElementDeclaration.PCDATA) {
CMDataType dataType = ed.getDataType();
if (dataType != null) {
printDataTypeInfo(sb, dataType);
}
} else {
CMDescriptionBuilder builder = new CMDescriptionBuilder();
String description = builder.buildDescription(node);
if ((description != null) && (description.length() > 0)) {
sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Content_Model____2 + SPACE + BOLD_END);
sb.append(description + PARAGRAPH_END);
}
}
} else if (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
CMAttributeDeclaration ad = (CMAttributeDeclaration) node;
sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Attribute____3 + SPACE + BOLD_END);
sb.append(node.getNodeName());
sb.append(PARAGRAPH_END);
printDocumentation(sb, node);
CMDataType dataType = ad.getAttrType();
if (dataType != null) {
printDataTypeInfo(sb, dataType);
}
} else if (node.getNodeType() == CMNode.DATA_TYPE) {
sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Data_Type____4 + SPACE + BOLD_END);
sb.append(node.getNodeName());
sb.append(PARAGRAPH_END);
printDocumentation(sb, node);
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class DOMContentBuilderImpl method visitCMElementDeclaration.
public void visitCMElementDeclaration(CMElementDeclaration ed) {
int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
int min = Math.max(ed.getMinOccur(), forcedMin);
// a group.
if (!cmGroupStack.isEmpty()) {
CMGroup group = (CMGroup) cmGroupStack.peek();
int gmin = group.getMinOccur();
if (gmin == 0)
if (buildOptionalElements(buildPolicy)) {
/* do nothing: min = min */
} else {
// min = 0
min = min * gmin;
}
else {
min = min * gmin;
}
}
int max = Math.min(ed.getMaxOccur(), getNumOfRepeatableElements());
if (max < min)
max = min;
alwaysVisit = false;
// involved.
if (// leave
buildFirstSubstitution(buildPolicy) || isAbstract(ed)) // this
// for
// backward
// compatibility
// for now
{
// Note - To change so that if ed is optional, we do not
// generate anything here.
ed = getSubstitution(ed);
// Note - the returned ed may be an abstract element in
// which case the xml will be invalid.
}
if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
visitedCMElementDeclarationList.add(ed);
for (int i = 1; i <= max; i++) {
// create an Element for each
Element element = null;
if (rootElement != null) {
element = rootElement;
rootElement = null;
} else {
element = createElement(ed, computeName(ed, currentParent), currentParent);
}
// visit the children of the GrammarElement
Node oldParent = currentParent;
currentParent = element;
handlePushParent(element, ed);
namespaceTable.addElement(element);
boolean oldAttachNodesToParent = attachNodesToParent;
attachNodesToParent = true;
// instead of calling super.visitCMElementDeclaration()
// we duplicate the code with some minor modifications
CMNamedNodeMap nodeMap = ed.getAttributes();
int size = nodeMap.getLength();
for (int j = 0; j < size; j++) {
visitCMNode(nodeMap.item(j));
}
CMContent content = ed.getContent();
if (content != null) {
visitCMNode(content);
}
if (ed.getContentType() == CMElementDeclaration.PCDATA) {
CMDataType dataType = ed.getDataType();
if (dataType != null) {
visitCMDataType(dataType);
}
}
// end duplication
attachNodesToParent = oldAttachNodesToParent;
handlePopParent(element, ed);
currentParent = oldParent;
linkNode(element);
}
int size = visitedCMElementDeclarationList.size();
visitedCMElementDeclarationList.remove(size - 1);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method addTagInsertionProposals.
protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) {
List cmnodes = null;
Node parent = contentAssistRequest.getParent();
String error = null;
// 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;
}
// have a content model (so can't propose any children..)
if ((parent != null) && (parent instanceof IDOMNode) && isCommentNode((IDOMNode) parent)) {
// loop and find non comment node?
while ((parent != null) && isCommentNode((IDOMNode) parent)) {
parent = parent.getParentNode();
}
}
if (parent.getNodeType() == Node.ELEMENT_NODE) {
CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
if (parentDecl != null) {
// XSD-specific ability - no filtering
CMDataType childType = parentDecl.getDataType();
if (childType != null) {
String[] childStrings = childType.getEnumeratedValues();
String defaultValue = childType.getImpliedValue();
if (childStrings != null || defaultValue != 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++) {
if (!childStrings[i].equals(defaultValue)) {
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 (defaultValue != null) {
CustomCompletionProposal textProposal = new CustomCompletionProposal(defaultValue, begin, length, defaultValue.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT), defaultValue, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
contentAssistRequest.addProposal(textProposal);
}
}
}
}
if ((parentDecl != null) && (parentDecl.getContentType() == CMElementDeclaration.PCDATA)) {
addPCDATAProposal(parentDecl.getNodeName(), contentAssistRequest);
} else {
// retrieve the list of all possible children within this
// parent context
cmnodes = getAvailableChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT);
// retrieve the list of the possible children within this
// parent context and at this index
List strictCMNodeSuggestions = null;
if (XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT.equals(XMLUIPlugin.getInstance().getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY))) {
strictCMNodeSuggestions = getValidChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT);
}
Iterator nodeIterator = cmnodes.iterator();
if (!nodeIterator.hasNext()) {
if (getCMElementDeclaration(parent) != null) {
error = NLS.bind(XMLUIMessages._Has_no_available_child, (new Object[] { parent.getNodeName() }));
} else {
error = NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[] { parent.getNodeName() }));
}
}
String matchString = contentAssistRequest.getMatchString();
// matchstring
while ((matchString.length() > 0) && (Character.isWhitespace(matchString.charAt(0)) || beginsWith(matchString, "<"))) {
// $NON-NLS-1$
matchString = matchString.substring(1);
}
while (nodeIterator.hasNext()) {
Object o = nodeIterator.next();
if (o instanceof CMElementDeclaration) {
CMElementDeclaration elementDecl = (CMElementDeclaration) o;
// only add proposals for the child element's that
// begin with the matchstring
String tagname = getRequiredName(parent, elementDecl);
boolean isStrictCMNodeSuggestion = strictCMNodeSuggestions != null ? strictCMNodeSuggestions.contains(elementDecl) : false;
Image image = CMImageUtil.getImage(elementDecl);
if (image == null) {
if (strictCMNodeSuggestions != null) {
image = isStrictCMNodeSuggestion ? XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC_EMPHASIZED) : XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC_DEEMPHASIZED);
} else {
image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
}
}
// elementDecl);
if (beginsWith(tagname, matchString)) {
String proposedText = getRequiredText(parent, elementDecl);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811
// place cursor in first empty quotes
int markupAdjustment = getCursorPositionForProposedText(proposedText);
String proposedInfo = getAdditionalInfo(parentDecl, elementDecl);
int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION;
CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, relevance);
contentAssistRequest.addProposal(proposal);
}
}
}
if (contentAssistRequest.getProposals().size() == 0) {
if (error != null) {
setErrorMessage(error);
} else if ((contentAssistRequest.getMatchString() != null) && (contentAssistRequest.getMatchString().length() > 0)) {
setErrorMessage(NLS.bind(XMLUIMessages.No_known_child_tag, (new Object[] { parent.getNodeName(), contentAssistRequest.getMatchString() })));
// $NON-NLS-1$ = "No known child tag names of <{0}> begin with \"{1}\"."
} else {
setErrorMessage(NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[] { parent.getNodeName() })));
}
}
}
} else if (parent.getNodeType() == Node.DOCUMENT_NODE) {
// Can only prompt with elements if the cursor position is past
// the XML processing
// instruction and DOCTYPE declaration
boolean xmlpiFound = false;
boolean doctypeFound = false;
int minimumOffset = -1;
for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
// $NON-NLS-1$
boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml"));
boolean doctype = child.getNodeType() == Node.DOCUMENT_TYPE_NODE;
if (xmlpi || (doctype && (minimumOffset < 0))) {
minimumOffset = ((IDOMNode) child).getFirstStructuredDocumentRegion().getStartOffset() + ((IDOMNode) child).getFirstStructuredDocumentRegion().getTextLength();
}
xmlpiFound = xmlpiFound || xmlpi;
doctypeFound = doctypeFound || doctype;
}
if (contentAssistRequest.getReplacementBeginPosition() >= minimumOffset) {
List childDecls = getAvailableRootChildren((Document) parent, childPosition);
for (int i = 0; i < childDecls.size(); i++) {
CMElementDeclaration ed = (CMElementDeclaration) childDecls.get(i);
if (ed != null) {
Image image = CMImageUtil.getImage(ed);
if (image == null) {
image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
}
String proposedText = getRequiredText(parent, ed);
String tagname = getRequiredName(parent, ed);
// account for the < 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);
}
}
}
}
}
Aggregations