static JvmParameterizedTypeReference parseType(Notifier context, String typeName, AbstractBuilder caller) { ResourceSet resourceSet = toResource(context).getResourceSet(); URI uri = caller.computeUnusedUri(resourceSet); Resource resource = caller.getResourceFactory().createResource(uri); resourceSet.getResources().add(resource); try (StringInputStream is = new StringInputStream(generateTypenameCode(typeName))) { resource.load(is, null); SarlScript script = resource.getContents().isEmpty() ? null : (SarlScript) resource.getContents().get(0); SarlEvent topElement = (SarlEvent) script.getXtendTypes().get(0); SarlField member = (SarlField) topElement.getMembers().get(0); JvmTypeReference reference = member.getType(); if (reference instanceof JvmParameterizedTypeReference) { final JvmParameterizedTypeReference pref = (JvmParameterizedTypeReference) reference; if (!pref.getArguments().isEmpty()) { EcoreUtil2.resolveAll(resource); return pref; } } } catch (Exception exception) { throw new TypeNotPresentException(typeName, exception); } finally { resourceSet.getResources().remove(resource); } throw new TypeNotPresentException(typeName, null); }
/** Create a field declaration. * * @param field the field to generate. * @param it the output * @param context the generation context. */ protected void generatePythonField(SarlField field, PyAppendable it, IExtraLanguageGeneratorContext context) { generateBlockComment(getTypeBuilder().getDocumentation(field), it); if (!field.isStatic()) { it.append("self."); //$NON-NLS-1$ } final String fieldName = it.declareUniqueNameVariable(field, field.getName()); it.append(fieldName); it.append(" = "); //$NON-NLS-1$ if (field.getInitialValue() != null) { generate(field.getInitialValue(), null, it, context); } else { it.append(PyExpressionGenerator.toDefaultValue(field.getType())); } it.newLine(); }