Skip to content

Commit

Permalink
Cleanup in Environment, remove unused lookup function
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=137266170
  • Loading branch information
laurentlb authored and laszlocsomor committed Oct 27, 2016
1 parent 6a3565e commit 1afb0b2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ private static boolean validateAssignmentStatements(
continue;
}
String target = ((Identifier) lvalue).getName();
if (pkgEnv.lookup(target, null) != null) {
if (pkgEnv.hasVariable(target)) {
eventHandler.handle(Event.error(stmt.getLocation(), "Reassignment of builtin build "
+ "function '" + target + "' not permitted"));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ public Environment update(String varname, Object value) throws EvalException {
return this;
}

private boolean hasVariable(String varname) {
public boolean hasVariable(String varname) {
return lookup(varname) != null;
}

Expand Down Expand Up @@ -756,19 +756,6 @@ public Object lookup(String varname) {
return dynamicValue;
}

/**
* Like {@link #lookup(String)}, but instead of throwing an exception in the case
* where <code>varname</code> is not defined, <code>defaultValue</code> is returned instead.
*/
public Object lookup(String varname, Object defaultValue) {
Preconditions.checkState(!isSkylark);
Object value = lookup(varname);
if (value != null) {
return value;
}
return defaultValue;
}

/**
* @return true if varname is a known global variable,
* because it has been read in the context of the current function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public void testLookupAndUpdate() throws Exception {
}

@Test
public void testLookupWithDefault() throws Exception {
assertEquals(21, getEnvironment().lookup("VERSION", 21));
public void testHasVariable() throws Exception {
assertThat(getEnvironment().hasVariable("VERSION")).isFalse();
update("VERSION", 42);
assertEquals(42, getEnvironment().lookup("VERSION", 21));
assertThat(getEnvironment().hasVariable("VERSION")).isTrue();
}

@Test
Expand Down

0 comments on commit 1afb0b2

Please sign in to comment.