Exemplo n.º 1
0
  /**
   * Converts a primitive type value. For EEnum: this implementation only converts an Enum to an
   * EEnum value.
   *
   * @param value the value to convert
   * @param eDataType its EDataType
   * @return the converted value
   */
  protected Object convertEAttributeValue(final Object value, final EDataType eDataType) {
    if (value instanceof Enum<?>) {
      final EDataType enumDataType = getDataTypeOrBaseType(eDataType);
      Check.isInstanceOf(enumDataType, EEnum.class);
      final EEnum eeNum = (EEnum) enumDataType;
      for (final EEnumLiteral enumLiteral : eeNum.getELiterals()) {
        // the code generation template uppercases enum
        if (enumLiteral.getName().toUpperCase(Locale.ENGLISH).equals(((Enum<?>) value).name())) {
          return enumLiteral.getInstance();
        }
      }
    }

    if (value instanceof Date && eDataType == XMLTypePackage.eINSTANCE.getDate()) {
      final Date date = (Date) value;
      final XMLCalendar xmlCalendar = new XMLCalendar(date, XMLCalendar.DATE);
      final Calendar calendar = Calendar.getInstance();
      calendar.setTime(date);
      xmlCalendar.clear();
      xmlCalendar.setYear(calendar.get(Calendar.YEAR));
      xmlCalendar.setMonth(1 + calendar.get(Calendar.MONTH));
      xmlCalendar.setDay(calendar.get(Calendar.DATE));
      // note xmlcalendar expects minutes, calendar gives millis
      xmlCalendar.setTimezone(calendar.get(Calendar.ZONE_OFFSET) / 60000);
      return xmlCalendar;
    }

    if (value instanceof Date && eDataType == XMLTypePackage.eINSTANCE.getDateTime()) {
      final Date date = (Date) value;
      return new XMLCalendar(date, XMLCalendar.DATETIME);
    }

    return value;
  }
  protected EEnum createEEnum(Diagram diagram, String enumName) {
    EEnum newEnum = EcoreFactory.eINSTANCE.createEEnum();
    newEnum.setName(enumName);

    diagram.eResource().getContents().add(newEnum);

    return newEnum;
  }
Exemplo n.º 3
0
  private EPackage createDynamicEPackage() {
    final EcoreFactory efactory = EcoreFactory.eINSTANCE;
    final EcorePackage epackage = EcorePackage.eINSTANCE;

    // Create a new EPackage and add the new EClasses
    EPackage topPackage = efactory.createEPackage();
    topPackage.setName("toppackage");
    topPackage.setNsPrefix("toppackage");
    topPackage.setNsURI("http:///www.elver.org/toppackage");

    EPackage subPackage1 = efactory.createEPackage();
    subPackage1.setName("subPackage1");
    subPackage1.setNsPrefix("subPackage1");
    subPackage1.setNsURI("http:///www.elver.org/subPackage1");

    {
      EClass schoolBookEClass = efactory.createEClass();
      schoolBookEClass.setName("class1");
      // create a new attribute for this EClass
      EAttribute level = efactory.createEAttribute();
      level.setName("level");
      level.setEType(epackage.getEInt());
      schoolBookEClass.getEStructuralFeatures().add(level);
      subPackage1.getEClassifiers().add(schoolBookEClass);
    }

    {
      EEnum schoolBookEClass = efactory.createEEnum();
      schoolBookEClass.setName("enum");
      subPackage1.getEClassifiers().add(schoolBookEClass);
    }

    {
      EClass schoolBookEClass = efactory.createEClass();
      schoolBookEClass.setName("class2");
      // create a new attribute for this EClass
      subPackage1.getEClassifiers().add(schoolBookEClass);
    }

    {
      EClass schoolBookEClass = efactory.createEClass();
      schoolBookEClass.setName("class3");
      // create a new attribute for this EClass
      EAttribute level = efactory.createEAttribute();
      level.setName("level");
      level.setEType(epackage.getEInt());
      schoolBookEClass.getEStructuralFeatures().add(level);
      subPackage1.getEClassifiers().add(schoolBookEClass);
    }

    EPackage subPackage2 = efactory.createEPackage();
    subPackage2.setName("subPackage2");
    subPackage2.setNsPrefix("subPackage2");
    subPackage2.setNsURI("http:///www.elver.org/subPackage2");

    topPackage.getESubpackages().add(subPackage1);
    return topPackage;
  }
 protected Collection<org.emftext.language.xpath3.resource.xpath3.ui.Xpath3CompletionProposal>
     handleEnumAttribute(
         org.emftext.language.xpath3.resource.xpath3.mopp.Xpath3ExpectedTerminal expectedTerminal,
         org.emftext.language.xpath3.resource.xpath3.mopp.Xpath3ExpectedStructuralFeature
             expectedFeature,
         EEnum enumType,
         String prefix,
         EObject container) {
   Collection<EEnumLiteral> enumLiterals = enumType.getELiterals();
   Collection<org.emftext.language.xpath3.resource.xpath3.ui.Xpath3CompletionProposal> result =
       new LinkedHashSet<
           org.emftext.language.xpath3.resource.xpath3.ui.Xpath3CompletionProposal>();
   for (EEnumLiteral literal : enumLiterals) {
     String unResolvedLiteral = literal.getLiteral();
     // use token resolver to get de-resolved value of the literal
     org.emftext.language.xpath3.resource.xpath3.IXpath3TokenResolverFactory tokenResolverFactory =
         metaInformation.getTokenResolverFactory();
     org.emftext.language.xpath3.resource.xpath3.IXpath3TokenResolver tokenResolver =
         tokenResolverFactory.createTokenResolver(expectedFeature.getTokenName());
     String resolvedLiteral =
         tokenResolver.deResolve(unResolvedLiteral, expectedFeature.getFeature(), container);
     boolean matchesPrefix = matches(resolvedLiteral, prefix);
     result.add(
         new org.emftext.language.xpath3.resource.xpath3.ui.Xpath3CompletionProposal(
             expectedTerminal,
             resolvedLiteral,
             prefix,
             matchesPrefix,
             expectedFeature.getFeature(),
             container));
   }
   return result;
 }
Exemplo n.º 5
0
  public void test_enumerationLiteralEquality_137546() {
    EObject ctx = fruitEFactory.create((EClass) fruitEPackage.getEClassifier(apple.getName()));
    helper.setContext(apple);

    EEnum ecolor = (EEnum) fruitEPackage.getEClassifier(color.getName());
    ctx.eSet(
        ctx.eClass().getEStructuralFeature(fruit_color.getName()),
        ecolor.getEEnumLiteral(color_green.getName()));

    try {
      assertTrue(check(helper, ctx, "ocltest::Color::green = self.color"));
      assertTrue(check(helper, ctx, "self.color = ocltest::Color::green"));
    } catch (Exception e) {
      fail("Failed to parse or evaluate: " + e.getLocalizedMessage());
    }
  }
Exemplo n.º 6
0
 @Override
 public List<String> resolveValues(TemplateVariable variable, XtextTemplateContext castedContext) {
   String enumerationName = (String) variable.getVariableType().getParams().iterator().next();
   EEnum enumeration =
       (EEnum) getEClassifierForGrammar(enumerationName, getGrammar(castedContext));
   if (enumeration == null) {
     return Collections.emptyList();
   }
   return Lists.transform(
       enumeration.getELiterals(),
       new Function<EEnumLiteral, String>() {
         public String apply(EEnumLiteral enumLiteral) {
           return enumLiteral.getLiteral();
         }
       });
 }
Exemplo n.º 7
0
 private static Map<String, EEnumLiteral> cacheLiterals(EEnum enumType) {
   Map<String, EEnumLiteral> map = new HashMap<String, EEnumLiteral>();
   EList<EEnumLiteral> literals = enumType.getELiterals();
   for (EEnumLiteral literal : literals) {
     String literalString = literal.getLiteral();
     map.put(literalString.toUpperCase(), literal);
   }
   literalValues.put(enumType, map);
   return map;
 }
Exemplo n.º 8
0
 /**
  * Use setParameterString instead, unless calling from an XML loader that has not yet created the
  * plan element.
  */
 public static void setParameterStringInData(EObject data, String parameterName, String newValue)
     throws UndefinedParameterException {
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   EClassifier type = feature.getEType();
   Object object;
   if (type instanceof EEnum) {
     EEnum enumType = (EEnum) type;
     object = enumType.getEEnumLiteral(newValue);
   } else if (type instanceof EDataType) {
     EDataType dataType = (EDataType) type;
     EPackage typePackage = dataType.getEPackage();
     EFactory factory = typePackage.getEFactoryInstance();
     object = factory.createFromString(dataType, newValue);
   } else {
     Logger logger = Logger.getLogger(ADParameterUtils.class);
     logger.warn("feature type '" + type + "'is not EDataType: " + parameterName);
     object = newValue;
   }
   data.eSet(feature, object);
 }
 private IScope calculateEnumLiteralScope(EEnum enumeration) {
   EList<EEnumLiteral> literals = enumeration.getELiterals();
   return Scopes.scopeFor(
       literals,
       new Function<EEnumLiteral, QualifiedName>() {
         public QualifiedName apply(EEnumLiteral literal) {
           QualifiedName qualifiedName =
               qualifiedNameConverter.toQualifiedName(literal.getLiteral());
           return qualifiedName;
         }
       },
       IScope.NULLSCOPE);
 }
Exemplo n.º 10
0
 /**
  * Add a value to a named AD multi-select EEnum parameter for the activity
  *
  * @param element
  * @param parameterName
  * @param newValue
  * @throws UndefinedParameterException
  */
 @SuppressWarnings("unchecked")
 public static void addParameterStringToList(
     EPlanElement element, String parameterName, String newValue)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   EClassifier type = feature.getEType();
   Object object;
   if (type instanceof EEnum) {
     EEnum enumType = (EEnum) type;
     object = enumType.getEEnumLiteral(newValue);
   } else if (type instanceof EDataType) {
     EDataType dataType = (EDataType) type;
     EPackage typePackage = dataType.getEPackage();
     EFactory factory = typePackage.getEFactoryInstance();
     object = factory.createFromString(dataType, newValue);
   } else {
     Logger logger = Logger.getLogger(ADParameterUtils.class);
     logger.warn("feature type '" + type + "'is not EDataType: " + parameterName);
     object = newValue;
   }
   addParameterObjectToList(element, parameterName, object);
 }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.obeonetwork.dsl.uml2.properties.uml.parts.CreationEventPropertiesEditionPart#initVisibility(EEnum
  *     eenum, Enumerator current)
  */
 public void initVisibility(EEnum eenum, Enumerator current) {
   visibility.setInput(eenum.getELiterals());
   visibility.modelUpdating(new StructuredSelection(current));
 }
Exemplo n.º 12
0
 /**
  * Initializes the annotations for <b>http://www.topcased.org/uuid</b>.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 protected void createUuidAnnotations() {
   String source = "http://www.topcased.org/uuid";
   addAnnotation(this, source, new String[] {"uuid", "11350778856090"});
   addAnnotation(containerEClass, source, new String[] {"uuid", "11350778856251"});
   addAnnotation(getContainer_Name(), source, new String[] {"uuid", "11350778856252"});
   addAnnotation(getContainer_PackageName(), source, new String[] {"uuid", "11350778856253"});
   addAnnotation(getContainer_Incomplete(), source, new String[] {"uuid", "11350778856254"});
   addAnnotation(getContainer_Deployments(), source, new String[] {"uuid", "11350778856255"});
   addAnnotation(getContainer_DeploymentGroups(), source, new String[] {"uuid", "11350778856256"});
   addAnnotation(getContainer_AllDeployments(), source, new String[] {"uuid", "11350778856407"});
   addAnnotation(deploymentEClass, source, new String[] {"uuid", "11350778856408"});
   addAnnotation(getDeployment_Component(), source, new String[] {"uuid", "11350778856409"});
   addAnnotation(getDeployment_Id(), source, new String[] {"uuid", "113507788564010"});
   addAnnotation(getDeployment_Type(), source, new String[] {"uuid", "113507788564011"});
   addAnnotation(getDeployment_Singleton(), source, new String[] {"uuid", "113507788564012"});
   addAnnotation(getDeployment_Lazy(), source, new String[] {"uuid", "113507788564013"});
   addAnnotation(getDeployment_Prototype(), source, new String[] {"uuid", "113507788564014"});
   addAnnotation(getDeployment_Initialized(), source, new String[] {"uuid", "113507788565615"});
   addAnnotation(getDeployment_Container(), source, new String[] {"uuid", "113507788565616"});
   addAnnotation(
       getDeployment_DeploymentGroup(), source, new String[] {"uuid", "113507788565617"});
   addAnnotation(getDeployment_Dependencies(), source, new String[] {"uuid", "113507788565618"});
   addAnnotation(getDeployment_Creators(), source, new String[] {"uuid", "113507788565619"});
   addAnnotation(getDeployment_Listeners(), source, new String[] {"uuid", "113507788565620"});
   addAnnotation(getDeployment_Referers(), source, new String[] {"uuid", "113507788565621"});
   addAnnotation(getDeployment_Root(), source, new String[] {"uuid", "113507788565622"});
   addAnnotation(getDeployment_Depends(), source, new String[] {"uuid", "113568774160969"});
   addAnnotation(deploymentGroupEClass, source, new String[] {"uuid", "113507788567123"});
   addAnnotation(getDeploymentGroup_Container(), source, new String[] {"uuid", "113507788567124"});
   addAnnotation(getDeploymentGroup_SubGroups(), source, new String[] {"uuid", "113507788567125"});
   addAnnotation(
       getDeploymentGroup_SuperGroup(), source, new String[] {"uuid", "113507788567126"});
   addAnnotation(
       getDeploymentGroup_Deployments(), source, new String[] {"uuid", "113507788567127"});
   addAnnotation(getDeploymentGroup_Name(), source, new String[] {"uuid", "113507788567128"});
   addAnnotation(parameterEClass, source, new String[] {"uuid", "113507788567129"});
   addAnnotation(
       (EOperation) parameterEClass.getEOperations().get(0),
       source,
       new String[] {"uuid", "113507788567130"});
   addAnnotation(dependencyEClass, source, new String[] {"uuid", "113507788568731"});
   addAnnotation(getDependency_Feature(), source, new String[] {"uuid", "113507788568732"});
   addAnnotation(getDependency_Deployment(), source, new String[] {"uuid", "113507788568733"});
   addAnnotation(referenceEClass, source, new String[] {"uuid", "113507788568734"});
   addAnnotation(getReference_Target(), source, new String[] {"uuid", "113507788568735"});
   addAnnotation(getReference_Listen(), source, new String[] {"uuid", "113507788568736"});
   addAnnotation(integerParameterEClass, source, new String[] {"uuid", "113507788568737"});
   addAnnotation(getIntegerParameter_Value(), source, new String[] {"uuid", "113507788568738"});
   addAnnotation(longParameterEClass, source, new String[] {"uuid", "113507788570339"});
   addAnnotation(getLongParameter_Value(), source, new String[] {"uuid", "113507788570340"});
   addAnnotation(floatParameterEClass, source, new String[] {"uuid", "113507788570341"});
   addAnnotation(getFloatParameter_Value(), source, new String[] {"uuid", "113507788570342"});
   addAnnotation(doubleParameterEClass, source, new String[] {"uuid", "113507788570343"});
   addAnnotation(getDoubleParameter_Value(), source, new String[] {"uuid", "113507788570344"});
   addAnnotation(booleanParameterEClass, source, new String[] {"uuid", "113507788570345"});
   addAnnotation(getBooleanParameter_Value(), source, new String[] {"uuid", "113507788571846"});
   addAnnotation(stringParameterEClass, source, new String[] {"uuid", "113507788571847"});
   addAnnotation(getStringParameter_Value(), source, new String[] {"uuid", "113507788571848"});
   addAnnotation(charParameterEClass, source, new String[] {"uuid", "113507788571849"});
   addAnnotation(getCharParameter_Value(), source, new String[] {"uuid", "113507788571850"});
   addAnnotation(creatorEClass, source, new String[] {"uuid", "113507788571851"});
   addAnnotation(getCreator_Operation(), source, new String[] {"uuid", "113507788571852"});
   addAnnotation(getCreator_Deployment(), source, new String[] {"uuid", "113507788573453"});
   addAnnotation(getCreator_Product(), source, new String[] {"uuid", "113507788573454"});
   addAnnotation(listenerEClass, source, new String[] {"uuid", "113507788573455"});
   addAnnotation(getListener_Deployment(), source, new String[] {"uuid", "113507788573456"});
   addAnnotation(getListener_Notifier(), source, new String[] {"uuid", "113507788573457"});
   addAnnotation(deploymentTypeEEnum, source, new String[] {"uuid", "113507788573458"});
   addAnnotation(
       (EEnumLiteral) deploymentTypeEEnum.getELiterals().get(0),
       source,
       new String[] {"uuid", "113507788573459"});
   addAnnotation(
       (EEnumLiteral) deploymentTypeEEnum.getELiterals().get(1),
       source,
       new String[] {"uuid", "113507788573460"});
   addAnnotation(
       (EEnumLiteral) deploymentTypeEEnum.getELiterals().get(2),
       source,
       new String[] {"uuid", "113507788573461"});
 }