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()));
}
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()));
}
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);
}
}
}
}
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);
}
}
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;
}
Aggregations