for(PPTypeInfo info : typeInfo) {
Type type = PPTPFactory.eINSTANCE.createType();
type.setName(info.getTypeName());
type.setDocumentation(info.getDocumentation());
for(Map.Entry<String, PPTypeInfo.Entry> entry : info.getParameters().entrySet()) {
Parameter parameter = PPTPFactory.eINSTANCE.createParameter();
parameter.setName(entry.getKey());
parameter.setDocumentation(entry.getValue().documentation);
parameter.setRequired(entry.getValue().isRequired());
type.getParameters().add(parameter);
}
for(Map.Entry<String, PPTypeInfo.Entry> entry : info.getProperties().entrySet()) {
Property property = PPTPFactory.eINSTANCE.createProperty();
property.setName(entry.getKey());
property.setDocumentation(entry.getValue().documentation);
property.setRequired(entry.getValue().isRequired());
type.getProperties().add(property);
}
getContents().add(type);
}
}
break;
case FUNCTION: {
List<PPFunctionInfo> functions = helper.getFunctionInfo(uri.path(), new InputStreamReader(
inputStream));
for(PPFunctionInfo info : functions) {
Function pptpFunc = PPTPFactory.eINSTANCE.createFunction();
pptpFunc.setName(info.getFunctionName());
pptpFunc.setRValue(info.isRValue());
pptpFunc.setDocumentation(info.getDocumentation());
getContents().add(pptpFunc);
}
}
break;
case META: {
PPTypeInfo info = helper.getMetaTypeInfo(uri.path(), new InputStreamReader(inputStream));
MetaType type = PPTPFactory.eINSTANCE.createMetaType();
type.setName(info.getTypeName());
type.setDocumentation(info.getDocumentation());
for(Map.Entry<String, PPTypeInfo.Entry> entry : info.getParameters().entrySet()) {
Parameter parameter = PPTPFactory.eINSTANCE.createParameter();
parameter.setName(entry.getKey());
parameter.setDocumentation(entry.getValue().documentation);
parameter.setRequired(entry.getValue().isRequired());
type.getParameters().add(parameter);
}
// TODO: Scan the puppet source for providers for the type
// This is a CHEAT -
// https://github.com/puppetlabs/geppetto/issues/37
Parameter p = PPTPFactory.eINSTANCE.createParameter();
p.setName("provider");
p.setDocumentation("");
p.setRequired(false);
type.getParameters().add(p);
getContents().add(type);
break;
}
case TYPEFRAGMENT: {
for(PPTypeInfo type : helper.getTypeFragments(uri.path(), new InputStreamReader(inputStream))) {
TypeFragment fragment = PPTPFactory.eINSTANCE.createTypeFragment();
fragment.setName(type.getTypeName());
// add the properties (will typically load just one).
for(Map.Entry<String, PPTypeInfo.Entry> entry : type.getProperties().entrySet()) {
Property property = PPTPFactory.eINSTANCE.createProperty();
property.setName(entry.getKey());
property.setDocumentation(entry.getValue().documentation);
property.setRequired(entry.getValue().isRequired());
fragment.getProperties().add(property);
}
// add the parameters (will typically load just one).
for(Map.Entry<String, PPTypeInfo.Entry> entry : type.getParameters().entrySet()) {
Parameter parameter = PPTPFactory.eINSTANCE.createParameter();
parameter.setName(entry.getKey());
parameter.setDocumentation(entry.getValue().documentation);
parameter.setRequired(entry.getValue().isRequired());
fragment.getParameters().add(parameter);
}
getContents().add(fragment);
}
break;