public static boolean sameOrOverrides(Feature feature1, Feature feature2) { // TODO add a stricter condition // But it's OK for now as // 1. this method is called only when feature1 and feature2 belong to the same data type hierarchy. // 2. Names are unique within a structure return feature1 == feature2 || feature1.getName().equals(feature2.getName()); }
private void checkRestrictionCardinality(Feature validatedProperty, Feature overriddenProperty) { if (validatedProperty.getMinOccurs() < overriddenProperty.getMinOccurs() || // (cardinalityMax(validatedProperty.getMaxOccurs()) > cardinalityMax( overriddenProperty.getMaxOccurs()))) { FeatureCardinalities cardinalities = FeatureCardinalities.getFeatureCardinalities(); String message = String.format( "The cardinality of property '%s' is incompatible with inherited property cardinality: '%s' ([%s, %s])", validatedProperty.getName(), cardinalities.getCardinality(overriddenProperty).getLabel(), overriddenProperty.getMinOccurs(), cardinalities.getCardinality(overriddenProperty).getUpperLabel()); error(message, validatedProperty, RapidmlPackage.Literals.ELEMENT__CARDINALITY); } }
private void processPropertyOverride(Feature declaredProperty, Iterable<Feature> overriddenPropertyHierarchy) { if (declaredProperty instanceof PrimitiveProperty) { PrimitiveProperty declaredPrimitiveProperty = (PrimitiveProperty) declaredProperty; for (PrimitiveProperty overriddenProperty : Iterables.filter(overriddenPropertyHierarchy, PrimitiveProperty.class)) { EList<Constraint> constraintsToCopy = overriddenProperty.getAllConstraints(); for (Constraint next : constraintsToCopy) { Constraint newConstraint = EcoreUtil.copy(next); declaredPrimitiveProperty.getAllConstraints().add(newConstraint); } } } if (declaredProperty.getDocumentation() == null) { for (Feature next : overriddenPropertyHierarchy) { if (next.getDocumentation() != null) { Documentation documentation = RapidmlFactory.eINSTANCE.createDocumentation(); documentation.setText(next.getDocumentation().getText()); declaredProperty.setDocumentation(documentation); } } } if (declaredProperty.getCardinality() == null) { for (Feature next : overriddenPropertyHierarchy) { if (next.getCardinality() != null) { declaredProperty.setCardinality(next.getCardinality()); } } } }
/** * Gets the cardinality of the data type property. * * @param property * the data type property * @return the cardinality of the data type property */ public Cardinality getCardinality(Feature property) { Cardinality cardinality = getCardinality(property.getMinOccurs(), property.getMaxOccurs()); return cardinality; }
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()); } } }
public String featureId(final ResourceDefinition aResource, final Feature aFeature) { String _name = aResource.getName(); String _plus = (_name + "."); String _name_1 = aFeature.getContainingDataType().getName(); String _plus_1 = (_plus + _name_1); String _plus_2 = (_plus_1 + "."); String _name_2 = aFeature.getName(); return (_plus_2 + _name_2); }
newProperty = newReferenceProperty; newProperty.setName(inheritedProperty.getName()); newProperty.setCardinality(inheritedProperty.getCardinality()); newProperty.setReadOnly(inheritedProperty.isReadOnly()); newProperty.setKey(inheritedProperty.isKey()); if (inheritedProperty.getDocumentation() != null) { Documentation documentation = RapidmlFactory.eINSTANCE.createDocumentation(); documentation.setText(inheritedProperty.getDocumentation().getText()); newProperty.setDocumentation(documentation); for (Extension next : inheritedProperty.getExtensions()) { if (next.getName() != null && next.getName().startsWith("gen-")) { newProperty.getExtensions().add(newExtension);
int _maxOccurs = field.getMaxOccurs(); boolean _equals = (_maxOccurs == (-1)); if (_equals) { _builder_2.append(type); _builder_2.append(" "); String _initialUpper = this.nameHelper.initialUpper(field.getName()); _builder_2.append(_initialUpper); _builder_2.append(" { get; set; }");
/** * 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); } } }
public boolean checkMultiplicity(final Feature prop, final MultiplicitySelector multiplicity) { boolean _or = false; if ((multiplicity == null)) { _or = true; } else { boolean _switchResult = false; if (multiplicity != null) { switch (multiplicity) { case SINGLE_VALUED: int _maxOccurs = prop.getMaxOccurs(); _switchResult = (_maxOccurs == 1); break; case MULTI_VALUED: int _maxOccurs_1 = prop.getMaxOccurs(); _switchResult = (_maxOccurs_1 != 1); break; default: break; } } _or = _switchResult; } return _or; }
public boolean checkRequired(final Feature prop, final Boolean required) { return (Objects.equal(required, null) || ((required).booleanValue() == (prop.getMinOccurs() > 0))); }
@Override public String apply(FeatureHierarchy input) { return input.getRoot().getContainingDataType().getName(); } }));
private String generateFeatureType(final Feature feature) { StringConcatenation _builder = new StringConcatenation(); String _featureType = this.paramHelper.featureType(feature, this.importHelper); _builder.append(_featureType); _builder.newLineIfNotEmpty(); { int[] _cardinality = feature.getCardinality(); boolean _tripleNotEquals = (_cardinality != null); if (_tripleNotEquals) { String _prettyPrintedMultiplicity = this.commonServices.getPrettyPrintedMultiplicity(feature); _builder.append(_prettyPrintedMultiplicity); } } _builder.newLineIfNotEmpty(); return _builder.toString(); }
int _maxOccurs = field.getMaxOccurs(); boolean _equals = (_maxOccurs == (-1)); if (_equals) { _builder_2.append(type); _builder_2.append(" "); String _initialUpper = this.nameHelper.initialUpper(field.getName()); _builder_2.append(_initialUpper); _builder_2.append(" { get; set; }");
@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); } } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public int getMaxOccurs() { if (getCardinality() == null || getCardinality().length != 2) { return getBaseProperty().getMaxOccurs(); } return getCardinality()[1]; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public int getMinOccurs() { if (getCardinality() == null || getCardinality().length != 2) { return getBaseProperty().getMinOccurs(); } return getCardinality()[0]; }
private Multimap<String, Feature> buildNameToInheritedPropertiesMap(Structure structure) { Multimap<String, Feature> inheritedProperties = LinkedHashMultimap.create(); for (Inheritable next : structure.getSupertypes()) { if (next instanceof Structure) { Structure supertype = (Structure) next; addInheritedProperties(supertype); for (Feature inheritedProperty : supertype.getOwnedFeatures()) { inheritedProperties.put(inheritedProperty.getName(), inheritedProperty); } } } return inheritedProperties; } }
EList<Feature> _ownedFeatures = this.type.getOwnedFeatures(); for (final Feature feature : _ownedFeatures) { boolean _containsKey = this.includedProperties.containsKey(feature.getName()); if (_containsKey) { final EffectiveRealization.ConstrainedFeature constrainedFeature = this.constrainFeature(feature, this.includedProperties.get(feature.getName())); constrainedFeatures.put(feature.getName(), constrainedFeature); Iterable<Feature> _filter = IterableExtensions.<Feature>filter(this.type.getOwnedFeatures(), _function); for (final Feature refProp : _filter) { boolean _containsKey_1 = this.includedProperties.containsKey(refProp.getName()); if (_containsKey_1) { boolean _containsKey_2 = this.nestedRefRealizations.containsKey(refProp.getName()); if (_containsKey_2) { final CompletableFuture<EffectiveRealization> future = new CompletableFuture<EffectiveRealization>(); future.complete(this.nestedRefRealizations.get(refProp.getName())); refRealizationFutures.put(refProp.getName(), future); } else { refRealizationFutures.put(refProp.getName(), this.provider.getPropertyRealization(((ReferenceProperty) refProp)).get());
private void checkPropertyRestrictionType(Feature validatedProperty, Collection<FeatureHierarchy> featuresHierarchies) { if (!featuresHierarchies.isEmpty()) { // Empty featuresHierarchies or several hierarchies should // be processed by another validator FeatureHierarchy featureHierarchy = featuresHierarchies.iterator().next(); if (featureHierarchy.getFeatures().size() == 1) { String message = String.format("'%s' restricts a property which does not exist in extended supertypes", validatedProperty.getName()); error(message, validatedProperty, RapidmlPackage.Literals.FEATURE__NAME); } else if (featureHierarchy.getFeatures().size() > 1) { Feature restrictedProperty = featureHierarchy.getFeatures().get(1); checkRestrictionCardinality(validatedProperty, restrictedProperty); if (validatedProperty instanceof PrimitiveProperty) { checkPrimitivePropertyRestrictionType((PrimitiveProperty) validatedProperty, restrictedProperty); } if (validatedProperty instanceof ReferenceProperty) { checkReferencePropertyRestrictionType((ReferenceProperty) validatedProperty, restrictedProperty); } } } }