@Override
@SuppressWarnings("unchecked")
public IncludeDefRefImpl getElement() throws XMLStreamException, QuickFixException {
DefDescriptor<LibraryDef> parentDescriptor = (DefDescriptor<LibraryDef>) parentHandler.getDefDescriptor();
if (parentDescriptor.getDefType() != DefType.LIBRARY) {
throw new InvalidDefinitionException("aura:include may only be set in a library.", getLocation());
}
validateAttributes();
builder.setLocation(getLocation());
String name = getAttributeValue(ATTRIBUTE_NAME);
if (AuraTextUtil.isNullEmptyOrWhitespace(name)) {
throw new InvalidDefinitionException(("aura:include must specify a valid library name."), getLocation());
}
builder.setDescriptor(SubDefDescriptorImpl.getInstance(name, parentDescriptor, IncludeDefRef.class));
builder.setIncludeDescriptor(DefDescriptorImpl.getInstance(
String.format("%s.%s", parentDescriptor.getNamespace(), name), IncludeDef.class, parentDescriptor));
String importNames = getAttributeValue(ATTRIBUTE_IMPORTS);
if (!AuraTextUtil.isNullEmptyOrWhitespace(importNames)) {
List<DefDescriptor<IncludeDef>> imports = Lists.newLinkedList();
for (String importName : Arrays.asList(importNames.trim().split("\\s*\\,\\s*"))) {
String[] parts = importName.split(":");
if (parts.length == 1) { // local import
imports.add(DefDescriptorImpl.getInstance(
String.format("%s.%s", parentDescriptor.getNamespace(), importName), IncludeDef.class,
parentDescriptor));
} else if (parts.length == 3) { // external import
DefDescriptor<LibraryDef> externalLibrary = DefDescriptorImpl.getInstance(
String.format("%s:%s", parts[0], parts[1]), LibraryDef.class);
imports.add(DefDescriptorImpl.getInstance(String.format("%s.%s", parts[0], parts[2]),
IncludeDef.class, externalLibrary));
} else { // invalid import name
throw new InvalidDefinitionException(String.format(
"Invalid name in aura:include imports property: %s", importName), getLocation());
}
}
builder.setImports(imports);
}