public static int kind(EStructuralFeature eStructuralFeature) {
      int result = 0;

      EClassifier eClassifier = eStructuralFeature.getEType();

      if (eClassifier.getInstanceClass() != null) {
        result |= HAS_INSTANCE_CLASS;
      }

      if (eStructuralFeature.isUnsettable()) {
        result |= IS_UNSETTABLE;
      }

      if (eStructuralFeature instanceof EReference) {
        EReference eReference = (EReference) eStructuralFeature;
        EReference inverseEReference = eReference.getEOpposite();
        if (eReference.isContainment()) {
          result |= IS_CONTAINMENT;
        }

        if (inverseEReference != null) {
          // This forces the feature ids to be assigned.
          //
          inverseEReference.getEContainingClass().getFeatureCount();
          result |= HAS_NAVIGABLE_INVERSE;
          if (inverseEReference.isMany()) {
            result |= HAS_MANY_INVERSE;
          }
          if (inverseEReference.isContainment()) {
            result |= IS_CONTAINER;
          }
        }

        if (eReference.isResolveProxies()) {
          result |= HAS_PROXIES;
        }

        result |= IS_EOBJECT;
      } else // if (eStructuralFeature instanceof EAttribute
      {
        if (eClassifier instanceof EEnum) {
          result |= IS_ENUM;
        } else {
          Class<?> instanceClass = eClassifier.getInstanceClass();
          if (instanceClass != null && instanceClass.isPrimitive()) {
            result |= IS_PRIMITIVE;
          }
        }
      }

      if (eStructuralFeature.isUnique()) {
        result |= IS_UNIQUE;
      }

      return result;
    }
  /**
   * Returns the new Id for the section
   *
   * @param selectionClass the selected class
   * @param selectionSize size of the selection
   * @return the new Id for the section
   */
  protected String getNewFragmentId(
      EClassifier selectionClass, Stereotype stereotype, int selectionSize) {
    for (int i = 0;
        i < 100;
        i++) { // no need to go to more than 100, because 100 is already a very big number of
               // fragments
      boolean found = false; // indicates if the id has been found in already fragments or not

      StringBuffer buffer = new StringBuffer();
      buffer.append("fragment_");
      if (selectionSize == 1) {
        buffer.append("single");
      } else if (selectionSize < 0) {
        buffer.append("multi");
      } else {
        buffer.append(selectionSize);
      }
      buffer.append("_");

      if (selectionClass != null && selectionClass.getInstanceClass() != null) {
        buffer.append(selectionClass.getInstanceClass().getSimpleName());
      } else if (stereotype != null && stereotype.getName() != null) {
        buffer.append(stereotype.getName());
      } else {
        buffer.append("NoName");
      }
      if (i > 0) {
        buffer.append(i);
      }
      String name = buffer.toString();

      Iterator<IFragmentDescriptorState> it =
          sectionDescriptorState.getFragmentDescriptorStates().iterator();
      while (it.hasNext()) {
        IFragmentDescriptorState fragmentDescriptorState = it.next();
        String id = fragmentDescriptorState.getDescriptor().getId();
        if (name.equalsIgnoreCase(id)) {
          found = true;
        }
      }

      if (!found) {
        return name;
      }
    }
    return "";
  }
  /**
   * Creates and returns a <em>proxy</em> object. The usage of a proxy object is strongly limited.
   * The only guarantee that can be made is that the following methods are callable and will behave
   * in the expected way:
   *
   * <ul>
   *   <li>{@link CDOObject#cdoID()} will return the {@link CDOID} of the target object
   *   <li>{@link CDOObject#cdoState()} will return {@link CDOState#PROXY PROXY}
   *   <li>{@link InternalEObject#eIsProxy()} will return <code>true</code>
   *   <li>{@link InternalEObject#eProxyURI()} will return the EMF proxy URI of the target object
   * </ul>
   *
   * Calling any other method on the proxy object will result in an {@link
   * UnsupportedOperationException} being thrown at runtime. Note also that the proxy object might
   * even not be cast to the concrete type of the target object. The proxy can only guaranteed to be
   * of <em>any</em> concrete subtype of the declared type of the given feature.
   *
   * <p>TODO {@link InternalEObject#eResolveProxy(InternalEObject)}
   */
  protected InternalEObject createProxy(
      InternalCDOView view, EStructuralFeature feature, CDOID id) {
    EClassifier eType = feature.getEType();
    Class<?> instanceClass = eType.getInstanceClass();

    Class<?>[] interfaces = {instanceClass, InternalEObject.class, LegacyProxy.class};
    ClassLoader classLoader = CDOLegacyWrapper.class.getClassLoader();
    LegacyProxyInvocationHandler handler = new LegacyProxyInvocationHandler(this, id);
    return (InternalEObject) Proxy.newProxyInstance(classLoader, interfaces, handler);
  }
  protected CellEditor createCellEditor(Object element, String property) {
    Composite parent = tableViewer.getTable();
    if (cellEditor == null && feature != null) {
      EClassifier ec = feature.getEType();
      Class ic = ec.getInstanceClass();

      if (boolean.class.equals(ic)) {
        cellEditor = new CustomCheckboxCellEditor(parent);
      } else if (ec instanceof EEnum) {
        cellEditor = new CustomComboBoxCellEditor(parent, (EObject) element, feature);
      } else if (ModelUtil.isMultiChoice((EObject) element, feature)) {
        cellEditor = new CustomComboBoxCellEditor(parent, (EObject) element, feature);
      } else if (ec instanceof EDataType) {
        cellEditor = new EDataTypeCellEditor((EDataType) ec, parent);
      } else if (ic == EObject.class) {
        cellEditor = new StringWrapperCellEditor(parent);
      }
      setCellEditor(cellEditor);
    }
    return cellEditor;
  }
 /** @generated */
 protected Object getValidNewValue(EAttribute feature, Object value) {
   EClassifier type = feature.getEType();
   if (type instanceof EDataType) {
     Class iClass = type.getInstanceClass();
     if (Boolean.TYPE.equals(iClass)) {
       if (value instanceof Boolean) {
         // ok
       } else if (value instanceof String) {
         value = Boolean.valueOf((String) value);
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
       }
     } else if (Character.TYPE.equals(iClass)) {
       if (value instanceof Character) {
         // ok
       } else if (value instanceof String) {
         String s = (String) value;
         if (s.length() == 0) {
           value = null;
         } else {
           value = new Character(s.charAt(0));
         }
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
       }
     } else if (Byte.TYPE.equals(iClass)) {
       if (value instanceof Byte) {
         // ok
       } else if (value instanceof Number) {
         value = new Byte(((Number) value).byteValue());
       } else if (value instanceof String) {
         String s = (String) value;
         if (s.length() == 0) {
           value = null;
         } else {
           try {
             value = Byte.valueOf(s);
           } catch (NumberFormatException nfe) {
             value =
                 new InvalidValue(
                     NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
           }
         }
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
       }
     } else if (Short.TYPE.equals(iClass)) {
       if (value instanceof Short) {
         // ok
       } else if (value instanceof Number) {
         value = new Short(((Number) value).shortValue());
       } else if (value instanceof String) {
         String s = (String) value;
         if (s.length() == 0) {
           value = null;
         } else {
           try {
             value = Short.valueOf(s);
           } catch (NumberFormatException nfe) {
             value =
                 new InvalidValue(
                     NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
           }
         }
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
       }
     } else if (Integer.TYPE.equals(iClass)) {
       if (value instanceof Integer) {
         // ok
       } else if (value instanceof Number) {
         value = new Integer(((Number) value).intValue());
       } else if (value instanceof String) {
         String s = (String) value;
         if (s.length() == 0) {
           value = null;
         } else {
           try {
             value = Integer.valueOf(s);
           } catch (NumberFormatException nfe) {
             value =
                 new InvalidValue(
                     NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
           }
         }
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
       }
     } else if (Long.TYPE.equals(iClass)) {
       if (value instanceof Long) {
         // ok
       } else if (value instanceof Number) {
         value = new Long(((Number) value).longValue());
       } else if (value instanceof String) {
         String s = (String) value;
         if (s.length() == 0) {
           value = null;
         } else {
           try {
             value = Long.valueOf(s);
           } catch (NumberFormatException nfe) {
             value =
                 new InvalidValue(
                     NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
           }
         }
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
       }
     } else if (Float.TYPE.equals(iClass)) {
       if (value instanceof Float) {
         // ok
       } else if (value instanceof Number) {
         value = new Float(((Number) value).floatValue());
       } else if (value instanceof String) {
         String s = (String) value;
         if (s.length() == 0) {
           value = null;
         } else {
           try {
             value = Float.valueOf(s);
           } catch (NumberFormatException nfe) {
             value =
                 new InvalidValue(
                     NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
           }
         }
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
       }
     } else if (Double.TYPE.equals(iClass)) {
       if (value instanceof Double) {
         // ok
       } else if (value instanceof Number) {
         value = new Double(((Number) value).doubleValue());
       } else if (value instanceof String) {
         String s = (String) value;
         if (s.length() == 0) {
           value = null;
         } else {
           try {
             value = Double.valueOf(s);
           } catch (NumberFormatException nfe) {
             value =
                 new InvalidValue(
                     NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
           }
         }
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
       }
     } else if (type instanceof EEnum) {
       if (value instanceof String) {
         EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
         if (literal == null) {
           value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
         } else {
           value = literal.getInstance();
         }
       } else {
         value =
             new InvalidValue(
                 NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
       }
     }
   }
   return value;
 }
 /**
  * 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);
 }