Example #1
0
 /** Returns true if there is a conflict the a parent Scope for the given variable name. */
 private boolean hasParentConflict(String varName, LegalScope legalScope) {
   LegalScope parent = legalScope.getParentScope();
   while (parent != null) {
     if (variableDefs.containsKey(varName, parent)) {
       // Conflict with a higher level scope
       return true;
     }
     parent = parent.getParentScope();
   }
   return false;
 }
Example #2
0
 /**
  * Returns true if the given LegalScope and variable name are a legal combination, knowing
  * previous assertions of a FormatManager for the given LegalScope and variable name.
  *
  * <p>If no previous FormatManager was stored via assertLegalScope for the given LegalScope and
  * variable name, then this will unconditionally return false.
  *
  * <p>If a FormatManager was stored via assertLegalScope for a LegalScope and variable name, then
  * this will return true if the given LegalScope is compatible with the stored LegalScope.
  *
  * @param legalScope The LegalScope to be used to determine if the given combination is legal
  * @param varName The variable name to be used to determine if the given combination is legal
  * @return true if the given LegalScope and variable name are a legal combination; false otherwise
  */
 public boolean isLegalVariableID(LegalScope legalScope, String varName) {
   if (variableDefs.containsKey(varName, Objects.requireNonNull(legalScope))) {
     return true;
   }
   // Recursively check parent
   LegalScope parent = legalScope.getParentScope();
   return (parent != null) && isLegalVariableID(parent, varName);
 }
Example #3
0
 /**
  * Returns the FormatManager for the given LegalScope and variable name, knowing previous
  * assertions of a FormatManager for the given LegalScope and variable name.
  *
  * <p>If no previous FormatManager was stored via assertLegalScope for the given LegalScope and
  * variable name, then this will unconditionally return null.
  *
  * @param legalScope The LegalScope to be used to determine the FormatManager for the given
  *     variable name
  * @param varName The variable name to be used to determine the FormatManager
  * @return The FormatManager for the given LegalScope and variable name
  */
 public FormatManager<?> getVariableFormat(LegalScope legalScope, String varName) {
   FormatManager<?> format = variableDefs.get(varName, Objects.requireNonNull(legalScope));
   if (format == null) {
     LegalScope parent = legalScope.getParentScope();
     // Recursively check parent, if possible
     if (parent != null) {
       return getVariableFormat(parent, varName);
     }
   }
   return format;
 }