private void processOverrides(Structure structure, Multimap<String, Feature> inheritedProperties) { for (Feature declaredProperty : structure.getOwnedFeatures()) { if (declaredProperty.isRestriction()) { Iterable<Feature> overriddenPropertyHierarchy = inheritedProperties.get(declaredProperty.getName()); processPropertyOverride(declaredProperty, overriddenPropertyHierarchy); inheritedProperties.removeAll(declaredProperty.getName()); } } }
@Check public void checkDuplicatePropertyAndInheritedPropertyHierarchies(Structure structure) { Multimap<String, FeatureHierarchy> inheritedFeatures = getInheritedFeaturesMap(structure); for (String inheritedFeatureName : inheritedFeatures.keySet()) { Collection<FeatureHierarchy> featuresForName = inheritedFeatures.get(inheritedFeatureName); checkFeatureNameDuplicates(structure, featuresForName); checkForDuplicateFeatureHierarchies(structure, inheritedFeatureName, featuresForName); } for (Feature property : structure.getOwnedFeatures()) { if (property.isRestriction()) { Collection<FeatureHierarchy> featuresForName = inheritedFeatures.get(property.getName()); checkPropertyRestrictionType(property, featuresForName); } } }
/** * Checks for properties with duplicates names within the same structure and also in the inheritance hierarchy */ private void checkFeatureNameDuplicates(Structure structure, Collection<FeatureHierarchy> featuresForName) { for (FeatureHierarchy hierarchy : featuresForName) { Feature root = hierarchy.getRoot(); if (root.getContainingDataType() == structure && !root.isRestriction() && hierarchy.getFeatures().size() > 1) { Feature inheritedFeature = hierarchy.getFeatures().get(1); error(String.format("Duplicate name: property '%s' is already defined in '%s'", root.getName(), inheritedFeature.getContainingDataType().getName()), root, RapidmlPackage.Literals.FEATURE__NAME); } } }