diff --git a/pom.xml b/pom.xml index 193873153d..5674b4adba 100644 --- a/pom.xml +++ b/pom.xml @@ -227,7 +227,7 @@ com.mysql mysql-connector-j - 8.3.0 + 9.4.0 jar compile @@ -394,7 +394,7 @@ com.squareup.okio okio-jvm - 3.10.0 + 3.16.0 com.google.code.gson diff --git a/src/main/java/com/laytonsmith/core/ArgumentValidation.java b/src/main/java/com/laytonsmith/core/ArgumentValidation.java index f03bd479cb..7ff0a4c889 100644 --- a/src/main/java/com/laytonsmith/core/ArgumentValidation.java +++ b/src/main/java/com/laytonsmith/core/ArgumentValidation.java @@ -4,6 +4,7 @@ import com.laytonsmith.PureUtilities.Common.StringUtils; import com.laytonsmith.annotations.MEnum; import com.laytonsmith.annotations.typeof; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.CRE.CRECastException; import com.laytonsmith.core.exceptions.CRE.CREFormatException; import com.laytonsmith.core.exceptions.CRE.CRERangeException; @@ -19,6 +20,7 @@ import com.laytonsmith.core.constructs.CNumber; import com.laytonsmith.core.constructs.CString; import com.laytonsmith.core.constructs.CVoid; +import com.laytonsmith.core.constructs.InstanceofUtil; import com.laytonsmith.core.constructs.Target; import com.laytonsmith.core.exceptions.ConfigRuntimeException; import com.laytonsmith.core.natives.interfaces.Booleanish; @@ -39,6 +41,14 @@ private ArgumentValidation() { // } + /** + * @deprecated Use {@link #getItemFromArray(CArray, String, Target, Mixed, Environment)} instead. + */ + @Deprecated + public static Mixed getItemFromArray(CArray object, String key, Target t, Mixed defaultItem) throws ConfigRuntimeException { + return getItemFromArray(object, key, t, defaultItem, null); + } + /** * Returns an item from an array, as a generic construct. This provides a standard way of returning an item from an * array. If defaultItem is null, then it is required that the item be present in the object. If it is not, a @@ -49,11 +59,12 @@ private ArgumentValidation() { * @param t The code target * @param defaultItem The default item to return if the specified key isn't present in the array. If this is a java * null, and the key isn't present, a standard error message is thrown. + * @param env The environment * @return The item in the array, or the defaultItem. * @throws ConfigRuntimeException A FormatException is thrown if it doesn't contain the appropriate value and the * defaultItem is null. */ - public static Mixed getItemFromArray(CArray object, String key, Target t, Mixed defaultItem) throws ConfigRuntimeException { + public static Mixed getItemFromArray(CArray object, String key, Target t, Mixed defaultItem, Environment env) throws ConfigRuntimeException { if(object.containsKey(key)) { return object.get(key, t); } else if(defaultItem == null) { @@ -63,14 +74,23 @@ public static Mixed getItemFromArray(CArray object, String key, Target t, Mixed } } + /** + * @deprecated Use {@link #getArray(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static CArray getArray(Mixed construct, Target t) { + return getArray(construct, t, null); + } + /** * Returns a CArray object from a given construct, throwing a common error message if not. * * @param construct * @param t + * @param env * @return */ - public static CArray getArray(Mixed construct, Target t) { + public static CArray getArray(Mixed construct, Target t, Environment env) { if(construct.isInstanceOf(CArray.TYPE)) { return ((CArray) construct); } else { @@ -106,6 +126,14 @@ public static T getObject(Mixed construct, Target t, Class } } + /** + * @deprecated Use {@link #getNumber(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static double getNumber(Mixed c, Target t) { + return getNumber(c, t, null); + } + /** * This function pulls a numerical equivalent from any given construct. It throws a ConfigRuntimeException if it * cannot be converted, for instance the string "s" cannot be cast to a number. The number returned will always be a @@ -113,9 +141,10 @@ public static T getObject(Mixed construct, Target t, Class * * @param c * @param t + * @param env * @return */ - public static double getNumber(Mixed c, Target t) { + public static double getNumber(Mixed c, Target t, Environment env) { // TODO: Formalize this in the same way that Booleanish is formalized. if(c instanceof CMutablePrimitive) { c = ((CMutablePrimitive) c).get(); @@ -124,9 +153,9 @@ public static double getNumber(Mixed c, Target t) { if(c == null || c instanceof CNull) { return 0.0; } - if(c instanceof CNumber) { + if(InstanceofUtil.isInstanceof(c, CNumber.class, env)) { d = ((CNumber) c).getNumber(); - } else if(c instanceof CString) { + } else if(InstanceofUtil.isInstanceof(c, CString.class, env)) { try { d = Double.parseDouble(c.val()); } catch (NumberFormatException e) { @@ -138,7 +167,7 @@ public static double getNumber(Mixed c, Target t) { } else { d = 0; } - } else if(c instanceof CDecimal) { + } else if(InstanceofUtil.isInstanceof(c, CDecimal.class, env)) { throw new CRECastException("Expecting a number, but received a decimal value instead. This cannot be" + " automatically cast, please use double(@decimal) to manually cast down to a double.", t); } else { @@ -168,14 +197,31 @@ public static double getNumber(Mixed c, Target t) { + ")[\\x00-\\x20]*" // trailing whitespace ); + /** + * @deprecated Use {@link #isNumber(Mixed, Environment)} instead. + */ + @Deprecated + public static boolean isNumber(Mixed c) { + return isNumber(c, null); + } + /** * Validates that a construct's value is a number or string that can be returned by GetNumber() * * @param c Mixed + * @param env * @return boolean */ - public static boolean isNumber(Mixed c) { - return c instanceof CNumber || VALID_DOUBLE.matcher(c.val()).matches(); + public static boolean isNumber(Mixed c, Environment env) { + return InstanceofUtil.isInstanceof(c, CNumber.class, env) || VALID_DOUBLE.matcher(c.val()).matches(); + } + + /** + * @deprecated Use {@link #getDouble(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static double getDouble(Mixed c, Target t) { + return getDouble(c, t, null); } /** @@ -183,19 +229,28 @@ public static boolean isNumber(Mixed c) { * * @param c * @param t + * @param env * @return */ - public static double getDouble(Mixed c, Target t) { + public static double getDouble(Mixed c, Target t, Environment env) { if(c instanceof CMutablePrimitive) { c = ((CMutablePrimitive) c).get(); } try { - return getNumber(c, t); + return getNumber(c, t, env); } catch (ConfigRuntimeException e) { throw new CRECastException("Expecting a double, but received " + c.val() + " instead", t); } } + /** + * @deprecated Use {@link #getDouble32(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static float getDouble32(Mixed c, Target t) { + return getDouble32(c, t, null); + } + /** * Returns a 32-bit float from the construct. Since the backing value is actually a double, if the number contained * in the construct is not within range after truncating, an exception is thrown (fail fast). When needing a float @@ -203,25 +258,35 @@ public static double getDouble(Mixed c, Target t) { * * @param c * @param t + * @param env * @return */ - public static float getDouble32(Mixed c, Target t) { - double l = getDouble(c, t); + public static float getDouble32(Mixed c, Target t, Environment env) { + double l = getDouble(c, t, env); if(Math.abs(l) > Float.MAX_VALUE) { throw new CRERangeException("Expecting a 32 bit float, but a larger value was found: " + l, t); } return (float) l; } + /** + * @deprecated Use {@link #getInt(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static long getInt(Mixed c, Target t) { + return getInt(c, t, null); + } + /** * Returns a long from any given construct. * * @param c * @param t + * @param env * @throws CRECastException If the value cannot be converted to a long * @return */ - public static long getInt(Mixed c, Target t) { + public static long getInt(Mixed c, Target t, Environment env) { if(c instanceof CMutablePrimitive) { c = ((CMutablePrimitive) c).get(); } @@ -247,6 +312,14 @@ public static long getInt(Mixed c, Target t) { return i; } + /** + * @deprecated Use {@link #getInt32(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static int getInt32(Mixed c, Target t) { + return getInt32(c, t, null); + } + /** * Returns a 32 bit int from the construct. Since the backing value is actually a long, if the number contained in * the construct is not the same after truncating, an exception is thrown (fail fast). When needing an int from a @@ -254,15 +327,16 @@ public static long getInt(Mixed c, Target t) { * * @param c * @param t + * @param env * @throws CRERangeException If the value would be truncated * @throws CRECastException If the value cannot be cast to an int * @return */ - public static int getInt32(Mixed c, Target t) { + public static int getInt32(Mixed c, Target t, Environment env) { if(c instanceof CMutablePrimitive) { c = ((CMutablePrimitive) c).get(); } - long l = getInt(c, t); + long l = getInt(c, t, env); int i = (int) l; if(i != l) { throw new CRERangeException("Expecting a 32 bit integer, but a larger value was found: " + l, t); @@ -270,6 +344,14 @@ public static int getInt32(Mixed c, Target t) { return i; } + /** + * @deprecated Use {@link #getInt16(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static short getInt16(Mixed c, Target t) { + return getInt16(c, t, null); + } + /** * Returns a 16 bit int from the construct (a short). Since the backing value is actually a long, if the number * contained in the construct is not the same after truncating, an exception is thrown (fail fast). When needing an @@ -277,15 +359,16 @@ public static int getInt32(Mixed c, Target t) { * * @param c * @param t + * @param env * @throws CRERangeException If the value would be truncated * @throws CRECastException If the value cannot be cast to an int * @return */ - public static short getInt16(Mixed c, Target t) { + public static short getInt16(Mixed c, Target t, Environment env) { if(c instanceof CMutablePrimitive) { c = ((CMutablePrimitive) c).get(); } - long l = getInt(c, t); + long l = getInt(c, t, env); short s = (short) l; if(s != l) { throw new CRERangeException("Expecting a 16 bit integer, but a larger value was found: " + l, t); @@ -293,6 +376,14 @@ public static short getInt16(Mixed c, Target t) { return s; } + /** + * @deprecated Use {@link #getInt8(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static byte getInt8(Mixed c, Target t) { + return getInt8(c, t, null); + } + /** * Returns an 8 bit int from the construct (a byte). Since the backing value is actually a long, if the number * contained in the construct is not the same after truncating, an exception is thrown (fail fast). When needing a @@ -300,15 +391,16 @@ public static short getInt16(Mixed c, Target t) { * * @param c * @param t + * @param env * @throws CRERangeException If the value would be truncated * @throws CRECastException If the value cannot be cast to an int * @return */ - public static byte getInt8(Mixed c, Target t) { + public static byte getInt8(Mixed c, Target t, Environment env) { if(c instanceof CMutablePrimitive) { c = ((CMutablePrimitive) c).get(); } - long l = getInt(c, t); + long l = getInt(c, t, env); byte b = (byte) l; if(b != l) { throw new CRERangeException("Expecting an 8 bit integer, but a larger value was found: " + l, t); @@ -316,6 +408,14 @@ public static byte getInt8(Mixed c, Target t) { return b; } + /** + * @deprecated Use {@link #getBooleanObject(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static boolean getBooleanObject(Mixed c, Target t) { + return getBooleanObject(c, t, null); + } + /** * Returns a the boolean value from the underlying CBoolean, or throws a CastException if the underlying type is * not a CBoolean. @@ -325,10 +425,19 @@ public static byte getInt8(Mixed c, Target t) { * to validate the type, use {@link #getObject(Mixed, Target, Class)} * @param c * @param t + * @param env * @return */ - public static boolean getBooleanObject(Mixed c, Target t) { - return getBooleanish(c, t); + public static boolean getBooleanObject(Mixed c, Target t, Environment env) { + return getBooleanish(c, t, env); + } + + /** + * @deprecated Use {@link #getBoolean(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static boolean getBoolean(Mixed c, Target t) { + return getBoolean(c, t, null); } /** @@ -338,14 +447,23 @@ public static boolean getBooleanObject(Mixed c, Target t) { * {@link #getBooleanish} or {@link #getBooleanObject}. * @param c * @param t + * @param env * @return * @deprecated Use {@link #getBooleanish} for current behavior, or {@link #getBooleanObject} for strict behavior. * Generally speaking, if it seems reasonable for the user to send a non-boolean data type in this parameter, then * getBooleanish should be used. If it indicates a probable error, getBooleanObject should be used. */ @Deprecated - public static boolean getBoolean(Mixed c, Target t) { - return getBooleanish(c, t); + public static boolean getBoolean(Mixed c, Target t, Environment env) { + return getBooleanish(c, t, env); + } + + /** + * @deprecated Use {@link #getBooleanish(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static boolean getBooleanish(Mixed c, Target t) { + return getBooleanish(c, t, null); } /** @@ -355,9 +473,10 @@ public static boolean getBoolean(Mixed c, Target t) { * * @param c The value to convert * @param t The code target + * @param env * @return */ - public static boolean getBooleanish(Mixed c, Target t) { + public static boolean getBooleanish(Mixed c, Target t, Environment env) { if(c instanceof CVoid) { // Eventually, we may want to turn this into a warning, maybe even a compiler error, but for now, // to keep backwards compatibility, we want to keep this as is. @@ -369,20 +488,29 @@ public static boolean getBooleanish(Mixed c, Target t) { if(c == null) { return false; } - if(c instanceof Booleanish) { + if(InstanceofUtil.isInstanceof(c, Booleanish.class, env)) { return ((Booleanish) c).getBooleanValue(t); } throw new CRECastException("Could not convert value of type " + c.typeof() + " to a " + Booleanish.TYPE, t); } + /** + * @deprecated Use {@link #getByteArray(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static CByteArray getByteArray(Mixed c, Target t) { + return getByteArray(c, t, null); + } + /** * Returns a CByteArray object from the given construct. * * @param c * @param t + * @param env * @return */ - public static CByteArray getByteArray(Mixed c, Target t) { + public static CByteArray getByteArray(Mixed c, Target t, Environment env) { if(c instanceof CByteArray) { return (CByteArray) c; } else if(c instanceof CNull) { @@ -412,58 +540,94 @@ public static String getString(Mixed c, Target t) { return c.val(); } + /** + * @deprecated Use {@link #getStringObject(Mixed, Target, Environment)} instead. + */ + @Deprecated + public static String getStringObject(Mixed c, Target t) { + return getStringObject(c, t, null); + } + /** * Returns a String object from the given construct. Note that unlike {@link #getString}, this strictly expects a * string object, and will throw a CRECastException if it is not a string. * * @param c * @param t + * @param env * @return */ - public static String getStringObject(Mixed c, Target t) { + public static String getStringObject(Mixed c, Target t, Environment env) { if(!c.isInstanceOf(CString.class)) { throw new CRECastException("Expected a string, but found " + c.typeof() + " instead.", t); } return c.val(); } + /** + * @deprecated Use {@link #anyDoubles(Environment, Mixed...)} instead. + */ + @Deprecated + public static boolean anyDoubles(Mixed... c) { + return anyDoubles(null, c); + } + /** * Returns true if any of the constructs are a CDouble, false otherwise. * + * @param env * @param c * @return */ - public static boolean anyDoubles(Mixed... c) { + public static boolean anyDoubles(Environment env, Mixed... c) { for(Mixed c1 : c) { - if(c1 instanceof CDouble || c1 instanceof CString && c1.val().indexOf(".", 1) > -1) { + if(InstanceofUtil.isInstanceof(c1, CDouble.class, env) || InstanceofUtil.isInstanceof(c1, CString.class, env) && c1.val().indexOf(".", 1) > -1) { return true; } } return false; } + /** + * @deprecated Use {@link #anyStrings(Environment, Mixed...)} instead. + */ + @Deprecated + public static boolean anyStrings(Mixed... c) { + return anyStrings(null, c); + } + /** * Return true if any of the constructs are CStrings, false otherwise. * + * @param env * @param c * @return */ - public static boolean anyStrings(Mixed... c) { + public static boolean anyStrings(Environment env, Mixed... c) { for(Mixed c1 : c) { - if(c1 instanceof CString) { + if(InstanceofUtil.isInstanceof(c1, CString.class, env)) { return true; } } return false; } + /** + * @deprecated Use {@link #anyNulls(Environment, Mixed...)} instead. + */ + @Deprecated + public static boolean anyNulls(Mixed... c) { + return anyNulls(null, c); + } + /** * Returns true if any of the constructs are null * + * @param env * @param c * @return */ - public static boolean anyNulls(Mixed... c) { + public static boolean anyNulls(Environment env, Mixed... c) { for(Mixed c1 : c) { if(c1 instanceof CNull) { return true; @@ -472,13 +636,22 @@ public static boolean anyNulls(Mixed... c) { return false; } + /** + * @deprecated Use {@link #anyBooleans(Environment, Mixed...)} instead. + */ + @Deprecated + public static boolean anyBooleans(Mixed... c) { + return anyBooleans(null, c); + } + /** * Returns true if any of the constructs are CBooleans, false otherwise. * + * @param env * @param c * @return */ - public static boolean anyBooleans(Mixed... c) { + public static boolean anyBooleans(Environment env, Mixed... c) { for(Mixed c1 : c) { if(c1 instanceof CBoolean) { return true; @@ -515,6 +688,14 @@ public static > T getEnum(Mixed c, Class enumClass, Target } } + /** + * @deprecated Use {@link #getEnumSet(Mixed, Class, Target, Environment)} instead. + */ + @Deprecated + public static > Set getEnumSet(Mixed c, Class enumClass, Target t) { + return getEnumSet(c, enumClass, t, null); + } + /** * Returns a set of the given enum value. The input value may be either a single value or an array. If * it is a single value, the set will be of size 1. Null is also supported, and will return a set of size @@ -523,9 +704,10 @@ public static > T getEnum(Mixed c, Class enumClass, Target * @param c * @param enumClass * @param t + * @param env * @return */ - public static > Set getEnumSet(Mixed c, Class enumClass, Target t) { + public static > Set getEnumSet(Mixed c, Class enumClass, Target t, Environment env) { if(c instanceof CNull) { return EnumSet.noneOf(enumClass); } diff --git a/src/main/java/com/laytonsmith/core/constructs/CArray.java b/src/main/java/com/laytonsmith/core/constructs/CArray.java index 3e603f41ef..df90b50747 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CArray.java +++ b/src/main/java/com/laytonsmith/core/constructs/CArray.java @@ -97,7 +97,13 @@ public CArray(Target t, int initialCapacity, Collection items) { this(t, initialCapacity, getArray(items)); } + /** @deprecated Use {@code CArray(Target, int, Environment, Mixed[]} instead. */ + @Deprecated public CArray(Target t, int initialCapacity, Mixed... items) { + this(t, initialCapacity, null, items); + } + + public CArray(Target t, int initialCapacity, Environment env, Mixed... items) { super("{}", ConstructType.ARRAY, t); if(initialCapacity == -1) { associativeMode = true; @@ -117,8 +123,8 @@ public CArray(Target t, int initialCapacity, Mixed... items) { for(Mixed item : items) { if(item instanceof CEntry) { Mixed value = ((CEntry) item).construct; - associativeArray.put(normalizeConstruct(((CEntry) item).ckey), value); - if(value.isInstanceOf(CArray.TYPE)) { + associativeArray.put(normalizeConstruct(((CEntry) item).ckey, env), value); + if(value.isInstanceOf(CArray.TYPE, null, env)) { ((CArray) value).parent = this; } } else { @@ -134,7 +140,7 @@ public CArray(Target t, int initialCapacity, Mixed... items) { max = -1; //Special case, there are no integer indexes in here yet. } associativeArray.put(Integer.toString(max + 1), item); - if(item.isInstanceOf(CArray.TYPE)) { + if(item.isInstanceOf(CArray.TYPE, null, env)) { ((CArray) item).parent = this; } } @@ -144,7 +150,7 @@ public CArray(Target t, int initialCapacity, Mixed... items) { if(items != null) { for(Mixed item : items) { array.add(item); - if(item.isInstanceOf(CArray.TYPE)) { + if(item.isInstanceOf(CArray.TYPE, null, env)) { ((CArray) item).parent = this; } } @@ -182,12 +188,19 @@ private static Mixed[] getArray(Collection items) { return c; } + /** @deprecated Use {@link #asList(Environment)} instead. */ + @Deprecated + public List asList() { + return asList(null); + } + /** * Returns a List based on the array. This is only applicable if this is a normal array. * + * @param env * @return */ - public List asList() { + public List asList(Environment env) { if(inAssociativeMode()) { throw new RuntimeException("asList can only be called on a normal array"); } else { @@ -216,13 +229,33 @@ public boolean inAssociativeMode() { * * @param t * @return + * @deprecated Use {@link #GetAssociativeArray(Target, GenericParameters, Environment)} instead. */ + @Deprecated public static CArray GetAssociativeArray(Target t) { - return new CArray(t, -1); + return GetAssociativeArray(t, null, null); } + /** @deprecated Use {@link #GetAssociativeArray(Target, GenericParameters, Environment, Mixed[])} instead. */ + @Deprecated public static CArray GetAssociativeArray(Target t, Mixed[] args) { - return new CArray(t, -1, args); + return GetAssociativeArray(t, null, null, args); + } + + /** + * Returns a new empty CArray that is in associative mode. + * + * @param t + * @param genericParameters + * @param env + * @return + */ + public static CArray GetAssociativeArray(Target t, GenericParameters genericParameters, Environment env) { + return new CArray(t, -1, genericParameters, env); + } + + public static CArray GetAssociativeArray(Target t, GenericParameters genericParameters, Environment env, Mixed[] args) { + return new CArray(t, -1, env, args); } /** @@ -261,18 +294,31 @@ public void reverse(Target t) { } } + /** @deprecated Use {@link #push(Mixed, Target, Environment)} instead. */ + @Deprecated + public final void push(Mixed c, Target t) { + push(c, t, null); + } + /** * Pushes a new Construct onto the end of the array. * * @param c * @param t + * @param env */ - public final void push(Mixed c, Target t) { - push(c, null, t); + public final void push(Mixed c, Target t, Environment env) { + push(c, null, t, env); } public final void push(String s) { - push(new CString(s, Target.UNKNOWN), Target.UNKNOWN); + push(new CString(s, Target.UNKNOWN), Target.UNKNOWN, null); + } + + /** @deprecated Use {@link #push(Mixed, Integer, Target, Environment)} instead. */ + @Deprecated + public void push(Mixed c, Integer index, Target t) throws IllegalArgumentException, IndexOutOfBoundsException { + push(c, index, t, null); } /** @@ -282,10 +328,13 @@ public final void push(String s) { * should use {@link #set} anyways for an associative array. * * @param c The Construct to add to the array + * @param index The index to push on. May be null. + * @param t The code target + * @param env The environment * @throws IllegalArgumentException If index is not null, and this is an associative array. * @throws IndexOutOfBoundsException If the index is not null, and the index specified is out of range. */ - public void push(Mixed c, Integer index, Target t) throws IllegalArgumentException, IndexOutOfBoundsException { + public void push(Mixed c, Integer index, Target t, Environment env) throws IllegalArgumentException, IndexOutOfBoundsException { if(!associativeMode) { if(index != null) { array.add(index, c); @@ -311,20 +360,28 @@ public void push(Mixed c, Integer index, Target t) throws IllegalArgumentExcepti associativeArray.put(Integer.toString(max + 1), c); } } - if(c.isInstanceOf(CArray.TYPE)) { + if(c.isInstanceOf(CArray.TYPE, null, env)) { ((CArray) c).parent = this; } setDirty(); } + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated + @Override + public Set keySet() { + return keySet(null); + } + /** * Returns the key set for this array. If it's an associative array, it simply returns the key set of the map, * otherwise it generates a set of CInts from 0 to size-1, and returns that. * + * @param env * @return */ @Override - public Set keySet() { + public Set keySet(Environment env) { Set set; if(!associativeMode) { set = new LinkedHashSet<>(array.size()); @@ -367,25 +424,34 @@ private void setAssociative() { array = null; // null out the original array container so it can be GC'd } + /** @deprecated Use {@link #set(Mixed, Mixed, Target, Environment)} instead. */ + @Deprecated + public void set(Mixed index, Mixed c, Target t) { + set(index, c, t, null); + } + /** + * Sets the value at the given index. * - * @param index - * @param c + * @param index The index. Should be either an int or a string. + * @param c The element to set. + * @param t The code target. + * @param env The environment. */ @Override - public void set(Mixed index, Mixed c, Target t) { + public void set(Mixed index, Mixed c, Target t, Environment env) { if(!associativeMode) { if(index instanceof CNull) { // Invalid normal array index setAssociative(); } else { try { - int indx = ArgumentValidation.getInt32(index, t); + int indx = ArgumentValidation.getInt32(index, t, env); if(indx > nextIndex || indx < 0) { // Out of range setAssociative(); } else if(indx == nextIndex) { - this.push(c, t); + this.push(c, t, env); } else { array.set(indx, c); } @@ -396,49 +462,80 @@ public void set(Mixed index, Mixed c, Target t) { } } if(associativeMode) { - associativeArray.put(normalizeConstruct(index), c); + associativeArray.put(normalizeConstruct(index, env), c); } - if(c.isInstanceOf(CArray.TYPE)) { + if(c.isInstanceOf(CArray.TYPE, null, env)) { ((CArray) c).parent = this; } setDirty(); } + /** @deprecated Use {@link #set(int, Mixed, Target, Environment)} instead. */ + @Deprecated public final void set(int index, Mixed c, Target t) { - this.set(new CInt(index, t), c, t); + this.set(index, c, t, null); + } + + public final void set(int index, Mixed c, Target t, Environment env) { + this.set(new CInt(index, t), c, t, env); } /* Shortcuts */ + /** @deprecated Use {@link #set(String, Mixed, Target, Environment)} instead. */ + @Deprecated public final void set(String index, Mixed c, Target t) { - set(new CString(index, t), c, t); + set(index, c, t, null); } + public final void set(String index, Mixed c, Target t, Environment env) { + set(new CString(index, t), c, t, env); + } + + /** @deprecated Use {@link #set(String, String, Target, Environment)} instead. */ + @Deprecated public final void set(String index, String value, Target t) { - set(index, new CString(value, t), t); + set(index, value, t, null); + } + + public final void set(String index, String value, Target t, Environment env) { + set(index, new CString(value, t), t, env); } + /** @deprecated Use {@link #set(String, String, Environment)} instead. */ + @Deprecated public final void set(String index, String value) { - set(index, value, Target.UNKNOWN); + set(index, value, (Environment) null); + } + + public final void set(String index, String value, Environment env) { + set(index, value, Target.UNKNOWN, env); } public final void set(String index, double value) { - set(index, new CDouble(value, Target.UNKNOWN), Target.UNKNOWN); + set(index, new CDouble(value, Target.UNKNOWN), Target.UNKNOWN, null); } public final void set(String index, long value) { - set(index, new CInt(value, Target.UNKNOWN), Target.UNKNOWN); + set(index, new CInt(value, Target.UNKNOWN), Target.UNKNOWN, null); } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) { + return get(index, t, null); + } + + @Override + public Mixed get(Mixed index, Target t, Environment env) { if(!associativeMode) { try { - return array.get(ArgumentValidation.getInt32(index, t)); + return array.get(ArgumentValidation.getInt32(index, t, env)); } catch (IndexOutOfBoundsException e) { throw new CREIndexOverflowException("The element at index \"" + index.val() + "\" does not exist", t, e); } } else { - Mixed val = associativeArray.get(normalizeConstruct(index)); + Mixed val = associativeArray.get(normalizeConstruct(index, env)); if(val != null) { if(val instanceof CEntry) { return ((CEntry) val).construct(); @@ -453,18 +550,38 @@ public Mixed get(Mixed index, Target t) { } } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated public final Mixed get(long index, Target t) { - return this.get(new CInt(index, t), t); + return this.get(new CInt(index, t), t, null); } + public final Mixed get(long index, Target t, Environment env) { + return this.get(new CInt(index, t), t, env); + } + + /** @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated @Override public final Mixed get(int index, Target t) { - return this.get(new CInt(index, t), t); + return this.get(new CInt(index, t), t, null); } + @Override + public final Mixed get(int index, Target t, Environment env) { + return this.get(new CInt(index, t), t, env); + } + + /** @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated @Override public final Mixed get(String index, Target t) { - return this.get(new CString(index, t), t); + return this.get(new CString(index, t), t, null); + } + + @Override + public final Mixed get(String index, Target t, Environment env) { + return this.get(new CString(index, t), t, env); } public boolean containsKey(String c) { @@ -499,13 +616,20 @@ public final boolean contains(int i) { return contains(new CString(Integer.toString(i), Target.UNKNOWN)); } + /** @deprecated Use {@link #indexesOf(Mixed, Environment)} instead. */ + @Deprecated + public CArray indexesOf(Mixed value) { + return indexesOf(value, null); + } + /** * Returns an array of the keys of all the values that are equal to the value specified * - * @param value - * @return + * @param value The value to find the index(es) of + * @param env The environment + * @return An array of keys where the corresponding value is equal to the value specified. */ - public CArray indexesOf(Mixed value) { + public CArray indexesOf(Mixed value, Environment env) { CArray ret = new CArray(Target.UNKNOWN); if(associativeMode) { for(String key : associativeArray.keySet()) { @@ -526,7 +650,8 @@ public CArray indexesOf(Mixed value) { @Override public String val() { if(valueDirty) { - getString(new Stack<>(), this.getTarget()); + // TODO: Hmmmmmm. Might need env here. + getString(new Stack<>(), this.getTarget(), null); } return mutVal; } @@ -544,23 +669,23 @@ public String toString() { * @param t * @return */ - protected String getString(Stack arrays, Target t) { + protected String getString(Stack arrays, Target t, Environment env) { if(!valueDirty) { return mutVal; } StringBuilder b = new StringBuilder(); b.append("{"); if(!inAssociativeMode()) { - for(int i = 0; i < this.size(); i++) { - Mixed value = this.get(i, t); + for(int i = 0; i < this.size(env); i++) { + Mixed value = this.get(i, t, env); String v; - if(value.isInstanceOf(CArray.TYPE)) { + if(value.isInstanceOf(CArray.TYPE, null, env)) { if(arrays.contains(value)) { //Check for recursion v = "*recursion*"; } else { arrays.add(((CArray) value)); - v = ((CArray) value).getString(arrays, t); + v = ((CArray) value).getString(arrays, t, env); arrays.pop(); } } else { @@ -579,16 +704,16 @@ protected String getString(Stack arrays, Target t) { } first = false; String v; - if(this.get(key, t) == null) { + if(this.get(key, t, env) == null) { v = "null"; } else { - Mixed value = this.get(key, t); - if(value.isInstanceOf(CArray.TYPE)) { + Mixed value = this.get(key, t, env); + if(value.isInstanceOf(CArray.TYPE, null, env)) { if(arrays.contains(value)) { v = "*recursion*"; } else { arrays.add(((CArray) value)); - v = ((CArray) value).getString(arrays, t); + v = ((CArray) value).getString(arrays, t, env); } } else { v = value.val(); @@ -603,8 +728,15 @@ protected String getString(Stack arrays, Target t) { return mutVal; } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { if(associativeMode) { return associativeArray.size(); } else { @@ -632,11 +764,23 @@ public CArray clone() { return clone; } + /** @deprecated Use {@link #deepClone(Target, Environment)} instead. */ + @Deprecated public CArray deepClone(Target t) { - return deepClone(this, t, new ArrayList<>()); + return deepClone(t, null); + } + + public CArray deepClone(Target t, Environment env) { + return deepClone(this, t, new ArrayList<>(), env); } + /** @deprecated Use {@link #deepClone(CArray, Target, ArrayList, Environment)} instead. */ + @Deprecated protected CArray deepClone(CArray array, Target t, ArrayList cloneRefs) { + return deepClone(array, t, cloneRefs, null); + } + + protected CArray deepClone(CArray array, Target t, ArrayList cloneRefs, Environment env) { // Return the clone reference if this array has been cloned before (both clones will have the same reference). for(CArray[] refCouple : cloneRefs) { @@ -646,69 +790,90 @@ protected CArray deepClone(CArray array, Target t, ArrayList cloneRefs } // Create the clone to put array in and add it to the cloneRefs list. - CArray clone = new CArray(t, (int) array.size()); + CArray clone = new CArray(t, (int) array.size(env)); clone.associativeMode = array.associativeMode; cloneRefs.add(new CArray[]{array, clone}); // Iterate over the array, recursively calling this method to perform a deep clone. - for(Mixed key : array.keySet()) { - Mixed value = array.get(key, t); - if(value.isInstanceOf(CArray.TYPE)) { - value = deepClone((CArray) value, t, cloneRefs); + for(Mixed key : array.keySet(env)) { + Mixed value = array.get(key, t, env); + if(value.isInstanceOf(CArray.TYPE, null, env)) { + value = deepClone((CArray) value, t, cloneRefs, env); } - clone.set(key, value, t); + clone.set(key, value, t, env); } return clone; } - private String normalizeConstruct(Mixed c) { - if(c.isInstanceOf(CArray.TYPE)) { + private String normalizeConstruct(Mixed c, Environment env) { + if(c.isInstanceOf(CArray.TYPE, null, env)) { throw new CRECastException("Arrays cannot be used as the key in an associative array", c.getTarget()); - } else if(c.isInstanceOf(CString.TYPE) || c.isInstanceOf(CInt.TYPE)) { + } else if(c.isInstanceOf(CString.TYPE, null, env) || c.isInstanceOf(CInt.TYPE, null, env)) { return c.val(); } else if(c instanceof CNull) { return ""; - } else if(c.isInstanceOf(CBoolean.TYPE)) { + } else if(c.isInstanceOf(CBoolean.TYPE, null, env)) { if(((CBoolean) c).getBoolean()) { return "1"; } else { return "0"; } } else if(c instanceof CLabel) { - return normalizeConstruct(((CLabel) c).cVal()); + return normalizeConstruct(((CLabel) c).cVal(), env); } else { return c.val(); } } + /** @deprecated Use {@link #remove(int, Environment)} instead. */ + @Deprecated + public Mixed remove(int i) { + return remove(i, null); + } + /** * Removes the value at the specified integer key. * - * @param i - * @return + * @param i The index to remove at + * @param env The environment + * @return The value that was removed */ - public Mixed remove(int i) { - return remove(new CInt(i, Target.UNKNOWN)); + public Mixed remove(int i, Environment env) { + return remove(new CInt(i, Target.UNKNOWN), env); + } + + /** @deprecated Use {@link #remove(String, Environment)} instead. */ + @Deprecated + public Mixed remove(String s) { + return remove(s, null); } /** * Removes the value at the specified string key. * - * @param s - * @return + * @param s The index to remove at + * @param env The environment + * @return The value that was removed */ - public Mixed remove(String s) { - return remove(new CString(s, Target.UNKNOWN)); + public Mixed remove(String s, Environment env) { + return remove(new CString(s, Target.UNKNOWN), env); + } + + /** @deprecated Use {@link #remove(Mixed, Environment)} instead. */ + @Deprecated + public Mixed remove(Mixed construct) { + return remove(construct, null); } /** * Removes the value at the specified key * * @param construct The value to remove + * @param env The environment * @return The removed value, or CNull if nothing was removed. */ - public Mixed remove(Mixed construct) { - String c = normalizeConstruct(construct); + public Mixed remove(Mixed construct, Environment env) { + String c = normalizeConstruct(construct, env); Mixed ret; if(!associativeMode) { try { @@ -757,14 +922,21 @@ public void removeValues(Mixed construct) { setDirty(); } + /** @deprecated Use {@link #createNew(Target, Environment)} instead. */ + @Deprecated + public CArray createNew(Target t) { + return createNew(t, null); + } + /** * Creates a new, empty array, with the same type. Note to subclasses: By default, this method expects a constructor * that accepts a {@link Target}. If this assumption is not valid, you may override this method as needed. * - * @param t - * @return + * @param t The code target + * @param env The environment + * @return A new empty array */ - public CArray createNew(Target t) { + public CArray createNew(Target t, Environment env) { try { Constructor con = (Constructor) this.getClass().getConstructor(Target.class); try { @@ -821,9 +993,16 @@ public boolean canBeAssociative() { return true; } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed slice(int begin, int end, Target t) { - return new ArrayHandling.array_get().exec(t, null, null, new CSlice(begin, end, t)); + return slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { + return new ArrayHandling.array_get().exec(t, env, null, new CSlice(begin, end, t)); } @Override @@ -866,7 +1045,13 @@ public enum ArraySortType { STRING_IC } + /** @deprecated Use {@link #sort(ArraySortType, Environment)} instead. */ + @Deprecated public void sort(final ArraySortType sort) { + sort(sort, null); + } + + public void sort(final ArraySortType sort, Environment env) { if(this.associativeMode) { array = new ArrayList<>(associativeArray.values()); this.associativeArray.clear(); @@ -887,12 +1072,12 @@ public int compare(Mixed o1, Mixed o2) { } else { c = o2; } - if(c.isInstanceOf(CArray.TYPE)) { + if(c.isInstanceOf(CArray.TYPE, null, env)) { throw new CRECastException("Cannot sort an array of arrays.", CArray.this.getTarget()); } - if(!(c.isInstanceOf(CBoolean.TYPE) || c.isInstanceOf(CString.TYPE) || c.isInstanceOf(CInt.TYPE) - || c.isInstanceOf(CDouble.TYPE) || c instanceof CNull || c.isInstanceOf(CClassType.TYPE))) { - throw new CREFormatException("Unsupported type being sorted: " + c.typeof(), CArray.this.getTarget()); + if(!(c.isInstanceOf(CBoolean.TYPE, null, env) || c.isInstanceOf(CString.TYPE, null, env) || c.isInstanceOf(CInt.TYPE, null, env) + || c.isInstanceOf(CDouble.TYPE, null, env) || c instanceof CNull || c.isInstanceOf(CClassType.TYPE, null, env))) { + throw new CREFormatException("Unsupported type being sorted: " + c.typeof(env), CArray.this.getTarget()); } } if(o1 instanceof CNull || o2 instanceof CNull) { @@ -904,12 +1089,12 @@ public int compare(Mixed o1, Mixed o2) { return o1.val().compareTo(""); } } - if(o1.isInstanceOf(CBoolean.TYPE) || o2.isInstanceOf(CBoolean.TYPE)) { - if(ArgumentValidation.getBooleanish(o1, Target.UNKNOWN) == ArgumentValidation.getBooleanish(o2, Target.UNKNOWN)) { + if(o1.isInstanceOf(CBoolean.TYPE, null, env) || o2.isInstanceOf(CBoolean.TYPE, null, env)) { + if(ArgumentValidation.getBooleanish(o1, Target.UNKNOWN, env) == ArgumentValidation.getBooleanish(o2, Target.UNKNOWN, env)) { return 0; } else { - int oo1 = ArgumentValidation.getBooleanish(o1, Target.UNKNOWN) ? 1 : 0; - int oo2 = ArgumentValidation.getBooleanish(o2, Target.UNKNOWN) ? 1 : 0; + int oo1 = ArgumentValidation.getBooleanish(o1, Target.UNKNOWN, env) ? 1 : 0; + int oo2 = ArgumentValidation.getBooleanish(o2, Target.UNKNOWN, env) ? 1 : 0; return (oo1 < oo2) ? -1 : 1; } } @@ -923,13 +1108,13 @@ public int compare(Mixed o1, Mixed o2) { } public int compareRegular(Mixed o1, Mixed o2) { - if(ArgumentValidation.getBooleanObject(new DataHandling.is_numeric().exec(Target.UNKNOWN, null, null, o1), Target.UNKNOWN) - && ArgumentValidation.getBooleanObject(new DataHandling.is_numeric().exec(Target.UNKNOWN, null, null, o2), Target.UNKNOWN)) { + if(ArgumentValidation.getBooleanObject(new DataHandling.is_numeric().exec(Target.UNKNOWN, null, null, o1), Target.UNKNOWN, env) + && ArgumentValidation.getBooleanObject(new DataHandling.is_numeric().exec(Target.UNKNOWN, null, null, o2), Target.UNKNOWN, env)) { return compareNumeric(o1, o2); - } else if(ArgumentValidation.getBooleanObject(new DataHandling.is_numeric().exec(Target.UNKNOWN, null, null, o1), Target.UNKNOWN)) { + } else if(ArgumentValidation.getBooleanObject(new DataHandling.is_numeric().exec(Target.UNKNOWN, null, null, o1), Target.UNKNOWN, env)) { //The first is a number, the second is a string return -1; - } else if(ArgumentValidation.getBooleanObject(new DataHandling.is_numeric().exec(Target.UNKNOWN, null, null, o2), Target.UNKNOWN)) { + } else if(ArgumentValidation.getBooleanObject(new DataHandling.is_numeric().exec(Target.UNKNOWN, null, null, o2), Target.UNKNOWN, env)) { //The second is a number, the first is a string return 1; } else { @@ -939,8 +1124,8 @@ public int compareRegular(Mixed o1, Mixed o2) { } public int compareNumeric(Mixed o1, Mixed o2) { - double d1 = ArgumentValidation.getNumber(o1, o1.getTarget()); - double d2 = ArgumentValidation.getNumber(o2, o2.getTarget()); + double d1 = ArgumentValidation.getNumber(o1, o1.getTarget(), env); + double d2 = ArgumentValidation.getNumber(o2, o2.getTarget(), env); return Double.compare(d1, d2); } @@ -951,8 +1136,14 @@ public int compareString(String o1, String o2) { this.setDirty(); } + /** @deprecated Use {@link #isEmpty(Environment)} instead. */ + @Deprecated public boolean isEmpty() { - return size() == 0; + return isEmpty(null); + } + + public boolean isEmpty(Environment env) { + return size(env) == 0; } /** @@ -986,9 +1177,16 @@ public CClassType[] getInterfaces() { ArrayAccessSet.TYPE}; } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { - return size() > 0; + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { + return size(env) > 0; } } diff --git a/src/main/java/com/laytonsmith/core/constructs/CBoolean.java b/src/main/java/com/laytonsmith/core/constructs/CBoolean.java index f4f079863f..df6126656b 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CBoolean.java +++ b/src/main/java/com/laytonsmith/core/constructs/CBoolean.java @@ -3,6 +3,7 @@ import com.laytonsmith.PureUtilities.Version; import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.MSVersion; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.objects.ObjectModifier; import java.util.EnumSet; import java.util.Set; @@ -89,8 +90,15 @@ public boolean getBoolean() { return val; } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return val; } diff --git a/src/main/java/com/laytonsmith/core/constructs/CByteArray.java b/src/main/java/com/laytonsmith/core/constructs/CByteArray.java index a6f93a368f..9aac413bc0 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CByteArray.java +++ b/src/main/java/com/laytonsmith/core/constructs/CByteArray.java @@ -5,6 +5,7 @@ import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.ArgumentValidation; import com.laytonsmith.core.MSVersion; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.CRE.CRERangeException; import com.laytonsmith.core.exceptions.CRE.CREReadOnlyException; import com.laytonsmith.core.exceptions.CRE.CREUnsupportedOperationException; @@ -28,7 +29,7 @@ * */ @typeof("ms.lang.byte_array") -public class CByteArray extends CArray implements Sizeable, ArrayAccess { +public final class CByteArray extends CArray implements Sizeable, ArrayAccess { @SuppressWarnings("FieldNameHidesFieldInSuperclass") public static final CClassType TYPE = CClassType.get(CByteArray.class); @@ -389,9 +390,16 @@ public CByteArray getBytes(int size, Integer pos) { * Returns the current size of the byte array. This is not to be confused with the capacity. * * @return + * @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { return maxValue; } @@ -485,8 +493,15 @@ public boolean canBeAssociative() { return false; } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed slice(int begin, int end, Target t) { + return slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { return getBytes(end - begin, begin); } @@ -525,8 +540,15 @@ public void push(Mixed c, Integer index, Target t) throws IllegalArgumentExcepti throw new CREUnsupportedOperationException("Modifying a byte array using array_push() is not supported.", t); } + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { + return keySet(null); + } + + @Override + public Set keySet(Environment env) { throw new CREUnsupportedOperationException("Getting a key set from a byte array is not supported.", getTarget()); } @@ -535,8 +557,15 @@ public Set stringKeySet() { throw new CREUnsupportedOperationException("Getting a string key set from a byte array is not supported.", getTarget()); } + /** @deprecated Use {@link #set(Mixed, Mixed, Target, Environment)} instead. */ + @Deprecated @Override public void set(Mixed index, Mixed c, Target t) throws ConfigRuntimeException { + set(index, c, t, null); + } + + @Override + public void set(Mixed index, Mixed c, Target t, Environment env) throws ConfigRuntimeException { throw new CREUnsupportedOperationException("Modifying a byte array using array_set() is not supported.", t); } @@ -549,9 +578,16 @@ protected CArray deepClone(CArray array, Target t, ArrayList cloneRefs return CByteArray.wrap(newArray, t); } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) throws ConfigRuntimeException { - int i = ArgumentValidation.getInt32(index, t); + return get(index, t, null); + } + + @Override + public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException { + int i = ArgumentValidation.getInt32(index, t, env); byte b = getByte(i); return new CInt(b, t); } @@ -647,14 +683,28 @@ public void push(Mixed c, Integer i, Target t) { throw new CREByteArrayReadOnlyException("Arrays copied from ByteArrays are read only", t); } + /** @deprecated Use {@link #set(Mixed, Mixed, Target, Environment)} instead. */ + @Deprecated @Override public void set(Mixed index, Mixed c, Target t) { + set(index, c, t, null); + } + + @Override + public void set(Mixed index, Mixed c, Target t, Environment env) { throw new CREByteArrayReadOnlyException("Arrays copied from ByteArrays are read only", t); } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) { - int i = ArgumentValidation.getInt32(index, t); + return get(index, t, null); + } + + @Override + public Mixed get(Mixed index, Target t, Environment env) { + int i = ArgumentValidation.getInt32(index, t, env); try { return new CInt(backing[i], t); } catch (ArrayIndexOutOfBoundsException e) { @@ -662,8 +712,15 @@ public Mixed get(Mixed index, Target t) { } } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { return backing.length; } @@ -718,7 +775,7 @@ public CClassType[] getSuperclasses() { @Override public Set getObjectModifiers() { - return EnumSet.of(ObjectModifier.STATIC); + return EnumSet.of(ObjectModifier.STATIC, ObjectModifier.FINAL); } @Override diff --git a/src/main/java/com/laytonsmith/core/constructs/CClassType.java b/src/main/java/com/laytonsmith/core/constructs/CClassType.java index 554e3d1996..9eb555a9e6 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CClassType.java +++ b/src/main/java/com/laytonsmith/core/constructs/CClassType.java @@ -592,11 +592,18 @@ public CClassType typeof() { // TODO: These getters will eventually be re-done to support static methods, but for now that is out of scope, // so we just specifically support enums for now. + /** @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(String index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException { if(isEnum()) { try { - return NativeTypeList.getNativeEnumType(fqcn).get(index, t); + return NativeTypeList.getNativeEnumType(fqcn).get(index, t, env); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } @@ -604,11 +611,18 @@ public Mixed get(String index, Target t) throws ConfigRuntimeException { throw new CREUnsupportedOperationException("Unsupported operation", t); } + /** @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(int index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException { if(isEnum()) { try { - return NativeTypeList.getNativeEnumType(fqcn).get(index, t); + return NativeTypeList.getNativeEnumType(fqcn).get(index, t, env); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } @@ -616,11 +630,18 @@ public Mixed get(int index, Target t) throws ConfigRuntimeException { throw new CREUnsupportedOperationException("Unsupported operation", t); } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException { if(isEnum()) { try { - return NativeTypeList.getNativeEnumType(fqcn).get(index, t); + return NativeTypeList.getNativeEnumType(fqcn).get(index, t, env); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } @@ -628,11 +649,18 @@ public Mixed get(Mixed index, Target t) throws ConfigRuntimeException { throw new CREUnsupportedOperationException("Unsupported operation", t); } + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { + return keySet(null); + } + + @Override + public Set keySet(Environment env) { if(isEnum()) { try { - return NativeTypeList.getNativeEnumType(fqcn).keySet(); + return NativeTypeList.getNativeEnumType(fqcn).keySet(env); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } @@ -640,11 +668,18 @@ public Set keySet() { return new HashSet<>(); } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { if(isEnum()) { try { - return NativeTypeList.getNativeEnumType(fqcn).size(); + return NativeTypeList.getNativeEnumType(fqcn).size(env); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } @@ -662,8 +697,15 @@ public boolean canBeAssociative() { return true; } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed slice(int begin, int end, Target t) { + return slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { throw new CREUnsupportedOperationException("Unsupported operation", t); } @@ -677,8 +719,15 @@ public Class getNativeType() { return nativeClass; } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return true; } @@ -741,6 +790,7 @@ public GenericTypeParameters getTypeGenericParameters() { /** * Stub for generics support — not yet implemented. */ + @Override public GenericParameters getGenericParameters() { throw new UnsupportedOperationException("Not yet implemented"); } diff --git a/src/main/java/com/laytonsmith/core/constructs/CClosure.java b/src/main/java/com/laytonsmith/core/constructs/CClosure.java index ae8d0131c4..0ad103b6de 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CClosure.java +++ b/src/main/java/com/laytonsmith/core/constructs/CClosure.java @@ -350,8 +350,15 @@ public CClassType[] getInterfaces() { return new CClassType[]{Callable.TYPE, Booleanish.TYPE}; } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return true; } } diff --git a/src/main/java/com/laytonsmith/core/constructs/CDecimal.java b/src/main/java/com/laytonsmith/core/constructs/CDecimal.java index 640f54f9d8..8aaf7e7af6 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CDecimal.java +++ b/src/main/java/com/laytonsmith/core/constructs/CDecimal.java @@ -3,6 +3,7 @@ import com.laytonsmith.PureUtilities.Version; import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.MSVersion; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.CRE.CREFormatException; import java.math.BigDecimal; @@ -83,8 +84,15 @@ public CDecimal duplicate() { return new CDecimal(val, getTarget()); } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return val.compareTo(new BigDecimal(0)) != 0; } diff --git a/src/main/java/com/laytonsmith/core/constructs/CFixedArray.java b/src/main/java/com/laytonsmith/core/constructs/CFixedArray.java index 6f57ecb57e..ac18ea4477 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CFixedArray.java +++ b/src/main/java/com/laytonsmith/core/constructs/CFixedArray.java @@ -9,6 +9,7 @@ import com.laytonsmith.core.exceptions.CRE.CREIndexOverflowException; import com.laytonsmith.core.exceptions.CRE.CREUnsupportedOperationException; import com.laytonsmith.core.exceptions.ConfigRuntimeException; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.natives.interfaces.ArrayAccessSet; import com.laytonsmith.core.natives.interfaces.Booleanish; import com.laytonsmith.core.natives.interfaces.Mixed; @@ -43,13 +44,27 @@ public boolean isDynamic() { return true; } + /** @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(String index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException { return null; } + /** @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(int index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException { if(index < 0 || index >= data.length) { throw new CREIndexOverflowException("Index overflows array size", t); } @@ -60,13 +75,27 @@ public Mixed get(int index, Target t) throws ConfigRuntimeException { return d; } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) throws ConfigRuntimeException { - return get(ArgumentValidation.getInt32(index, t), t); + return get(index, t, null); } + @Override + public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException { + return get(ArgumentValidation.getInt32(index, t, env), t, env); + } + + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { + return keySet(null); + } + + @Override + public Set keySet(Environment env) { Set set = new LinkedHashSet<>(data.length); for(int i = 0; i < data.length; i++) { set.add(new CInt(i, Target.UNKNOWN)); @@ -80,9 +109,16 @@ private void validateSet(Mixed value, Target t) { } } + /** @deprecated Use {@link #set(Mixed, Mixed, Target, Environment)} instead. */ + @Deprecated @Override public void set(Mixed index, Mixed value, Target t) { - int in = ArgumentValidation.getInt32(index, t); + set(index, value, t, null); + } + + @Override + public void set(Mixed index, Mixed value, Target t, Environment env) { + int in = ArgumentValidation.getInt32(index, t, env); set(in, value, t); } @@ -104,18 +140,39 @@ public boolean canBeAssociative() { return false; } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed slice(int begin, int end, Target t) { + return slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { throw new CREUnsupportedOperationException("slices are not yet implemented on fixed_array", t); } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { - return size() > 0; + return getBooleanValue(null, t); } + @Override + public boolean getBooleanValue(Environment env, Target t) { + return size(env) > 0; + } + + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { return data.length; } diff --git a/src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java b/src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java index ca2c2e831e..552b78d3cf 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java +++ b/src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java @@ -4,20 +4,24 @@ import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.ArgumentValidation; import com.laytonsmith.core.MSVersion; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.CRE.CRECastException; import com.laytonsmith.core.exceptions.CRE.CREFormatException; import com.laytonsmith.core.natives.interfaces.Mixed; import com.laytonsmith.core.natives.interfaces.Sizeable; import com.laytonsmith.core.natives.interfaces.ValueType; +import com.laytonsmith.core.objects.ObjectModifier; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; +import java.util.Set; import java.util.Stack; /** * */ @typeof("ms.lang.mutable_primitive") -public class CMutablePrimitive extends CArray implements Sizeable { +public final class CMutablePrimitive extends CArray implements Sizeable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") public static final CClassType TYPE = CClassType.get(CMutablePrimitive.class); @@ -51,8 +55,15 @@ public void set(Mixed value, Target t) { this.value = value; } + /** @deprecated Use {@link #set(Mixed, Mixed, Target, Environment)} instead. */ + @Deprecated @Override public void set(Mixed index, Mixed c, Target t) { + set(index, c, t, null); + } + + @Override + public void set(Mixed index, Mixed c, Target t, Environment env) { throw new CRECastException("mutable_primitives cannot have values set in them", t); } @@ -74,8 +85,15 @@ public Mixed get() { return value; } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) { + return get(index, t, null); + } + + @Override + public Mixed get(Mixed index, Target t, Environment env) { return value; } @@ -99,10 +117,17 @@ protected String getQuote() { return new CString(value.val(), Target.UNKNOWN).getQuote(); } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { if(value.isInstanceOf(Sizeable.TYPE)) { - return ArgumentValidation.getObject(value, Target.UNKNOWN, Sizeable.class).size(); + return ArgumentValidation.getObject(value, Target.UNKNOWN, Sizeable.class).size(env); } else { return 0; } @@ -136,7 +161,7 @@ protected List getArray() { } @Override - protected String getString(Stack arrays, Target t) { + protected String getString(Stack arrays, Target t, Environment env) { return value.val(); } @@ -165,4 +190,9 @@ public CClassType[] getInterfaces() { return new CClassType[]{Sizeable.TYPE}; } + @Override + public Set getObjectModifiers() { + return EnumSet.of(ObjectModifier.FINAL); + } + } diff --git a/src/main/java/com/laytonsmith/core/constructs/CNull.java b/src/main/java/com/laytonsmith/core/constructs/CNull.java index 67420cda4f..065867aff1 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CNull.java +++ b/src/main/java/com/laytonsmith/core/constructs/CNull.java @@ -3,6 +3,7 @@ import com.laytonsmith.PureUtilities.Version; import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.MSVersion; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.natives.interfaces.Booleanish; /** @@ -106,8 +107,15 @@ public CClassType[] getInterfaces() { throw new RuntimeException("Cannot call getInterfaces on null"); } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return false; } diff --git a/src/main/java/com/laytonsmith/core/constructs/CNumber.java b/src/main/java/com/laytonsmith/core/constructs/CNumber.java index 4edc77996e..7af9266def 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CNumber.java +++ b/src/main/java/com/laytonsmith/core/constructs/CNumber.java @@ -3,6 +3,7 @@ import com.laytonsmith.PureUtilities.Version; import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.MSVersion; +import com.laytonsmith.core.environments.Environment; /** * @@ -41,8 +42,15 @@ public Version since() { public abstract double getNumber(); + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return getNumber() != 0.0; } } diff --git a/src/main/java/com/laytonsmith/core/constructs/CReal2dMatrix.java b/src/main/java/com/laytonsmith/core/constructs/CReal2dMatrix.java index c395025fca..30ee10e35a 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CReal2dMatrix.java +++ b/src/main/java/com/laytonsmith/core/constructs/CReal2dMatrix.java @@ -4,6 +4,7 @@ import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.ArgumentValidation; import com.laytonsmith.core.MSVersion; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.CRE.CREIllegalArgumentException; import com.laytonsmith.core.exceptions.CRE.CREIndexOverflowException; import com.laytonsmith.core.exceptions.CRE.CRELengthException; @@ -154,26 +155,54 @@ public boolean isAssociative() { return false; } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public CReal2dMatrixRow get(Mixed index, Target t) throws ConfigRuntimeException { - return get(ArgumentValidation.getInt32(index, t), t); + return (CReal2dMatrixRow) get(index, t, null); } + @Override + public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException { + return get(ArgumentValidation.getInt32(index, t, env), t, env); + } + + /** @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(String index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException { throw new CREIllegalArgumentException("Matrices cannot be indexed into with non-numeric values.", t); } + /** @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated @Override public CReal2dMatrixRow get(int index, Target t) throws ConfigRuntimeException { + return (CReal2dMatrixRow) get(index, t, null); + } + + @Override + public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException { if(index >= getRowCount() || index < 0) { throw new CRERangeException("Matrix range out of bounds.", t); } return new CReal2dMatrixRow(this, index); } + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { + return keySet(null); + } + + @Override + public Set keySet(Environment env) { Set set = new HashSet<>(); for(int i = 0; i < getRowCount(); i++) { set.add(new CInt(i, Target.UNKNOWN)); @@ -181,13 +210,27 @@ public Set keySet() { return set; } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return data.length != 0; } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public CArray slice(int begin, int end, Target t) { + return (CArray) slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { CArray ret = new CArray(t); int step = (begin <= end) ? 1 : -1; @@ -204,8 +247,15 @@ public CArray slice(int begin, int end, Target t) { return ret; } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { return getRowCount(); } diff --git a/src/main/java/com/laytonsmith/core/constructs/CReal2dMatrixRow.java b/src/main/java/com/laytonsmith/core/constructs/CReal2dMatrixRow.java index 9beb85bd2d..3b26bff39a 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CReal2dMatrixRow.java +++ b/src/main/java/com/laytonsmith/core/constructs/CReal2dMatrixRow.java @@ -6,6 +6,7 @@ import com.laytonsmith.core.MSVersion; import com.laytonsmith.core.exceptions.CRE.CRECastException; import com.laytonsmith.core.exceptions.ConfigRuntimeException; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.natives.interfaces.AbstractMixedClass; import com.laytonsmith.core.natives.interfaces.ArrayAccessSet; import com.laytonsmith.core.natives.interfaces.Mixed; @@ -52,23 +53,51 @@ public CClassType[] getInterfaces() { return new CClassType[]{com.laytonsmith.core.natives.interfaces.Iterable.TYPE, ArrayAccessSet.TYPE}; } + /** @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(String index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException { throw new CRECastException("Real2dMatrix only supports int keys.", t); } + /** @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated @Override public CDouble get(int index, Target t) throws ConfigRuntimeException { + return (CDouble) get(index, t, null); + } + + @Override + public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException { return new CDouble(getNative(index, t), t); } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) throws ConfigRuntimeException { - return get(ArgumentValidation.getInt32(index, t), t); + return get(index, t, null); } + @Override + public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException { + return get(ArgumentValidation.getInt32(index, t, env), t, env); + } + + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { + return keySet(null); + } + + @Override + public Set keySet(Environment env) { Set set = new HashSet<>(); for(int i = 0; i < parent.columns; i++) { set.add(new CInt(i, Target.UNKNOWN)); @@ -86,37 +115,65 @@ public boolean canBeAssociative() { return false; } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed slice(int begin, int end, Target t) { + return slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { CArray ret = new CArray(t); int step = (begin <= end) ? 1 : -1; // Note: loop includes 'begin', excludes 'end', just like typical slice semantics for(int i = begin; i != end; i += step) { - CDouble d = get(i, t); + CDouble d = (CDouble) get(i, t, env); ret.push(d, t); } return ret; } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { // 0 dimension matrices are not possible, so this will // always have at least one value in it, thus always // true. return true; } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { return parent.columns; } + /** @deprecated Use {@link #set(Mixed, Mixed, Target, Environment)} instead. */ + @Deprecated @Override public void set(Mixed index, Mixed value, Target t) { - int in = ArgumentValidation.getInt32(index, t); - double d = ArgumentValidation.getDouble(value, t); + set(index, value, t, null); + } + + @Override + public void set(Mixed index, Mixed value, Target t, Environment env) { + int in = ArgumentValidation.getInt32(index, t, env); + double d = ArgumentValidation.getDouble(value, t, env); setNative(in, d, t); } diff --git a/src/main/java/com/laytonsmith/core/constructs/CResource.java b/src/main/java/com/laytonsmith/core/constructs/CResource.java index 7967b75a1c..80b710373a 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CResource.java +++ b/src/main/java/com/laytonsmith/core/constructs/CResource.java @@ -6,8 +6,11 @@ import com.laytonsmith.core.MSVersion; import com.laytonsmith.core.functions.ResourceManager.res_free_resource; import com.laytonsmith.core.natives.interfaces.Mixed; +import com.laytonsmith.core.objects.ObjectModifier; import java.io.File; +import java.util.EnumSet; +import java.util.Set; import java.util.concurrent.atomic.AtomicLong; /** @@ -17,7 +20,7 @@ * created. */ @typeof("ms.lang.Resource") -public class CResource extends Construct implements Finalizable { +public final class CResource extends Construct implements Finalizable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") public static final CClassType TYPE = CClassType.get(CResource.class); @@ -130,4 +133,8 @@ public CClassType[] getInterfaces() { return CClassType.EMPTY_CLASS_ARRAY; } + @Override + public Set getObjectModifiers() { + return EnumSet.of(ObjectModifier.FINAL); + } } diff --git a/src/main/java/com/laytonsmith/core/constructs/CSlice.java b/src/main/java/com/laytonsmith/core/constructs/CSlice.java index 67c682c3fd..37842a2a24 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CSlice.java +++ b/src/main/java/com/laytonsmith/core/constructs/CSlice.java @@ -4,6 +4,7 @@ import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.ArgumentValidation; import com.laytonsmith.core.MSVersion; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.CRE.CRECastException; import com.laytonsmith.core.exceptions.CRE.CRERangeException; import com.laytonsmith.core.exceptions.ConfigCompileException; @@ -103,7 +104,7 @@ public String toString() { } @Override - protected String getString(Stack arrays, Target t) { + protected String getString(Stack arrays, Target t, Environment env) { //We don't need to consider arrays, because we can't //get stuck in an infinite loop. return val(); @@ -114,22 +115,43 @@ public boolean inAssociativeMode() { return false; } + /** @deprecated Use {@link #set(Mixed, Mixed, Target, Environment)} instead. */ + @Deprecated @Override public void set(Mixed index, Mixed c, Target t) { + set(index, c, t, null); + } + + @Override + public void set(Mixed index, Mixed c, Target t, Environment env) { throw new CRECastException("CSlices cannot set values", t); } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) { - long i = ArgumentValidation.getInt(index, t); + return get(index, t, null); + } + + @Override + public Mixed get(Mixed index, Target t, Environment env) { + long i = ArgumentValidation.getInt(index, t, env); if(i > max) { throw new CRERangeException("Index out of bounds. Index: " + i + " Size: " + max, t); } return new CInt(start + (direction * i), t); } + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { + return keySet(null); + } + + @Override + public Set keySet(Environment env) { // To keep our memory footprint down, we create a "fake" keyset here, which doesn't // require actually creating an entire Set. Removing items from the set isn't supported, // but all iteration options are. @@ -165,8 +187,15 @@ public int size() { }; } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { return size; } diff --git a/src/main/java/com/laytonsmith/core/constructs/CString.java b/src/main/java/com/laytonsmith/core/constructs/CString.java index 988f047cc2..d0bface90a 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CString.java +++ b/src/main/java/com/laytonsmith/core/constructs/CString.java @@ -60,8 +60,15 @@ public boolean isDynamic() { return false; } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { return val().length(); } @@ -70,8 +77,15 @@ public boolean canBeAssociative() { return false; } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed slice(int begin, int end, Target t) { + return slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { if(begin > end) { return new CString("", t); } @@ -87,8 +101,15 @@ public String getQuote() { return super.getQuote(); } + /** @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(int index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException { try { return new CString(this.val().charAt(index), t); } catch (StringIndexOutOfBoundsException e) { @@ -96,17 +117,31 @@ public Mixed get(int index, Target t) throws ConfigRuntimeException { } } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public final Mixed get(Mixed index, Target t) throws ConfigRuntimeException { - int i = ArgumentValidation.getInt32(index, t); - return get(i, t); + return get(index, t, null); } + @Override + public final Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException { + int i = ArgumentValidation.getInt32(index, t, env); + return get(i, t, env); + } + + /** @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated @Override public final Mixed get(String index, Target t) { + return get(index, t, null); + } + + @Override + public final Mixed get(String index, Target t, Environment env) { try { int i = Integer.parseInt(index); - return get(i, t); + return get(i, t, env); } catch (NumberFormatException e) { throw new CREFormatException("Expecting numerical index, but received " + index, t); } @@ -117,8 +152,15 @@ public boolean isAssociative() { return false; } + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { + return keySet(null); + } + + @Override + public Set keySet(Environment env) { return new AbstractSet() { @Override public int size() { @@ -175,8 +217,15 @@ public CString duplicate() { return new CString(val(), getTarget()); } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { if(val().equals("false")) { MSLog.GetLogger().e(MSLog.Tags.FALSESTRING, "String \"false\" evaluates as true (non-empty strings are" + " true). This is most likely not what you meant to do. This warning can globally be disabled" diff --git a/src/main/java/com/laytonsmith/core/constructs/Construct.java b/src/main/java/com/laytonsmith/core/constructs/Construct.java index b8a8a86104..1c267813f9 100644 --- a/src/main/java/com/laytonsmith/core/constructs/Construct.java +++ b/src/main/java/com/laytonsmith/core/constructs/Construct.java @@ -7,6 +7,9 @@ import com.laytonsmith.core.SimpleDocumentation; import com.laytonsmith.core.Static; import com.laytonsmith.core.exceptions.MarshalException; +import com.laytonsmith.core.constructs.generics.GenericParameters; +import com.laytonsmith.core.constructs.generics.LeftHandGenericUse; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.natives.interfaces.Mixed; import com.laytonsmith.core.objects.AccessModifier; import com.laytonsmith.core.objects.ObjectModifier; @@ -192,9 +195,9 @@ private static Object json_encode0(Mixed c, Target t) throws MarshalException { return c.val(); } else if(c instanceof CVoid) { return ""; - } else if(c instanceof CInt) { + } else if(InstanceofUtil.isInstanceof(c, CInt.class, null)) { return ((CInt) c).getInt(); - } else if(c instanceof CDouble) { + } else if(InstanceofUtil.isInstanceof(c, CDouble.class, null)) { return ((CDouble) c).getDouble(); } else if(c instanceof CBoolean) { return ((CBoolean) c).getBoolean(); @@ -411,13 +414,13 @@ public static Construct GetConstruct(Object o, boolean allowResources) throws Cl public static Object GetPOJO(Mixed c) throws ClassCastException { if(c instanceof CNull) { return null; - } else if(c instanceof CString) { + } else if(InstanceofUtil.isInstanceof(c, CString.class, null)) { return c.val(); } else if(c instanceof CBoolean) { return Boolean.valueOf(((CBoolean) c).getBoolean()); - } else if(c instanceof CInt) { + } else if(InstanceofUtil.isInstanceof(c, CInt.class, null)) { return Long.valueOf(((CInt) c).getInt()); - } else if(c instanceof CDouble) { + } else if(InstanceofUtil.isInstanceof(c, CDouble.class, null)) { return Double.valueOf(((CDouble) c).getDouble()); } else if(c.isInstanceOf(CByteArray.TYPE)) { return ((CByteArray) c).asByteArrayCopy(); @@ -495,10 +498,12 @@ protected String getQuote() { * This method may be overridden in special cases, such as dynamic types, but for most types, this * @return * @throws IllegalArgumentException If the class isn't public facing. + * @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated @Override public CClassType typeof() { - return typeof(this); + return typeof((Environment) null); } /** @@ -511,6 +516,11 @@ public static CClassType typeof(Mixed that) { return CClassType.get(that.getClass()); } + @Override + public CClassType typeof(Environment env) { + return typeof(this); + } + /** * Overridden from {@link SimpleDocumentation}. This should just return the value of the typeof annotation, * unconditionally. @@ -605,8 +615,22 @@ public static boolean isInstanceof(Mixed that, Class type) { return that.typeof().doesExtend(CClassType.get(type)); } + /** + * @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. + */ + @Deprecated @Override public boolean isInstanceOf(CClassType type) { + return isInstanceOf(type, null, null); + } + + @Override + public boolean isInstanceOf(Class type) { + return type.isAssignableFrom(this.getClass()); + } + + @Override + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) { if(type.getNativeType() != null) { return type.getNativeType().isAssignableFrom(this.getClass()); } @@ -614,8 +638,8 @@ public boolean isInstanceOf(CClassType type) { } @Override - public boolean isInstanceOf(Class type) { - return type.isAssignableFrom(this.getClass()); + public GenericParameters getGenericParameters() { + return null; } /** diff --git a/src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java b/src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java index fd1a37c764..17eb62aab4 100644 --- a/src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java +++ b/src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java @@ -39,7 +39,7 @@ public static Set getAllCastableClasses(CClassType c, Environment en */ private static Set getAllCastableClassesWithBlacklist(CClassType c, Set blacklist, Environment env) { - if(blacklist.contains(c)) { + if(blacklist.contains(c) || CNull.TYPE.equals(c)) { return blacklist; } blacklist.add(c); @@ -108,6 +108,9 @@ public static boolean isInstanceof(CClassType type, FullyQualifiedClassName inst * @return */ public static boolean isInstanceof(Mixed value, Class instanceofThis, Environment env) { + if(instanceofThis.isAssignableFrom(value.getClass())) { + return true; + } FullyQualifiedClassName typeof = typeof(instanceofThis); return typeof == null ? false : isInstanceof(value, typeof, env); } diff --git a/src/main/java/com/laytonsmith/core/constructs/LeftHandSideType.java b/src/main/java/com/laytonsmith/core/constructs/LeftHandSideType.java index ae7ffc0ec8..676e4a5262 100644 --- a/src/main/java/com/laytonsmith/core/constructs/LeftHandSideType.java +++ b/src/main/java/com/laytonsmith/core/constructs/LeftHandSideType.java @@ -748,6 +748,7 @@ public String toString() { return val(); } + @Override public GenericParameters getGenericParameters() { return null; } diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java index 76dc6339ba..0dd97d8f6b 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java @@ -14,6 +14,8 @@ import com.laytonsmith.core.constructs.Construct; import com.laytonsmith.core.constructs.NativeTypeList; import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.constructs.generics.GenericParameters; +import com.laytonsmith.core.constructs.generics.LeftHandGenericUse; import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.ConfigRuntimeException; import com.laytonsmith.core.exceptions.StackTraceManager; @@ -189,25 +191,53 @@ public String val() { * @param t * @return * @throws ConfigRuntimeException + * @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(String index, Target t) throws ConfigRuntimeException { - return exceptionObject.get(index, t); + return get(index, t, null); } + @Override + public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException { + return exceptionObject.get(index, t, env); + } + + /** @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(int index, Target t) throws ConfigRuntimeException { - return exceptionObject.get(index, t); + return get(index, t, null); + } + + @Override + public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException { + return exceptionObject.get(index, t, env); } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) throws ConfigRuntimeException { - return exceptionObject.get(index, t); + return get(index, t, null); } + @Override + public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException { + return exceptionObject.get(index, t, env); + } + + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { - return exceptionObject.keySet(); + return keySet(null); + } + + @Override + public Set keySet(Environment env) { + return exceptionObject.keySet(env); } @Override @@ -220,9 +250,16 @@ public boolean canBeAssociative() { return exceptionObject.canBeAssociative(); } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed slice(int begin, int end, Target t) { - return exceptionObject.slice(begin, end, t); + return slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { + return exceptionObject.slice(begin, end, t, env); } @Override @@ -294,9 +331,11 @@ public CClassType[] getSuperclasses() { throw new UnsupportedOperationException(); } + /** @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. */ + @Deprecated @Override public boolean isInstanceOf(CClassType type) { - return Construct.isInstanceof(this, type); + return isInstanceOf(type, null, null); } @Override @@ -304,13 +343,37 @@ public boolean isInstanceOf(Class type) { return Construct.isInstanceof(this, type); } + @Override + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) { + return Construct.isInstanceof(this, type); + } + + /** @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated @Override public CClassType typeof() { + return typeof(null); + } + + @Override + public CClassType typeof(Environment env) { return Construct.typeof(this); } + @Override + public GenericParameters getGenericParameters() { + return null; + } + + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return true; } diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixed.java b/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixed.java index 67150e8dd5..74e3e95f47 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixed.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixed.java @@ -6,6 +6,9 @@ import com.laytonsmith.core.constructs.CClassType; import com.laytonsmith.core.constructs.Construct; import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.constructs.generics.GenericParameters; +import com.laytonsmith.core.constructs.generics.LeftHandGenericUse; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.objects.AccessModifier; import com.laytonsmith.core.objects.ObjectModifier; import java.net.URL; @@ -60,8 +63,15 @@ public CClassType getContainingClass() { return null; } + /** @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. */ + @Deprecated @Override public boolean isInstanceOf(CClassType type) { + return isInstanceOf(type, null, null); + } + + @Override + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) { if(type.getNativeType() != null) { return type.getNativeType().isAssignableFrom(this.getClass()); } @@ -81,12 +91,24 @@ public boolean isInstanceOf(Class type) { * This method may be overridden in special cases, such as dynamic types, but for most types, this * @return * @throws IllegalArgumentException If the class isn't public facing. + * @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated @Override public CClassType typeof() { + return typeof(null); + } + + @Override + public CClassType typeof(Environment env) { return Construct.typeof(this); } + @Override + public GenericParameters getGenericParameters() { + return null; + } + @Override public URL getSourceJar() { return ClassDiscovery.GetClassContainer(this.getClass()); diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixedInterfaceRunner.java b/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixedInterfaceRunner.java index 658ba2c1a0..56a7a192ee 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixedInterfaceRunner.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixedInterfaceRunner.java @@ -10,6 +10,9 @@ import com.laytonsmith.core.constructs.CClassType; import com.laytonsmith.core.constructs.Construct; import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.constructs.generics.GenericParameters; +import com.laytonsmith.core.constructs.generics.LeftHandGenericUse; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.objects.AccessModifier; import java.net.URL; import java.util.EnumSet; @@ -113,15 +116,24 @@ public CClassType getContainingClass() { * * @return * @throws IllegalArgumentException If the class isn't public facing. + * @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated @Override public final CClassType typeof() { + return typeof(null); + } + + @Override + public final CClassType typeof(Environment env) { return Construct.typeof(this); } + /** @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. */ + @Deprecated @Override public boolean isInstanceOf(CClassType type) { - return Construct.isInstanceof(this, type); + return isInstanceOf(type, null, null); } @Override @@ -129,4 +141,14 @@ public boolean isInstanceOf(Class type) { return Construct.isInstanceof(this, type); } + @Override + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) { + return Construct.isInstanceof(this, type); + } + + @Override + public GenericParameters getGenericParameters() { + return null; + } + } diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccess.java b/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccess.java index b9cdf4caa3..2e78caf9bb 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccess.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccess.java @@ -4,6 +4,7 @@ import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.constructs.CClassType; import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.ConfigRuntimeException; import java.util.Set; @@ -23,9 +24,21 @@ public interface ArrayAccess extends Booleanish { * @param index * @param t * @return + * @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated public Mixed get(String index, Target t) throws ConfigRuntimeException; + /** + * Return the mixed at this location, with environment context. + * + * @param index + * @param t + * @param env + * @return + */ + Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException; + /** * Returns the mixed at this location. This should throw an exception if the index does not exist. This method will * not be called if {@link #isAssociative()} returns true. @@ -34,9 +47,22 @@ public interface ArrayAccess extends Booleanish { * @param t * @return * @throws ConfigRuntimeException + * @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated public Mixed get(int index, Target t) throws ConfigRuntimeException; + /** + * Returns the mixed at this location, with environment context. + * + * @param index + * @param t + * @param env + * @return + * @throws ConfigRuntimeException + */ + Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException; + /** * Returns the mixed at this location. This should throw an exception if the index does not exist. This method may * be called whether or not it isAssociative returns true. @@ -45,17 +71,40 @@ public interface ArrayAccess extends Booleanish { * @param t * @return * @throws ConfigRuntimeException + * @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated public Mixed get(Mixed index, Target t) throws ConfigRuntimeException; + /** + * Returns the mixed at this location, with environment context. + * + * @param index + * @param t + * @param env + * @return + * @throws ConfigRuntimeException + */ + Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException; + /** * If {@link #isAssociative()} returns true, this should return a set of all keys. If {@link #isAssociative()} * returns false, this method will not be called. * * @return + * @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated public Set keySet(); + /** + * Returns the key set with environment context. + * + * @param env + * @return + */ + Set keySet(Environment env); + /** * Unlike {@link #canBeAssociative()}, this is a runtime flag. If the underlying object is associative (that is, it * is an unordered, non numeric key set), this should return true. If this is true, then @@ -80,23 +129,26 @@ public interface ArrayAccess extends Booleanish { * Returns a slice at the specified location. Should throw an exception if an element in the range doesn't exist. * The range is inclusive. * - * @implNote In general, MethodScript supports undefined begin and end slices, as well as reverse slices. For - * CArray type only, this is fully covered, but for other slice types, only negative slice numbers are converted, - * and subclasses must handle both forward and reverse slices if applicable. A good way to handle that is as such: - *

-	 * int start = Math.min(begin, end);
-	 * int stop = Math.max(begin, end);
-	 * int step = (begin <= end) ? 1 : -1;
-	 * for(int i = start; i != stop; i += step) { ... }
-	 * 
- * * @param begin * @param end * @param t * @return + * @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated public Mixed slice(int begin, int end, Target t); + /** + * Returns a slice at the specified location, with environment context. + * + * @param begin + * @param end + * @param t + * @param env + * @return + */ + Mixed slice(int begin, int end, Target t, Environment env); + @Override public String docs(); diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccessSet.java b/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccessSet.java index 1fa79ea07b..63838ffc5b 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccessSet.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccessSet.java @@ -3,6 +3,7 @@ import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.constructs.CClassType; import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.environments.Environment; /** * Things that implement this can set the value via square bracket notation. The generic type provided is the index @@ -23,6 +24,18 @@ public interface ArrayAccessSet extends Mixed { * @param index The zero-based index. * @param value The value to set. * @param t The code target. + * @deprecated Use {@link #set(Mixed, Mixed, Target, Environment)} instead. */ + @Deprecated public void set(Mixed index, Mixed value, Target t); + + /** + * Sets the value at the specified index in the object, with environment context. + * + * @param index The zero-based index. + * @param value The value to set. + * @param t The code target. + * @param env The environment. + */ + void set(Mixed index, Mixed value, Target t, Environment env); } diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/Booleanish.java b/src/main/java/com/laytonsmith/core/natives/interfaces/Booleanish.java index 8074cdd2ab..b6a8850e86 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/Booleanish.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/Booleanish.java @@ -4,7 +4,7 @@ import com.laytonsmith.core.ArgumentValidation; import com.laytonsmith.core.constructs.CClassType; import com.laytonsmith.core.constructs.Target; - +import com.laytonsmith.core.environments.Environment; /** * A value that is Booleanish is a non-boolean value, that can be converted to Boolean. @@ -28,6 +28,18 @@ public interface Booleanish extends Mixed { * @param t The code target, in case there are errors that are thrown, the correct target can be provided in the * error. * @return True if the value is trueish, false if it is falseish. + * @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated boolean getBooleanValue(Target t); + + /** + * Returns true if this value is a trueish value, with environment context. + * + * @param env The environment. + * @param t The code target. + * @return True if the value is trueish, false if it is falseish. + */ + boolean getBooleanValue(Environment env, Target t); + } diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java b/src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java index 2aa4e17be3..62825e3c54 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java @@ -15,6 +15,9 @@ import com.laytonsmith.core.constructs.CClassType; import com.laytonsmith.core.constructs.Construct; import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.constructs.generics.GenericParameters; +import com.laytonsmith.core.constructs.generics.LeftHandGenericUse; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.CRE.CREIllegalArgumentException; import com.laytonsmith.core.exceptions.CRE.CREIndexOverflowException; import com.laytonsmith.core.exceptions.CRE.CREUnsupportedOperationException; @@ -137,9 +140,11 @@ public URL getSourceJar() { return ClassDiscovery.GetClassContainer(enumClass); } + /** @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. */ + @Deprecated @Override public boolean isInstanceOf(CClassType type) { - return Mixed.TYPE.equals(type) || MEnumType.TYPE.equals(type) || this.typeof().equals(type); + return isInstanceOf(type, null, null); } @Override @@ -147,8 +152,20 @@ public boolean isInstanceOf(Class type) { return type.isAssignableFrom(this.getClass()); } + @Override + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) { + return Mixed.TYPE.equals(type) || MEnumType.TYPE.equals(type) || this.typeof(env).equals(type); + } + + /** @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated @Override public CClassType typeof() { + return typeof(null); + } + + @Override + public CClassType typeof(Environment env) { try { return CClassType.get(fqcn); } catch (ClassNotFoundException ex) { @@ -246,8 +263,15 @@ public String toString() { return v.toString(); } + /** @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated @Override public CClassType typeof() { + return typeof(null); + } + + @Override + public CClassType typeof(Environment env) { try { return CClassType.get(fqcn); } catch (ClassNotFoundException ex) { @@ -255,9 +279,11 @@ public CClassType typeof() { } } + /** @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. */ + @Deprecated @Override public boolean isInstanceOf(CClassType type) { - return Construct.isInstanceof(this, type); + return isInstanceOf(type, null, null); } @Override @@ -265,6 +291,16 @@ public boolean isInstanceOf(Class type) { return Construct.isInstanceof(this, type); } + @Override + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) { + return Construct.isInstanceof(this, type); + } + + @Override + public GenericParameters getGenericParameters() { + return null; + } + @Override public CClassType getContainingClass() { return null; @@ -327,8 +363,15 @@ public int size() { }; } + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return true; } @@ -428,9 +471,11 @@ public CClassType getContainingClass() { return null; } + /** @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. */ + @Deprecated @Override public boolean isInstanceOf(CClassType type) { - return TYPE.equals(type); + return isInstanceOf(type, null, null); } @Override @@ -438,11 +483,28 @@ public boolean isInstanceOf(Class type) { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) { + return TYPE.equals(type); + } + + /** @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated @Override public CClassType typeof() { + return typeof(null); + } + + @Override + public CClassType typeof(Environment env) { return TYPE; } + @Override + public GenericParameters getGenericParameters() { + return null; + } + @Override public URL getSourceJar() { return ClassDiscovery.GetClassContainer(MEnumType.class); @@ -472,8 +534,15 @@ public List values() { } return values; } + /** @deprecated Use {@link #get(String, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(String index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(String index, Target t, Environment env) throws ConfigRuntimeException { for(MEnumTypeValue v : values()) { if(v.name().equals(index)) { return v; @@ -482,26 +551,54 @@ public Mixed get(String index, Target t) throws ConfigRuntimeException { throw new CREIllegalArgumentException(index + " cannot be found in " + typeof(), t); } + /** @deprecated Use {@link #get(int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(int index, Target t) throws ConfigRuntimeException { + return get(index, t, null); + } + + @Override + public Mixed get(int index, Target t, Environment env) throws ConfigRuntimeException { if(index >= values().size()) { throw new CREIndexOverflowException("The index " + index + " is out of bounds", t); } return values().get(index); } + /** @deprecated Use {@link #get(Mixed, Target, Environment)} instead. */ + @Deprecated @Override public Mixed get(Mixed index, Target t) throws ConfigRuntimeException { - return get(index.val(), t); + return get(index, t, null); } + @Override + public Mixed get(Mixed index, Target t, Environment env) throws ConfigRuntimeException { + return get(index.val(), t, env); + } + + /** @deprecated Use {@link #keySet(Environment)} instead. */ + @Deprecated @Override public Set keySet() { + return keySet(null); + } + + @Override + public Set keySet(Environment env) { return values().stream().collect(Collectors.toSet()); } + /** @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated @Override public long size() { + return size(null); + } + + @Override + public long size(Environment env) { return values().size(); } @@ -515,8 +612,15 @@ public boolean canBeAssociative() { return true; } + /** @deprecated Use {@link #slice(int, int, Target, Environment)} instead. */ + @Deprecated @Override public Mixed slice(int begin, int end, Target t) { + return slice(begin, end, t, null); + } + + @Override + public Mixed slice(int begin, int end, Target t, Environment env) { throw new CREUnsupportedOperationException("Cannot slice an enum", t); } @@ -526,8 +630,15 @@ public Mixed slice(int begin, int end, Target t) { */ protected abstract List getValues(); + /** @deprecated Use {@link #getBooleanValue(Environment, Target)} instead. */ + @Deprecated @Override public boolean getBooleanValue(Target t) { + return getBooleanValue(null, t); + } + + @Override + public boolean getBooleanValue(Environment env, Target t) { return true; } diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java b/src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java index 3333761733..a654046807 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java @@ -10,6 +10,9 @@ import com.laytonsmith.core.constructs.CClassType; import com.laytonsmith.core.constructs.Construct; import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.constructs.generics.GenericParameters; +import com.laytonsmith.core.constructs.generics.LeftHandGenericUse; +import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.objects.AccessModifier; import java.util.Set; @@ -116,9 +119,22 @@ public interface Mixed extends Cloneable, Documentation { * * @param type * @return + * @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. */ + @Deprecated public boolean isInstanceOf(CClassType type); + /** + * Checks if this value is an instance of the given type, with environment context. + * The lhsGenericParameters parameter is for future generic type checking and may be null. + * + * @param type + * @param lhsGenericParameters + * @param env + * @return + */ + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env); + /** * Generally speaking, we cannot use Java's instanceof keyword to determine if something is an instanceof, because * user classes do not extend the hierarchy of objects in MethodScript. Essentially, we need to extend Java's @@ -143,9 +159,27 @@ public interface Mixed extends Cloneable, Documentation { * * @return * @throws IllegalArgumentException If the class isn't public facing. + * @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated public CClassType typeof(); + /** + * Returns the typeof this value, as a CClassType object, with environment context. + * + * @param env + * @return + * @throws IllegalArgumentException If the class isn't public facing. + */ + public CClassType typeof(Environment env); + + /** + * Returns the generic parameters for this value, or null if none. + * + * @return + */ + public GenericParameters getGenericParameters(); + /** * Casts the class to the specified type. This only works with Java types, and so for dynamic elements, this * may throw a RuntimeException. For dynamic types, use the other castTo. diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/Sizeable.java b/src/main/java/com/laytonsmith/core/natives/interfaces/Sizeable.java index 33cee2f9cb..8fb7b97738 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/Sizeable.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/Sizeable.java @@ -2,6 +2,7 @@ import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.constructs.CClassType; +import com.laytonsmith.core.environments.Environment; /** * Any object that can report a size should implement this. @@ -16,6 +17,16 @@ public interface Sizeable extends Mixed { * Returns the size of this object. * * @return + * @deprecated Use {@link #size(Environment)} instead. */ + @Deprecated long size(); + + /** + * Returns the size of this object, with environment context. + * + * @param env + * @return + */ + long size(Environment env); } diff --git a/src/main/java/com/laytonsmith/core/objects/UserObject.java b/src/main/java/com/laytonsmith/core/objects/UserObject.java index f370fcd56e..f2bbb48f95 100644 --- a/src/main/java/com/laytonsmith/core/objects/UserObject.java +++ b/src/main/java/com/laytonsmith/core/objects/UserObject.java @@ -9,6 +9,8 @@ import com.laytonsmith.core.constructs.CNull; import com.laytonsmith.core.constructs.Construct; import com.laytonsmith.core.constructs.Target; +import com.laytonsmith.core.constructs.generics.GenericParameters; +import com.laytonsmith.core.constructs.generics.LeftHandGenericUse; import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.natives.interfaces.Mixed; import java.net.URL; @@ -149,9 +151,11 @@ public CClassType getContainingClass() { return objectDefinition.getContainingClass(); } + /** @deprecated Use {@link #isInstanceOf(CClassType, LeftHandGenericUse, Environment)} instead. */ + @Deprecated @Override public boolean isInstanceOf(CClassType type) { - return Construct.isInstanceof(this, type); + return isInstanceOf(type, null, null); } @Override @@ -159,11 +163,28 @@ public boolean isInstanceOf(Class type) { return Construct.isInstanceof(this, type); } + @Override + public boolean isInstanceOf(CClassType type, LeftHandGenericUse lhsGenericParameters, Environment env) { + return Construct.isInstanceof(this, type); + } + + /** @deprecated Use {@link #typeof(Environment)} instead. */ + @Deprecated @Override public CClassType typeof() { + return typeof(null); + } + + @Override + public CClassType typeof(Environment env) { return objectDefinition.getType(); } + @Override + public GenericParameters getGenericParameters() { + return null; + } + @Override public URL getSourceJar() { return null;