Exemplo n.º 1
0
 protected Object convertValue(EStructuralFeature feature, Object value) {
   String constantName = String.valueOf(value).toUpperCase();
   Class<?> constants = SWT.class;
   String constantClass =
       EcoreUtil.getAnnotation(feature, SwtBuilder.getAnnotationUri(), "constantClass");
   if (constantClass != null) {
     try {
       constants = context.convert(constantClass, Class.class);
     } catch (Exception e) {
       throw new IllegalArgumentException(
           "Conversion from " + value + " failed: " + e.getMessage(), e);
     }
   }
   if (feature.getEType() == EcorePackage.eINSTANCE.getEString()) {
     String type = EcoreUtil.getAnnotation(feature, SwtBuilder.getAnnotationUri(), "type");
     if ("int".equals(type)) {
       value = SwtBuilder.getStaticField(constants, constantName, Integer.class, SWT.DEFAULT);
     } else if (type != null) {
       try {
         Class<?> typeClass = context.convert(type, Class.class);
         value = SwtBuilder.getStaticField(constants, constantName, typeClass, null);
       } catch (Exception e) {
         throw new IllegalArgumentException(
             "Conversion from " + value + " to " + type + " failed: " + e.getMessage(), e);
       }
     }
   } else if (feature.getEType()
       == org.eclipse.e4.tm.swt.styles.StylesPackage.eINSTANCE.getSwtConstant()) {
     value = SwtBuilder.getStaticField(constants, constantName, Integer.class, SWT.DEFAULT);
   }
   return value;
 }
Exemplo n.º 2
0
  protected Declaration handleStyleFeature(Style style, EStructuralFeature feature) {
    Declaration declaration = CssFactory.eINSTANCE.createDeclaration();
    declaration.setProperty(feature.getName());

    GMFToCSSConverter converter = GMFToCSSConverter.instance;

    if (isString(feature)) {
      declaration.setExpression(converter.convert((String) style.eGet(feature)));
    }

    if (isInteger(feature)) {
      if (feature.getName().endsWith("Color")) {
        Color color = FigureUtilities.integerToColor((Integer) style.eGet(feature));
        declaration.setExpression(converter.convert(color));
        color.dispose();
      } else {
        declaration.setExpression(converter.convert((Integer) style.eGet(feature)));
      }
    }

    if (feature.getEType() == NotationPackage.eINSTANCE.getGradientData()) {
      declaration.setExpression(converter.convert((GradientData) style.eGet(feature)));
    }

    if (feature.getEType() instanceof EEnum) {
      declaration.setExpression(converter.convert((Enumerator) style.eGet(feature)));
    }

    if (isBoolean(feature)) {
      declaration.setExpression(converter.convert((Boolean) style.eGet(feature)));
    }

    return declaration;
  }
Exemplo n.º 3
0
 public DateFilterUtil(Class<T> eObjClass, EStructuralFeature... dateFeature) {
   final EStructuralFeature tail = dateFeature[dateFeature.length - 1];
   this.dateFeature = FeaturePath.fromList(dateFeature);
   if (!Date.class.isAssignableFrom(tail.getEType().getInstanceClass())) {
     throw new IllegalArgumentException(
         "feature type " + tail.getEType().getInstanceClass() + " not a Date subclass");
   }
 }
  @SuppressWarnings("unchecked")
  private void writeTable(PrintWriter out, EObject eObject) {
    out.println("<h1>" + eObject.eClass().getName() + "</h1>");
    out.println("<table>");
    for (EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) {
      if (eStructuralFeature.getEAnnotation("hidden") == null) {
        out.println("<tr>");
        out.println("<td>" + eStructuralFeature.getName() + "</td>");
        Object eGet = eObject.eGet(eStructuralFeature);
        if (eStructuralFeature instanceof EAttribute) {
          if (eStructuralFeature.getUpperBound() == 1) {
            out.println("<td>" + eGet + "</td>");
          } else {
            List<Object> list = (List<Object>) eGet;
            out.println("<td>");
            for (Object object : list) {
              out.println(object + " ");
            }
            out.println("</td>");
          }
        } else if (eStructuralFeature instanceof EReference) {
          if (eStructuralFeature.getUpperBound() == 1) {
            if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) {
              EObject value = (EObject) eGet;
              if (value != null) {
                out.println(
                    "<td>"
                        + value.eGet(value.eClass().getEStructuralFeature("wrappedValue"))
                        + "</td>");
              }
            } else {

            }
          } else {
            if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) {
              List<EObject> list = (List<EObject>) eGet;
              out.println("<td>");
              for (EObject object : list) {
                out.println(
                    "<td>"
                        + object.eGet(object.eClass().getEStructuralFeature("wrappedValue"))
                        + "</td>");
              }
              out.println("</td>");
            } else {

            }
          }
        }
      }
      out.println("</tr>");
    }
    out.println("</table>");
  }
  /* (non-Javadoc)
   * @see com.hundsun.ares.studio.jres.ui.viewers.BaseEObjectColumnLabelProvider#getCopyText(java.lang.Object)
   */
  @Override
  public String getCopyText(Object element) {
    Parameter p = (Parameter) getOwner(element);

    EStructuralFeature feature = getEStructuralFeature(element);

    if (feature.getEType().equals(EcorePackage.Literals.EBOOLEAN)
        || feature.getEType().equals(EcorePackage.Literals.EBOOLEAN_OBJECT)) {
      return BooleanUtils.toStringTrueFalse((Boolean) p.eGet(feature));
    } else {
      return super.getCopyText(element);
    }
  }
Exemplo n.º 6
0
  protected boolean isInteger(EStructuralFeature feature) {
    if (feature.getEType() == EcorePackage.eINSTANCE.getEInt()
        || feature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
      return true;
    }

    if (feature.getEType() instanceof EDataType) {
      EDataType datatype = (EDataType) feature.getEType();
      return datatype.getName().equals("Integer");
    }

    return false;
  }
Exemplo n.º 7
0
 private void writeEmbedded(PrintWriter out, EObject eObject) throws SerializerException {
   EClass class1 = eObject.eClass();
   out.print(upperCases.get(class1));
   out.print(OPEN_PAREN);
   EStructuralFeature structuralFeature = class1.getEStructuralFeature(WRAPPED_VALUE);
   if (structuralFeature != null) {
     Object realVal = eObject.eGet(structuralFeature);
     if (structuralFeature.getEType() == ECORE_PACKAGE_INSTANCE.getEDouble()) {
       Object stringVal =
           eObject.eGet(class1.getEStructuralFeature(structuralFeature.getName() + "AsString"));
       if (stringVal != null && model.isUseDoubleStrings()) {
         out.print(stringVal);
       } else {
         if (((Double) realVal).isInfinite() || (((Double) realVal).isNaN())) {
           LOGGER.info("Serializing infinite or NaN double as 0.0");
           out.print("0.0");
         } else {
           out.print(realVal);
         }
       }
     } else {
       writePrimitive(out, realVal);
     }
   }
   out.print(CLOSE_PAREN);
 }
Exemplo n.º 8
0
 /**
  * Get the value of the named AD parameter for the activity as a string. Works with several types,
  * not just strings -- enums, for example.
  *
  * @param element
  * @param parameterName
  * @return null if the parameter is not found
  */
 public static String getParameterString(EPlanElement element, String parameterName) {
   EObject data = element.getData();
   if (data == null) return null;
   EStructuralFeature feature;
   try {
     feature = getParameterFeature(data, parameterName);
   } catch (UndefinedParameterException e) {
     return null;
   }
   Object object = data.eGet(feature);
   if (object instanceof EEnumLiteral) {
     EEnumLiteral literal = (EEnumLiteral) object;
     return literal.getName();
   }
   EClassifier type = feature.getEType();
   if (type instanceof EDataType) {
     EDataType dataType = (EDataType) type;
     EPackage typePackage = dataType.getEPackage();
     EFactory factory = typePackage.getEFactoryInstance();
     String string = factory.convertToString(dataType, object);
     return string;
   }
   LogUtil.warnOnce("feature type '" + type + "'is not EDataType: " + parameterName);
   return String.valueOf(object);
 }
 public void addNavigatedDependency(
     EStructuralFeature navigationFeature, EStructuralFeature dependantFeature) {
   if (navigationFeature == null || dependantFeature == null) {
     return;
   }
   if (!source.eClass().getEAllStructuralFeatures().contains(navigationFeature)) {
     return;
   }
   if (!(navigationFeature.getEType() instanceof EClass)
       || !dependantFeature
           .getEContainingClass()
           .isSuperTypeOf((EClass) navigationFeature.getEType())) {
     return;
   }
   addNavigatedDependencyInternal(navigationFeature, dependantFeature);
 }
 protected EObject createInitialModel() {
   EClass eClass = ExtendedMetaData.INSTANCE.getDocumentRoot(dsPackage);
   EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature("data");
   EObject rootObject = dsFactory.create(eClass);
   rootObject.eSet(eStructuralFeature, EcoreUtil.create((EClass) eStructuralFeature.getEType()));
   return rootObject;
 }
Exemplo n.º 11
0
 public CharSequence assignmentOperator(final EStructuralFeature it) {
   StringConcatenation _builder = new StringConcatenation();
   {
     boolean _isMany = it.isMany();
     if (_isMany) {
       _builder.append("+=");
     } else {
       boolean _and = false;
       EClassifier _eType = it.getEType();
       boolean _isBoolean = Ecore2XtextExtensions.isBoolean(_eType);
       if (!_isBoolean) {
         _and = false;
       } else {
         boolean _isPrefixBooleanFeature = Ecore2XtextExtensions.isPrefixBooleanFeature(it);
         _and = (_isBoolean && _isPrefixBooleanFeature);
       }
       if (_and) {
         _builder.append("?=");
       } else {
         _builder.append("=");
       }
     }
   }
   return _builder;
 }
Exemplo n.º 12
0
 public Dynamic(InternalEObject owner, EStructuralFeature eStructuralFeature) {
   super(
       kind(eStructuralFeature),
       wrapperClassFor(eStructuralFeature.getEType().getInstanceClass()),
       owner);
   this.eStructuralFeature = eStructuralFeature;
 }
 /** Constructor. */
 public EEnumComboBoxDataProvider(Object axisElement) {
   Object object = AxisUtils.getRepresentedElement(axisElement);
   Assert.isTrue(object instanceof EStructuralFeature);
   EStructuralFeature feature = (EStructuralFeature) object;
   EClassifier type = feature.getEType();
   Assert.isTrue(type instanceof EEnum);
   this.eenum = (EEnum) type;
 }
Exemplo n.º 14
0
 /**
  * Returns the default alignment for the specific value type.
  *
  * <p>If you want to change the alignment use the <code>uibindings/model</code> and <code>
  * uibindings/model/feature elements</code>.
  *
  * @param valueType the value type to test
  * @return the default alignment
  */
 public static int defaultAlignment(Object valueType) {
   if (valueType instanceof EStructuralFeature) {
     final EStructuralFeature sf = (EStructuralFeature) valueType;
     valueType = sf.getEType();
   }
   final Integer alignment = DEFAULT_ALIGNMENT.get(valueType);
   if (alignment != null) return alignment;
   return SWT.NONE;
 }
Exemplo n.º 15
0
 private void writeObject(PrintWriter out, EObject object, EStructuralFeature feature)
     throws SerializerException {
   Object ref = object.eGet(feature);
   if (ref == null || (feature.isUnsettable() && !object.eIsSet(feature))) {
     EClassifier type = feature.getEType();
     if (type instanceof EClass) {
       EStructuralFeature structuralFeature = ((EClass) type).getEStructuralFeature(WRAPPED_VALUE);
       if (structuralFeature != null) {
         String name = structuralFeature.getEType().getName();
         if (name.equals(IFC_BOOLEAN)
             || name.equals(IFC_LOGICAL)
             || structuralFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean()) {
           out.print(BOOLEAN_UNDEFINED);
         } else {
           out.print(DOLLAR);
         }
       } else {
         out.print(DOLLAR);
       }
     } else {
       if (type == EcorePackage.eINSTANCE.getEBoolean()) {
         out.print(BOOLEAN_UNDEFINED);
       } else if (feature.isMany()) {
         out.print("()");
       } else {
         out.print(DOLLAR);
       }
     }
   } else {
     if (ref instanceof EObject) {
       writeEmbedded(out, (EObject) ref);
     } else if (feature.getEType() == ECORE_PACKAGE_INSTANCE.getEDouble()) {
       Object stringValue =
           object.eGet(object.eClass().getEStructuralFeature(feature.getName() + "AsString"));
       if (stringValue != null && model.isUseDoubleStrings()) {
         out.print(stringValue);
       } else {
         writePrimitive(out, ref);
       }
     } else {
       writePrimitive(out, ref);
     }
   }
 }
Exemplo n.º 16
0
    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;
    }
Exemplo n.º 17
0
  @Override
  protected void saveEObjectSingle(EObject o, EStructuralFeature f) {
    StringBuffer buffer = new StringBuffer();

    EObject value = (EObject) helper.getValue(o, f);
    if (value != null) {
      String id = helper.getHREF(value);
      if (id != null) {
        id = convertURI(id);
        buffer.setLength(0);
        // if (!id.startsWith("#"))
        // {
        if (!o.eClass().getEPackage().getNsURI().equals(f.getEType().getEPackage().getNsURI())) {

          EClass eClass = value.eClass();
          EClass expectedType = (EClass) f.getEType();
          if (saveTypeInfo
              ? xmlTypeInfo.shouldSaveType(eClass, expectedType, f)
              : eClass != expectedType
                  && (expectedType.isAbstract()
                      || f.getEGenericType().getETypeParameter() != null)) {
            buffer.append(helper.getQName(eClass));
            buffer.append(' ');
          }
        }
        // }
        buffer.append(id);
        if (!toDOM) {
          String name = helper.getQName(f);
          doc.startAttribute(name);
          doc.addAttributeContent(buffer.toString());
          doc.endAttribute();
        } else {
          helper.populateNameInfo(nameInfo, f);
          Attr attr =
              document.createAttributeNS(nameInfo.getNamespaceURI(), nameInfo.getQualifiedName());
          attr.setNodeValue(buffer.toString());
          ((Element) currentNode).setAttributeNodeNS(attr);
          handler.recordValues(attr, o, f, value);
        }
      }
    }
  }
Exemplo n.º 18
0
 public EnvironmentView(
     @NonNull EnvironmentFactoryInternal environmentFactory,
     @NonNull EStructuralFeature reference,
     @Nullable String name) {
   this.environmentFactory = environmentFactory;
   this.reference = reference;
   this.requiredType = reference.getEType();
   this.isQualifier = false;
   this.name = name;
 }
Exemplo n.º 19
0
 /**
  * Returns whether activity contains AD parameter of given type
  *
  * @param element
  * @param parameterType
  * @return
  */
 @SuppressWarnings("unchecked")
 public static boolean isParameterForType(EPlanElement element, EClass parameterType) {
   EObject data = element.getData();
   EList<EStructuralFeature> structuralFeatures = data.eClass().getEStructuralFeatures();
   for (int i = 0; i < structuralFeatures.size(); i++) {
     final EStructuralFeature feature = structuralFeatures.get(i);
     if (parameterType == feature.getEType()) return true;
   }
   return false;
 }
Exemplo n.º 20
0
  /**
   * 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);
  }
Exemplo n.º 21
0
 /**
  * Get the value of the AD parameter by type for the activity
  *
  * @param element
  * @param parameterType
  * @return
  */
 @SuppressWarnings("unchecked")
 public static <T> Option<T> getParameterObjectByType(EPlanElement element, EClass parameterType) {
   EObject data = element.getData();
   EList<EStructuralFeature> structuralFeatures = data.eClass().getEStructuralFeatures();
   for (int i = 0; i < structuralFeatures.size(); i++) {
     final EStructuralFeature feature = structuralFeatures.get(i);
     if (parameterType == feature.getEType()) return Option.fromNull((T) data.eGet(feature));
   }
   return Option.none();
 }
Exemplo n.º 22
0
 /**
  * Add ReferenceableObject.
  *
  * @param referenceableObject
  * @param eContainingFeature
  * @return
  */
 private EObject add(
     ReferenceableObject referenceableObject, final EStructuralFeature eContainingFeature) {
   assertNotNull("The editeur is not opened.", editor);
   final EObject container = getEObjectFromReferenceableEObject(referenceableObject);
   assertNotNull("No container is found to launch add action.", container);
   final SWTBotTreeItem selectNode = selectNode(editor, container);
   assertNotNull("No element is selected in the editor", selectNode);
   SWTBotHelper.clickContextMenu(selectNode, eContainingFeature.getEType().getName());
   SWTBotHelper.waitAllUiEvents();
   return (EObject) EEFModelHelper.eGet(container, eContainingFeature);
 }
Exemplo n.º 23
0
  /**
   * This method retrieves the value from the feature at the given index. It retrieves the value
   * either from the views's store or the internal pre-registration Map.
   *
   * @param feature the feature to retrieve the value from
   * @param index the given index of the object in the feature
   * @return the value from the feature at the given index
   */
  private Object getValueFromRevision(EStructuralFeature feature, int index) {
    InternalCDORevision revision = cdoRevision();
    Object object = revision.get(feature, index);
    if (object == null) {
      return null;
    }

    if (object instanceof CDOElementProxy) {
      // Resolve proxy
      CDOElementProxy proxy = (CDOElementProxy) object;
      object =
          viewAndState
              .view
              .getSession()
              .resolveElementProxy(revision, feature, index, proxy.getIndex());
    }

    if (object instanceof CDOLegacyWrapper) {
      return ((CDOLegacyWrapper) object).cdoInternalInstance();
    }

    CDOType type = CDOModelUtil.getType(feature.getEType());
    object = viewAndState.view.getStore().convertToEMF(instance, revision, feature, index, object);

    if (type == CDOType.OBJECT) {
      if (object instanceof CDOID) {
        CDOID id = (CDOID) object;
        if (id.isNull()) {
          return null;
        }

        object = getRegisteredWrapper(id);
        if (object != null) {
          return ((CDOLegacyWrapper) object).cdoInternalInstance();
        }

        if (id.isExternal()) {
          object =
              viewAndState
                  .view
                  .getResourceSet()
                  .getEObject(URI.createURI(id.toURIFragment()), true);
        } else {
          object = viewAndState.view.getObject(id);
        }

        if (object instanceof CDOObjectWrapper) {
          return ((CDOObjectWrapper) object).cdoInternalInstance();
        }
      }
    }

    return object;
  }
Exemplo n.º 24
0
 public static boolean isMultiChoice(EObject object, EStructuralFeature feature) {
   if (feature.getEType() instanceof EClass) {
     ExtendedPropertiesAdapter adapter =
         (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
     if (adapter != null) {
       Object result = adapter.getProperty(feature, ExtendedPropertiesAdapter.UI_IS_MULTI_CHOICE);
       if (result instanceof Boolean) return ((Boolean) result);
     }
   }
   return getChoiceOfValues(object, feature) != null;
 }
Exemplo n.º 25
0
 public static boolean canEditInline(EObject object, EStructuralFeature feature) {
   if (feature.getEType() instanceof EClass) {
     ExtendedPropertiesAdapter adapter =
         (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
     if (adapter != null) {
       Object result = adapter.getProperty(feature, ExtendedPropertiesAdapter.UI_CAN_EDIT_INLINE);
       if (result instanceof Boolean) return ((Boolean) result);
     }
   }
   return false;
 }
Exemplo n.º 26
0
 public static boolean canCreateNew(EObject object, EStructuralFeature feature) {
   if (feature.getEType() instanceof EClass) {
     ExtendedPropertiesAdapter adapter =
         (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
     if (adapter != null) {
       Object result = adapter.getProperty(feature, ExtendedPropertiesAdapter.UI_CAN_CREATE_NEW);
       if (result instanceof Boolean) return ((Boolean) result);
     }
     return true;
   }
   return false;
 }
Exemplo n.º 27
0
 @Override
 public boolean isStereotype(
     @NonNull EnvironmentFactoryInternal environmentFactory, @NonNull EClass eClass) {
   for (EStructuralFeature eFeature : eClass.getEAllStructuralFeatures()) {
     EClassifier eType = eFeature.getEType();
     if (eType != null) {
       assert !eType.eIsProxy() : "Unresolved proxy: '" + EcoreUtil.getURI(eType) + "'";
       EPackage ePackage = eType.getEPackage();
       assert !"http://www.eclipse.org/uml2/5.0.0/UML".equals(ePackage.getNsURI());
     }
   }
   return false;
 }
Exemplo n.º 28
0
  public static Collection<EClass> filterByFeatureSeqInitializer(
      Collection<EClass> eClasses, FeatureSeqInitializer featureSeqInitializer) {
    if (featureSeqInitializer.getCreatingInitializer() != null) {
      EStructuralFeature feature = featureSeqInitializer.getCreatingInitializer().getFeature();
      if (feature != null && feature.getEType() instanceof EClass) {
        for (Iterator<EClass> it = eClasses.iterator(); it.hasNext(); ) {
          EClass nextEClass = it.next();
          EClass typeEClass = (EClass) feature.getEType();
          if (nextEClass == null
              || nextEClass.isAbstract()
              || nextEClass.isInterface()
              || !typeEClass.isSuperTypeOf(nextEClass)) {
            it.remove();
          }
        }
      }
    } else if (featureSeqInitializer.getElementClass() != null) {
      return Collections.singleton(featureSeqInitializer.getElementClass());
    }

    return eClasses;
  }
Exemplo n.º 29
0
  /**
   * Method which looks up structural features of an eobject by type.
   *
   * @param eobject The eobject.
   * @param propertyType The type of the properties.
   * @return The list of structure features, or an empty list if none are found.
   */
  public static List /*<EStructuralFeature>*/ features(EObject eobject, Class propertyType) {
    List match = new ArrayList();
    List features = eobject.eClass().getEAllStructuralFeatures();

    for (Iterator itr = features.iterator(); itr.hasNext(); ) {
      EStructuralFeature feature = (EStructuralFeature) itr.next();

      if (feature.getEType().getInstanceClass().isAssignableFrom(propertyType)) {
        match.add(feature);
      }
    }

    return match;
  }
Exemplo n.º 30
0
 private void write(PrintWriter out, IdEObject object) throws SerializerException {
   EClass eClass = object.eClass();
   if (eClass.getEAnnotation("hidden") != null) {
     return;
   }
   out.print(DASH);
   int convertedKey = getExpressId(object);
   if (convertedKey == -1) {
     throw new SerializerException(
         "Going to serialize an object with id -1 (" + object.eClass().getName() + ")");
   }
   out.print(String.valueOf(convertedKey));
   out.print("= ");
   String upperCase = upperCases.get(eClass);
   if (upperCase == null) {
     throw new SerializerException("Type not found: " + eClass.getName());
   }
   out.print(upperCase);
   out.print(OPEN_PAREN);
   boolean isFirst = true;
   for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
     if (!feature.isDerived() && feature.getEAnnotation("hidden") == null) {
       EClassifier type = feature.getEType();
       if (type instanceof EEnum) {
         if (!isFirst) {
           out.print(COMMA);
         }
         writeEnum(out, object, feature);
         isFirst = false;
       } else if (type instanceof EClass) {
         if (!isInverse(feature)) {
           if (!isFirst) {
             out.print(COMMA);
           }
           writeEClass(out, object, feature);
           isFirst = false;
         }
       } else if (type instanceof EDataType) {
         if (!isFirst) {
           out.print(COMMA);
         }
         writeEDataType(out, object, feature);
         isFirst = false;
       }
     }
   }
   out.println(PAREN_CLOSE_SEMICOLON);
 }