private String paramType(final Structure complexType) { return complexType.getName(); }
private String interpolate(final String pattern) { String result = pattern.replaceAll("\\$\\{TypeName\\}", this.type.getName()); result = result.replaceAll("\\$\\{RealizationRuleName\\}", Overlay.<Base>of(this.rule).getPathInParent()); return result; }
public String getTypePocoName(final Structure type) { String _xblockexpression = null; { final String name = type.getName(); final String suggested = this.initialUpper(name); _xblockexpression = this.resolve(suggested, name, this.typePocoNames); } return _xblockexpression; }
public String getTypeInterfaceName(final Structure type) { String _xblockexpression = null; { final String name = type.getName(); String _initialUpper = this.initialUpper(name); final String suggested = ("I" + _initialUpper); _xblockexpression = this.resolve(suggested, name, this.typeInterfaceNames); } return _xblockexpression; }
@Override public String apply(FeatureHierarchy input) { return input.getRoot().getContainingDataType().getName(); } }));
protected void checkCircularContainment(Set<Structure> containmentChain, Structure currentDataType) { if (currentDataType == null) { return; } if (containmentChain.contains(currentDataType)) { String dataTypeNames = Joiner.on(", ").join(transform(containmentChain, getName())); String message = String.format("Circular containment dependencies: %s and %s", dataTypeNames, currentDataType.getName()); warning(message, RapidmlPackage.Literals.REFERENCE_PROPERTY__CONTAINER); return; } containmentChain.add(currentDataType); for (Structure type : getContainmentReferencePropertyTypes(currentDataType)) { checkCircularContainment(containmentChain, type); } }
private String getRefTypeName(ReferenceProperty prop) { DataModel thisDataModel = (DataModel) prop.getContainingDataType().eContainer(); ZenModel thisModel = (ZenModel) thisDataModel.eContainer(); Structure refType = prop.getType(); DataModel refDataModel = (DataModel) refType.eContainer(); ZenModel refModel = (ZenModel) refDataModel.eContainer(); if (thisDataModel == refDataModel) { return refType.getName(); } else if (thisModel == refModel) { return String.format("%s.%s", refDataModel.getName(), refType.getName()); } else { return String.format("%s.%s.%s", refModel.getName(), refDataModel.getName(), refType.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); }
private JsonNode createDataModelMetadata(DataModel dm) { ObjectNode dmRoot = newObjectNode(); ObjectNode structs = dmRoot.putObject("structures"); for (DataType type : dm.getOwnedDataTypes()) { if (type instanceof Structure) { Structure struct = (Structure) type; structs.set(struct.getName(), createStructureMetadata(struct)); } // TODO fill in enums object // TODO fill in simpleTypes object } return dmRoot; }
@Check public void checkRealization(ServiceDataResource resource) { if (isWithAutoRealizations(resource)) { try { new EffectiveRealizationRegistry().getRealization(resource); } catch (NoRealizationException e) { error(String.format("Cannot find an auto-realization rule matching data structure %s in this context.", resource.getActualType().getName()), resource, RapidmlPackage.Literals.RESOURCE_DEFINITION__NAME); } } }
/** * 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); } } }
private JsonNode createStructureMetadata(Structure struct) { ObjectNode root = newObjectNode(); root.put("name", struct.getName()); ObjectNode fields = root.putObject("fields"); for (PrimitiveProperty prop : struct.getPrimitiveProperties()) { ObjectNode field = fields.putObject(prop.getName()); field.put("name", prop.getName()); field.put("type", prop.getPrimitiveType().getName()); field.put("multi", prop.getMaxOccurs() < 0); } for (ReferenceProperty prop : struct.getReferenceProperties()) { ObjectNode field = fields.putObject(prop.getName()); field.put("name", prop.getName()); field.put("type", "ref"); field.put("multi", prop.getMaxOccurs() < 0); field.put("refType", getRefTypeName(prop)); } return root; }
@Check public void checkContainerReferenceProperty(ReferenceProperty referenceProperty) { if (referenceProperty.isContainer()) { ReferenceProperty inverse = referenceProperty.getInverse(); if (inverse != null && !inverse.isContainment()) { String message = String.format( "The inverse reference property '%s' of the data type '%s' is not a containing reference. An inverse container reference property must specify a containing reference as its inverse.", inverse.getName(), inverse.getContainingDataType().getName()); error(message, RapidmlPackage.Literals.REFERENCE_PROPERTY__CONTAINER); return; } } }
private void checkReferencePropertyRestrictionType(ReferenceProperty validatedProperty, Feature overriddenProperty) { Structure restrictionType = validatedProperty.getType(); if (overriddenProperty instanceof ReferenceProperty) { Structure overriddenType = ((ReferenceProperty) overriddenProperty).getType(); if (overriddenType == restrictionType) {// same type return; } if (restrictionType.getAllSupertypes().contains(overriddenType)) {// covariance return; } String message = String.format( "The type of property '%s' is incompatible with inherited property type: '%s'", validatedProperty.getName(), overriddenType.getName()); error(message, validatedProperty, RapidmlPackage.Literals.REFERENCE_PROPERTY__TYPE); } }
/** * @deprecated use {@link CommonServices#getRequestTypeName(TypedRequest)} or * {@link CommonServices#getResponseTypeName(TypedResponse)} instead * @param message typed message * @return generated type name for XSD generator that avoid name clashes */ @Deprecated public static String getMessageTypeName(TypedMessage message) { Method method = (Method) message.eContainer(); String methodName = method.getHttpMethod().getName().toLowerCase() + method.getContainingResourceDefinition().getName(); final Structure type = message.getActualType(); ImmutableList<TypedMessage> list = ImmutableList.copyOf(Iterators.filter( Iterators.filter(method.getContainingResourceDefinition().eAllContents(), TypedMessage.class), new Predicate<TypedMessage>() { @Override public boolean apply(TypedMessage input) { return input.getActualType() == type; } })); String baseName = Strings.toFirstUpper(methodName) + '_' + message.getActualType().getName(); if (list.size() > 1) { return baseName + '_' + (list.indexOf(message) + 1); } return baseName; }
/** * The container keyword must be used on any reference that is the inverse of a containing reference. The container * keyword must not be used on any reference that is not the inverse of a containing reference. */ @Check public void checkContainmentReferenceProperty(ReferenceProperty referenceProperty) { if (referenceProperty.isContainment()) { ReferenceProperty inverse = referenceProperty.getInverse(); if (inverse != null && !inverse.isContainer()) { String message = String.format( "The inverse reference property '%s' of the data type '%s' is not a container reference. An inverse containing reference property must specify a container reference as its inverse.", inverse.getName(), inverse.getContainingDataType().getName()); error(message, RapidmlPackage.Literals.REFERENCE_PROPERTY__CONTAINMENT); } } }
private CharSequence generate(final Feature field) { CharSequence _xblockexpression = null; { String _switchResult = null; boolean _matched = false; if (field instanceof PrimitiveProperty) { _matched=true; _switchResult = this.typeHelper.getCsharpType(((PrimitiveProperty)field).getType().getName()); } if (!_matched) { if (field instanceof ReferenceProperty) { _matched=true; String _name = ((ReferenceProperty)field).getDataType().getName(); _switchResult = ("I" + _name); } } final String typeName = _switchResult; _xblockexpression = this.generate(field, typeName); } return _xblockexpression; }
private CharSequence generateFieldProperty(final Feature field) { CharSequence _xblockexpression = null; { String _switchResult = null; boolean _matched = false; if (field instanceof PrimitiveProperty) { _matched=true; _switchResult = this.typeHelper.getCsharpType(((PrimitiveProperty)field).getType().getName()); } if (!_matched) { if (field instanceof ReferenceProperty) { _matched=true; String _name = ((ReferenceProperty)field).getDataType().getName(); _switchResult = ("I" + _name); } } final String typeName = _switchResult; _xblockexpression = this.generateFieldProperty(field, typeName); } return _xblockexpression; }
public void generate() { EList<DataModel> _dataModels = this.model.getDataModels(); for (final DataModel dataModel : _dataModels) { final Function1<DataType, Boolean> _function = (DataType it) -> { return Boolean.valueOf((it instanceof Structure)); }; final Function1<DataType, Structure> _function_1 = (DataType it) -> { return ((Structure) it); }; Iterable<Structure> _map = IterableExtensions.<DataType, Structure>map(IterableExtensions.<DataType>filter(dataModel.getOwnedDataTypes(), _function), _function_1); for (final Structure type : _map) { { @Extension final FileHelper fileHelper = FileHelper.of(type, FileRole.POCOS, this.context, this.config); fileHelper.writeFile(this.generatePoco(type), fileHelper.getCsharpFileName(type.getName())); } } } }