Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 216 additions & 34 deletions src/main/java/com/laytonsmith/core/ArgumentValidation.java

Large diffs are not rendered by default.

370 changes: 284 additions & 86 deletions src/main/java/com/laytonsmith/core/constructs/CArray.java

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/main/java/com/laytonsmith/core/constructs/CBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
65 changes: 61 additions & 4 deletions src/main/java/com/laytonsmith/core/constructs/CByteArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<Mixed> keySet() {
return keySet(null);
}

@Override
public Set<Mixed> keySet(Environment env) {
throw new CREUnsupportedOperationException("Getting a key set from a byte array is not supported.", getTarget());
}

Expand All @@ -535,8 +557,15 @@ public Set<String> 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);
}

Expand All @@ -549,9 +578,16 @@ protected CArray deepClone(CArray array, Target t, ArrayList<CArray[]> 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);
}
Expand Down Expand Up @@ -647,23 +683,44 @@ 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) {
throw new CRERangeException("Index out of range. Found " + i + ", but array length is only " + backing.length, t);
}
}

/** @deprecated Use {@link #size(Environment)} instead. */
@Deprecated
@Override
public long size() {
return size(null);
}

@Override
public long size(Environment env) {
return backing.length;
}

Expand Down Expand Up @@ -718,7 +775,7 @@ public CClassType[] getSuperclasses() {

@Override
public Set<ObjectModifier> getObjectModifiers() {
return EnumSet.of(ObjectModifier.STATIC);
return EnumSet.of(ObjectModifier.STATIC, ObjectModifier.FINAL);
}

@Override
Expand Down
60 changes: 55 additions & 5 deletions src/main/java/com/laytonsmith/core/constructs/CClassType.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,59 +592,94 @@ 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);
}
}
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);
}
}
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);
}
}
throw new CREUnsupportedOperationException("Unsupported operation", t);
}

/** @deprecated Use {@link #keySet(Environment)} instead. */
@Deprecated
@Override
public Set<Mixed> keySet() {
return keySet(null);
}

@Override
public Set<Mixed> keySet(Environment env) {
if(isEnum()) {
try {
return NativeTypeList.getNativeEnumType(fqcn).keySet();
return NativeTypeList.getNativeEnumType(fqcn).keySet(env);
} catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
}
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);
}
Expand All @@ -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);
}

Expand All @@ -677,8 +719,15 @@ public Class<? extends Mixed> 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;
}

Expand Down Expand Up @@ -741,6 +790,7 @@ public GenericTypeParameters getTypeGenericParameters() {
/**
* Stub for generics support — not yet implemented.
*/
@Override
public GenericParameters getGenericParameters() {
throw new UnsupportedOperationException("Not yet implemented");
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/laytonsmith/core/constructs/CClosure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/laytonsmith/core/constructs/CDecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
Loading
Loading