Esempio n. 1
0
 protected Map<TemplateParameter, ParameterableElement> getIterationBindings(
     Iteration candidateIteration) {
   Type sourceType = this.sourceType;
   if (!(sourceType instanceof CollectionType)
       && (candidateIteration.getOwningType() instanceof CollectionType)) {
     sourceType = metaModelManager.getCollectionType("Set", sourceType); // Implicit oclAsSet()
   }
   if (!(sourceType instanceof CollectionType)) { // May be InvalidType
     return null;
   }
   HashMap<TemplateParameter, ParameterableElement> bindings =
       new HashMap<TemplateParameter, ParameterableElement>();
   bindings.put(
       candidateIteration.getOwningType().getOwnedTemplateSignature().getOwnedParameter().get(0),
       ((CollectionType) sourceType).getElementType());
   PivotUtil.getAllTemplateParameterSubstitutions(bindings, sourceType);
   TemplateSignature templateSignature = candidateIteration.getOwnedTemplateSignature();
   if (templateSignature != null) {
     List<TemplateParameter> templateParameters = templateSignature.getOwnedParameter();
     int accIndex = 0;
     for (NavigatingArgCS csArgument : csArguments) {
       if (csArgument.getRole() == NavigationRole.ACCUMULATOR) {
         if (accIndex < templateParameters.size()) {
           Variable argument = PivotUtil.getPivot(Variable.class, csArgument);
           Type argumentType = argument.getType();
           TemplateParameter accParameter = templateParameters.get(accIndex);
           bindings.put(accParameter, argumentType);
         }
         accIndex++;
       }
     }
   }
   return bindings;
 }
Esempio n. 2
0
 public boolean matches(EnvironmentView environmentView, Type forType, EObject eObject) {
   if (eObject instanceof Iteration) {
     Iteration candidateIteration = (Iteration) eObject;
     int iteratorCount = candidateIteration.getOwnedIterator().size();
     if ((0 < iterators) && (iteratorCount != iterators)) {
       return false;
     }
     int accumulatorCount = candidateIteration.getOwnedAccumulator().size();
     if (accumulatorCount != accumulators) {
       return false;
     }
     Map<TemplateParameter, ParameterableElement> bindings =
         getIterationBindings(candidateIteration);
     if (bindings != null) {
       installBindings(environmentView, forType, eObject, bindings);
     }
     return true;
   } else if (eObject instanceof Operation) {
     if (iterators > 0) {
       return false;
     }
     if (accumulators > 0) {
       return false;
     }
     Operation candidateOperation = (Operation) eObject;
     List<Parameter> candidateParameters = candidateOperation.getOwnedParameter();
     if (expressions != candidateParameters.size()) {
       return false;
     }
     Map<TemplateParameter, ParameterableElement> bindings =
         getOperationBindings(candidateOperation);
     for (int i = 0; i < expressions; i++) {
       Parameter candidateParameter = candidateParameters.get(i);
       NavigatingArgCS csExpression = csArguments.get(i);
       OclExpression expression = PivotUtil.getPivot(OclExpression.class, csExpression);
       if (expression == null) {
         return false;
       }
       Type candidateType = metaModelManager.getTypeWithMultiplicity(candidateParameter);
       if (candidateType instanceof SelfType) {
         candidateType = candidateOperation.getOwningType();
       }
       Type expressionType = expression.getType();
       expressionType =
           PivotUtil.getBehavioralType(expressionType); // FIXME make this a general facility
       if (!metaModelManager.conformsTo(expressionType, candidateType, bindings)) {
         return false;
       }
     }
     if (bindings != null) {
       installBindings(environmentView, forType, eObject, bindings);
     }
     return true;
   } else {
     return false;
   }
 }