Пример #1
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;
   }
 }