@@ -34,9 +34,21 @@ public static JScriptBox create() {
34
34
return new JScriptBox ();
35
35
}
36
36
37
- /** Sets all of the properties contained in the given map. */
37
+ /** Sets all of the properties contained in the given map. Throws an error if one of the entry keys isn't a valid identifier. */
38
38
public JScriptBox setAll (Map <String , ?> map ) {
39
- names .putAll (map );
39
+ for (Map .Entry <String , ?> entry : map .entrySet ()) {
40
+ set (entry .getKey ()).toValue (entry .getValue ());
41
+ }
42
+ return this ;
43
+ }
44
+
45
+ /** Sets all of the properties contained in the given map for which the key is a valid identifier. */
46
+ public JScriptBox setAllValid (Map <String , ?> map ) {
47
+ for (Map .Entry <String , ?> entry : map .entrySet ()) {
48
+ if (isValidIdentifier (entry .getKey ())) {
49
+ set (entry .getKey ()).toValue (entry .getValue ());
50
+ }
51
+ }
40
52
return this ;
41
53
}
42
54
@@ -47,13 +59,17 @@ public NameSetter set(String name) {
47
59
48
60
/** Checks that the given name is a valid identifier. */
49
61
static String checkValidIdentifier (String name ) {
50
- Check .that (name .length () > 0 &&
51
- Character .isJavaIdentifierStart (name .codePointAt (0 )) &&
52
- name .codePoints ().skip (1 ).allMatch (Character ::isJavaIdentifierPart ),
53
- "'%0' is not a valid identifier" , name );
62
+ Check .that (isValidIdentifier (name ), "'%0' is not a valid identifier" , name );
54
63
return name ;
55
64
}
56
65
66
+ /** Checks that the given name is a valid identifier. */
67
+ static boolean isValidIdentifier (String name ) {
68
+ return name .length () > 0 &&
69
+ Character .isJavaIdentifierStart (name .codePointAt (0 )) &&
70
+ name .codePoints ().skip (1 ).allMatch (Character ::isJavaIdentifierPart );
71
+ }
72
+
57
73
/** Fluent API for setting names in this JsHarness. */
58
74
public class NameSetter {
59
75
private final String name ;
0 commit comments