/**
  * Loads the imports for the given root into the given {@link ExecEnv}.
  *
  * @param root the root AST node
  * @param env the {@link ExecEnv}
  */
 protected void loadImports(final org.eclipselabs.simpleocl.Module root, final ExecEnv env) {
   String uriPrefix = root.eResource().getURI().toPlatformString(true);
   uriPrefix = uriPrefix.substring(0, uriPrefix.lastIndexOf('/') + 1);
   final ModuleResolver mr = new DefaultModuleResolver(uriPrefix, new ResourceSetImpl());
   for (Import imp : root.getImports()) {
     try {
       env.loadModule(mr, imp.getName(), false);
     } catch (Exception e) {
       SimpleoclUIPlugin.logError(e.getLocalizedMessage(), e);
     }
   }
 }
 /**
  * Loads the metamodels for the given root into the given {@link ExecEnv}.
  *
  * @param root the root AST node
  * @param env the {@link ExecEnv}
  */
 protected void loadMetamodels(final org.eclipselabs.simpleocl.Module root, final ExecEnv env) {
   final ResourceSet rs = new ResourceSetImpl();
   for (OclMetamodel oclMetamodel : root.getMetamodels()) {
     String uriString = oclMetamodel.getUri();
     if (uriString == null || uriString.trim().isEmpty()) {
       continue;
     }
     try {
       URI uri = URI.createURI(uriString);
       Resource res = rs.getResource(uri, true);
       Metamodel metamodel = EmftvmFactory.eINSTANCE.createMetamodel();
       metamodel.setResource(res);
       env.registerMetaModel(oclMetamodel.getName(), metamodel);
     } catch (Exception e) {
       SimpleoclUIPlugin.logError(e.getLocalizedMessage(), e);
     }
   }
 }
 /**
  * Returns the EMFTVM syntax completion proposals for the given prefix and root.
  *
  * @param prefix the syntax prefix
  * @param root the root AST node
  * @param propertyCallType the {@link PropertyCallType}
  * @return the syntax completion proposals
  */
 protected List<SyntaxCompletionProposal> getEMFTVMProposals(
     final String prefix, final EObject root, final PropertyCallType propertyCallType) {
   final String strippedPrefix = stripPropertyCallPrefix(prefix);
   final boolean isCollectionOp = propertyCallType == PropertyCallType.COLLECTION;
   final boolean isStatic = propertyCallType == PropertyCallType.STATIC;
   final SortedSet<String> features = new TreeSet<String>();
   final Map<String, URL> images = new HashMap<String, URL>();
   final Map<String, String> displayStrings = new HashMap<String, String>();
   final ExecEnv env = EmftvmFactory.eINSTANCE.createExecEnv();
   if (root instanceof org.eclipselabs.simpleocl.Module) {
     loadImports((org.eclipselabs.simpleocl.Module) root, env);
   }
   for (Module module : env.getModules().values()) {
     for (Feature f : module.getFeatures()) {
       if (!f.getName().matches("^\\w+")) {
         continue;
       }
       if (isStatic != f.isStatic()) {
         continue;
       }
       EClassifier context = f.getEContext();
       if (context != null
           && isCollectionOp != Collection.class.isAssignableFrom(context.getInstanceClass())) {
         continue;
       }
       String name = f.getName();
       if (strippedPrefix.isEmpty() || name.startsWith(strippedPrefix)) {
         StringBuilder sb = new StringBuilder(name);
         StringBuilder displayString = new StringBuilder(name);
         if (f instanceof Operation) {
           sb.append('(');
           displayString.append('(');
           boolean first = true;
           for (Parameter par : ((Operation) f).getParameters()) {
             if (!first) {
               sb.append(", ");
               displayString.append(", ");
             }
             sb.append(par.getName());
             displayString.append(par.getName()).append(" : ");
             if (!EMFTVMUtil.NATIVE.equals(par.getTypeModel())) {
               displayString.append(par.getTypeModel()).append("!");
             }
             displayString.append(par.getType());
             first = false;
           }
           sb.append(')');
           displayString.append(") - ");
           if (!EMFTVMUtil.NATIVE.equals(f.getContextModel())) {
             displayString.append(f.getContextModel()).append("!");
           }
           displayString.append(f.getContext());
         }
         ItemProviderAdapter itemProviderAdapter =
             (ItemProviderAdapter) emftvmItemProviderFactory.createAdapter(f);
         images.put(sb.toString(), getItemProviderImageURL(itemProviderAdapter.getImage(f)));
         displayStrings.put(sb.toString(), displayString.toString());
         features.add(sb.toString());
       }
     }
     if (isStatic) {
       for (Rule r : module.getRules()) {
         if (r.getMode() != RuleMode.MANUAL) {
           continue;
         }
         String name = r.getName();
         if (strippedPrefix.isEmpty() || name.startsWith(strippedPrefix)) {
           StringBuilder sb = new StringBuilder(name);
           StringBuilder displayString = new StringBuilder(name);
           sb.append('(');
           displayString.append('(');
           boolean first = true;
           for (InputRuleElement re : r.getInputElements()) {
             if (!first) {
               sb.append(", ");
               displayString.append(", ");
             }
             sb.append(re.getName());
             displayString.append(re.getName()).append(" : ");
             if (!EMFTVMUtil.NATIVE.equals(re.getTypeModel())) {
               displayString.append(re.getTypeModel()).append("!");
             }
             displayString.append(re.getType());
             first = false;
           }
           sb.append(')');
           displayString.append(')');
           ItemProviderAdapter itemProviderAdapter =
               (ItemProviderAdapter) emftvmItemProviderFactory.createAdapter(r);
           images.put(sb.toString(), getItemProviderImageURL(itemProviderAdapter.getImage(r)));
           displayStrings.put(sb.toString(), displayString.toString());
           features.add(sb.toString());
         }
       }
     }
   }
   final Map<String, String> builtinOps;
   if (isCollectionOp) {
     builtinOps = COLLECTION_OPS;
   } else if (isStatic) {
     builtinOps = Collections.<String, String>emptyMap();
   } else {
     builtinOps = REGULAR_OPS;
   }
   final ItemProviderAdapter itemProviderAdapter =
       new OperationItemProvider(emftvmItemProviderFactory);
   for (String f : builtinOps.keySet()) {
     if (strippedPrefix.isEmpty() || f.startsWith(strippedPrefix)) {
       features.add(f);
       images.put(f, getItemProviderImageURL(itemProviderAdapter.getImage((Object) null)));
       displayStrings.put(f, builtinOps.get(f));
     }
   }
   return buildProposals(prefix, root, features, images, displayStrings);
 }