@Check public void checkImportDeclarationUnique(ZenModel model) { HashSet<String> aliases = new HashSet<>(); HashSet<String> namespaces = new HashSet<>(); for (ImportDeclaration importDecl : model.getImports()) { if (!Strings.isNullOrEmpty(importDecl.getAlias()) && !aliases.add(importDecl.getAlias())) { error(NLS.bind(Messages.XtextDslJavaValidator_duplicateAlias, importDecl.getAlias()), importDecl, RapidmlPackage.Literals.IMPORT_DECLARATION__ALIAS); } if (!Strings.isNullOrEmpty(importDecl.getImportedNamespace()) && !namespaces.add(importDecl.getImportedNamespace())) { error(NLS.bind(Messages.XtextDslJavaValidator_duplicateNamespace, importDecl.getImportedNamespace()), importDecl, RapidmlPackage.Literals.IMPORT_DECLARATION__IMPORTED_NAMESPACE); } } }
/** * @param model * model * @return list of resource definitions that imported using import RESTfulInterfaces */ static List<ResourceDefinition> getImportedResources(ZenModel model) { ArrayList<ResourceDefinition> result = new ArrayList<>(); for (ImportDeclaration importDecl : model.getImports()) { String uri = importDecl.getImportURI(); if (!Strings.isNullOrEmpty(uri)) { Resource modelResource = importDecl.eResource(); Resource resource = getResource(modelResource, uri); if (resource != null && resource.getErrors().isEmpty() && !resource.getContents().isEmpty()) { ZenModel zenModel = (ZenModel) resource.getContents().get(0); String namespace = Strings.isNullOrEmpty(zenModel.getNamespace()) ? zenModel.getName() : zenModel .getNamespace() + "." + zenModel.getName(); //$NON-NLS-1$ for (ResourceAPI resourceAPI : zenModel.getResourceAPIs()) { String ifaceFQN = namespace + "." + resourceAPI.getName(); //$NON-NLS-1$ if (ifaceFQN.equals(importDecl.getImportedNamespace())) { result.addAll(resourceAPI.getOwnedResourceDefinitions()); } } } } } return result; }
public void addInheritedProperties(ZenModel model) { if (model == null) { // can be null when an import declaration is declared, but elements from it are never used return; } if (TagUtils.getTagWithName(model, TagUtils.DATATYPE_PROCESSED).isPresent()) { return; } TagUtils.addTag(model, TagUtils.DATATYPE_PROCESSED).setValue("true"); for (Structure structure : EcoreUtil2.getAllContentsOfType(model, Structure.class)) { addInheritedProperties(structure); } for (ImportDeclaration import_: model.getImports()) { addInheritedProperties(import_.getImportedModel()); } }