use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testTagFileHasTagContentModel.
public void testTagFileHasTagContentModel() throws IOException, CoreException {
String DPROJECT_NAME = getName();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(DPROJECT_NAME);
if (!project.exists()) {
// Create new project
project = BundleResourceUtil.createSimpleProject(DPROJECT_NAME, null, null);
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
IFile tagFile = project.getFile("test1.tag");
tagFile.create(new ByteArrayInputStream(new byte[0]), IResource.FORCE, null);
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tagFile);
model.getStructuredDocument().set("<" + JSP20Namespace.ElementName.DOBODY + "/>");
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) model.getDocument().getDocumentElement()).getAdapterFor(ModelQueryAdapter.class);
CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration(model.getDocument().getDocumentElement());
assertNotNull("no CMElementDeclaration for '" + JSP20Namespace.ElementName.DOBODY + "'", declaration);
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
project.delete(true, null);
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class TestModelClone method checkModelQuery.
private void checkModelQuery(IStructuredModel model, Class class1) {
Document doc = ((IDOMModel) model).getDocument();
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) doc).getExistingAdapter(ModelQueryAdapter.class);
assertNotNull("model did not have modelQueryAdapter", modelQueryAdapter);
assertTrue("modelQueryAdapter is wrong class", class1.equals(JSPModelQueryImpl.class));
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class TestModelClone method checkEmbeddedModelQuery.
private void checkEmbeddedModelQuery(IStructuredModel model, Class outerQueryAdapter, Class outerQueryClass, Class embeddedQueryClass) {
Document doc = ((IDOMModel) model).getDocument();
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) doc).getExistingAdapter(ModelQueryAdapter.class);
assertNotNull("model did not have modelQueryAdapter", modelQueryAdapter);
Class expected = outerQueryAdapter;
Class actual = modelQueryAdapter.getClass();
assertEquals("document's model query is not as expected", expected, actual);
ModelQuery modelQuery = modelQueryAdapter.getModelQuery();
expected = outerQueryClass;
actual = modelQuery.getClass();
assertEquals("model query adapter's model query is not as expected", expected, actual);
ModelQuery nodeQuery = getEmbeddedModelQuery(doc);
assertNotNull("node does not have a modelQueryAdapter", nodeQuery);
expected = embeddedQueryClass;
actual = nodeQuery.getClass();
assertEquals("documents model query is not as expected", expected, actual);
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class TestModelAdapters method testJSPModel.
public void testJSPModel() throws IOException {
IModelManager modelManager = getModelManager();
IDOMModel structuredModel = (IDOMModel) modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
try {
boolean test = structuredModel.getId().equals(IModelManager.UNMANAGED_MODEL);
assertTrue(test);
ModelQueryAdapter modelQueryAdapter = structuredModel.getAdapter(ModelQueryAdapter.class);
assertNotNull("initial modelQueryAdapter should not be null", modelQueryAdapter);
IStructuredModel newModel = structuredModel.newInstance();
// IDOMDocument newDocument = ((IDOMModel)
// newModel).getDocument();
// INodeNotifier notifier = newDocument;
ModelQueryAdapter result = newModel.getAdapter(ModelQueryAdapter.class);
assertNotNull("newInstance modelQueryAdapter should not be null", result);
} finally {
// even though model is unmanaged, release still required, since
// adapter factories, etc., may be depending on it.
structuredModel.releaseFromEdit();
// if above complete's normally (with no exceptions)
// consider passed.
assertTrue(true);
}
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class ElementNodeFormatter method formatEndTag.
protected void formatEndTag(IDOMNode node, IStructuredFormatContraints formatContraints) {
if (!isEndTagMissing(node)) {
// end tag exists
IStructuredDocument structuredDocument = node.getModel().getStructuredDocument();
String lineDelimiter = structuredDocument.getLineDelimiter();
String nodeIndentation = getNodeIndent(node);
IDOMNode lastChild = (IDOMNode) node.getLastChild();
if (lastChild != null && lastChild.getNodeType() != Node.TEXT_NODE) {
if (isEndTagMissing(lastChild)) {
// find deepest child
IDOMNode deepestChild = (IDOMNode) lastChild.getLastChild();
while (deepestChild != null && deepestChild.getLastChild() != null && isEndTagMissing(deepestChild)) {
lastChild = deepestChild;
deepestChild = (IDOMNode) deepestChild.getLastChild();
}
if (deepestChild != null) {
if (deepestChild.getNodeType() == Node.TEXT_NODE) {
// Special indentation handling if lastChild's end
// tag is missing and deepestChild is a text node.
String nodeText = deepestChild.getNodeValue();
if (!nodeText.endsWith(lineDelimiter + nodeIndentation)) {
nodeText = StringUtils.appendIfNotEndWith(nodeText, lineDelimiter);
nodeText = StringUtils.appendIfNotEndWith(nodeText, nodeIndentation);
}
replaceNodeValue(deepestChild, nodeText);
} else
insertAfterNode(lastChild, lineDelimiter + nodeIndentation);
}
} else
// indent end tag
insertAfterNode(lastChild, lineDelimiter + nodeIndentation);
} else if (lastChild == null && firstStructuredDocumentRegionContainsLineDelimiters(node)) {
// BUG174243 do not indent end tag if node has empty content
// (otherwise new text node would be introduced)
ModelQueryAdapter adapter = (ModelQueryAdapter) ((IDOMDocument) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
CMElementDeclaration elementDeclaration = (CMElementDeclaration) adapter.getModelQuery().getCMNode(node);
if ((elementDeclaration == null) || (elementDeclaration.getContentType() != CMElementDeclaration.EMPTY)) {
// indent end tag
replace(structuredDocument, node.getFirstStructuredDocumentRegion().getEndOffset(), 0, lineDelimiter + nodeIndentation);
}
}
// format end tag name
IStructuredDocumentRegion endTagStructuredDocumentRegion = node.getLastStructuredDocumentRegion();
if (endTagStructuredDocumentRegion.getRegions().size() >= 3) {
ITextRegion endTagNameRegion = endTagStructuredDocumentRegion.getRegions().get(1);
removeRegionSpaces(node, endTagStructuredDocumentRegion, endTagNameRegion);
}
}
}
Aggregations