}
// can't extend itself
if (extendsDescriptor.equals(descriptor)) {
String msg = String.format("Theme %s cannot extend itself", descriptor);
throw new InvalidDefinitionException(msg, getLocation());
}
// ensure no circular hierarchy
DefDescriptor<ThemeDef> current = extendsDescriptor;
while (current != null) {
if (current.equals(descriptor)) {
String msg = String.format("%s must not through its parent eventually extend itself", descriptor);
throw new InvalidDefinitionException(msg, getLocation());
}
current = current.getDef().getExtendsDescriptor();
}
// it would be a mistake to extend an imported theme
if (imports.contains(extendsDescriptor)) {
String msg = String.format("Cannot extend and import from the same theme %s", extendsDescriptor);
throw new InvalidDefinitionException(msg, getLocation());
}
// cmp themes can't extend other themes. This is an arbitrary restriction to prevent improper usage.
// if changing, be sure to look over any impact on appendDependencies as well.
if (isCmpTheme) {
String msg = String.format("Component theme %s must not extend any other theme", descriptor);
throw new InvalidDefinitionException(msg, getLocation());
}
// the parent theme must not be a cmp theme. This would usually be a mistake/improper usage.
if (extendsDescriptor.getDef().isCmpTheme()) {
String msg = String.format("Theme %s must not extend from a component theme", descriptor);
throw new InvalidDefinitionException(msg, getLocation());
}
}
// cmp themes cannot import. most of the time this would be improper usage.
// if changing, be sure to look over any impact on appendDependencies as well.
if (isCmpTheme && !imports.isEmpty()) {
throw new InvalidDefinitionException("Component themes cannot import another theme", getLocation());
}
for (DefDescriptor<ThemeDef> theme : imports) {
ThemeDef def = theme.getDef();
// can't import a cmp theme
if (def.isCmpTheme()) {
String msg = String.format("Theme %s cannot be imported because it is a component theme", theme);
throw new InvalidDefinitionException(msg, getLocation());
}
// can't import a theme with a parent. This is an arbitrary restriction to enforce a level of var lookup
// simplicity and prevent misuse of imports.
if (def.getExtendsDescriptor() != null) {
String msg = String.format("Theme %s cannot be imported since it uses the 'extends' attribute", theme);
throw new InvalidDefinitionException(msg, getLocation());
}
// can't import a theme that uses a provider.
if (def.getDescriptorProvider() != null || def.getMapProvider() != null) {
String msg = String.format("Theme %s cannot be imported since it uses a provider", theme);
throw new InvalidDefinitionException(msg, getLocation());
}
}
// vars
for (VarDef def : vars.values()) {