Search in sources :

Example 16 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class XSDUnusedTests method testImport008.

public void testImport008() {
    XSDSchema schema = getXSDSchema(TC_ROOT_FOLDER + "/Unused/test/Main007.xsd");
    importManager.performRemoval(schema);
    List list = importManager.getUnusedXSDDirectives();
    assertTrue(list.size() == 2);
    XSDSchemaDirective d1 = (XSDSchemaDirective) list.get(0);
    assertTrue("../Import1.xsd".equals(d1.getSchemaLocation()));
    XSDSchemaDirective d2 = (XSDSchemaDirective) list.get(1);
    assertTrue("../Include2.xsd".equals(d2.getSchemaLocation()));
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) List(java.util.List) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 17 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class XSDUnusedTests method testImport010.

public void testImport010() {
    XSDSchema schema = getXSDSchema(TC_ROOT_FOLDER + "/Unused/test/Main009.xsd");
    importManager.performRemoval(schema);
    List list = importManager.getUnusedXSDDirectives();
    assertTrue(list.size() == 1);
    XSDSchemaDirective d1 = (XSDSchemaDirective) list.get(0);
    assertTrue("../Import1.xsd".equals(d1.getSchemaLocation()));
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) List(java.util.List) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 18 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class XSDDirectivesManager method addToUnusedImports.

/**
 * From a list of used schemas, update the unusedImports list for the given schema
 *
 * @param schema
 * @param unusedImports
 * @param usedSchemas
 */
protected void addToUnusedImports(XSDSchema schema, List usedSchemas) {
    // now that we have the list of usedSchemas, get the list of unused
    // schemas by comparing this list to what is actually in the schema
    Iterator iter = schema.getContents().iterator();
    while (iter.hasNext()) {
        Object o = iter.next();
        if (o instanceof XSDSchemaDirective) {
            XSDSchemaDirective directive = (XSDSchemaDirective) o;
            boolean isUsed = false;
            Iterator iter2 = usedSchemas.iterator();
            while (iter2.hasNext()) {
                XSDSchema usedSchema = (XSDSchema) iter2.next();
                if (directive instanceof XSDImport && directive.getResolvedSchema() == usedSchema) {
                    isUsed = true;
                    break;
                }
                if (directive instanceof XSDInclude && ((XSDInclude) directive).getIncorporatedSchema() == usedSchema) {
                    isUsed = true;
                    usedDirectIncludes.add(usedSchema);
                    break;
                }
                // blindly accept redefines as used
                if (directive instanceof XSDRedefine) {
                    isUsed = true;
                    break;
                }
            }
            // If it is an include, we need to check if it is used indirectly
            if (directive instanceof XSDInclude && !isUsed) {
                XSDInclude inc = (XSDInclude) directive;
                XSDSchema incSchema = inc.getIncorporatedSchema();
                if (incSchema != null) {
                    XSDSchema usedSchema = getUsedIncludeSchema(incSchema, inc);
                    if (usedSchema != null) {
                        usedIndirectIncludes.add(directive);
                        usedIndirectIncludesMap.put(directive, usedSchema);
                        isUsed = true;
                    } else {
                        isUsed = false;
                    }
                }
            }
            // Also any redefines should be considered used
            if (!isUsed && !unusedDirectives.contains(directive) && !(directive instanceof XSDRedefine)) {
                unusedDirectives.add(directive);
            }
        }
    }
    Iterator iter3 = usedIndirectIncludes.iterator();
    while (iter3.hasNext()) {
        Object o = iter3.next();
        if (o instanceof XSDInclude) {
            XSDInclude inc = (XSDInclude) o;
            XSDSchema targetSchema = (XSDSchema) usedIndirectIncludesMap.get(inc);
            if (usedIncludeSchemas.contains(targetSchema) && usedDirectIncludes.contains(targetSchema)) {
                unusedDirectives.add(inc);
            } else {
                usedDirectIncludes.add(targetSchema);
            }
        }
    }
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDRedefine(org.eclipse.xsd.XSDRedefine) Iterator(java.util.Iterator) EObject(org.eclipse.emf.ecore.EObject) XSDImport(org.eclipse.xsd.XSDImport) XSDSchema(org.eclipse.xsd.XSDSchema) XSDInclude(org.eclipse.xsd.XSDInclude)

Example 19 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class XSDDirectivesManager method removeUnusedImports.

/**
 * Remove the list of all unused imports.  Imports is used in the generic term here.
 */
protected void removeUnusedImports() {
    Iterator iter = unusedDirectives.iterator();
    while (iter.hasNext()) {
        XSDSchemaDirective xsdDirective = (XSDSchemaDirective) iter.next();
        removeXSDDirective(xsdDirective);
    }
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) Iterator(java.util.Iterator)

Example 20 with XSDSchemaDirective

use of org.eclipse.xsd.XSDSchemaDirective in project webtools.sourceediting by eclipse.

the class XSDSchemaDirectiveAdapter method getText.

public String getText() {
    XSDSchemaDirective directive = (XSDSchemaDirective) target;
    String result = "";
    String location = directive.getSchemaLocation();
    if (location == null || location.equals("")) {
        result = "(" + Messages._UI_LABEL_NO_LOCATION_SPECIFIED + ")";
    } else {
        result = location;
    }
    // (otherwise the namespace is obviously the same as the containing schema's)
    if (directive instanceof XSDImport) {
        XSDImport importObj = (XSDImport) directive;
        String namespace = importObj.getNamespace();
        if (namespace != null) {
            result += "  {" + namespace + "}";
        }
    }
    return result;
}
Also used : XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDImport(org.eclipse.xsd.XSDImport)

Aggregations

XSDSchemaDirective (org.eclipse.xsd.XSDSchemaDirective)33 XSDSchema (org.eclipse.xsd.XSDSchema)28 List (java.util.List)24 Iterator (java.util.Iterator)5 XSDImport (org.eclipse.xsd.XSDImport)4 XSDRedefine (org.eclipse.xsd.XSDRedefine)4 EObject (org.eclipse.emf.ecore.EObject)3 ArrayList (java.util.ArrayList)2 Adapter (org.eclipse.emf.common.notify.Adapter)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 XSDSchemaDirectiveAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter)2 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)2 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)2 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)2 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)2 XSDInclude (org.eclipse.xsd.XSDInclude)2 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)2 MissingJarsException (com.amalto.workbench.service.MissingJarsException)1 InaccessibleWSDLException (com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException)1 IOException (java.io.IOException)1