Example #1
0
 /**
  * Constructs an Environment. This is the main, most basic constructor.
  *
  * @param globalFrame a frame for the global Environment
  * @param dynamicFrame a frame for the dynamic Environment
  * @param eventHandler an EventHandler for warnings, errors, etc
  * @param importedExtensions Extension-s from which to import bindings with load()
  * @param isSkylark true if in Skylark context
  * @param fileContentHashCode a hash for the source file being evaluated, if any
  * @param isLoadingPhase true if in loading phase
  */
 private Environment(
     Frame globalFrame,
     Frame dynamicFrame,
     EventHandler eventHandler,
     Map<String, Extension> importedExtensions,
     boolean isSkylark,
     @Nullable String fileContentHashCode,
     boolean isLoadingPhase) {
   this.globalFrame = Preconditions.checkNotNull(globalFrame);
   this.dynamicFrame = Preconditions.checkNotNull(dynamicFrame);
   Preconditions.checkArgument(globalFrame.mutability().isMutable());
   Preconditions.checkArgument(dynamicFrame.mutability().isMutable());
   this.eventHandler = eventHandler;
   this.importedExtensions = importedExtensions;
   this.isSkylark = isSkylark;
   this.fileContentHashCode = fileContentHashCode;
   this.isLoadingPhase = isLoadingPhase;
 }
Example #2
0
 /** Builds the Environment. */
 public Environment build() {
   Preconditions.checkArgument(mutability.isMutable());
   if (parent != null) {
     Preconditions.checkArgument(!parent.mutability().isMutable());
   }
   Frame globalFrame = new Frame(mutability, parent);
   Frame dynamicFrame = new Frame(mutability, null);
   if (importedExtensions == null) {
     importedExtensions = ImmutableMap.of();
   }
   return new Environment(
       globalFrame,
       dynamicFrame,
       eventHandler,
       importedExtensions,
       isSkylark,
       fileContentHashCode,
       isLoadingPhase);
 }
Example #3
0
 @Override
 public Mutability mutability() {
   // the mutability of the environment is that of its dynamic frame.
   return dynamicFrame.mutability();
 }