Exemplo n.º 1
0
 @Override
 public Object getIndex(Object key, Location loc) throws EvalException {
   if (!(key instanceof SkylarkClassObjectConstructor)) {
     throw new EvalException(
         loc,
         String.format(
             "Type Target only supports indexing by object constructors, got %s instead",
             EvalUtils.getDataTypeName(key)));
   }
   SkylarkClassObjectConstructor constructor = (SkylarkClassObjectConstructor) key;
   SkylarkProviders provider = getProvider(SkylarkProviders.class);
   if (provider != null) {
     Object declaredProvider = provider.getDeclaredProvider(constructor.getKey());
     if (declaredProvider != null) {
       return declaredProvider;
     }
   }
   // Either provider or declaredProvider is null
   throw new EvalException(
       loc,
       String.format(
           "Object of type Target doesn't contain declared provider %s",
           constructor.getKey().getExportedName()));
 }
Exemplo n.º 2
0
 @Override
 public boolean containsKey(Object key, Location loc) throws EvalException {
   if (!(key instanceof SkylarkClassObjectConstructor)) {
     throw new EvalException(
         loc,
         String.format(
             "Type Target only supports querying by object constructors, got %s instead",
             EvalUtils.getDataTypeName(key)));
   }
   SkylarkClassObjectConstructor constructor = (SkylarkClassObjectConstructor) key;
   SkylarkProviders provider = getProvider(SkylarkProviders.class);
   if (provider != null) {
     Object declaredProvider = provider.getDeclaredProvider(constructor.getKey());
     if (declaredProvider != null) {
       return true;
     }
   }
   return false;
 }