/* (non-Javadoc)
  * @see org.rascalmpl.tasks.ITaskRegistry#getProducer(Type, IValue)
  */
 @Override
 public ITask<Type, IValue, IValue> getProducer(Type key, IValue name) {
   lock.lock();
   try {
     Map<Type, ITask<Type, IValue, IValue>> producerMap = keyedProducers.get(key);
     if (producerMap != null) {
       Type nameType = name.getType();
       if (producerMap.containsKey(nameType)) return producerMap.get(nameType);
       for (Map.Entry<Type, ITask<Type, IValue, IValue>> t : producerMap.entrySet()) {
         if (nameType.isSubtypeOf(t.getKey())) return t.getValue();
       }
     }
     throw new ImplementationError("No suitable producer found for " + key + "(" + name + ")");
   } finally {
     lock.unlock();
   }
 }
Example #2
0
  @Override
  public <U extends IValue, V extends IValue> Result<U> fieldUpdate(
      String name, Result<V> repl, TypeStore store) {
    if (!getType().hasFieldNames()) {
      throw new UndeclaredFieldError(name, getType(), ctx.getCurrentAST());
    }

    try {
      int index = getType().getFieldIndex(name);
      Type type = getType().getFieldType(index);
      if (!type.isSubtypeOf(repl.getType())) {
        throw new UnexpectedTypeError(type, repl.getType(), ctx.getCurrentAST());
      }
      return makeResult(getType(), getValue().set(index, repl.getValue()), ctx);
    } catch (UndeclaredFieldException e) {
      throw new UndeclaredFieldError(name, getType(), ctx.getCurrentAST());
    }
  }