Search in sources :

Example 1 with CMVisitor

use of org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor in project webtools.sourceediting by eclipse.

the class TestCyclicGroupReferences method testCyclicGroupReferences.

/**
 * Test CMVisitor for cyclic group references.
 */
public void testCyclicGroupReferences() {
    // $NON-NLS-1$
    IFile file = getFile("Test.xml");
    CMVisitor cmVisitor = new CMVisitor();
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForRead(file);
        // $NON-NLS-1$
        assertNotNull("failure loading model", model);
        IDOMModel domModel = (IDOMModel) model;
        IDOMDocument document = domModel.getDocument();
        // $NON-NLS-1$
        assertNotNull("failure getting document", document);
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model);
        // $NON-NLS-1$
        assertNotNull("ModelQuery is missing", modelQuery);
        IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
        // $NON-NLS-1$
        assertNotNull("missing document element", documentElement);
        CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
        assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        cmElementDeclaration);
        cmVisitor.visitCMElementDeclaration(cmElementDeclaration);
    } catch (Throwable th) {
        fail("Test failed :" + th.getClass().getName());
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) CMVisitor(org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)1 CMVisitor (org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor)1 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)1 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1