Exemple #1
0
 public static MetaModelManager getMetaModelManager(Resource resource) {
   MetaModelManagerResourceAdapter adapter =
       MetaModelManagerResourceAdapter.getAdapter(resource, null);
   MetaModelManager metaModelManager = adapter.getMetaModelManager();
   assert metaModelManager != null;
   return metaModelManager;
 }
Exemple #2
0
 /**
  * Create an Xtext resource containing the parsed expression within a typeContext and supervised
  * by a metaModelManager.
  *
  * <p>Provided an EssentialOCL resource registration has been made the created resource named
  * internal.essentialocl may be cast to an XtextResource. Semantic errors may be found at the
  * Resource.errors and may be converted to ParseExceptions by invoking checkResourceErrors.
  *
  * @param metaModelManager the overall type / meta-model domain
  * @param typeContext the type that provides the scope of expression
  * @param expression to be parsed
  * @return the Xtext resource which may be cast to XtextResource
  * @throws IOException if resource loading fails
  */
 public static Resource createXtextResource(
     MetaModelManager metaModelManager, URI uri, NamedElement typeContext, String expression)
     throws IOException {
   InputStream inputStream = new ByteArrayInputStream(expression.getBytes());
   ResourceSetImpl resourceSet = new ResourceSetImpl();
   Resource resource = resourceSet.createResource(uri);
   MetaModelManagerResourceAdapter.getAdapter(resource, metaModelManager);
   if (resource instanceof EvaluationContext) {
     ((EvaluationContext) resource).setContext(typeContext, null);
   }
   resource.load(inputStream, null);
   return resource;
 }