private EOperation findOperation(EObject object, String className, String methodName) {

    // We try to find the corresponding EOperation in the execution
    // metamodel
    for (EOperation operation : object.eClass().getEAllOperations()) {
      // TODO !!! this is not super correct yet as overloading allows the
      // definition of 2 methods with the same name !!!
      if (operation.getName().equalsIgnoreCase(methodName)) {
        return operation;
      }
    }

    // If we didn't find it, we try to find the class that should contain
    // this operation
    EClass containingEClass = null;
    if (getFQN(object.eClass(), "").equalsIgnoreCase(className)) containingEClass = object.eClass();
    else
      for (EClass candidate : object.eClass().getEAllSuperTypes()) {
        if (getFQN(candidate, "").equalsIgnoreCase(className)) containingEClass = candidate;
      }

    // Then we create the missing operation (VERY approximatively)
    EOperation operation = EcoreFactory.eINSTANCE.createEOperation();
    if (containingEClass != null) containingEClass.getEOperations().add(operation);
    operation.setName(methodName);
    return operation;
  }
 /**
  * Initializes the annotations for <b>http://www.eclipse.org/uml2/1.1.0/GenModel</b>.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 protected void createGenModel_1Annotations() {
   String source = "http://www.eclipse.org/uml2/1.1.0/GenModel";
   addAnnotation(
       pcmRandomVariableEClass.getEOperations().get(0),
       source,
       new String[] {
         "body", "not self.specification.oclIsUndefined() and self.specification <> \'\'"
       });
 }
 protected void handleEClassifier(
     EClassifier classifier, Set<EPackage> visitedPackages, Set<Object> visited) {
   if (classifier != null && visited.add(classifier)) {
     handleEPackage(classifier.getEPackage(), visitedPackages);
     handleETypeParameters(classifier.getETypeParameters(), visitedPackages, visited);
     if (classifier instanceof EClass) {
       EClass eClass = (EClass) classifier;
       handleEStructuralFeatures(eClass.getEStructuralFeatures(), visitedPackages, visited);
       handleEOperations(eClass.getEOperations(), visitedPackages, visited);
       handleEGenericTypes(eClass.getEGenericSuperTypes(), visitedPackages, visited);
     }
   }
 }
 /**
  * Initializes the annotations for <b>http://www.eclipse.org/uml2/1.1.0/GenModel</b>.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 protected void createGenModel_1Annotations() {
   String source = "http://www.eclipse.org/uml2/1.1.0/GenModel";
   addAnnotation(
       specifiedReliabilityAnnotationEClass.getEOperations().get(0),
       source,
       new String[] {
         "body",
         "(self.role_SpecifiedQoSAnnotation.oclIsTypeOf(pcm::repository::OperationRequiredRole)) and (self.role_SpecifiedQoSAnnotation.oclAsType(pcm::repository::OperationRequiredRole).requiringEntity_RequiredRole.oclIsTypeOf(pcm::system::System))\r\n\r\n\r\n"
       });
   addAnnotation(
       specifiedReliabilityAnnotationEClass.getEOperations().get(1),
       source,
       new String[] {
         "body",
         "self.externalFailureOccurrenceDescriptions__SpecifiedReliabilityAnnotation.failureProbability.oclAsType(Real)->sum()<=1.0"
       });
   addAnnotation(
       specifiedReliabilityAnnotationEClass.getEOperations().get(2),
       source,
       new String[] {
         "body",
         "self.externalFailureOccurrenceDescriptions__SpecifiedReliabilityAnnotation->forAll(x:pcm::reliability::ExternalFailureOccurrenceDescription,y:pcm::reliability::ExternalFailureOccurrenceDescription  | x<>y implies x.failureType__ExternalFailureOccurrenceDescription <> y.failureType__ExternalFailureOccurrenceDescription )"
       });
 }
  @Override
  public Object caseEClass(EClass object) {
    Type type = getType(object);

    if (object.isInterface()) {
    } else { // class
      Class clazz = (Class) type;
      clazz.setAbstract(object.isAbstract());
    }

    Set<Type> assocAndGen = new HashSet<>();
    Set<Type> dependencies = new HashSet<>();

    for (EClass eSuperType : object.getESuperTypes()) {
      Type superType = getType(eSuperType);
      assocAndGen.add(superType);

      if (eSuperType.isInterface()) {
        type.addInterface((Interface) superType);
      } else {
        type.addSuperClass((Class) superType);
      }
    }

    for (EStructuralFeature eFeature : object.getEStructuralFeatures()) {
      Attribute attr = (Attribute) doSwitch(eFeature);
      type.addAttribute(attr);

      assocAndGen.add(attr.type);
    }
    for (EOperation eOperation : object.getEOperations()) {
      Operation op = (Operation) doSwitch(eOperation);
      type.addOperation(op);

      dependencies.add(op.type);
      for (TypedElement fpar : op.formalParameters()) {
        dependencies.add(fpar.type);
      }
    }
    dependencies.removeAll(assocAndGen);
    for (Type dep : dependencies) {
      type.addDependency(dep);
    }

    return type;
  }
  public void test_OperationCallExp_checkArgumentCount() {
    OperationCallExp o = factory.createOperationCallExp();

    EClass fruitUtil = (EClass) fruitPackage.getEClassifier("FruitUtil");
    EOperation oper = fruitUtil.getEOperations().get(0);
    o.setReferredOperation(oper);

    OCLExpression arg = factory.createUnspecifiedValueExp();
    o.getArgument().add(arg);
    CollectionType ctype = factory.createOrderedSetType();
    ctype.setElementType(color);
    arg.setType(ctype);

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().add(factory.createCollectionLiteralExp());

    assertProblem(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().clear();

    assertProblem(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);
  }
  /**
   * Obtains the operations declared on the specified type.
   *
   * @param classifierName The name of the classifier which operation are sought.
   * @return The operations it declares. <code>null</code> if none.
   */
  public synchronized EList<EOperation> getExistingOperations(String classifierName) {
    EList<EOperation> result = new BasicEList<EOperation>();

    if (PRIMITIVE_STRING_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(stringType.getEOperations()));
    } else if (TYPE_OCLANY_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(oclAnyType.getEOperations()));
    } else if (TYPE_EOBJECT_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(eObjectType.getEOperations()));
    } else if (TYPE_COLLECTION_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(collectionType.getEOperations()));
    } else if (TYPE_ORDEREDSET_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(orderedSetType.getEOperations()));
    } else if (TYPE_SEQUENCE_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(sequenceType.getEOperations()));
    }
    return result;
  }
Example #8
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getDiagram__CreateSubtype__String_String_String_String_String_String() {
   return diagramEClass.getEOperations().get(0);
 }
Example #9
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getDiagram__CreateInstance__String_MultiModel() {
   return diagramEClass.getEOperations().get(1);
 }
Example #10
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getDealership__Home__HttpServletRequestContext() {
   return dealershipEClass.getEOperations().get(0);
 }
Example #11
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getEditor__DeleteInstance() {
   return editorEClass.getEOperations().get(6);
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getParameter__GetObjectValue() {
   return parameterEClass.getEOperations().get(0);
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getFlowProperty__GetIcon() {
   return flowPropertyEClass.getEOperations().get(0);
 }
Example #14
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getEditor__GetSupertype() {
   return editorEClass.getEOperations().get(1);
 }
Example #15
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getApplication__GetAllChildren() {
   return applicationEClass.getEOperations().get(0);
 }
Example #16
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getLibrary__GetBookByName__String() {
   return libraryEClass.getEOperations().get(0);
 }
Example #17
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getEditor__GetMetatype() {
   return editorEClass.getEOperations().get(0);
 }
Example #18
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getLibrary__ToString() {
   return libraryEClass.getEOperations().get(1);
 }
Example #19
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getCar__Home__HttpServletRequestContext() {
   return carEClass.getEOperations().get(0);
 }
Example #20
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getDealership__InventoryTable__HttpServletRequestContext() {
   return dealershipEClass.getEOperations().get(1);
 }
Example #21
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getDiagram__InvokeInstanceWizard__IStructuredSelection() {
   return diagramEClass.getEOperations().get(2);
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getIPredicate__Match__Object() {
   return iPredicateEClass.getEOperations().get(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"});
 }
Example #24
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getEditor__DeleteType() {
   return editorEClass.getEOperations().get(3);
 }
  public void propagateEOperations(JavaResource resource, GenClass genClass) {
    GenPackage genPackage = genClass.getGenPackage();
    EPackage ePackage = genPackage.getEcorePackage();
    if (resource.getContents().isEmpty()
        || !(resource.getContents().get(0) instanceof CompilationUnit)) {
      return;
    }
    CompilationUnit cu = (CompilationUnit) resource.getContents().get(0);
    Class customClass = (Class) cu.getClassifiers().get(0);
    EClass eClass = genClass.getEcoreClass();

    if (eClass == null) {
      return;
    }

    Set<Method> annotatedMethods = getAnnotatedMethods(customClass);

    for (Method method : annotatedMethods) {
      for (AnnotationInstanceOrModifier modifier : method.getAnnotationsAndModifiers()) {
        if (modifier instanceof Public) {
          EOperation newEOperation = EcoreFactory.eINSTANCE.createEOperation();
          newEOperation.setName(method.getName());
          Type opType = method.getTypeReference().getTarget();
          newEOperation.setEType(
              eClassifierForCustomClass(opType, method.getTypeReference(), ePackage));
          if (isMulti(opType)) {
            newEOperation.setUpperBound(-1);
          }
          for (Parameter parameter : method.getParameters()) {
            EParameter newEParameter = EcoreFactory.eINSTANCE.createEParameter();
            newEParameter.setName(parameter.getName());
            Type paramType = parameter.getTypeReference().getTarget();
            newEParameter.setEType(
                eClassifierForCustomClass(paramType, parameter.getTypeReference(), ePackage));
            // TODO generics, ...
            newEOperation.getEParameters().add(newEParameter);
          }
          // TODO @jendrik: why is that needed?
          //					for (AnnotationInstanceOrModifier annotationInstance :
          // method.getAnnotationsAndModifiers()) {
          //						if (annotationInstance instanceof AnnotationInstance) {
          //							Classifier javaAnnotation = ((AnnotationInstance)
          // annotationInstance).getAnnotation();
          //							if (javaAnnotation.eIsProxy()) {
          //								continue;
          //							}
          //							EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
          //							eAnnotation.setSource(javaAnnotation.getContainingCompilationUnit(
          //									).getNamespacesAsString() + javaAnnotation.getName());
          //							newEOperation.getEAnnotations().add(eAnnotation);
          //						}
          //					}
          boolean operationAlreadyExists = false;
          List<EOperation> operations = eClass.getEOperations();
          List<EOperation> existingOperations = new ArrayList<EOperation>(operations);
          // must be done here already for ensuring that compared operations have the same parent
          eClass.getEOperations().add(newEOperation);
          for (EOperation existingOperation : existingOperations) {
            boolean removed = removeAnnotation(existingOperation);
            if (EcoreUtil.equals(existingOperation, newEOperation)) {
              operationAlreadyExists = true;
              removeAnnotation(existingOperation);
              annotateAsGenerated(existingOperation);
              break;
            }
            if (removed) {
              annotateAsGenerated(existingOperation);
            }
          }
          if (!operationAlreadyExists) {
            annotateAsGenerated(newEOperation);
          } else {
            eClass.getEOperations().remove(newEOperation);
          }
          break;
        }
      }
    }

    try {
      Resource ecoreResource = ePackage.eResource();
      URI originalURI = ecoreResource.getURI();
      if (originalURI.isFile()) {
        String workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
        URI platformURI =
            URI.createPlatformResourceURI(
                originalURI.toFileString().substring(workspacePath.length()), true);
        ecoreResource.setURI(platformURI);
      }
      new ResourceSaver().saveResource(ecoreResource);
      ecoreResource.setURI(originalURI);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #26
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getEditor__CreateInstance__String_MultiModel() {
   return editorEClass.getEOperations().get(4);
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getFlowPort__GetIcon() {
   return flowPortEClass.getEOperations().get(0);
 }
Example #28
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getEditor__InvokeInstanceWizard__IStructuredSelection() {
   return editorEClass.getEOperations().get(5);
 }
Example #29
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getEditor__CreateSubtype__String_String_String_String_String_String() {
   return editorEClass.getEOperations().get(2);
 }
Example #30
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public EOperation getBook__IsAvailable() {
   return bookEClass.getEOperations().get(0);
 }