use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class AttributeContextInformationProvider method getInfoForText.
/**
* @param node
*/
IContextInformation[] getInfoForText(IDOMNode node) {
Node parent = node.getParentNode();
String contextString = node.getNodeName();
// $NON-NLS-1$
StringBuffer info = new StringBuffer(" ");
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) {
// $NON-NLS-1$ //$NON-NLS-2$
info.append("<" + cmNode.getNodeName() + ">");
if (i < children.getLength() - 1) {
// $NON-NLS-1$
info.append(" ");
}
}
}
}
}
if (!info.toString().trim().equals("")) {
return new IContextInformation[] { new ContextInformation(contextString, info.toString()) };
} else {
return EMPTY_CONTEXT_INFO;
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class DOMContentBuilderImpl method visitCMGroup.
public void visitCMGroup(CMGroup e) {
cmGroupStack.push(e);
int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
int min = Math.max(e.getMinOccur(), forcedMin);
int max = 0;
if (// unbounded
e.getMaxOccur() == -1)
max = getNumOfRepeatableElements();
else
max = Math.min(e.getMaxOccur(), getNumOfRepeatableElements());
if (max < min)
max = min;
alwaysVisit = false;
for (int i = 1; i <= max; i++) {
if (e.getOperator() == CMGroup.CHOICE && buildFirstChoice(buildPolicy)) {
CMNode hintNode = null;
// todo... the CMGroup should specify the hint... but it seems
// as though
// the Yamato guys are making the CMElement specify the hint.
// I do it that way for now until... we should fix this post
// GA
//
int listSize = visitedCMElementDeclarationList.size();
if (listSize > 0) {
CMElementDeclaration ed = (CMElementDeclaration) visitedCMElementDeclarationList.get(listSize - 1);
// $NON-NLS-1$
Object contentHint = ed.getProperty("contentHint");
if (contentHint instanceof CMNode) {
hintNode = (CMNode) contentHint;
}
}
// see if this hint corresponds to a valid choice
//
CMNode cmNode = null;
if (hintNode != null) {
CMNodeList nodeList = e.getChildNodes();
int nodeListLength = nodeList.getLength();
for (int j = 0; j < nodeListLength; j++) {
if (hintNode == nodeList.item(j)) {
cmNode = hintNode;
}
}
}
//
if (cmNode == null) {
CMNodeList nodeList = e.getChildNodes();
if (nodeList.getLength() > 0) {
cmNode = nodeList.item(0);
}
}
if (cmNode != null) {
// Visit the node only if it is not a GROUP (model group). If it is an element, then visit it.
if (!(cmNode.getNodeType() == CMNode.GROUP && min > 0)) {
visitCMNode(cmNode);
}
}
} else if (// ALL
e.getOperator() == CMGroup.ALL || // SEQUENCE
e.getOperator() == CMGroup.SEQUENCE) {
// visit all of the content
super.visitCMGroup(e);
}
}
cmGroupStack.pop();
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class DOMContentBuilderImpl method getSubstitution.
protected CMElementDeclaration getSubstitution(CMElementDeclaration ed) {
CMElementDeclaration result = ed;
// $NON-NLS-1$
CMNodeList l = (CMNodeList) ed.getProperty("SubstitutionGroup");
if (l != null) {
for (int i = 0; i < l.getLength(); i++) {
CMNode candidate = l.item(i);
if (!isAbstract(candidate) && (candidate instanceof CMElementDeclaration)) {
result = (CMElementDeclaration) candidate;
break;
}
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class BugFixesTest method testGlobalAttr4Documentation.
private void testGlobalAttr4Documentation(CMNamedNodeMap attributes) {
CMAttributeDeclaration attribute = (CMAttributeDeclaration) attributes.getNamedItem("globalAttr4");
assertNotNull("Missing globalAttr1 attribute.");
CMNodeList documentation = (CMNodeList) attribute.getProperty("documentation");
if (documentation.getLength() == 0) {
fail("Documentation element not returned for globalAttr4");
}
assertNull("globalAttr4 returned data when non expected.", ((DocumentationImpl) documentation.item(0)).getValue());
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class BugFixesTest method testLocalAttrDocumentation.
private void testLocalAttrDocumentation(CMNamedNodeMap attributes) {
CMAttributeDeclaration attribute = (CMAttributeDeclaration) attributes.getNamedItem("localAttr");
assertNotNull("Missing localAttr attribute.");
CMNodeList documentation = (CMNodeList) attribute.getProperty("documentation");
if (documentation.getLength() == 0) {
fail("Unable to find documentation for localAttr");
}
assertEquals("Wrong number of documentation annotations.", 2, documentation.getLength());
assertEquals("Incorrect annotation for localAttr:", "PASS! Multiple documentation elements for local attribute part 1", ((DocumentationImpl) documentation.item(0)).getValue().trim());
assertEquals("Incorrect annotation for localAttr:", "PASS! Multiple documentation elements for local attribute part 2", ((DocumentationImpl) documentation.item(1)).getValue().trim());
}
Aggregations