@Override @SuppressWarnings("unchecked") public IncludeDefImpl getElement() throws XMLStreamException, QuickFixException { if (parentHandler.getDefDescriptor().getDefType() != DefType.LIBRARY) { error("aura:include may only be set in a library."); } DefDescriptor<LibraryDef> parentDescriptor = (DefDescriptor<LibraryDef>) parentHandler.getDefDescriptor(); builder.setLocation(getLocation()); String name = getAttributeValue(ATTRIBUTE_NAME); if (!AuraTextUtil.isNullEmptyOrWhitespace(name)) { builder.setName(name); } else { error("aura:include must specify a valid library name."); } if (name.toLowerCase().endsWith(".js")) { name = name.substring(0, name.length() - 3); } builder.setDescriptor( DefDescriptorImpl.getInstance( String.format("js://%s.%s", parentDescriptor.getNamespace(), name), IncludeDef.class, parentDescriptor)); String imports = getAttributeValue(ATTRIBUTE_IMPORTS); if (!AuraTextUtil.isNullEmptyOrWhitespace(imports)) { builder.setImports(Arrays.asList(imports.split("\\s*\\,\\s*"))); } String exports = getAttributeValue(ATTRIBUTE_EXPORTS); if (!AuraTextUtil.isNullEmptyOrWhitespace(exports)) { builder.setExports(exports); } builder.setParentDescriptor(parentDescriptor); int next = xmlReader.next(); if (next != XMLStreamConstants.END_ELEMENT || !TAG.equalsIgnoreCase(getTagName())) { error("expected end of %s tag", TAG); } builder.setOwnHash(source.getHash()); return builder.build(); }
@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); } String export = getAttributeValue(ATTRIBUTE_EXPORT); if (!AuraTextUtil.isNullEmptyOrWhitespace(export)) { builder.setExport(export); } builder.setDescription(getAttributeValue(RootTagHandler.ATTRIBUTE_DESCRIPTION)); int next = xmlReader.next(); if (next != XMLStreamConstants.END_ELEMENT || !TAG.equalsIgnoreCase(getTagName())) { error("expected end of %s tag", TAG); } builder.setOwnHash(source.getHash()); return builder.build(); }