use of org.eclipse.wst.xml.core.internal.contentmodel.CMContent in project webtools.sourceediting by eclipse.
the class CMUtility method isRepeatable.
public static boolean isRepeatable(CMNode child) {
boolean result = false;
if (child instanceof CMContent) {
CMContent content = (CMContent) child;
result = content.getMaxOccur() > 1 || content.getMaxOccur() == -1;
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMContent 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.CMContent in project webtools.sourceediting by eclipse.
the class CMDescriptionBuilder method visitCMElementDeclaration.
public void visitCMElementDeclaration(CMElementDeclaration ed) {
if (ed == root && !isRootVisited) {
isRootVisited = true;
CMContent content = ed.getContent();
if (content != null) {
if (content.getNodeType() != CMNode.GROUP) {
// $NON-NLS-1$
sb.append("(");
visitCMNode(content);
// $NON-NLS-1$
sb.append(")");
} else {
visitCMNode(content);
}
}
} else {
sb.append(ed.getElementName());
addOccurenceSymbol(ed);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMContent in project webtools.sourceediting by eclipse.
the class ContentBuilder method visitCMElementDeclaration.
public void visitCMElementDeclaration(CMElementDeclaration ed) {
int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0;
int min = Math.max(ed.getMinOccur(), forcedMin);
alwaysVisit = false;
if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
visitedCMElementDeclarationList.add(ed);
for (int i = 1; i <= min; i++) {
createElementNodeStart(ed);
// 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
createElementNodeEnd(ed);
}
int size = visitedCMElementDeclarationList.size();
visitedCMElementDeclarationList.remove(size - 1);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMContent in project webtools.sourceediting by eclipse.
the class CMValidator method validate.
/**
*/
public void validate(CMElementDeclaration ed, List elementContent, ElementContentComparator comparator, Result result) {
int contentType = ed.getContentType();
if (contentType == CMElementDeclaration.MIXED || contentType == CMElementDeclaration.ELEMENT) {
ElementList elementList = createElementList(contentType, elementContent, comparator, result);
if (result.isValid == true) {
boolean isGraphValidationNeeded = !(elementList == null && contentType == CMElementDeclaration.MIXED);
// explicitly handle 'All' groups
//
CMContent content = ed.getContent();
if (content != null && content.getNodeType() == CMNode.GROUP) {
CMGroup group = (CMGroup) content;
if (group.getOperator() == CMGroup.ALL) {
isGraphValidationNeeded = false;
validatAllGroupContent(elementContent, comparator, group, result);
}
}
if (isGraphValidationNeeded) {
// validate the elementList using a graph
//
result.isValid = false;
GraphNode node = lookupOrCreateGraph(ed);
validateElementList(elementList, node, comparator, result, false);
}
}
} else if (contentType == CMElementDeclaration.PCDATA) {
int size = elementContent.size();
for (int i = 0; i < size; i++) {
Object o = elementContent.get(i);
if (comparator.isElement(o)) {
result.isValid = false;
result.errorIndex = i;
// $NON-NLS-1$
result.errorMessage = "Element may only include PCDATA content";
break;
}
}
} else if (contentType == CMElementDeclaration.EMPTY) {
int size = elementContent.size();
for (int i = 0; i < size; i++) {
Object o = elementContent.get(i);
if (!comparator.isIgnorable(o)) {
result.isValid = false;
result.errorIndex = i;
// $NON-NLS-1$
result.errorMessage = "Element may not contain PCDATA or Element content";
break;
}
}
}
// else if (contentType == CMElementDeclaration.ANY)
// {
// assume elementContent will always be valid for this content type
// }
}
Aggregations