Example #1
0
 public LambdaType getLambdaType(
     String typeName, Type contextType, List<? extends Type> parameterTypes, Type resultType) {
   if (contextType == null) {
     return null;
   }
   Map<Type, List<LambdaType>> contextMap = lambdaTypes.get(contextType);
   if (contextMap == null) {
     contextMap = new HashMap<Type, List<LambdaType>>();
     lambdaTypes.put(contextType, contextMap);
   }
   int iMax = parameterTypes.size();
   Type firstParameterType = iMax > 0 ? parameterTypes.get(0) : null;
   List<LambdaType> lambdasList = contextMap.get(firstParameterType);
   if (lambdasList == null) {
     lambdasList = new ArrayList<LambdaType>();
     contextMap.put(firstParameterType, lambdasList);
   }
   for (LambdaType candidateLambda : lambdasList) {
     List<? extends Type> candidateTypes = candidateLambda.getParameterType();
     if (iMax == candidateTypes.size()) {
       boolean gotIt = true;
       for (int i = 1; i < iMax; i++) {
         Type requiredType = parameterTypes.get(i);
         Type candidateType = candidateTypes.get(i);
         if (requiredType != candidateType) {
           gotIt = false;
           break;
         }
       }
       if (gotIt) {
         return candidateLambda;
       }
     }
   }
   LambdaType lambdaType = PivotFactory.eINSTANCE.createLambdaType();
   lambdaType.setName(typeName);
   lambdaType.setContextType(contextType);
   lambdaType.getParameterType().addAll(parameterTypes);
   lambdaType.setResultType(resultType);
   lambdaType.getSuperClass().add(metaModelManager.getOclLambdaType());
   metaModelManager.addOrphanClass(lambdaType);
   return lambdaType;
 }
Example #2
0
 public static Map<TemplateParameter, ParameterableElement> getAllTemplateParameterSubstitutions(
     Map<TemplateParameter, ParameterableElement> bindings,
     Type argumentType,
     LambdaType lambdaType) {
   Type resultType = lambdaType.getResultType();
   if (resultType != null) {
     TemplateParameter resultTemplateParameter = resultType.getOwningTemplateParameter();
     if (resultTemplateParameter != null) {
       if (bindings == null) {
         bindings = new HashMap<TemplateParameter, ParameterableElement>();
       }
       bindings.put(resultTemplateParameter, argumentType);
     }
   }
   // FIXME There is much more to do
   // FIXME Conflict checking
   return bindings;
 }