Permalink
Browse files

De-stringly-typing

  • Loading branch information...
neilellis committed Sep 12, 2017
1 parent c5af6f1 commit 8543fb026a9e839bb96fcbc94fc31fe28f3aa47c
Showing with 403 additions and 304 deletions.
  1. +2 −2 pre-commit-hook.sh → build.sh
  2. +17 −17 dollar-core/src/main/java/dollar/api/Scope.java
  3. +103 −0 dollar-core/src/main/java/dollar/api/VarKey.java
  4. +3 −3 dollar-core/src/test/java/dollar/DollarArrayTest.java
  5. +3 −3 dollar-core/src/test/java/dollar/DollarControlFlowTest.java
  6. +3 −3 dollar-core/src/test/java/dollar/DollarErrorTest.java
  7. +4 −4 dollar-core/src/test/java/dollar/DollarHttpTest.java
  8. +3 −3 dollar-core/src/test/java/dollar/DollarMapTest.java
  9. +3 −3 dollar-core/src/test/java/dollar/DollarNumberTest.java
  10. +30 −30 dollar-core/src/test/java/dollar/DollarOperatorsRegressionTest.java
  11. +2 −2 dollar-core/src/test/java/dollar/DollarPubSubTest.java
  12. +3 −3 dollar-core/src/test/java/dollar/DollarQueueTest.java
  13. +3 −3 dollar-core/src/test/java/dollar/DollarRangeTest.java
  14. +2 −2 dollar-core/src/test/java/dollar/DollarRedisTest.java
  15. +3 −3 dollar-core/src/test/java/dollar/DollarVoidTest.java
  16. +3 −3 dollar-core/src/test/java/dollar/DollarYamlTest.java
  17. +1 −1 dollar-core/src/test/java/dollar/FromJsonStringTest.java
  18. +8 −8 dollar-core/src/test/java/dollar/ToStringTest.java
  19. +5 −5 dollar-docs/src/test/java/dollar/docs/DocTest.java
  20. +1 −1 dollar-examples/src/main/resources/quick/test_java.ds
  21. +1 −1 dollar-examples/src/test/java/dollar/DollarBasicTest.java
  22. +3 −3 dollar-examples/src/test/java/dollar/DollarLambdaTest.java
  23. +5 −5 dollar-examples/src/test/java/dollar/DollarParserTest.java
  24. +3 −3 dollar-examples/src/test/java/dollar/DollarSerializationTest.java
  25. +3 −3 dollar-examples/src/test/java/dollar/DollarTypeTest.java
  26. +6 −6 dollar-examples/src/test/java/dollar/internal/runtime/script/ParserQuickTest.java
  27. +27 −30 dollar-examples/src/test/java/dollar/internal/runtime/script/ParserSlowTest.java
  28. +5 −5 dollar-examples/src/test/java/dollar/json/JsonUtilTest.java
  29. +2 −1 ...plugins/dollar-github-resolver-plugin/src/main/java/dollar/plugins/pipe/GithubModuleResolver.java
  30. +3 −2 ...ollar-simple-execution-plugin/src/main/java/dollar/execution/simple/ScopeAwareDollarExecutor.java
  31. +3 −3 dollar-runtime/src/test/java/dollar/DollarDependenciesTest.java
  32. +13 −12 dollar-script/src/main/java/dollar/internal/runtime/script/DollarObject.java
  33. +13 −11 dollar-script/src/main/java/dollar/internal/runtime/script/DollarParserImpl.java
  34. +12 −19 dollar-script/src/main/java/dollar/internal/runtime/script/DollarScriptSupport.java
  35. +12 −12 dollar-script/src/main/java/dollar/internal/runtime/script/Func.java
  36. +3 −2 dollar-script/src/main/java/dollar/internal/runtime/script/PureScope.java
  37. +45 −52 dollar-script/src/main/java/dollar/internal/runtime/script/ScriptScope.java
  38. +2 −1 dollar-script/src/main/java/dollar/internal/runtime/script/api/DollarParser.java
  39. +4 −3 ...script/src/main/java/dollar/internal/runtime/script/api/exceptions/VariableNotFoundException.java
  40. +6 −5 dollar-script/src/main/java/dollar/internal/runtime/script/operators/AssignmentOperator.java
  41. +10 −9 dollar-script/src/main/java/dollar/internal/runtime/script/operators/CollectOperator.java
  42. +3 −2 dollar-script/src/main/java/dollar/internal/runtime/script/operators/DefinitionOperator.java
  43. +3 −3 dollar-script/src/main/java/dollar/internal/runtime/script/operators/ParameterOperator.java
  44. +3 −2 dollar-script/src/main/java/dollar/internal/runtime/script/operators/PureDefinitionOperator.java
  45. +10 −9 dollar-script/src/main/java/dollar/internal/runtime/script/operators/WindowOperator.java
  46. +1 −1 dollar-script/src/test/java/dollar/internal/runtime/script/ParserMainTest.java
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
if [[ -f ~/.bash_profile ]]
then
source ~/.bash_profile &> /dev/null
source ~/.bash_profile
fi
export MAVEN_OPTS="$MAVEN_OPTS -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
mvn -Drat.skip=true -Dmaven.source.skip=true -Dsource.skip=true -DgenerateReports=false -Dmaven.javadoc.skip=true -pl dollar-examples -am --offline install &> /tmp/pre-commit.log
mvn -Drat.skip=true -Dmaven.source.skip=true -Dsource.skip=true -DgenerateReports=false -Dmaven.javadoc.skip=true -pl dollar-examples -am --offline install
@@ -45,14 +45,14 @@
* @param key the name of the variable
* @param listener the listener
*/
void addListener(@NotNull String key, @NotNull Listener listener);
void addListener(@NotNull VarKey key, @NotNull Listener listener);
/**
* Remove all variables, listeners etc from this scope.
*/
void clear();
@Nullable var constraintOf(@NotNull String key);
@Nullable var constraintOf(@NotNull VarKey key);
/**
* Returns a deep copy of this scope
@@ -89,15 +89,15 @@
* @param key the name of the variable
* @return the value of the variable or $void() unless mustFind is true, in which case a VariableNotFoundException is thrown
*/
@NotNull var get(@NotNull String key, boolean mustFind);
@NotNull var get(@NotNull VarKey key, boolean mustFind);
/**
* Get a variable's value by name.
*
* @param key the name of the variable
* @return the value of the variable or $void()
*/
@NotNull var get(@NotNull String key);
@NotNull var get(@NotNull VarKey key);
/**
* Handle the error using any error handlers in this or parent scopes.
@@ -133,15 +133,15 @@
* @param key the name of the variable
* @return true if in this scope or a parent
*/
boolean has(@NotNull String key);
boolean has(@NotNull VarKey key);
/**
* Returns true if the *parameter* is in this scope.
*
* @param key the parameter name
* @return true if the supplied parameter is in *this* scope.
*/
boolean hasParameter(@NotNull String key);
boolean hasParameter(@NotNull VarKey key);
/**
* Returns true if the supplied scope is this, or an ancestor of this, scope.
@@ -173,7 +173,7 @@
* @param id an id to associate with this listener
* @param listener the var object to be notified
*/
void listen(@NotNull String key, @NotNull String id, @NotNull var listener);
void listen(@NotNull VarKey key, @NotNull String id, @NotNull var listener);
/**
* Listen to a variable ('key') if the variable changes then {@link Pipeable#pipe(var...)}
@@ -183,23 +183,23 @@
* @param id an id to associate with this listener
* @param listener the var object to be notified
*/
void listen(@NotNull String key, @NotNull String id, @NotNull Pipeable listener);
void listen(@NotNull VarKey key, @NotNull String id, @NotNull Pipeable listener);
/**
* Notify all listeners that the value of a variable has changed.
*
* @param key the name of the variable
* @return its new value
*/
@Nullable var notify(@NotNull String key);
@Nullable var notify(@NotNull VarKey key);
/**
* Notify all listeners that the value of a variable has changed
*
* @param key the name of the variable
* @param value its new value
*/
void notifyScope(@NotNull String key, @NotNull var value);
void notifyScope(@NotNull VarKey key, @NotNull var value);
/**
* Gets the value of a parameter from this scope or it's ancestors.
@@ -208,7 +208,7 @@
* @return the value associated or throws an exception if not found.
*/
@NotNull
Variable parameter(@NotNull String key);
Variable parameter(@NotNull VarKey key);
/**
* Add a parameter to this scope.
@@ -218,7 +218,7 @@
* @return the value
*/
@NotNull
Variable parameter(@NotNull String key, @NotNull var value);
Variable parameter(@NotNull VarKey key, @NotNull var value);
/**
* Gets all the numeric parameters as a sorted List.
@@ -256,7 +256,7 @@
* @param key name of the variable.
* @return the Scope associated with the variable or null of none found
*/
@Nullable Scope scopeForKey(@NotNull String key);
@Nullable Scope scopeForKey(@NotNull VarKey key);
/**
* Creates or updates a variable.
@@ -268,7 +268,7 @@
* @param varFlags a set of flags relating to the variable
* @return the variable definition
*/
@NotNull Variable set(@NotNull String key,
@NotNull Variable set(@NotNull VarKey key,
@NotNull var value,
@Nullable var constraint,
@Nullable SubType subType,
@@ -288,20 +288,20 @@
* @return get the subtype (computed from the constraint) of a given variable
*/
@Nullable
SubType subTypeOf(@NotNull String key);
SubType subTypeOf(@NotNull VarKey key);
/**
* Returns the details of a variable.
*
* @param key the name of the variable
* @return the full Variable definition
*/
@NotNull Variable variable(@NotNull String key);
@NotNull Variable variable(@NotNull VarKey key);
/**
* Returns all the variables in this scope, including parameter variables
*
* @return all variables in *this* scope
*/
@NotNull Map<String, Variable> variables();
@NotNull Map<VarKey, Variable> variables();
}
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2014-2017 Neil Ellis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dollar.api;
import com.google.common.base.Objects;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class VarKey {
@NotNull
public static final VarKey COLLECTED = of("collected");
@NotNull
public static final VarKey COUNT = of("count");
@NotNull
public static final VarKey IT = of("it");
@NotNull
public static final VarKey ONE = of(1);
@NotNull
public static final VarKey PREVIOUS = of("previous");
@NotNull
public static final VarKey STAR = of("*");
@NotNull
public static final VarKey THIS = of("this");
@NotNull
public static final VarKey THREE = of(3);
@NotNull
public static final VarKey TWO = of(2);
@NotNull
private final String key;
private VarKey(@NotNull String key) {
this.key = removePrefix(key);
}
public static VarKey of(@NotNull String key) {
return new VarKey(key);
}
public static VarKey of(int i) {
return new VarKey(String.valueOf(i));
}
public static VarKey of(@NotNull var variableName) {
return VarKey.of(variableName.toString());
}
public static VarKey random() {
return new VarKey(UUID.randomUUID().toString());
}
@NotNull
public static String removePrefix(@NotNull String key) {
if (key.startsWith("_")) {
return key.substring(1);
} else {
return key;
}
}
@NotNull
public String asString() {
return key;
}
@Override
public int hashCode() {
return Objects.hashCode(key);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VarKey varKey = (VarKey) o;
return Objects.equal(key, varKey.key);
}
@NotNull
public String toString() {
return key;
}
public boolean isNumeric() {
return key.matches("[0-9]+");
}
}
@@ -18,8 +18,8 @@
import dollar.api.DollarStatic;
import dollar.api.var;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.List;
@@ -29,7 +29,7 @@
public class DollarArrayTest {
private static var list;
@BeforeClass
@BeforeAll
public static void setUp() {
list = DollarStatic.$list("Neil", "Dimple", "Charlie");
}
@@ -17,16 +17,16 @@
package dollar;
import dollar.api.var;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static dollar.api.DollarStatic.$;
import static org.junit.Assert.assertEquals;
public class DollarControlFlowTest {
private static var map;
@BeforeClass
@BeforeAll
public static void setUp() {
map = $($("Neil", 0), $("Dimple", 10), $("Charlie", 100));
}
@@ -17,15 +17,15 @@
package dollar;
import dollar.api.var;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static dollar.api.DollarStatic.$list;
public class DollarErrorTest {
private static var list;
@BeforeClass
@BeforeAll
public static void setUp() {
list = $list("Neil", "Dimple", "Charlie");
}
@@ -19,19 +19,19 @@
import com.jayway.restassured.RestAssured;
import dollar.api.DollarStatic;
import dollar.api.var;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
import java.util.Date;
class DollarHttpTest {
private static var profile;
static {
RestAssured.port = 4567;
}
private static var profile;
@BeforeClass
@BeforeAll
public static void setUp() {
profile = DollarStatic.$("name", "Neil")
.$("age", new Date().getYear() + 1900 - 1970)
@@ -17,8 +17,8 @@
package dollar;
import dollar.api.var;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static dollar.api.DollarStatic.$;
import static junit.framework.TestCase.assertEquals;
@@ -28,7 +28,7 @@
private static var list;
private static var map;
@BeforeClass
@BeforeAll
public static void setUp() {
map = $("color", "red").$("size", "large");
}
@@ -18,15 +18,15 @@
import dollar.api.DollarStatic;
import dollar.api.var;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
public class DollarNumberTest {
private static var list;
@BeforeClass
@BeforeAll
public static void setUp() {
}
Oops, something went wrong.

0 comments on commit 8543fb0

Please sign in to comment.