Skip to content

Commit df329e5

Browse files
committed
Merge remote-tracking branch 'origin/master' into genericsTake2
2 parents fe1d4d3 + b8e6b8e commit df329e5

7 files changed

Lines changed: 89 additions & 45 deletions

File tree

src/main/java/com/laytonsmith/PureUtilities/Common/StringUtils.java

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public static String Join(Map map, String entryGlue, String elementGlue, String
5050
* @param entryGlue The glue to use between the key and value of each pair in the map
5151
* @param elementGlue The glue to use between each key-value element pairs in the map
5252
* @param lastElementGlue The glue for the last two elements
53-
* @param elementGlueForTwoItems If only two items are in the map, then this glue is used instead. If it is null, then
54-
* lastElementGlue is used instead.
53+
* @param elementGlueForTwoItems If only two items are in the map, then this glue is used instead. If it is null,
54+
* then lastElementGlue is used instead.
5555
* @return The concatenated string
5656
*/
5757
public static String Join(Map map, String entryGlue, String elementGlue, String lastElementGlue, String elementGlueForTwoItems) {
@@ -65,8 +65,8 @@ public static String Join(Map map, String entryGlue, String elementGlue, String
6565
* @param entryGlue The glue to use between the key and value of each pair in the map
6666
* @param elementGlue The glue to use between each key-value element pairs in the map
6767
* @param lastElementGlue The glue for the last two elements
68-
* @param elementGlueForTwoItems If only two items are in the map, then this glue is used instead. If it is null, then
69-
* lastElementGlue is used instead.
68+
* @param elementGlueForTwoItems If only two items are in the map, then this glue is used instead. If it is null,
69+
* then lastElementGlue is used instead.
7070
* @param empty If the map is completely empty, this string is simply returned. If null, an empty string is used.
7171
* @return The concatenated string
7272
*/
@@ -84,6 +84,7 @@ public static String Join(Map map, String entryGlue, String elementGlue, String
8484
/**
8585
* Joins a set together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the Object)
8686
* using the specified string for glue.
87+
*
8788
* @param <T> The set type
8889
* @param set The set to concatenate
8990
* @param glue The glue to use
@@ -95,6 +96,7 @@ public static <T> String Join(Set<T> set, String glue) {
9596

9697
/**
9798
* Joins a set together, rendering each item with the custom renderer.
99+
*
98100
* @param <T> The set type
99101
* @param set The set to concatenate
100102
* @param glue The glue to use
@@ -134,9 +136,10 @@ public static <T> String Join(T[] list, String glue, Renderer<T> r) {
134136

135137
/**
136138
* Joins a set together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the Object)
137-
* using the specified string for glue. If
138-
* lastGlue is null, it is the same as glue, but otherwise it is used to glue just the last two items together,
139-
* which is useful for sets that are being read by a human, to have a proper conjunction at the end.
139+
* using the specified string for glue. If lastGlue is null, it is the same as glue, but otherwise it is used to
140+
* glue just the last two items together, which is useful for sets that are being read by a human, to have a proper
141+
* conjunction at the end.
142+
*
140143
* @param <T> The set type
141144
* @param set The set to concatenate
142145
* @param glue The glue to use
@@ -149,9 +152,10 @@ public static <T> String Join(Set<T> set, String glue, String lastGlue) {
149152

150153
/**
151154
* Joins a set together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the Object)
152-
* using the specified string for glue.
153-
* If lastGlue is null, it is the same as glue, but otherwise it is used to glue just the last two items together,
154-
* which is useful for sets that are being read by a human, to have a proper conjunction at the end.
155+
* using the specified string for glue. If lastGlue is null, it is the same as glue, but otherwise it is used to
156+
* glue just the last two items together, which is useful for sets that are being read by a human, to have a proper
157+
* conjunction at the end.
158+
*
155159
* @param <T> The set type
156160
* @param set The set to concatenate
157161
* @param glue The glue to use
@@ -166,9 +170,10 @@ public static <T> String Join(Set<T> set, String glue, String lastGlue, String g
166170

167171
/**
168172
* Joins a set together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the Object)
169-
* using the specified string for glue.
170-
* If lastGlue is null, it is the same as glue, but otherwise it is used to glue just the last two items together,
171-
* which is useful for sets that are being read by a human, to have a proper conjunction at the end.
173+
* using the specified string for glue. If lastGlue is null, it is the same as glue, but otherwise it is used to
174+
* glue just the last two items together, which is useful for sets that are being read by a human, to have a proper
175+
* conjunction at the end.
176+
*
172177
* @param <T> The set type
173178
* @param set The set to concatenate
174179
* @param glue The glue to use
@@ -184,9 +189,10 @@ public static <T> String Join(Set<T> set, String glue, String lastGlue, String g
184189

185190
/**
186191
* Joins a set together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the Object)
187-
* using the specified string for glue.
188-
* If lastGlue is null, it is the same as glue, but otherwise it is used to glue just the last two items together,
189-
* which is useful for sets that are being read by a human, to have a proper conjunction at the end.
192+
* using the specified string for glue. If lastGlue is null, it is the same as glue, but otherwise it is used to
193+
* glue just the last two items together, which is useful for sets that are being read by a human, to have a proper
194+
* conjunction at the end.
195+
*
190196
* @param <T>
191197
* @param set The set to concatenate
192198
* @param glue The glue to use
@@ -221,8 +227,9 @@ public boolean isEmpty() {
221227
}
222228

223229
/**
224-
* Joins an array together (using StringBuilder's {@link StringBuilder#append(Object)} method
225-
* to "toString" the Object) using the specified string for glue.
230+
* Joins an array together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the
231+
* Object) using the specified string for glue.
232+
*
226233
* @param <T> The array type
227234
* @param list The array to concatenate
228235
* @param glue The glue to use
@@ -233,10 +240,11 @@ public static <T> String Join(T[] list, String glue) {
233240
}
234241

235242
/**
236-
* Joins an array together (using StringBuilder's {@link StringBuilder#append(Object)} method
237-
* to "toString" the Object) using the specified string for glue.
238-
* If lastGlue is null, it is the same as glue, but otherwise it is used to glue just the last two items together,
239-
* which is useful for lists that are being read by a human, to have a proper conjunction at the end.
243+
* Joins an array together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the
244+
* Object) using the specified string for glue. If lastGlue is null, it is the same as glue, but otherwise it is
245+
* used to glue just the last two items together, which is useful for lists that are being read by a human, to have
246+
* a proper conjunction at the end.
247+
*
240248
* @param <T> The array type
241249
* @param list The array to concatenate
242250
* @param glue The glue to use
@@ -248,10 +256,11 @@ public static <T> String Join(T[] list, String glue, String lastGlue) {
248256
}
249257

250258
/**
251-
* Joins an array together (using StringBuilder's {@link StringBuilder#append(Object)} method
252-
* to "toString" the Object) using the specified string for glue.
253-
* If lastGlue is null, it is the same as glue, but otherwise it is used to glue just the last two items together,
254-
* which is useful for lists that are being read by a human, to have a proper conjunction at the end.
259+
* Joins an array together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the
260+
* Object) using the specified string for glue. If lastGlue is null, it is the same as glue, but otherwise it is
261+
* used to glue just the last two items together, which is useful for lists that are being read by a human, to have
262+
* a proper conjunction at the end.
263+
*
255264
* @param <T> The array type
256265
* @param list The array to concatenate
257266
* @param glue The glue to use
@@ -265,10 +274,11 @@ public static <T> String Join(T[] list, String glue, String lastGlue, String glu
265274
}
266275

267276
/**
268-
* Joins an array together (using StringBuilder's {@link StringBuilder#append(Object)} method
269-
* to "toString" the Object) using the specified string for glue.
270-
* If lastGlue is null, it is the same as glue, but otherwise it is used to glue just the last two items together,
271-
* which is useful for lists that are being read by a human, to have a proper conjunction at the end.
277+
* Joins an array together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the
278+
* Object) using the specified string for glue. If lastGlue is null, it is the same as glue, but otherwise it is
279+
* used to glue just the last two items together, which is useful for lists that are being read by a human, to have
280+
* a proper conjunction at the end.
281+
*
272282
* @param <T> The array type
273283
* @param list The array to concatenate
274284
* @param glue The glue to use
@@ -382,10 +392,11 @@ public static String Join(final List list, String glue, String lastGlue, String
382392
}
383393

384394
/**
385-
* Joins a list together (using StringBuilder's {@link StringBuilder#append(Object)} method
386-
* to "toString" the Object) using the specified string for glue.
387-
* If lastGlue is null, it is the same as glue, but otherwise it is used to glue just the last two items together,
388-
* which is useful for lists that are being read by a human, to have a proper conjunction at the end.
395+
* Joins a list together (using StringBuilder's {@link StringBuilder#append(Object)} method to "toString" the
396+
* Object) using the specified string for glue. If lastGlue is null, it is the same as glue, but otherwise it is
397+
* used to glue just the last two items together, which is useful for lists that are being read by a human, to have
398+
* a proper conjunction at the end.
399+
*
389400
* @param <T> The list type
390401
* @param list The list to concatenate
391402
* @param glue The glue to use

src/main/java/com/laytonsmith/core/Procedure.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Procedure(String name, CClassType returnType, List<IVariable> varList, Li
7373
this.procComment = procComment;
7474
for(int i = 0; i < varList.size(); i++) {
7575
IVariable var = varList.get(i);
76-
if(isVarArg.get(i) && i != varList.size() - 1) {
76+
if(var.getDefinedType().isVariadicType() && i != varList.size() - 1) {
7777
throw new CREFormatException("Varargs can only be added to the last argument.", t);
7878
}
7979
try {
@@ -82,7 +82,7 @@ public Procedure(String name, CClassType returnType, List<IVariable> varList, Li
8282
this.varList.put(var.getVariableName(), var);
8383
}
8484
this.varIndex.add(var);
85-
if(isVarArg.get(i) && var.ival() != CNull.UNDEFINED) {
85+
if(var.getDefinedType().isVariadicType() && var.ival() != CNull.UNDEFINED) {
8686
throw new CREFormatException("Varargs may not have default values", t);
8787
}
8888
this.originals.put(var.getVariableName(), var.ival());
@@ -225,10 +225,10 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
225225
arguments.push(c, t);
226226
if(this.varIndex.size() > varInd
227227
|| (!this.varIndex.isEmpty()
228-
&& this.isVarArg.get(this.varIndex.size() - 1))) {
228+
&& this.varIndex.get(this.varIndex.size() - 1).getDefinedType().isVariadicType())) {
229229
IVariable var;
230230
if(varInd < this.varIndex.size() - 1
231-
|| !this.isVarArg.get(this.varIndex.size() - 1)) {
231+
|| !this.varIndex.get(this.varIndex.size() - 1).getDefinedType().isVariadicType()) {
232232
var = this.varIndex.get(varInd);
233233
} else {
234234
var = this.varIndex.get(this.varIndex.size() - 1);
@@ -254,7 +254,7 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
254254

255255
// Type check vararg parameter.
256256
if(var.getDefinedType().isVariadicType()) {
257-
if(InstanceofUtil.isInstanceof(c.typeof(env), var.getDefinedType().getNakedType(t, env), env)) {
257+
if(InstanceofUtil.isInstanceof(c.typeof(env), var.getDefinedType().getVarargsBaseType(), env)) {
258258
vararg.push(c, t, env);
259259
continue;
260260
} else {

src/main/java/com/laytonsmith/core/compiler/FileOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public static enum SuppressWarning implements Documentation {
369369
UnexpectedStatement("In strict mode, unexpected statements are an error, but in non-strict mode, they are"
370370
+ " a warning.", MSVersion.V3_3_5, SeverityLevel.HIGH),
371371
GenericTypeOverrides("When using generics, defining a typename which matches an in-scope actual object type"
372-
+ " can lead to confusion, since referneces to the original type will no longer reference the"
372+
+ " can lead to confusion, since references to the original type will no longer reference the"
373373
+ " actual type, but rather the typename. Thus, this should be avoided.", MSVersion.V3_3_6,
374374
SeverityLevel.HIGH),
375375
PossibleUnexpectedExecution("If the parenthesis following a token is on a different line as the previous"

src/main/java/com/laytonsmith/core/constructs/CClosure.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public CClosure(ParseTree node, Environment env, LeftHandSideType returnType, St
7777
this.isVarArgs = isVarArgs;
7878
if(types.length > 0) {
7979
for(int i = 0; i < types.length - 1; i++) {
80-
if(isVarArgs[i]) {
80+
if(types[i].isVariadicType()) {
8181
throw new CREFormatException("Varargs can only be added to the last argument.", t);
8282
}
8383
}
@@ -253,10 +253,10 @@ protected void execute(Mixed... values) throws ConfigRuntimeException, ProgramFl
253253
boolean isVarArg = false;
254254
if(this.names.length > i
255255
|| (this.names.length != 0
256-
&& this.isVarArgs[this.names.length - 1])) {
256+
&& this.types[this.names.length - 1].isVariadicType())) {
257257
String name;
258258
if(i < this.names.length - 1
259-
|| !this.isVarArgs[this.types.length - 1]) {
259+
|| !this.types[this.types.length - 1].isVariadicType()) {
260260
name = names[i];
261261
} else {
262262
name = this.names[this.names.length - 1];

src/main/java/com/laytonsmith/core/constructs/LeftHandSideType.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
public final class LeftHandSideType extends Construct implements SourceType {
5555

5656
/**
57-
* Merges the inputs to create a single type union class.For instance, if {@code int | string} and
57+
* Merges the inputs to create a single type union class. For instance, if {@code int | string} and
5858
* {@code array | string} are passed in, the resulting type would be {@code int | string | array}. Note that for
5959
* subtypes with generic parameters, these are not merged unless they are completely equal.
6060
*
@@ -764,4 +764,24 @@ public boolean isVariadicType() {
764764
return isVariadicType;
765765
}
766766

767+
/**
768+
* Returns the base type of this variadic type, with generics preserved but the variadic flag removed.
769+
* For instance, {@code myclass<a>...} returns {@code myclass<a>}.
770+
* @return The base {@link LeftHandSideType} of this type.
771+
* @throws IllegalStateException If this is not a variadic type.
772+
*/
773+
public LeftHandSideType getVarargsBaseType() throws IllegalStateException {
774+
if(!this.isVariadicType) {
775+
throw new IllegalStateException("LeftHandSideType is not a vararg type.");
776+
}
777+
String newVal = val();
778+
if(newVal.endsWith("...")) {
779+
newVal = newVal.substring(0, newVal.length() - 3);
780+
}
781+
LeftHandSideType newType = new LeftHandSideType(newVal, getTarget(), null, types, isTypenameList,
782+
genericTypeName, null);
783+
newType.isVariadicType = false;
784+
return newType;
785+
}
786+
767787
}

src/main/java/com/laytonsmith/core/constructs/SourceType.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@
88
*/
99
public interface SourceType extends Mixed {
1010

11+
/**
12+
* Returns true if this type was defined as a variadic type (i.e. `string ...`).
13+
*
14+
* @return
15+
*/
1116
boolean isVariadicType();
1217

18+
/**
19+
* For a non-variadic type, this returns a new instance as a variadic type (i.e. if this represents `string` then
20+
* `string ...` is returned).
21+
*
22+
* @param env
23+
* @return
24+
*/
1325
SourceType asVariadicType(Environment env);
1426
}

src/test/java/com/laytonsmith/core/constructs/LeftHandSideTypeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.laytonsmith.core.Static;
44
import com.laytonsmith.core.environments.Environment;
55
import com.laytonsmith.core.natives.interfaces.Booleanish;
6+
import com.laytonsmith.testing.AbstractIntegrationTest;
67
import com.laytonsmith.testing.StaticTest;
78
import java.util.Arrays;
89
import java.util.List;
@@ -13,7 +14,7 @@
1314
/**
1415
*
1516
*/
16-
public class LeftHandSideTypeTest {
17+
public class LeftHandSideTypeTest extends AbstractIntegrationTest {
1718

1819
Environment env;
1920

0 commit comments

Comments
 (0)