diff --git a/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassDiscovery.java b/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassDiscovery.java index 5c4edbec1..a88fa8350 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassDiscovery.java +++ b/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassDiscovery.java @@ -11,6 +11,7 @@ import com.laytonsmith.PureUtilities.Common.FileUtil; import com.laytonsmith.PureUtilities.Common.StreamUtils; import com.laytonsmith.PureUtilities.Common.StringUtils; +import com.laytonsmith.PureUtilities.Pair; import com.laytonsmith.PureUtilities.ProgressIterator; import com.laytonsmith.PureUtilities.ZipIterator; import java.io.File; @@ -139,6 +140,8 @@ public ClassDiscovery() { * Cache for constructor annotations. Whenever a new URL is added to the URL cache, this is cleared. */ private final Map, Set>> constructorAnnotationCache = new HashMap<>(); + private final Map, Class>, Set>> + classesWithAnnotationThatExtendCache = new HashMap<>(); /** * By default null, but this can be set per instance. */ @@ -462,6 +465,7 @@ public void invalidateCaches() { fieldAnnotationCache.clear(); methodAnnotationCache.clear(); constructorAnnotationCache.clear(); + classesWithAnnotationThatExtendCache.clear(); dirtyURLs.addAll(urlCache); } @@ -717,6 +721,15 @@ public Set> getClassesWithAnnotation(Class */ @SuppressWarnings("unchecked") public Set> getClassesWithAnnotationThatExtend(Class annotation, Class superClass) { + Pair, Class> id = new Pair<>(annotation, superClass); + if(classesWithAnnotationThatExtendCache.containsKey(id)) { + // This (insane) double cast is necessary, because the cache will certainly contain the value of the + // correct type, + // but there's no way for us to encode T into the generic type of the definition, so we just do this, + // lie to the compiler, and go about our merry way. We do the same below. + // I'm totally open to a better approach though. + return (Set>) (Object) classesWithAnnotationThatExtendCache.get(id); + } Set> mirrors = new HashSet<>(); for(ClassMirror c : getClassesWithAnnotation(annotation)) { if(doesClassExtend(c, superClass)) { @@ -728,6 +741,7 @@ public Set> getClassesWithAnnotationThatExtend(Clas // ourselves here. mirrors.add(new ClassMirror<>(superClass)); } + classesWithAnnotationThatExtendCache.put(id, (Set>) (Object) mirrors); return mirrors; } diff --git a/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java b/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java index 0ad6bb343..981ad2b75 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java +++ b/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java @@ -457,7 +457,7 @@ public Class loadClass() throws NoClassDefFoundError { try { return info.classReferenceMirror.loadClass(); } catch (ClassNotFoundException ex) { - throw new NoClassDefFoundError(); + throw new NoClassDefFoundError(ex.getMessage()); } } diff --git a/src/main/java/com/laytonsmith/PureUtilities/Common/ClassUtils.java b/src/main/java/com/laytonsmith/PureUtilities/Common/ClassUtils.java index 699ba3212..43710492e 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/Common/ClassUtils.java +++ b/src/main/java/com/laytonsmith/PureUtilities/Common/ClassUtils.java @@ -1,8 +1,10 @@ package com.laytonsmith.PureUtilities.Common; import java.util.HashSet; +import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -43,6 +45,7 @@ public static Class forCanonicalName(String className, boolean initialize, Class return forCanonicalName(className, true, initialize, classLoader); } + private static final Map CANONICAL_CLASS_CACHE = new ConcurrentHashMap<>(); /** * Private version, which accepts the useInitializer parameter. * @@ -53,7 +56,11 @@ public static Class forCanonicalName(String className, boolean initialize, Class * @return * @throws ClassNotFoundException */ - private static Class forCanonicalName(String className, boolean useInitializer, boolean initialize, ClassLoader classLoader) throws ClassNotFoundException { + private static Class forCanonicalName(String className, boolean useInitializer, boolean initialize, + ClassLoader classLoader) throws ClassNotFoundException { + if(CANONICAL_CLASS_CACHE.containsKey(className)) { + return CANONICAL_CLASS_CACHE.get(className); + } if("void".equals(className)) { return void.class; } @@ -144,6 +151,7 @@ private static Class forCanonicalName(String className, boolean useInitializer, throw ex; } } + CANONICAL_CLASS_CACHE.put(className, c); return c; } diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCCommand.java b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCCommand.java index e04f9e877..c90330848 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCCommand.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCCommand.java @@ -253,7 +253,7 @@ public boolean handleCustomCommand(MCCommandSender sender, String label, String[ Mixed fret = closure.executeCallable(null, t, new CString(label, t), new CString(sender.getName(), t), cargs, new CArray(t) // reserved for an obgen style command array ); - if(fret instanceof CBoolean) { + if(fret.isInstanceOf(CBoolean.class)) { return ((CBoolean) fret).getBoolean(); } } catch (ConfigRuntimeException cre) { diff --git a/src/main/java/com/laytonsmith/core/ArgumentValidation.java b/src/main/java/com/laytonsmith/core/ArgumentValidation.java index fc230046d..646da9d6f 100644 --- a/src/main/java/com/laytonsmith/core/ArgumentValidation.java +++ b/src/main/java/com/laytonsmith/core/ArgumentValidation.java @@ -233,10 +233,10 @@ public static long getInt(Mixed c, Target t) { if(c == null || c instanceof CNull) { return 0; } - if(c instanceof CInt) { - i = ((CInt) c).getInt(); - } else if(c instanceof CBoolean) { - if(((CBoolean) c).getBoolean()) { + if(c.isInstanceOf(CInt.class)) { + i = getObject(c, t, CInt.class).getInt(); + } else if(c.isInstanceOf(CBoolean.class)) { + if(getObject(c, t, CBoolean.class).getBoolean()) { i = 1; } else { i = 0; diff --git a/src/main/java/com/laytonsmith/core/FullyQualifiedClassName.java b/src/main/java/com/laytonsmith/core/FullyQualifiedClassName.java index 734980180..c4cd114ab 100644 --- a/src/main/java/com/laytonsmith/core/FullyQualifiedClassName.java +++ b/src/main/java/com/laytonsmith/core/FullyQualifiedClassName.java @@ -6,11 +6,14 @@ package com.laytonsmith.core; import com.laytonsmith.PureUtilities.Common.StringUtils; +import com.laytonsmith.annotations.MEnum; +import com.laytonsmith.annotations.typeof; import com.laytonsmith.core.compiler.CompilerEnvironment; import com.laytonsmith.core.constructs.NativeTypeList; import com.laytonsmith.core.constructs.Target; import com.laytonsmith.core.environments.Environment; import com.laytonsmith.core.exceptions.CRE.CRECastException; +import com.laytonsmith.core.natives.interfaces.Mixed; import com.laytonsmith.core.objects.ObjectDefinitionNotFoundException; import com.laytonsmith.core.objects.ObjectDefinitionTable; import java.util.ArrayList; @@ -26,6 +29,7 @@ public final class FullyQualifiedClassName implements Comparable nativeClass; private FullyQualifiedClassName(String name) { Objects.requireNonNull(name, "The name passed in may not be null"); @@ -70,13 +74,56 @@ public static FullyQualifiedClassName forName(String unqualified, Target t, Envi } /** - * If the class is known for sure to be within the default import list, this method can be used. + * If the type represents an enum tagged with {@link MEnum}, then this method should be used, but is otherwise + * identical to {@link #forNativeClass(java.lang.Class)}. + * @param clazz + * @return + */ + public static FullyQualifiedClassName forNativeEnum(Class clazz) { + MEnum m = clazz.getAnnotation(MEnum.class); + if(m == null) { + throw new Error("Native enum " + clazz + " does not provide an MEnum annotation"); + } + String fqcn = m.value(); + FullyQualifiedClassName f = new FullyQualifiedClassName(fqcn); + try { + f.nativeClass = NativeTypeList.getNativeEnumType(f).typeof().getNativeType(); + } catch (ClassNotFoundException ex) { + // This can't happen, it would have already been the above error. + throw new Error(ex); + } + return f; + } + + /** + * If the type represents a native class, this method can be used. Not only does it never throw an exception + * (except an Error, if the class does not define a typeof annotation), getNativeClass will return a reference + * to the Class object, which is useful for shortcutting various operations. + * @param clazz + * @return + */ + public static FullyQualifiedClassName forNativeClass(Class clazz) { + typeof t = clazz.getAnnotation(typeof.class); + if(t == null) { + throw new Error("Native class " + clazz + " does not provide a typeof annotation"); + } + String fqcn = t.value(); + FullyQualifiedClassName f = new FullyQualifiedClassName(fqcn); + f.nativeClass = clazz; + return f; + } + + /** + * If the class is known for sure to be within the default import list, this method can be used. If the native + * class is available, this MUST not be used, as it causes too much of a performance hit. Instead, use + * {@link #forNativeClass(java.lang.Class)} or {@link #forNativeEnum(java.lang.Class)}. DynamicEnums are not + * specially supported, but they can safely use this method, though their use should be very limited. * @param unqualified The (potentially) unqualified type. * @param t The code target. * @return The FullyQualifiedClassName. * @throws CRECastException If the class type can't be found */ - public static FullyQualifiedClassName forDefaultClasses(String unqualified, Target t) throws CRECastException { + private static FullyQualifiedClassName forDefaultClasses(String unqualified, Target t) throws CRECastException { String fqcn = NativeTypeList.resolveNativeType(unqualified); if(fqcn == null) { throw new CRECastException("Cannot find \"" + unqualified + "\" type", t); @@ -88,6 +135,8 @@ public static FullyQualifiedClassName forDefaultClasses(String unqualified, Targ * If you know for a fact that the name is already fully qualified, this step skips qualification. If you aren't * sure whether or not the name is fully qualified, don't use the method, the other methods will accept a fully * qualified class name, but not change it, but if it isn't fully qualified, then it will do so. + * + * If this represents a native class, use {@link #forNativeClass(java.lang.Class)} instead. * @param qualified * @return */ @@ -130,6 +179,14 @@ public boolean isTypeUnion() { return this.fullyQualifiedName.contains("|"); } + /** + * Returns the underlying native class, iff this is a native class. + * @return + */ + public Class getNativeClass() { + return nativeClass; + } + public String getSimpleName() { List parts = new ArrayList<>(); for(String t : fullyQualifiedName.split("\\|")) { diff --git a/src/main/java/com/laytonsmith/core/MainSandbox.java b/src/main/java/com/laytonsmith/core/MainSandbox.java index f07668a1c..767d1b968 100644 --- a/src/main/java/com/laytonsmith/core/MainSandbox.java +++ b/src/main/java/com/laytonsmith/core/MainSandbox.java @@ -31,12 +31,14 @@ public static void main(String[] args) throws Exception { || m.getSimpleName().equals("CLabel") || m.getSimpleName().equals("CLabel") || m.getSimpleName().equals("AbstractCREException") + || m.getSimpleName().equals("CSlice") + || m.getSimpleName().equals("CArray") ) { continue; } l.add(m.getSimpleName()); } - System.out.println(" instanceof (" + StringUtils.Join(l, "|") + ")([^a-zA-Z0-9])"); + System.out.println(" instanceof (" + StringUtils.Join(l, "|") + ")(?![a-zA-Z0-9])"); System.out.println(".isInstanceOf($1.class)$2"); } diff --git a/src/main/java/com/laytonsmith/core/Method.java b/src/main/java/com/laytonsmith/core/Method.java index d58616198..53085d48b 100644 --- a/src/main/java/com/laytonsmith/core/Method.java +++ b/src/main/java/com/laytonsmith/core/Method.java @@ -20,7 +20,7 @@ public class Method extends Construct implements Callable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.Method"); + public static final CClassType TYPE = CClassType.get(Method.class); private final CClassType returnType; private final String name; diff --git a/src/main/java/com/laytonsmith/core/ObjectGenerator.java b/src/main/java/com/laytonsmith/core/ObjectGenerator.java index 6525c2e1c..bdb64448c 100644 --- a/src/main/java/com/laytonsmith/core/ObjectGenerator.java +++ b/src/main/java/com/laytonsmith/core/ObjectGenerator.java @@ -286,7 +286,7 @@ public MCItemStack item(Mixed i, Target t, boolean legacy) { } } else { Mixed type = item.get("type", t); - if(type instanceof CString) { + if(type.isInstanceOf(CString.class)) { int seperatorIndex = type.val().indexOf(':'); if(seperatorIndex != -1) { try { @@ -634,7 +634,7 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti Mixed li = ma.get("lore", t); if(li instanceof CNull) { //do nothing - } else if(li instanceof CString) { + } else if(li.isInstanceOf(CString.class)) { List ll = new ArrayList<>(); ll.add(li.val()); meta.setLore(ll); @@ -940,7 +940,7 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti Mixed color = ma.get("color", t); if(color instanceof CArray) { ((MCPotionMeta) meta).setColor(color((CArray) color, t)); - } else if(color instanceof CString) { + } else if(color.isInstanceOf(CString.class)) { ((MCPotionMeta) meta).setColor(StaticLayer.GetConvertor().GetColor(color.val(), t)); } } @@ -1193,7 +1193,7 @@ public Map enchants(CArray enchantArray, Target t) { Mixed value = enchantArray.get(key, t); if(enchantArray.isAssociative()) { etype = StaticLayer.GetEnchantmentByName(key); - if(etype != null && value instanceof CInt) { + if(etype != null && value.isInstanceOf(CInt.class)) { ret.put(etype, Static.getInt32(value, t)); continue; } @@ -1304,7 +1304,7 @@ public MCPotionData potionData(CArray pd, Target t) { boolean upgraded = false; if(pd.containsKey("extended")) { Mixed cext = pd.get("extended", t); - if(cext instanceof CBoolean) { + if(cext.isInstanceOf(CBoolean.class)) { extended = ((CBoolean) cext).getBoolean(); } else { throw new CREFormatException( @@ -1313,7 +1313,7 @@ public MCPotionData potionData(CArray pd, Target t) { } if(pd.containsKey("upgraded")) { Mixed cupg = pd.get("upgraded", t); - if(cupg instanceof CBoolean) { + if(cupg.isInstanceOf(CBoolean.class)) { upgraded = ((CBoolean) cupg).getBoolean(); } else { throw new CREFormatException( @@ -1367,11 +1367,11 @@ public MCFireworkEffect fireworkEffect(CArray fe, Target t) { } else { for(Mixed color : ccolors.asList()) { MCColor mccolor; - if(color instanceof CString) { + if(color.isInstanceOf(CString.class)) { mccolor = StaticLayer.GetConvertor().GetColor(color.val(), t); } else if(color instanceof CArray) { mccolor = color((CArray) color, t); - } else if(color instanceof CInt && ccolors.size() == 3) { + } else if(color.isInstanceOf(CInt.class) && ccolors.size() == 3) { // Appears to be a single color builder.addColor(color(ccolors, t)); break; @@ -1382,7 +1382,7 @@ public MCFireworkEffect fireworkEffect(CArray fe, Target t) { builder.addColor(mccolor); } } - } else if(colors instanceof CString) { + } else if(colors.isInstanceOf(CString.class)) { String split[] = colors.val().split("\\|"); if(split.length == 0) { builder.addColor(MCColor.WHITE); @@ -1406,9 +1406,9 @@ public MCFireworkEffect fireworkEffect(CArray fe, Target t) { MCColor mccolor; if(color instanceof CArray) { mccolor = color((CArray) color, t); - } else if(color instanceof CString) { + } else if(color.isInstanceOf(CString.class)) { mccolor = StaticLayer.GetConvertor().GetColor(color.val(), t); - } else if(color instanceof CInt && ccolors.size() == 3) { + } else if(color.isInstanceOf(CInt.class) && ccolors.size() == 3) { // Appears to be a single color builder.addFadeColor(color(ccolors, t)); break; @@ -1418,7 +1418,7 @@ public MCFireworkEffect fireworkEffect(CArray fe, Target t) { } builder.addFadeColor(mccolor); } - } else if(colors instanceof CString) { + } else if(colors.isInstanceOf(CString.class)) { String split[] = colors.val().split("\\|"); for(String s : split) { builder.addFadeColor(StaticLayer.GetConvertor().GetColor(s, t)); @@ -1504,7 +1504,7 @@ public MCRecipe recipe(Mixed c, Target t) { } int i = 0; for(Mixed row : shaped.asList()) { - if(row instanceof CString && row.val().length() >= 1 && row.val().length() <= 3) { + if(row.isInstanceOf(CString.class) && row.val().length() >= 1 && row.val().length() <= 3) { shape[i] = row.val(); i++; } else { @@ -1520,7 +1520,7 @@ public MCRecipe recipe(Mixed c, Target t) { for(String key : shapedIngredients.stringKeySet()) { MCMaterial mat = null; Mixed ingredient = shapedIngredients.get(key, t); - if(ingredient instanceof CString) { + if(ingredient.isInstanceOf(CString.class)) { mat = StaticLayer.GetMaterial(ingredient.val()); if(mat == null) { // maybe legacy item format @@ -1534,7 +1534,7 @@ public MCRecipe recipe(Mixed c, Target t) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "Numeric item formats (eg. \"0:0\" are deprecated.", t); } catch (NumberFormatException ex) {} } - } else if(ingredient instanceof CInt) { + } else if(ingredient.isInstanceOf(CInt.class)) { mat = StaticLayer.GetMaterialFromLegacy(Static.getInt32(ingredient, t), 0); MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "Numeric item ingredients are deprecated.", t); } else if(ingredient instanceof CArray) { @@ -1553,7 +1553,7 @@ public MCRecipe recipe(Mixed c, Target t) { throw new CREFormatException("Ingredients array is invalid.", t); } for(Mixed ingredient : ingredients.asList()) { - if(ingredient instanceof CString) { + if(ingredient.isInstanceOf(CString.class)) { MCMaterial mat = StaticLayer.GetMaterial(ingredient.val()); if(mat == null) { // maybe legacy item format @@ -1581,7 +1581,7 @@ public MCRecipe recipe(Mixed c, Target t) { case FURNACE: Mixed input = recipe.get("input", t); - if(input instanceof CString) { + if(input.isInstanceOf(CString.class)) { MCMaterial mat = StaticLayer.GetMaterial(input.val()); if(mat == null) { throw new CREFormatException("Furnace input is invalid: " + input.val(), t); diff --git a/src/main/java/com/laytonsmith/core/Static.java b/src/main/java/com/laytonsmith/core/Static.java index b91546b3e..c79ee1452 100644 --- a/src/main/java/com/laytonsmith/core/Static.java +++ b/src/main/java/com/laytonsmith/core/Static.java @@ -55,6 +55,7 @@ import com.laytonsmith.core.exceptions.CRE.CRENullPointerException; import com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException; import com.laytonsmith.core.exceptions.CRE.CRERangeException; +import com.laytonsmith.core.exceptions.CRE.CREThrowable; import com.laytonsmith.core.exceptions.ConfigRuntimeException; import com.laytonsmith.core.functions.Function; import com.laytonsmith.core.natives.interfaces.Mixed; @@ -578,7 +579,12 @@ public static Construct resolveConstruct(String val, Target t, boolean returnBar } String fqType = NativeTypeList.resolveNativeType(val); if(fqType != null) { - return CClassType.get(fqType); + try { + return CClassType.get(FullyQualifiedClassName.forFullyQualifiedClass(fqType)); + } catch (ClassNotFoundException ex) { + // Can't happen, because we just resolved the type, and it wasn't null. + throw new Error(ex); + } } if(returnBareStrings) { return new CBareString(val, t); @@ -755,7 +761,7 @@ public static MCOfflinePlayer GetUser(String search, Target t) { try { ofp = getServer().getOfflinePlayer(GetUUID(search, t)); } catch (ConfigRuntimeException cre) { - if(cre instanceof CRELengthException) { + if(cre instanceof CREThrowable && ((CREThrowable) cre).isInstanceOf(CRELengthException.class)) { throw new CRELengthException("The given string was the wrong size to identify a player." + " A player name is expected to be between 1 and 16 characters. " + cre.getMessage(), t); } else { @@ -789,7 +795,7 @@ public static MCPlayer GetPlayer(String player, Target t) throws ConfigRuntimeEx try { m = getServer().getPlayer(GetUUID(player, t)); } catch (ConfigRuntimeException cre) { - if(cre instanceof CRELengthException) { + if(cre instanceof CREThrowable && ((CREThrowable) cre).isInstanceOf(CRELengthException.class)) { throw new CRELengthException("The given string was the wrong size to identify a player." + " A player name is expected to be between 1 and 16 characters. " + cre.getMessage(), t); } else { diff --git a/src/main/java/com/laytonsmith/core/compiler/OptimizationUtilities.java b/src/main/java/com/laytonsmith/core/compiler/OptimizationUtilities.java index 5efb35a64..fa6fdf39e 100644 --- a/src/main/java/com/laytonsmith/core/compiler/OptimizationUtilities.java +++ b/src/main/java/com/laytonsmith/core/compiler/OptimizationUtilities.java @@ -75,7 +75,9 @@ private static String optimize0(ParseTree node) { return b.toString(); } else if(node.getData() instanceof CString) { //strings - return new StringBuilder().append("'").append(node.getData().val().replaceAll("\t", "\\t").replaceAll("\n", "\\n").replace("\\", "\\\\").replace("'", "\\'")).append("'").toString(); + return new StringBuilder().append("'").append(node.getData().val() + .replaceAll("\t", "\\t").replaceAll("\n", "\\n").replace("\\", "\\\\") + .replace("'", "\\'")).append("'").toString(); } else if(node.getData() instanceof IVariable) { return ((IVariable) node.getData()).getVariableName(); } else if(node.getData() instanceof Variable) { diff --git a/src/main/java/com/laytonsmith/core/constructs/CArray.java b/src/main/java/com/laytonsmith/core/constructs/CArray.java index f3a79f08f..8e8d011d7 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CArray.java +++ b/src/main/java/com/laytonsmith/core/constructs/CArray.java @@ -18,12 +18,14 @@ import com.laytonsmith.core.functions.DataHandling; import com.laytonsmith.core.natives.interfaces.Booleanish; import com.laytonsmith.core.natives.interfaces.Mixed; +import com.laytonsmith.core.objects.ObjectModifier; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.EnumSet; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; @@ -43,7 +45,7 @@ public class CArray extends Construct implements Iterable, Booleanish, com.laytonsmith.core.natives.interfaces.Iterable { - public static final CClassType TYPE = CClassType.get("ms.lang.array"); + public static final CClassType TYPE = CClassType.get(CArray.class); private boolean associativeMode = false; private long nextIndex = 0; private List array; @@ -622,11 +624,11 @@ private static CArray deepClone(CArray array, Target t, ArrayList clon private String normalizeConstruct(Mixed c) { if(c instanceof CArray) { throw new CRECastException("Arrays cannot be used as the key in an associative array", c.getTarget()); - } else if(c instanceof CString || c instanceof CInt) { + } else if(c.isInstanceOf(CString.class) || c.isInstanceOf(CInt.class)) { return c.val(); } else if(c instanceof CNull) { return ""; - } else if(c instanceof CBoolean) { + } else if(c.isInstanceOf(CBoolean.class)) { if(((CBoolean) c).getBoolean()) { return "1"; } else { @@ -874,8 +876,8 @@ public int compare(Mixed o1, Mixed o2) { if(c instanceof CArray) { throw new CRECastException("Cannot sort an array of arrays.", CArray.this.getTarget()); } - if(!(c instanceof CBoolean || c instanceof CString || c instanceof CInt - || c instanceof CDouble || c instanceof CNull || c instanceof CClassType)) { + if(!(c.isInstanceOf(CBoolean.class) || c.isInstanceOf(CString.class) || c.isInstanceOf(CInt.class) + || c.isInstanceOf(CDouble.class) || c instanceof CNull || c.isInstanceOf(CClassType.class))) { throw new CREFormatException("Unsupported type being sorted: " + c.typeof(), CArray.this.getTarget()); } } @@ -888,7 +890,7 @@ public int compare(Mixed o1, Mixed o2) { return o1.val().compareTo(""); } } - if(o1 instanceof CBoolean || o2 instanceof CBoolean) { + if(o1.isInstanceOf(CBoolean.class) || o2.isInstanceOf(CBoolean.class)) { if(ArgumentValidation.getBoolean(o1, Target.UNKNOWN) == ArgumentValidation.getBoolean(o2, Target.UNKNOWN)) { return 0; } else { @@ -959,6 +961,11 @@ public void ensureCapacity(int capacity) { ((ArrayList) array).ensureCapacity(capacity); } + @Override + public Set getObjectModifiers() { + return EnumSet.of(ObjectModifier.FINAL); + } + @Override public CClassType[] getSuperclasses() { return new CClassType[]{Mixed.TYPE}; diff --git a/src/main/java/com/laytonsmith/core/constructs/CBareString.java b/src/main/java/com/laytonsmith/core/constructs/CBareString.java index 37576e82f..5c4446a93 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CBareString.java +++ b/src/main/java/com/laytonsmith/core/constructs/CBareString.java @@ -14,7 +14,7 @@ public class CBareString extends CString { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.barestring"); + public static final CClassType TYPE = CClassType.get(CBareString.class); public CBareString(String value, Target t) { super(value, t); diff --git a/src/main/java/com/laytonsmith/core/constructs/CBoolean.java b/src/main/java/com/laytonsmith/core/constructs/CBoolean.java index e3a23f46e..f4f079863 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CBoolean.java +++ b/src/main/java/com/laytonsmith/core/constructs/CBoolean.java @@ -14,7 +14,7 @@ public final class CBoolean extends CPrimitive implements Cloneable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.boolean"); + public static final CClassType TYPE = CClassType.get(CBoolean.class); public static final long serialVersionUID = 1L; diff --git a/src/main/java/com/laytonsmith/core/constructs/CByteArray.java b/src/main/java/com/laytonsmith/core/constructs/CByteArray.java index f92ce192b..e086e294f 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CByteArray.java +++ b/src/main/java/com/laytonsmith/core/constructs/CByteArray.java @@ -28,7 +28,7 @@ public class CByteArray extends CArray implements Sizeable, ArrayAccess { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.byte_array"); + public static final CClassType TYPE = CClassType.get(CByteArray.class); /** * Initial size of the ByteBuffer @@ -529,7 +529,7 @@ public CClassType[] getInterfaces() { private static class CArrayByteBacking extends CArray { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.ByteBackingArray"); + public static final CClassType TYPE = CClassType.get(CArrayByteBacking.class); private final byte[] backing; private String value = null; @@ -631,7 +631,7 @@ public CClassType getContainingClass() { public static class CREByteArrayReadOnlyException extends CREReadOnlyException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.ByteArrayReadOnlyException"); + public static final CClassType TYPE = CClassType.get(CREByteArrayReadOnlyException.class); public CREByteArrayReadOnlyException(java.lang.String msg, com.laytonsmith.core.constructs.Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/constructs/CClassType.java b/src/main/java/com/laytonsmith/core/constructs/CClassType.java index 37071a685..3fc54f45c 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CClassType.java +++ b/src/main/java/com/laytonsmith/core/constructs/CClassType.java @@ -60,7 +60,7 @@ public final class CClassType extends Construct implements com.laytonsmith.core. public static final CClassType[] EMPTY_CLASS_ARRAY = new CClassType[0]; static { - CACHE.put(FullyQualifiedClassName.forFullyQualifiedClass("ms.lang.ClassType"), TYPE); + CACHE.put(FullyQualifiedClassName.forNativeClass(CClassType.class), TYPE); } private final boolean isTypeUnion; @@ -78,6 +78,13 @@ public final class CClassType extends Construct implements com.laytonsmith.core. */ private Mixed[] invalidType = UNINITIALIZED; + /** + * If this was constructed against a native class, we can do some optimizations in the course + * of operation. This may be null, and all code in this class must support the mechanisms if this + * is null anyways, but if it isn't null, then this can perhaps be used to help optimize. + */ + private Class nativeClass = null; + /** * This *MUST* contain a list of non type union types. */ @@ -88,15 +95,18 @@ public final class CClassType extends Construct implements com.laytonsmith.core. * *

IMPORTANT: The type MUST be fully qualified AND exist as a real, instantiable class, or this will cause * errors. The only time this method is preferred vs {@link #get(com.laytonsmith.core.FullyQualifiedClassName)} is - * when used to define the TYPE value. + * when used to define the TYPE value. The native class must also be provided at the same time, which is used + * for various operations to increase efficiency when dealing with native classes. * * Unlike the other getters, this will not throw a ClassNotFoundException, it will instead throw an Error. * @param type * @return */ - public static CClassType get(String type) { + public static CClassType get(Class type) { try { - return get(FullyQualifiedClassName.forFullyQualifiedClass(type)); + CClassType t = get(FullyQualifiedClassName.forNativeClass(type)); + t.nativeClass = type; + return t; } catch (ClassNotFoundException ex) { throw new Error(ex); } @@ -226,7 +236,11 @@ private CClassType(FullyQualifiedClassName type, Target t, boolean newDefinition found = true; } } else { - found = null != NativeTypeList.resolveNativeType(fqcn.getFQCN()); + if(fqcn.getNativeClass() != null) { + found = true; + } else { + found = null != NativeTypeList.resolveNativeType(fqcn.getFQCN()); + } } } // TODO: When user types are added, we will need to do some more digging here, and probably need @@ -256,7 +270,6 @@ private void instantiateInvalidType(Environment env) { } else if("ms.lang.ClassType".equals(fqcn)) { invalidType = new Mixed[]{this}; } else { - ObjectDefinitionTable odt = env.getEnv(CompilerEnvironment.class).getObjectDefinitionTable(); invalidType = new Mixed[types.size()]; for(int i = 0; i < invalidType.length; i++) { // TODO: For now, we must use this mechanism, since we don't populate the ODT with @@ -264,6 +277,7 @@ private void instantiateInvalidType(Environment env) { if(NativeTypeList.getNativeTypeList().contains(this.fqcn)) { invalidType[i] = NativeTypeList.getInvalidInstanceForUse(this.fqcn); } else { + ObjectDefinitionTable odt = env.getEnv(CompilerEnvironment.class).getObjectDefinitionTable(); ObjectDefinition od = odt.get(this.fqcn); invalidType[i] = new UserObject(Target.UNKNOWN, null, env, od, null); } @@ -314,6 +328,15 @@ public static boolean doesExtend(CClassType checkClass, CClassType superClass) { // more efficient check return true; } + if(checkClass.nativeClass != null && superClass.nativeClass != null + && superClass.nativeClass.isAssignableFrom(checkClass.nativeClass)) { + // Since native classes are not allowed to extend multiple superclasees, but + // in general, they are allowed to advertise that they do, for the sake of + // methodscript, this can only be used to return true, if it returns true, it + // definitely is, but if it returns false, that does not explicitely mean that + // it doesn't. + return true; + } for(CClassType tCheck : checkClass.getTypes()) { for(CClassType tSuper : superClass.getTypes()) { try { @@ -569,6 +592,14 @@ public Mixed slice(int begin, int end, Target t) { throw new CREUnsupportedOperationException("Unsupported operation", t); } - + /** + * If this was constructed against a native class, we can do some optimizations in the course + * of operation. This may be null, and all code that uses this method must support the mechanisms if this + * is null anyways, but if it isn't null, then this can perhaps be used to help optimize. + * @return + */ + public Class getNativeType() { + return nativeClass; + } } diff --git a/src/main/java/com/laytonsmith/core/constructs/CClosure.java b/src/main/java/com/laytonsmith/core/constructs/CClosure.java index ccb43a6f7..ed7123cc0 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CClosure.java +++ b/src/main/java/com/laytonsmith/core/constructs/CClosure.java @@ -42,7 +42,7 @@ public class CClosure extends Construct implements Callable { protected final CClassType returnType; @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.closure"); + public static final CClassType TYPE = CClassType.get(CClosure.class); public CClosure(ParseTree node, Environment env, CClassType returnType, String[] names, Mixed[] defaults, CClassType[] types, Target t) { @@ -81,7 +81,7 @@ private void condense(ParseTree node, StringBuilder b) { } } b.append(")"); - } else if(node.getData() instanceof CString) { + } else if(node.getData().isInstanceOf(CString.class)) { String data = ArgumentValidation.getString(node.getData(), node.getTarget()); // Convert: \ -> \\ and ' -> \' b.append("'").append(data.replace("\\", "\\\\").replaceAll("\t", "\\\\t").replaceAll("\n", "\\\\n") diff --git a/src/main/java/com/laytonsmith/core/constructs/CDecimal.java b/src/main/java/com/laytonsmith/core/constructs/CDecimal.java index 3885e9d2c..038c2595d 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CDecimal.java +++ b/src/main/java/com/laytonsmith/core/constructs/CDecimal.java @@ -14,7 +14,7 @@ public class CDecimal extends CPrimitive implements Cloneable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.decimal"); + public static final CClassType TYPE = CClassType.get(CDecimal.class); private final BigDecimal val; diff --git a/src/main/java/com/laytonsmith/core/constructs/CDouble.java b/src/main/java/com/laytonsmith/core/constructs/CDouble.java index 6bef448f2..53939ed67 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CDouble.java +++ b/src/main/java/com/laytonsmith/core/constructs/CDouble.java @@ -13,7 +13,7 @@ public class CDouble extends CNumber implements Cloneable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.double"); + public static final CClassType TYPE = CClassType.get(CDouble.class); public static final long serialVersionUID = 1L; final double val; diff --git a/src/main/java/com/laytonsmith/core/constructs/CIClosure.java b/src/main/java/com/laytonsmith/core/constructs/CIClosure.java index e39f0c1fe..20b1d411b 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CIClosure.java +++ b/src/main/java/com/laytonsmith/core/constructs/CIClosure.java @@ -28,7 +28,7 @@ public class CIClosure extends CClosure { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.iclosure"); + public static final CClassType TYPE = CClassType.get(CIClosure.class); public CIClosure(ParseTree node, Environment env, CClassType returnType, String[] names, Mixed[] defaults, CClassType[] types, Target t) { diff --git a/src/main/java/com/laytonsmith/core/constructs/CInt.java b/src/main/java/com/laytonsmith/core/constructs/CInt.java index 813dbf8cc..b2714cf39 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CInt.java +++ b/src/main/java/com/laytonsmith/core/constructs/CInt.java @@ -13,7 +13,7 @@ public class CInt extends CNumber implements Cloneable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.int"); + public static final CClassType TYPE = CClassType.get(CInt.class); public static final long serialVersionUID = 1L; final long val; diff --git a/src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java b/src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java index 905ef5771..fba8c3280 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java +++ b/src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java @@ -8,6 +8,7 @@ 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 java.util.ArrayList; import java.util.List; import java.util.Stack; @@ -19,7 +20,7 @@ public class CMutablePrimitive extends CArray implements Sizeable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.mutable_primitive"); + public static final CClassType TYPE = CClassType.get(CMutablePrimitive.class); private Mixed value = CNull.NULL; @@ -44,7 +45,7 @@ public boolean isDynamic() { * @param t */ public void set(Mixed value, Target t) { - if(value instanceof CArray) { + if(!value.isInstanceOf(ValueType.class)) { throw new CREFormatException("mutable_primitives can only store primitive values.", t); } this.value = value; diff --git a/src/main/java/com/laytonsmith/core/constructs/CNull.java b/src/main/java/com/laytonsmith/core/constructs/CNull.java index e417e3c8d..67420cda4 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CNull.java +++ b/src/main/java/com/laytonsmith/core/constructs/CNull.java @@ -12,7 +12,7 @@ public final class CNull extends Construct implements Cloneable, Booleanish { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("null"); + public static final CClassType TYPE = CClassType.get(CNull.class); public static final long serialVersionUID = 1L; diff --git a/src/main/java/com/laytonsmith/core/constructs/CNumber.java b/src/main/java/com/laytonsmith/core/constructs/CNumber.java index 8610f3f99..4edc77996 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CNumber.java +++ b/src/main/java/com/laytonsmith/core/constructs/CNumber.java @@ -11,7 +11,7 @@ public abstract class CNumber extends CPrimitive { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.number"); + public static final CClassType TYPE = CClassType.get(CNumber.class); public CNumber(String value, ConstructType type, Target t) { super(value, type, t); diff --git a/src/main/java/com/laytonsmith/core/constructs/CPackage.java b/src/main/java/com/laytonsmith/core/constructs/CPackage.java index cf1337641..f9532b969 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CPackage.java +++ b/src/main/java/com/laytonsmith/core/constructs/CPackage.java @@ -18,7 +18,7 @@ public class CPackage extends Construct { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.Package"); + public static final CClassType TYPE = CClassType.get(CPackage.class); public CPackage(Target t, String... parts) { super(StringUtils.Join(parts, CClassType.PATH_SEPARATOR), Construct.ConstructType.IDENTIFIER, t); diff --git a/src/main/java/com/laytonsmith/core/constructs/CPrimitive.java b/src/main/java/com/laytonsmith/core/constructs/CPrimitive.java index 7cb673602..c09d2eef5 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CPrimitive.java +++ b/src/main/java/com/laytonsmith/core/constructs/CPrimitive.java @@ -13,7 +13,7 @@ public abstract class CPrimitive extends Construct implements ValueType, Booleanish { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.primitive"); + public static final CClassType TYPE = CClassType.get(CPrimitive.class); public CPrimitive(String value, ConstructType type, Target t) { super(value, type, t); diff --git a/src/main/java/com/laytonsmith/core/constructs/CResource.java b/src/main/java/com/laytonsmith/core/constructs/CResource.java index 70f190e99..7b7f55b6b 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CResource.java +++ b/src/main/java/com/laytonsmith/core/constructs/CResource.java @@ -16,7 +16,7 @@ public class CResource extends Construct { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.resource"); + public static final CClassType TYPE = CClassType.get(CResource.class); private static final AtomicLong RESOURCE_POOL = new AtomicLong(0); diff --git a/src/main/java/com/laytonsmith/core/constructs/CSecureString.java b/src/main/java/com/laytonsmith/core/constructs/CSecureString.java index 9a096d418..35124f36f 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CSecureString.java +++ b/src/main/java/com/laytonsmith/core/constructs/CSecureString.java @@ -32,7 +32,7 @@ public class CSecureString extends CString { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.secure_string"); + public static final CClassType TYPE = CClassType.get(CSecureString.class); private byte[] encrypted; private Cipher decrypter; diff --git a/src/main/java/com/laytonsmith/core/constructs/CSlice.java b/src/main/java/com/laytonsmith/core/constructs/CSlice.java index 3680ba643..a2441dd30 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CSlice.java +++ b/src/main/java/com/laytonsmith/core/constructs/CSlice.java @@ -24,7 +24,7 @@ public class CSlice extends CArray { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.slice"); + public static final CClassType TYPE = CClassType.get(CSlice.class); private long start; private long finish; diff --git a/src/main/java/com/laytonsmith/core/constructs/CString.java b/src/main/java/com/laytonsmith/core/constructs/CString.java index 7e36f51bf..74470178f 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CString.java +++ b/src/main/java/com/laytonsmith/core/constructs/CString.java @@ -28,7 +28,7 @@ public class CString extends CPrimitive implements Cloneable, com.laytonsmith.core.natives.interfaces.Iterable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.string"); + public static final CClassType TYPE = CClassType.get(CString.class); public CString(String value, Target t) { super(value == null ? "" : value, ConstructType.STRING, t); diff --git a/src/main/java/com/laytonsmith/core/constructs/CVoid.java b/src/main/java/com/laytonsmith/core/constructs/CVoid.java index 41d3179a1..d3970c0cd 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CVoid.java +++ b/src/main/java/com/laytonsmith/core/constructs/CVoid.java @@ -14,7 +14,7 @@ public final class CVoid extends Construct implements Cloneable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("void"); + public static final CClassType TYPE = CClassType.get(CVoid.class); /** * Void values do not normally need to be duplicated, since they are immutable, and for values that have an unknown diff --git a/src/main/java/com/laytonsmith/core/constructs/Construct.java b/src/main/java/com/laytonsmith/core/constructs/Construct.java index 4fea4a60c..e1b3ec847 100644 --- a/src/main/java/com/laytonsmith/core/constructs/Construct.java +++ b/src/main/java/com/laytonsmith/core/constructs/Construct.java @@ -190,7 +190,7 @@ public static String json_encode(Mixed c, Target t) throws MarshalException { } private static Object json_encode0(Mixed c, Target t) throws MarshalException { - if(c instanceof CString || c instanceof Command) { + if(c.isInstanceOf(CString.class) || c instanceof Command) { return c.val(); } else if(c instanceof CVoid) { return ""; @@ -490,13 +490,11 @@ public CClassType typeof() { /** * Returns the typeof for the given class, using the same mechanism as the default. (Whether or not that subtype * overrode the original typeof() method. + * @param that + * @return */ public static CClassType typeof(Mixed that) { - typeof ann = that.getClass().getAnnotation(typeof.class); - if(ann == null) { - throw new IllegalArgumentException("Missing typeof annotation for " + that.getClass()); - } - return CClassType.get(ann.value()); + return CClassType.get(that.getClass()); } /** @@ -554,8 +552,7 @@ public ObjectType getObjectType() { } /** - * By default, all native methodscript objects are public. If this is not true, this method must be overridden. - * + * By default, all native methodscript objects have no modifiers. * @return */ @Override @@ -563,6 +560,11 @@ public Set getObjectModifiers() { return EnumSet.noneOf(ObjectModifier.class); } + /** + * By default, all native methodscript objects are public. If this is not true, this method must be overridden. + * + * @return + */ @Override public AccessModifier getAccessModifier() { return AccessModifier.PUBLIC; @@ -585,7 +587,7 @@ public static boolean isInstanceof(Mixed that, Class type) { // but anyways, for now, just return false. return false; } - return that.typeof().doesExtend(CClassType.get(type.getAnnotation(typeof.class).value())); + return that.typeof().doesExtend(CClassType.get(type)); } @Override diff --git a/src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java b/src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java index 4308b8292..1a50edb68 100644 --- a/src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java +++ b/src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java @@ -100,12 +100,12 @@ public static boolean isInstanceof(Mixed value, CClassType instanceofThis, Envir return isInstanceof(value, instanceofThis.getFQCN(), env); } - private static FullyQualifiedClassName typeof(Class c) { + private static FullyQualifiedClassName typeof(Class c) { typeof type = c.getAnnotation(typeof.class); if(type == null) { return null; } else { - return FullyQualifiedClassName.forFullyQualifiedClass(type.value()); + return FullyQualifiedClassName.forNativeClass(c); } } diff --git a/src/main/java/com/laytonsmith/core/constructs/NativeTypeList.java b/src/main/java/com/laytonsmith/core/constructs/NativeTypeList.java index f61e20d08..53e87056a 100644 --- a/src/main/java/com/laytonsmith/core/constructs/NativeTypeList.java +++ b/src/main/java/com/laytonsmith/core/constructs/NativeTypeList.java @@ -17,7 +17,9 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; /** @@ -39,6 +41,8 @@ public class NativeTypeList { */ public static final String INVALID_INSTANCE_METHOD_NAME = "ConstructInvalidInstance"; + private static final Map INVALID_INSTANCE_CACHE = new ConcurrentHashMap<>(); + /** * Given a simple name of a class, attempts to resolve * within the native types (not user defined types). If the class can't be found, null is returned, @@ -96,22 +100,21 @@ public static Set getNativeTypeList() { for(ClassMirror c : ClassDiscovery.getDefaultInstance() .getClassesWithAnnotationThatExtend(typeof.class, Mixed.class)) { nativeTypes.add((String) c.getAnnotation(typeof.class).getValue("value")); + fqNativeTypes.add(FullyQualifiedClassName.forNativeClass(c.loadClass())); } for(ClassMirror c : ClassDiscovery.getDefaultInstance() .getClassesWithAnnotationThatExtend(MEnum.class, Enum.class)) { String name = (String) c.getAnnotation(MEnum.class).getValue("value"); nativeTypes.add(name); + fqNativeTypes.add(FullyQualifiedClassName.forNativeEnum(c.loadClass())); } for(ClassMirror c : ClassDiscovery.getDefaultInstance() .getClassesWithAnnotationThatExtend(MDynamicEnum.class, DynamicEnum.class)) { String name = (String) c.getAnnotation(MDynamicEnum.class).getValue("value"); nativeTypes.add(name); - } - - for(String s : nativeTypes) { - fqNativeTypes.add(FullyQualifiedClassName.forFullyQualifiedClass(s)); + fqNativeTypes.add(FullyQualifiedClassName.forFullyQualifiedClass(name)); } } } @@ -119,6 +122,9 @@ public static Set getNativeTypeList() { return new HashSet<>(fqNativeTypes); } + + private static final Map> NATIVE_CLASS_CACHE + = new ConcurrentHashMap<>(); /** * Returns the java class for the given MethodScript object name. This cannot return anything of a type more * specific than Mixed. For classes that represent enums, an anonymous subclass of {@link MEnumType} will be @@ -132,6 +138,19 @@ public static Set getNativeTypeList() { * be thrown. */ public static Class getNativeClass(FullyQualifiedClassName fqcn) throws ClassNotFoundException { + if(fqcn.getNativeClass() != null) { + return fqcn.getNativeClass(); + } + // This is super super expensive, so we cannot afford to run this more than once per class. Even more + // ideally, this information should be stored WITH the class, so there's no runtime penalty whatsoever, + // but having a local cache is at least an improvement. + if(NATIVE_CLASS_CACHE.containsKey(fqcn)) { + Class c = NATIVE_CLASS_CACHE.get(fqcn); + if(c == null) { + // Storing null means it can't be found + throw new ClassNotFoundException("Could not find the class of type " + fqcn); + } + } if("auto".equals(fqcn.getFQCN())) { // This is an error, as auto is not a real type, but a meta type. Thus this method should never be called // with this input, and we can give a more specific error message. @@ -141,14 +160,18 @@ public static Class getNativeClass(FullyQualifiedClassName fqcn for(ClassMirror c : ClassDiscovery.getDefaultInstance() .getClassesWithAnnotationThatExtend(typeof.class, Mixed.class)) { if(c.getAnnotation(typeof.class).getProxy(typeof.class).value().equals(fqcn.getFQCN())) { + NATIVE_CLASS_CACHE.put(fqcn, c.loadClass()); return c.loadClass(); } } try { - return getNativeEnumType(fqcn).getClass(); + Class c = getNativeEnumType(fqcn).getClass(); + NATIVE_CLASS_CACHE.put(fqcn, c); + return c; } catch (ClassNotFoundException e) { // } + NATIVE_CLASS_CACHE.put(fqcn, null); throw new ClassNotFoundException("Could not find the class of type " + fqcn); } @@ -269,15 +292,23 @@ public static Class getInterfaceRunnerFor(FullyQ * @throws java.lang.ClassNotFoundException */ public static Mixed getInvalidInstanceForUse(FullyQualifiedClassName fqcn) throws ClassNotFoundException { + if(INVALID_INSTANCE_CACHE.containsKey(fqcn)) { + return INVALID_INSTANCE_CACHE.get(fqcn); + } Class c = getNativeClassOrInterfaceRunner(fqcn); if(ReflectionUtils.hasMethod(c, INVALID_INSTANCE_METHOD_NAME, Mixed.class)) { - return (Mixed) ReflectionUtils.invokeMethod(c, null, INVALID_INSTANCE_METHOD_NAME); + Mixed m = (Mixed) ReflectionUtils.invokeMethod(c, null, INVALID_INSTANCE_METHOD_NAME); + INVALID_INSTANCE_CACHE.put(fqcn, m); + return m; } + Mixed m; if(MEnumType.class.isAssignableFrom(c)) { - return getNativeEnumType(fqcn); + m = getNativeEnumType(fqcn); } else { // Not abstract - return ReflectionUtils.instantiateUnsafe(c); + m = ReflectionUtils.instantiateUnsafe(c); } + INVALID_INSTANCE_CACHE.put(fqcn, m); + return m; } /** @@ -297,8 +328,7 @@ public static Mixed getNativeInvalidInstanceForUse(Class clazz) throw new RuntimeException(clazz + " is missing typeof annotation!"); } try { - return getInvalidInstanceForUse(FullyQualifiedClassName - .forFullyQualifiedClass(clazz.getAnnotation(typeof.class).value())); + return getInvalidInstanceForUse(FullyQualifiedClassName.forNativeClass(clazz)); } catch (ClassNotFoundException e) { throw new Error(e); } diff --git a/src/main/java/com/laytonsmith/core/events/drivers/BlockEvents.java b/src/main/java/com/laytonsmith/core/events/drivers/BlockEvents.java index 66b394987..449088dfc 100644 --- a/src/main/java/com/laytonsmith/core/events/drivers/BlockEvents.java +++ b/src/main/java/com/laytonsmith/core/events/drivers/BlockEvents.java @@ -222,12 +222,12 @@ public void bind(BoundEvent event) { + " is deprecated for \"block\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("type")) { Mixed cid = prefilter.get("type"); - if(cid instanceof CInt) { + if(cid.isInstanceOf(CInt.class)) { int id = (int) ((CInt) cid).getInt(); int data = 0; if(prefilter.containsKey("data")) { Mixed cdata = prefilter.get("data"); - if(cdata instanceof CInt) { + if(cdata.isInstanceOf(CInt.class)) { data = (int) ((CInt) cdata).getInt(); } } @@ -315,7 +315,7 @@ public boolean modifyEvent(String key, Mixed value, BindableEvent e) { } if(key.equals("xp")) { - if(value instanceof CInt) { + if(value.isInstanceOf(CInt.class)) { int xp = Integer.parseInt(value.val()); event.setExpToDrop(xp); return true; @@ -367,12 +367,12 @@ public void bind(BoundEvent event) { + " is deprecated for \"block\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("type")) { Mixed cid = prefilter.get("type"); - if(cid instanceof CInt) { + if(cid.isInstanceOf(CInt.class)) { int id = (int) ((CInt) cid).getInt(); int data = 0; if(prefilter.containsKey("data")) { Mixed cdata = prefilter.get("data"); - if(cdata instanceof CInt) { + if(cdata.isInstanceOf(CInt.class)) { data = (int) ((CInt) cdata).getInt(); } } @@ -462,7 +462,7 @@ public boolean modifyEvent(String key, Mixed value, BindableEvent e) { + " is deprecated for \"block\". Converted to " + mat.getName(), value.getTarget()); return true; } else if(key.equals("type")) { - if(value instanceof CInt) { + if(value.isInstanceOf(CInt.class)) { MCMaterial mat = StaticLayer.GetMaterialFromLegacy((int) ((CInt) value).getInt(), 0); event.getBlock().setType(mat); MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "Mutable data key \"type\" in " + getName() @@ -516,12 +516,12 @@ public void bind(BoundEvent event) { + " is deprecated for \"block\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("type")) { Mixed cid = prefilter.get("type"); - if(cid instanceof CInt) { + if(cid.isInstanceOf(CInt.class)) { int id = (int) ((CInt) cid).getInt(); int data = 0; if(prefilter.containsKey("data")) { Mixed cdata = prefilter.get("data"); - if(cdata instanceof CInt) { + if(cdata.isInstanceOf(CInt.class)) { data = (int) ((CInt) cdata).getInt(); } } @@ -702,12 +702,12 @@ public void bind(BoundEvent event) { + " is deprecated for \"block\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("type")) { Mixed cid = prefilter.get("type"); - if(cid instanceof CInt) { + if(cid.isInstanceOf(CInt.class)) { int id = (int) ((CInt) cid).getInt(); int data = 0; if(prefilter.containsKey("data")) { Mixed cdata = prefilter.get("data"); - if(cdata instanceof CInt) { + if(cdata.isInstanceOf(CInt.class)) { data = (int) ((CInt) cdata).getInt(); } } @@ -727,12 +727,12 @@ public void bind(BoundEvent event) { + " is deprecated for \"toblock\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("totype")) { Mixed cid = prefilter.get("totype"); - if(cid instanceof CInt) { + if(cid.isInstanceOf(CInt.class)) { int id = (int) ((CInt) cid).getInt(); int data = 0; if(prefilter.containsKey("todata")) { Mixed cdata = prefilter.get("todata"); - if(cdata instanceof CInt) { + if(cdata.isInstanceOf(CInt.class)) { data = (int) ((CInt) cdata).getInt(); } } @@ -1168,12 +1168,12 @@ public void bind(BoundEvent event) { + " is deprecated for \"block\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("oldtype")) { Mixed cid = prefilter.get("oldtype"); - if(cid instanceof CInt) { + if(cid.isInstanceOf(CInt.class)) { int id = (int) ((CInt) cid).getInt(); int data = 0; if(prefilter.containsKey("olddata")) { Mixed cdata = prefilter.get("olddata"); - if(cdata instanceof CInt) { + if(cdata.isInstanceOf(CInt.class)) { data = (int) ((CInt) cdata).getInt(); } } @@ -1193,12 +1193,12 @@ public void bind(BoundEvent event) { + " is deprecated for \"newblock\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("newtype")) { Mixed cid = prefilter.get("newtype"); - if(cid instanceof CInt) { + if(cid.isInstanceOf(CInt.class)) { int id = (int) ((CInt) cid).getInt(); int data = 0; if(prefilter.containsKey("newdata")) { Mixed cdata = prefilter.get("newdata"); - if(cdata instanceof CInt) { + if(cdata.isInstanceOf(CInt.class)) { data = (int) ((CInt) cdata).getInt(); } } @@ -1382,7 +1382,7 @@ public void bind(BoundEvent event) { + " is deprecated for \"block\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("oldtype")) { Mixed cid = prefilter.get("oldtype"); - if(cid instanceof CInt) { + if(cid.isInstanceOf(CInt.class)) { int id = (int) ((CInt) cid).getInt(); MCMaterial mat = StaticLayer.GetMaterialFromLegacy(id, 0); if(mat == null) { diff --git a/src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java b/src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java index dbec88fde..aeed0e7d7 100644 --- a/src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java +++ b/src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java @@ -1367,7 +1367,7 @@ public boolean modifyEvent(String key, Mixed value, MCEntityDamageByEntityEvent event = (MCEntityDamageByEntityEvent) e; if(key.equals("amount")) { - if(value instanceof CInt) { + if(value.isInstanceOf(CInt.class)) { event.setDamage(Integer.parseInt(value.val())); return true; @@ -1451,7 +1451,7 @@ public boolean modifyEvent(String key, Mixed value, BindableEvent event) { if(value instanceof CNull) { ete.setTarget(null); return true; - } else if(value instanceof CString) { + } else if(value.isInstanceOf(CString.class)) { MCPlayer p = Static.GetPlayer(value.val(), value.getTarget()); if(p.isOnline()) { @@ -1575,7 +1575,7 @@ public void bind(BoundEvent event) { Map prefilter = event.getPrefilter(); if(prefilter.containsKey("from")) { Mixed type = prefilter.get("from"); - if(type instanceof CString && type.val().contains(":") || ArgumentValidation.isNumber(type)) { + if(type.isInstanceOf(CString.class) && type.val().contains(":") || ArgumentValidation.isNumber(type)) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The 0:0 block format in " + getName() + " is deprecated in \"from\" prefilter.", event.getTarget()); MCItemStack is = Static.ParseItemNotation(null, type.val(), 1, event.getTarget()); @@ -1584,7 +1584,7 @@ public void bind(BoundEvent event) { } if(prefilter.containsKey("to")) { Mixed type = prefilter.get("to"); - if(type instanceof CString && type.val().contains(":") || ArgumentValidation.isNumber(type)) { + if(type.isInstanceOf(CString.class) && type.val().contains(":") || ArgumentValidation.isNumber(type)) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The 0:0 block format in " + getName() + " is deprecated in \"to\" prefilter.", event.getTarget()); MCItemStack is = Static.ParseItemNotation(null, type.val(), 1, event.getTarget()); @@ -1675,7 +1675,7 @@ public void bind(BoundEvent event) { + " is deprecated for \"block\". Converted to " + mat.getName(), event.getTarget()); } else if(prefilter.containsKey("block")) { Mixed ctype = prefilter.get("block"); - if(ctype instanceof CString && ctype.val().contains(":") || ArgumentValidation.isNumber(ctype)) { + if(ctype.isInstanceOf(CString.class) && ctype.val().contains(":") || ArgumentValidation.isNumber(ctype)) { int type; String notation = ctype.val(); int separatorIndex = notation.indexOf(':'); diff --git a/src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java b/src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java index e23a910da..1e3b9fb3c 100644 --- a/src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java +++ b/src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java @@ -88,7 +88,7 @@ public void bind(BoundEvent event) { Map prefilter = event.getPrefilter(); if(prefilter.containsKey("slotitem")) { Mixed type = prefilter.get("slotitem"); - if(type instanceof CString && type.val().contains(":") || ArgumentValidation.isNumber(type)) { + if(type.isInstanceOf(CString.class) && type.val().contains(":") || ArgumentValidation.isNumber(type)) { MCItemStack is = Static.ParseItemNotation(null, prefilter.get("slotitem").val(), 1, event.getTarget()); prefilter.put("slotitem", new CString(is.getType().getName(), event.getTarget())); MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The item notation format for the \"slotitem\" prefilter" @@ -230,7 +230,7 @@ public void bind(BoundEvent event) { Map prefilter = event.getPrefilter(); if(prefilter.containsKey("cursoritem")) { Mixed type = prefilter.get("cursoritem"); - if(type instanceof CString && type.val().contains(":") || ArgumentValidation.isNumber(type)) { + if(type.isInstanceOf(CString.class) && type.val().contains(":") || ArgumentValidation.isNumber(type)) { MCItemStack is = Static.ParseItemNotation(null, prefilter.get("cursoritem").val(), 1, event.getTarget()); prefilter.put("cursoritem", new CString(is.getType().getName(), event.getTarget())); MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The item notation format for the \"cursoritem\" prefilter" @@ -689,7 +689,7 @@ public boolean modifyEvent(String key, Mixed value, BindableEvent event) { int[] expCosts = e.getExpLevelCostsOffered(); for(int i = 0; i <= 2; i++) { - if(cExpCosts.get(i, value.getTarget()) instanceof CInt) { + if(cExpCosts.get(i, value.getTarget()).isInstanceOf(CInt.class)) { expCosts[i] = (int) ((CInt) cExpCosts.get(i, value.getTarget())).getInt(); } else { throw new CREFormatException("Expected an intger at index " + i + "!", value.getTarget()); @@ -810,7 +810,7 @@ public void bind(BoundEvent event) { Map prefilter = event.getPrefilter(); if(prefilter.containsKey("main_hand")) { Mixed type = prefilter.get("main_hand"); - if(type instanceof CString && type.val().contains(":") || ArgumentValidation.isNumber(type)) { + if(type.isInstanceOf(CString.class) && type.val().contains(":") || ArgumentValidation.isNumber(type)) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The item notation format in the \"main_hand\"" + " prefilter in " + getName() + " is deprecated.", event.getTarget()); MCItemStack is = Static.ParseItemNotation(null, prefilter.get("main_hand").val(), 1, event.getTarget()); @@ -819,7 +819,7 @@ public void bind(BoundEvent event) { } if(prefilter.containsKey("off_hand")) { Mixed type = prefilter.get("off_hand"); - if(type instanceof CString && type.val().contains(":") || ArgumentValidation.isNumber(type)) { + if(type.isInstanceOf(CString.class) && type.val().contains(":") || ArgumentValidation.isNumber(type)) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The item notation format in the \"off_hand\"" + " prefilter in " + getName() + " is deprecated.", event.getTarget()); MCItemStack is = Static.ParseItemNotation(null, prefilter.get("off_hand").val(), 1, event.getTarget()); diff --git a/src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java b/src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java index db14e477f..6f8c302f0 100644 --- a/src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java +++ b/src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java @@ -813,7 +813,7 @@ public void bind(BoundEvent event) { } if(prefilter.containsKey("block")) { Mixed ctype = prefilter.get("block"); - if(ctype instanceof CString && ctype.val().contains(":") || ArgumentValidation.isNumber(ctype)) { + if(ctype.isInstanceOf(CString.class) && ctype.val().contains(":") || ArgumentValidation.isNumber(ctype)) { int type; String notation = ctype.val(); int separatorIndex = notation.indexOf(':'); diff --git a/src/main/java/com/laytonsmith/core/events/drivers/VehicleEvents.java b/src/main/java/com/laytonsmith/core/events/drivers/VehicleEvents.java index b59627881..7b7dd1d4e 100644 --- a/src/main/java/com/laytonsmith/core/events/drivers/VehicleEvents.java +++ b/src/main/java/com/laytonsmith/core/events/drivers/VehicleEvents.java @@ -229,7 +229,7 @@ public void bind(BoundEvent event) { Map prefilter = event.getPrefilter(); if(prefilter.containsKey("hittype")) { Mixed type = prefilter.get("hittype"); - if(type instanceof CString && type.val().contains(":") || ArgumentValidation.isNumber(type)) { + if(type.isInstanceOf(CString.class) && type.val().contains(":") || ArgumentValidation.isNumber(type)) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The 0:0 block format in " + getName() + " is deprecated in \"hittype\".", event.getTarget()); MCItemStack is = Static.ParseItemNotation(null, type.val(), 1, event.getTarget()); 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 fe7e9425f..a3f15cac3 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java @@ -87,7 +87,7 @@ public Set getObjectModifiers() { * @return */ public CClassType getExceptionType() { - return CClassType.get(getName()); + return Construct.typeof(this); } /** diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityException.java index ea61e133d..fe48f197e 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityException.java @@ -13,7 +13,7 @@ public class CREBadEntityException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.BadEntityException"); + public static final CClassType TYPE = CClassType.get(CREBadEntityException.class); public CREBadEntityException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityTypeException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityTypeException.java index 0229dc951..d41b5b1ff 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityTypeException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityTypeException.java @@ -13,7 +13,7 @@ public class CREBadEntityTypeException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.BadEntityTypeException"); + public static final CClassType TYPE = CClassType.get(CREBadEntityTypeException.class); public CREBadEntityTypeException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBindException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBindException.java index 9da87a73f..fcbb5b0da 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBindException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREBindException.java @@ -13,7 +13,7 @@ public class CREBindException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.BindException"); + public static final CClassType TYPE = CClassType.get(CREBindException.class); public CREBindException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRECastException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRECastException.java index b7e78c243..834436bc9 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRECastException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRECastException.java @@ -13,7 +13,7 @@ public class CRECastException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.CastException"); + public static final CClassType TYPE = CClassType.get(CRECastException.class); public CRECastException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREClassDefinitionError.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREClassDefinitionError.java index 74dc9c659..fec6573b9 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREClassDefinitionError.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREClassDefinitionError.java @@ -13,7 +13,7 @@ @typeof("ms.lang.ClassDefinitionError") public class CREClassDefinitionError extends CREError { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.ClassDefinitionError"); + public static final CClassType TYPE = CClassType.get(CREClassDefinitionError.class); public CREClassDefinitionError(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREEnchantmentException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREEnchantmentException.java index 25c83c70b..45ce8bcbe 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREEnchantmentException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREEnchantmentException.java @@ -13,7 +13,7 @@ public class CREEnchantmentException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.EnchantmentException"); + public static final CClassType TYPE = CClassType.get(CREEnchantmentException.class); public CREEnchantmentException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREError.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREError.java index a73f3a723..f4a6b58e0 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREError.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREError.java @@ -13,7 +13,7 @@ public class CREError extends CREThrowable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.Error"); + public static final CClassType TYPE = CClassType.get(CREError.class); public CREError(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREEventException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREEventException.java index f7df96ebe..c7790c897 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREEventException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREEventException.java @@ -13,7 +13,7 @@ public class CREEventException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.EventException"); + public static final CClassType TYPE = CClassType.get(CREEventException.class); public CREEventException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREException.java index 57aa05cf2..cb1652bee 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREException.java @@ -13,7 +13,7 @@ public class CREException extends CREThrowable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.Exception"); + public static final CClassType TYPE = CClassType.get(CREException.class); public CREException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREFormatException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREFormatException.java index d0220f772..2305b968e 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREFormatException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREFormatException.java @@ -13,7 +13,7 @@ public class CREFormatException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.FormatException"); + public static final CClassType TYPE = CClassType.get(CREFormatException.class); public CREFormatException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIOException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIOException.java index 0f5bec58a..76f9d77cf 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIOException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIOException.java @@ -13,7 +13,7 @@ public class CREIOException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.IOException"); + public static final CClassType TYPE = CClassType.get(CREIOException.class); public CREIOException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIllegalArgumentException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIllegalArgumentException.java index c311ccb76..9853b2d52 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIllegalArgumentException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIllegalArgumentException.java @@ -13,7 +13,7 @@ public class CREIllegalArgumentException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.IllegalArgumentException"); + public static final CClassType TYPE = CClassType.get(CREIllegalArgumentException.class); public CREIllegalArgumentException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIncludeException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIncludeException.java index cdff92366..53d4bd402 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIncludeException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIncludeException.java @@ -13,7 +13,7 @@ public class CREIncludeException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.IncludeException"); + public static final CClassType TYPE = CClassType.get(CREIncludeException.class); public CREIncludeException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIndexOverflowException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIndexOverflowException.java index 691d87e13..26fb90dfc 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIndexOverflowException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREIndexOverflowException.java @@ -13,7 +13,7 @@ public class CREIndexOverflowException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.IndexOverflowException"); + public static final CClassType TYPE = CClassType.get(CREIndexOverflowException.class); public CREIndexOverflowException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientArgumentsException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientArgumentsException.java index be51f3de7..1304ba5b8 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientArgumentsException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientArgumentsException.java @@ -13,7 +13,7 @@ public class CREInsufficientArgumentsException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.InsufficientArgumentsException"); + public static final CClassType TYPE = CClassType.get(CREInsufficientArgumentsException.class); public CREInsufficientArgumentsException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientPermissionException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientPermissionException.java index 0d9c16fd4..b141aeaeb 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientPermissionException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientPermissionException.java @@ -13,7 +13,7 @@ public class CREInsufficientPermissionException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.InsufficientPermissionException"); + public static final CClassType TYPE = CClassType.get(CREInsufficientPermissionException.class); public CREInsufficientPermissionException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidPluginException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidPluginException.java index 3c3dca25e..ce2e341f7 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidPluginException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidPluginException.java @@ -13,7 +13,7 @@ public class CREInvalidPluginException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.InvalidPluginException"); + public static final CClassType TYPE = CClassType.get(CREInvalidPluginException.class); public CREInvalidPluginException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidProcedureException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidProcedureException.java index 224ba2239..4e5505da4 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidProcedureException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidProcedureException.java @@ -13,7 +13,7 @@ public class CREInvalidProcedureException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.InvalidProcedureException"); + public static final CClassType TYPE = CClassType.get(CREInvalidProcedureException.class); public CREInvalidProcedureException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidWorldException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidWorldException.java index 40092885b..bd69175b7 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidWorldException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidWorldException.java @@ -13,7 +13,7 @@ public class CREInvalidWorldException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.InvalidWorldException"); + public static final CClassType TYPE = CClassType.get(CREInvalidWorldException.class); public CREInvalidWorldException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRELengthException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRELengthException.java index bd37123f1..a70c100b4 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRELengthException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRELengthException.java @@ -13,7 +13,7 @@ public class CRELengthException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.LengthException"); + public static final CClassType TYPE = CClassType.get(CRELengthException.class); public CRELengthException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRENotFoundException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRENotFoundException.java index af322523b..8a320f46a 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRENotFoundException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRENotFoundException.java @@ -13,7 +13,7 @@ public class CRENotFoundException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.NotFoundException"); + public static final CClassType TYPE = CClassType.get(CRENotFoundException.class); public CRENotFoundException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRENullPointerException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRENullPointerException.java index 0a2079fdd..4e93a674e 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRENullPointerException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRENullPointerException.java @@ -13,7 +13,7 @@ public class CRENullPointerException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.NullPointerException"); + public static final CClassType TYPE = CClassType.get(CRENullPointerException.class); public CRENullPointerException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREOAuthException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREOAuthException.java index 751b0715e..adf0afe0a 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREOAuthException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREOAuthException.java @@ -14,7 +14,7 @@ public class CREOAuthException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.auth.OAuthException"); + public static final CClassType TYPE = CClassType.get(CREOAuthException.class); public CREOAuthException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPlayerOfflineException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPlayerOfflineException.java index 6d7c5ad11..19f52cd0e 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPlayerOfflineException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPlayerOfflineException.java @@ -13,7 +13,7 @@ public class CREPlayerOfflineException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.PlayerOfflineException"); + public static final CClassType TYPE = CClassType.get(CREPlayerOfflineException.class); public CREPlayerOfflineException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginChannelException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginChannelException.java index 96d08f2c3..cae4e2cf2 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginChannelException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginChannelException.java @@ -13,7 +13,7 @@ public class CREPluginChannelException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.PluginChannelException"); + public static final CClassType TYPE = CClassType.get(CREPluginChannelException.class); public CREPluginChannelException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginInternalException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginInternalException.java index c8c1a1f78..5b73cd826 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginInternalException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginInternalException.java @@ -13,7 +13,7 @@ public class CREPluginInternalException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.PluginInternalException"); + public static final CClassType TYPE = CClassType.get(CREPluginInternalException.class); public CREPluginInternalException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRERangeException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRERangeException.java index 704d5bcc2..e866681e8 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRERangeException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRERangeException.java @@ -13,7 +13,7 @@ public class CRERangeException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.RangeException"); + public static final CClassType TYPE = CClassType.get(CRERangeException.class); public CRERangeException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREReadOnlyException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREReadOnlyException.java index 5f47c0428..ee297d536 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREReadOnlyException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREReadOnlyException.java @@ -13,7 +13,7 @@ public class CREReadOnlyException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.ReadOnlyException"); + public static final CClassType TYPE = CClassType.get(CREReadOnlyException.class); public CREReadOnlyException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRESQLException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRESQLException.java index 874eab860..1d8d80ad4 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRESQLException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRESQLException.java @@ -13,7 +13,7 @@ public class CRESQLException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.SQLException"); + public static final CClassType TYPE = CClassType.get(CRESQLException.class); public CRESQLException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREScoreboardException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREScoreboardException.java index 6c35e5b47..afefcf26d 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREScoreboardException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREScoreboardException.java @@ -13,7 +13,7 @@ public class CREScoreboardException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.ScoreboardException"); + public static final CClassType TYPE = CClassType.get(CREScoreboardException.class); public CREScoreboardException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRESecurityException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRESecurityException.java index f94359a49..d4e8c98a1 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CRESecurityException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CRESecurityException.java @@ -13,7 +13,7 @@ public class CRESecurityException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.SecurityException"); + public static final CClassType TYPE = CClassType.get(CRESecurityException.class); public CRESecurityException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREShellException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREShellException.java index 26b2c34dc..98334e864 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREShellException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREShellException.java @@ -13,7 +13,7 @@ public class CREShellException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.ShellException"); + public static final CClassType TYPE = CClassType.get(CREShellException.class); public CREShellException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREStackOverflowError.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREStackOverflowError.java index 81414fa14..7364dd7cd 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREStackOverflowError.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREStackOverflowError.java @@ -13,7 +13,7 @@ public class CREStackOverflowError extends CREError { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.StackOverflowError"); + public static final CClassType TYPE = CClassType.get(CREStackOverflowError.class); public CREStackOverflowError(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREThrowable.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREThrowable.java index 103b2a108..62ccb3718 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREThrowable.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREThrowable.java @@ -17,7 +17,7 @@ public class CREThrowable extends AbstractCREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.Throwable"); + public static final CClassType TYPE = CClassType.get(CREThrowable.class); @ForceImplementation public CREThrowable(String msg, Target t) { @@ -51,7 +51,19 @@ public CClassType[] getSuperclasses() { if(this.getClass() == CREThrowable.class) { return new CClassType[]{Mixed.TYPE}; } else { - return new CClassType[]{CClassType.get(this.getClass().getSuperclass().getAnnotation(typeof.class).value())}; +// try { + return new CClassType[]{ + CClassType.get( + // The superclass of a subclass to this class will always be of type Mixed, + // so this cast will never fail, but we need it to convince the compiler this is ok. + (Class) this.getClass().getSuperclass() + ) + }; +// } catch(ClassNotFoundException ex) { +// throw new Error("Subclasses can reliably return super.getSuperclasses() for this, ONLY if it follows" +// + " the rule that it only has one superclass, and that superclass is the underlying java" +// + " object as well. This appears to be wrong in " + this.getClass()); +// } } } diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnageableMobException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnageableMobException.java index d10b2f950..85b9ca0fb 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnageableMobException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnageableMobException.java @@ -13,7 +13,7 @@ public class CREUnageableMobException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.UnageableMobException"); + public static final CClassType TYPE = CClassType.get(CREUnageableMobException.class); public CREUnageableMobException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnsupportedOperationException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnsupportedOperationException.java index 5837cf4a4..7cdd8c2fe 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnsupportedOperationException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnsupportedOperationException.java @@ -19,7 +19,7 @@ public class CREUnsupportedOperationException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.UnsupportedOperationException"); + public static final CClassType TYPE = CClassType.get(CREUnsupportedOperationException.class); public CREUnsupportedOperationException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUntameableMobException.java b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUntameableMobException.java index e854a5742..b35e20abc 100644 --- a/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUntameableMobException.java +++ b/src/main/java/com/laytonsmith/core/exceptions/CRE/CREUntameableMobException.java @@ -13,7 +13,7 @@ public class CREUntameableMobException extends CREException { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("com.commandhelper.UntameableMobException"); + public static final CClassType TYPE = CClassType.get(CREUntameableMobException.class); public CREUntameableMobException(String msg, Target t) { super(msg, t); diff --git a/src/main/java/com/laytonsmith/core/functions/AbstractFunction.java b/src/main/java/com/laytonsmith/core/functions/AbstractFunction.java index 296ae73c2..ab5e6ef3e 100644 --- a/src/main/java/com/laytonsmith/core/functions/AbstractFunction.java +++ b/src/main/java/com/laytonsmith/core/functions/AbstractFunction.java @@ -155,10 +155,10 @@ public String profileMessage(Mixed... args) { //Arrays take too long to toString, so we don't want to actually toString them here if //we don't need to. b.append(""); - } else if(ccc instanceof CClosure) { + } else if(ccc.isInstanceOf(CClosure.class)) { //The toString of a closure is too long, so let's not output them either. b.append(""); - } else if(ccc instanceof CString) { + } else if(ccc.isInstanceOf(CString.class)) { String val = ccc.val().replace("\\", "\\\\").replace("'", "\\'"); int max = 1000; if(val.length() > max) { diff --git a/src/main/java/com/laytonsmith/core/functions/ArrayHandling.java b/src/main/java/com/laytonsmith/core/functions/ArrayHandling.java index 99812f190..4317c32e9 100644 --- a/src/main/java/com/laytonsmith/core/functions/ArrayHandling.java +++ b/src/main/java/com/laytonsmith/core/functions/ArrayHandling.java @@ -205,7 +205,8 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime return ca.get(index, t); } } catch (ConfigRuntimeException e) { - if(e instanceof CREIndexOverflowException) { + if(e instanceof CREThrowable + && ((CREThrowable) e).isInstanceOf(CREIndexOverflowException.class)) { if(defaultConstruct != null) { return defaultConstruct; } @@ -224,7 +225,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime throw e; } } - } else if(args[0] instanceof ArrayAccess) { + } else if(args[0].isInstanceOf(ArrayAccess.class)) { com.laytonsmith.core.natives.interfaces.Iterable aa = (com.laytonsmith.core.natives.interfaces.Iterable) args[0]; if(index instanceof CSlice) { @@ -291,10 +292,10 @@ public Mixed optimize(Target t, Environment env, Mixed... args) throws ConfigCom if(args.length == 0) { throw new CRECastException("Argument 1 of array_get must be an array", t); } - if(args[0] instanceof ArrayAccess) { + if(args[0].isInstanceOf(ArrayAccess.class)) { ArrayAccess aa = (ArrayAccess) args[0]; if(!aa.canBeAssociative()) { - if(!(args[1] instanceof CInt) && !(args[1] instanceof CSlice)) { + if(!(args[1].isInstanceOf(CInt.class)) && !(args[1] instanceof CSlice)) { throw new ConfigCompileException("Accessing an element as an associative array," + " when it can only accept integers.", t); } @@ -952,7 +953,7 @@ public Boolean runAsync() { @Override public CArray exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { - if(args[0] instanceof CArray && args[1] instanceof CInt) { + if(args[0] instanceof CArray && args[1].isInstanceOf(CInt.class)) { CArray original = (CArray) args[0]; int size = (int) ((CInt) args[1]).getInt(); Mixed fill = CNull.NULL; @@ -1109,7 +1110,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { // As an exception, strings aren't supported here. There's no reason to do this for a string that isn't accidental. - if(args[0] instanceof ArrayAccess && !(args[0] instanceof CString)) { + if(args[0].isInstanceOf(ArrayAccess.class) && !(args[0].isInstanceOf(CString.class))) { ArrayAccess ca = (ArrayAccess) args[0]; CArray ca2 = new CArray(t); for(Mixed c : ca.keySet()) { @@ -1248,7 +1249,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi throw new CREInsufficientArgumentsException("array_merge must be called with at least two parameters", t); } for(Mixed arg : args) { - if(arg instanceof ArrayAccess) { + if(arg.isInstanceOf(ArrayAccess.class)) { com.laytonsmith.core.natives.interfaces.Iterable cur = (com.laytonsmith.core.natives.interfaces.Iterable) arg; if(!cur.isAssociative()) { @@ -1257,7 +1258,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi } } else { for(Mixed key : cur.keySet()) { - if(key instanceof CInt) { + if(key.isInstanceOf(CInt.class)) { newArray.set(key, cur.get((int) ((CInt) key).getInt(), t), t); } else { newArray.set(key, cur.get(key.val(), t), t); @@ -1392,7 +1393,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { - if(!(args[0] instanceof ArrayAccess)) { + if(!(args[0].isInstanceOf(ArrayAccess.class))) { throw new CRECastException("Expecting argument 1 to be an ArrayAccess type object", t); } StringBuilder b = new StringBuilder(); @@ -1517,7 +1518,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi } try { if(args.length == 2) { - if(args[1] instanceof CClosure) { + if(args[1].isInstanceOf(CClosure.class)) { sortType = null; customSort = (CClosure) args[1]; } else { @@ -1576,7 +1577,7 @@ private CArray merge(CArray left, CArray right, CClosure closure, Target t) { int value; if(c instanceof CNull) { value = 0; - } else if(c instanceof CBoolean) { + } else if(c.isInstanceOf(CBoolean.class)) { if(((CBoolean) c).getBoolean()) { value = 1; } else { @@ -2304,7 +2305,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi if(!(args[0] instanceof com.laytonsmith.core.natives.interfaces.Iterable)) { throw new CRECastException("Expecting an array for argument 1", t); } - if(!(args[1] instanceof CClosure)) { + if(!(args[1].isInstanceOf(CClosure.class))) { throw new CRECastException("Expecting a closure for argument 2", t); } array = (com.laytonsmith.core.natives.interfaces.Iterable) args[0]; @@ -3037,7 +3038,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi throw new CREIllegalArgumentException("For associative arrays, only 2 parameters may be provided," + " the comparison mode value is not used.", t); } - if(args[2] instanceof CClosure) { + if(args[2].isInstanceOf(CClosure.class)) { closure = Static.getObject(args[2], t, CClosure.class); } else { mode = ArgumentValidation.getEnum(args[2], ArrayIntersectComparisonMode.class, t); diff --git a/src/main/java/com/laytonsmith/core/functions/BasicLogic.java b/src/main/java/com/laytonsmith/core/functions/BasicLogic.java index dc9116aea..5687acdda 100644 --- a/src/main/java/com/laytonsmith/core/functions/BasicLogic.java +++ b/src/main/java/com/laytonsmith/core/functions/BasicLogic.java @@ -421,7 +421,7 @@ public Mixed execs(Target t, Environment env, Script parent, ParseTree... nodes) if(evalStatement instanceof CSlice) { //More specific subclass of array, we can do more optimal handling here long rangeLeft = ((CSlice) evalStatement).getStart(); long rangeRight = ((CSlice) evalStatement).getFinish(); - if(value instanceof CInt) { + if(value.isInstanceOf(CInt.class)) { long v = Static.getInt(value, t); if((rangeLeft < rangeRight && v >= rangeLeft && v <= rangeRight) || (rangeLeft > rangeRight && v >= rangeRight && v <= rangeLeft) @@ -435,7 +435,7 @@ public Mixed execs(Target t, Environment env, Script parent, ParseTree... nodes) if(inner instanceof CSlice) { long rangeLeft = ((CSlice) inner).getStart(); long rangeRight = ((CSlice) inner).getFinish(); - if(value instanceof CInt) { + if(value.isInstanceOf(CInt.class)) { long v = Static.getInt(value, t); if((rangeLeft < rangeRight && v >= rangeLeft && v <= rangeRight) || (rangeLeft > rangeRight && v >= rangeRight && v <= rangeLeft) @@ -730,7 +730,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil if(value instanceof CSlice) { long rangeLeft = ((CSlice) value).getStart(); long rangeRight = ((CSlice) value).getFinish(); - if(children.get(0).getData() instanceof CInt) { + if(children.get(0).getData().isInstanceOf(CInt.class)) { long v = Static.getInt(children.get(0).getData(), t); if((rangeLeft < rangeRight && v >= rangeLeft && v <= rangeRight) || (rangeLeft > rangeRight && v >= rangeRight && v <= rangeLeft) @@ -990,7 +990,7 @@ public CBoolean exec(Target t, Environment environment, Mixed... args) throws Co throw new CREFormatException(this.getName() + " expects 2 arguments.", t); } if(args[1].typeof().equals(args[0].typeof())) { - if(args[0] instanceof CString && args[1] instanceof CString) { + if(args[0].isInstanceOf(CString.class) && args[1].isInstanceOf(CString.class)) { // Check for actual string equality, so we don't do type massaging // for numeric strings. Thus '2' !== '2.0' return CBoolean.get(args[0].val().equals(args[1].val())); diff --git a/src/main/java/com/laytonsmith/core/functions/BossBar.java b/src/main/java/com/laytonsmith/core/functions/BossBar.java index 35838c1e2..8eb9e5c4d 100644 --- a/src/main/java/com/laytonsmith/core/functions/BossBar.java +++ b/src/main/java/com/laytonsmith/core/functions/BossBar.java @@ -206,9 +206,9 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime if(bar == null) { throw new CRENotFoundException("That boss bar id does not exist.", t); } - if(args[1] instanceof CString) { + if(args[1].isInstanceOf(CString.class)) { bar.setTitle(args[1].val()); - } else if(args[1] instanceof CDouble) { + } else if(args[1].isInstanceOf(CDouble.class)) { try { bar.setProgress(Static.getDouble(args[1], t)); } catch (IllegalArgumentException ex) { diff --git a/src/main/java/com/laytonsmith/core/functions/Cmdline.java b/src/main/java/com/laytonsmith/core/functions/Cmdline.java index 2c746cd40..d65e1b3ff 100644 --- a/src/main/java/com/laytonsmith/core/functions/Cmdline.java +++ b/src/main/java/com/laytonsmith/core/functions/Cmdline.java @@ -1748,7 +1748,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { requireCmdlineMode(environment, this, t); - if(!(args[0] instanceof CClosure)) { + if(!(args[0].isInstanceOf(CClosure.class))) { throw new CRECastException("Expecting a closure for argument 1 of " + getName(), t); } environment.getEnv(GlobalEnv.class).SetCustom("cmdline_prompt", args[0]); diff --git a/src/main/java/com/laytonsmith/core/functions/Commands.java b/src/main/java/com/laytonsmith/core/functions/Commands.java index 21c8112e1..5342a7930 100644 --- a/src/main/java/com/laytonsmith/core/functions/Commands.java +++ b/src/main/java/com/laytonsmith/core/functions/Commands.java @@ -85,7 +85,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi * @param arg */ public static void customExec(Target t, Environment environment, MCCommand cmd, Mixed arg) { - if(arg instanceof CClosure) { + if(arg.isInstanceOf(CClosure.class)) { onTabComplete.remove(cmd.getName()); onTabComplete.put(cmd.getName(), (CClosure) arg); } else { @@ -350,7 +350,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi * @param arg */ public static void customExec(Target t, Environment environment, MCCommand cmd, Mixed arg) { - if(arg instanceof CClosure) { + if(arg.isInstanceOf(CClosure.class)) { onCommand.remove(cmd.getName()); onCommand.put(cmd.getName(), (CClosure) arg); } else { diff --git a/src/main/java/com/laytonsmith/core/functions/Compiler.java b/src/main/java/com/laytonsmith/core/functions/Compiler.java index b48c67c11..7ef84e419 100644 --- a/src/main/java/com/laytonsmith/core/functions/Compiler.java +++ b/src/main/java/com/laytonsmith/core/functions/Compiler.java @@ -456,7 +456,7 @@ public ParseTree optimizeSpecial(List list, boolean returnSConcat) th // Look for typed assignments for(int k = 0; k < list.size(); k++) { - if(list.get(k).getData() instanceof CClassType) { + if(list.get(k).getData().isInstanceOf(CClassType.class)) { if(k == list.size() - 1) { // This is not a typed assignment break; @@ -723,7 +723,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil if(children.size() != 1) { throw new ConfigCompileException(getName() + " can only take one parameter", t); } - if(!(children.get(0).getData() instanceof CString)) { + if(!(children.get(0).getData().isInstanceOf(CString.class))) { throw new ConfigCompileException("Only hardcoded strings may be passed into " + getName(), t); } String value = children.get(0).getData().val(); diff --git a/src/main/java/com/laytonsmith/core/functions/Crypto.java b/src/main/java/com/laytonsmith/core/functions/Crypto.java index f7e8586b7..f3484656d 100644 --- a/src/main/java/com/laytonsmith/core/functions/Crypto.java +++ b/src/main/java/com/laytonsmith/core/functions/Crypto.java @@ -59,7 +59,7 @@ private static CString getHMAC(String algorithm, Target t, Mixed[] args) { private static byte[] getByteArrayFromArg(Mixed c) { byte[] val; - if(c instanceof CSecureString) { + if(c.isInstanceOf(CSecureString.class)) { val = ArrayUtils.charToBytes(((CSecureString) c).getDecryptedCharArray()); } else { val = c.val().getBytes(); @@ -448,7 +448,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi } try { String val; - if(args[0] instanceof CSecureString) { + if(args[0].isInstanceOf(CSecureString.class)) { val = new String(((CSecureString) args[0]).getDecryptedCharArray()); } else { val = args[0].val(); @@ -519,7 +519,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { String val; - if(args[0] instanceof CSecureString) { + if(args[0].isInstanceOf(CSecureString.class)) { val = new String(((CSecureString) args[0]).getDecryptedCharArray()); } else { val = args[0].val(); diff --git a/src/main/java/com/laytonsmith/core/functions/DataHandling.java b/src/main/java/com/laytonsmith/core/functions/DataHandling.java index 53be55dce..dfe360749 100644 --- a/src/main/java/com/laytonsmith/core/functions/DataHandling.java +++ b/src/main/java/com/laytonsmith/core/functions/DataHandling.java @@ -185,7 +185,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil String v; if(value instanceof IVariable) { v = ((IVariable) value).getVariableName(); - } else if(value instanceof CString) { + } else if(value.isInstanceOf(CString.class)) { v = ((CString) value).getQuote(); } else { v = "@value"; @@ -365,7 +365,7 @@ public Mixed optimize(Target t, Environment env, Mixed... args) throws ConfigCom int offset = 0; if(args.length == 3) { offset = 1; - if(!(args[0] instanceof CClassType)) { + if(!(args[0].isInstanceOf(CClassType.class))) { throw new ConfigCompileException("Expecting a ClassType for parameter 1 to assign", t); } } @@ -1456,7 +1456,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil + " be hard coded, and should not be dynamically determinable, since this is always a sign" + " of loose code flow, which should be avoided.", t); } - if(!(children.get(0).getData() instanceof CInt)) { + if(!(children.get(0).getData().isInstanceOf(CInt.class))) { throw new ConfigCompileException("break() only accepts integer values.", t); } } @@ -1637,7 +1637,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { - return CBoolean.get(args[0] instanceof CString); + return CBoolean.get(args[0].isInstanceOf(CString.class)); } @Override @@ -1696,7 +1696,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { - return CBoolean.get(args[0] instanceof CByteArray); + return CBoolean.get(args[0].isInstanceOf(CByteArray.class)); } @Override @@ -1818,7 +1818,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { - return CBoolean.get(args[0] instanceof CInt || args[0] instanceof CDouble); + return CBoolean.get(args[0].isInstanceOf(CInt.class) || args[0].isInstanceOf(CDouble.class)); } @Override @@ -1881,7 +1881,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { - return CBoolean.get(args[0] instanceof CDouble); + return CBoolean.get(args[0].isInstanceOf(CDouble.class)); } @Override @@ -1942,7 +1942,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { - return CBoolean.get(args[0] instanceof CInt); + return CBoolean.get(args[0].isInstanceOf(CInt.class)); } @Override @@ -2002,7 +2002,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { - return CBoolean.get(args[0] instanceof CBoolean); + return CBoolean.get(args[0].isInstanceOf(CBoolean.class)); } @Override @@ -2284,7 +2284,7 @@ public static Procedure getProcedure(Target t, Environment env, Script parent, P List varNames = new ArrayList<>(); boolean usesAssign = false; CClassType returnType = Auto.TYPE; - if(nodes[0].getData() instanceof CClassType) { + if(nodes[0].getData().isInstanceOf(CClassType.class)) { returnType = (CClassType) nodes[0].getData(); ParseTree[] newNodes = new ParseTree[nodes.length - 1]; for(int i = 1; i < nodes.length; i++) { @@ -2379,7 +2379,7 @@ public static Mixed optimizeProcedure(Target t, Procedure myProc, List()); + FileOptions options = new FileOptions(new HashMap<>()); if(!children.isEmpty()) { options = children.get(0).getFileOptions(); } @@ -2391,7 +2391,8 @@ public static Mixed optimizeProcedure(Target t, Procedure myProc, List optimizationOptions() { public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { // There are two specific cases here where we will give more precise error messages. // If it's a string, yell at them - if(children.get(1).getData() instanceof CString) { + if(children.get(1).getData().isInstanceOf(CString.class)) { throw new ConfigCompileException("Unexpected string type passed to \"instanceof\"", t); } // If it's a variable, also yell at them @@ -4291,7 +4292,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil throw new ConfigCompileException("Variable types are not allowed in \"instanceof\"", t); } // Unknown error, but this is still never valid. - if(!(children.get(1).getData() instanceof CClassType)) { + if(!(children.get(1).getData().isInstanceOf(CClassType.class))) { throw new ConfigCompileException("Unexpected type for \"instanceof\": " + children.get(1).getData(), t); } // null is technically a type, but instanceof shouldn't work with that diff --git a/src/main/java/com/laytonsmith/core/functions/Debug.java b/src/main/java/com/laytonsmith/core/functions/Debug.java index 15a77a5bc..a2da61c12 100644 --- a/src/main/java/com/laytonsmith/core/functions/Debug.java +++ b/src/main/java/com/laytonsmith/core/functions/Debug.java @@ -497,7 +497,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil // throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); // } // Set set = new HashSet(); -// if(args[0] instanceof CString) { +// if(args[0].isInstanceOf(CString.class)) { // if(args[0].val().equals("*")) { // for(Event.Type t : Event.Type.values()) { // set.add(t); @@ -572,7 +572,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil // if(!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { // throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); // } -// if(args[0] instanceof CString) { +// if(args[0].isInstanceOf(CString.class)) { // EVENT_PLUGIN_FILTER.clear(); // EVENT_PLUGIN_FILTER.add(args[0].val().toUpperCase()); // } else if(args[0] instanceof CArray) { diff --git a/src/main/java/com/laytonsmith/core/functions/Echoes.java b/src/main/java/com/laytonsmith/core/functions/Echoes.java index dc896fef1..7bbf6b203 100644 --- a/src/main/java/com/laytonsmith/core/functions/Echoes.java +++ b/src/main/java/com/laytonsmith/core/functions/Echoes.java @@ -796,7 +796,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi if(args.length == 2) { symbol = args[1].val(); } - if(text instanceof CString) { + if(text.isInstanceOf(CString.class)) { String stext = text.val(); StringBuilder b = new StringBuilder(); int sl = symbol.length(); diff --git a/src/main/java/com/laytonsmith/core/functions/Enchantments.java b/src/main/java/com/laytonsmith/core/functions/Enchantments.java index b13956125..1aa96598d 100644 --- a/src/main/java/com/laytonsmith/core/functions/Enchantments.java +++ b/src/main/java/com/laytonsmith/core/functions/Enchantments.java @@ -69,7 +69,7 @@ public static MCEnchantment GetEnchantment(String name, Target t) { * @return */ public static int ConvertLevel(Mixed value) { - if(value instanceof CInt) { + if(value.isInstanceOf(CInt.class)) { return (int) ((CInt) value).getInt(); } String lc = value.val().toLowerCase().trim(); @@ -813,7 +813,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { if(children.size() == 1 - && (children.get(0).getData() instanceof CString || children.get(0).getData() instanceof CInt)) { + && (children.get(0).getData().isInstanceOf(CString.class) || children.get(0).getData().isInstanceOf(CInt.class))) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The string item format in " + getName() + " is deprecated.", t); } return null; diff --git a/src/main/java/com/laytonsmith/core/functions/EntityManagement.java b/src/main/java/com/laytonsmith/core/functions/EntityManagement.java index b49538e11..5c8b2e2a1 100644 --- a/src/main/java/com/laytonsmith/core/functions/EntityManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/EntityManagement.java @@ -1145,7 +1145,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi if(args.length >= 3) { l = ObjectGenerator.GetGenerator().location(args[2], null, t); if(args.length == 4) { - if(args[3] instanceof CClosure) { + if(args[3].isInstanceOf(CClosure.class)) { consumer = (CClosure) args[3]; } else { throw new CREIllegalArgumentException("Expected a closure as last argument for spawn_entity().", t); diff --git a/src/main/java/com/laytonsmith/core/functions/Environment.java b/src/main/java/com/laytonsmith/core/functions/Environment.java index eab8f8dd3..eee473b4b 100644 --- a/src/main/java/com/laytonsmith/core/functions/Environment.java +++ b/src/main/java/com/laytonsmith/core/functions/Environment.java @@ -853,7 +853,7 @@ public ParseTree optimizeDynamic(Target t, com.laytonsmith.core.environments.Env return null; } Mixed c = children.get(children.size() - 1).getData(); - if(c instanceof CString) { + if(c.isInstanceOf(CString.class)) { try { MCBiomeType.valueOf(c.val()); } catch (IllegalArgumentException ex) { @@ -1508,7 +1508,7 @@ public ParseTree optimizeDynamic(Target t, com.laytonsmith.core.environments.Env if(node.getData() instanceof CFunction && node.getData().val().equals("centry")) { children = node.getChildren(); if(children.get(0).getData().val().equals("sound") - && children.get(1).getData() instanceof CString) { + && children.get(1).getData().isInstanceOf(CString.class)) { try { MCSound.MCVanillaSound.valueOf(children.get(1).getData().val().toUpperCase()); } catch (IllegalArgumentException ex) { @@ -2066,7 +2066,7 @@ public Mixed exec(Target t, com.laytonsmith.core.environments.Environment enviro throws ConfigRuntimeException { String cmd = null; if(args.length == 2 && !(args[1] instanceof CNull)) { - if(!(args[1] instanceof CString)) { + if(!(args[1].isInstanceOf(CString.class))) { throw new CRECastException("Parameter 2 of " + getName() + " must be a string or null", t); } cmd = args[1].val(); @@ -2178,7 +2178,7 @@ public Mixed exec(Target t, com.laytonsmith.core.environments.Environment enviro ) throws ConfigRuntimeException { String name = null; if(args.length == 2 && !(args[1] instanceof CNull)) { - if(!(args[1] instanceof CString)) { + if(!(args[1].isInstanceOf(CString.class))) { throw new CRECastException("Parameter 2 of " + getName() + " must be a string or null", t); } name = args[1].val(); diff --git a/src/main/java/com/laytonsmith/core/functions/Exceptions.java b/src/main/java/com/laytonsmith/core/functions/Exceptions.java index a58daf637..4cc48617b 100644 --- a/src/main/java/com/laytonsmith/core/functions/Exceptions.java +++ b/src/main/java/com/laytonsmith/core/functions/Exceptions.java @@ -147,7 +147,7 @@ public Mixed execs(Target t, Environment env, Script that, ParseTree... nodes) { List interest = new ArrayList<>(); if(types != null) { Mixed ptypes = that.seval(types, env); - if(ptypes instanceof CString) { + if(ptypes.isInstanceOf(CString.class)) { interest.add(FullyQualifiedClassName.forName(ptypes.val(), t, env)); } else if(ptypes instanceof CArray) { CArray ca = (CArray) ptypes; @@ -347,7 +347,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { - if(args[0] instanceof CClosure) { + if(args[0].isInstanceOf(CClosure.class)) { CClosure old = environment.getEnv(GlobalEnv.class).GetExceptionHandler(); environment.getEnv(GlobalEnv.class).SetExceptionHandler((CClosure) args[0]); if(old == null) { @@ -530,7 +530,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil // TODO: Eh.. should probably move this check into the keyword, since techincally // catch (Exception @e = null) { } would work. ParseTree assign = children.get(i); - if(assign.getChildAt(0).getData() instanceof CString) { + if(assign.getChildAt(0).getData().isInstanceOf(CString.class)) { // This is an unknown exception type, because otherwise it would have been cast to a CClassType throw new ConfigCompileException("Unknown class type: " + assign.getChildAt(0).getData().val(), t); } diff --git a/src/main/java/com/laytonsmith/core/functions/ExecutionQueue.java b/src/main/java/com/laytonsmith/core/functions/ExecutionQueue.java index 7b9f6c9d3..7296ec6d3 100644 --- a/src/main/java/com/laytonsmith/core/functions/ExecutionQueue.java +++ b/src/main/java/com/laytonsmith/core/functions/ExecutionQueue.java @@ -57,7 +57,7 @@ public Boolean runAsync() { public Mixed exec(Target t, final Environment environment, Mixed... args) throws ConfigRuntimeException { final CClosure c; String queue = null; - if(!(args[0] instanceof CClosure)) { + if(!(args[0].isInstanceOf(CClosure.class))) { throw new CRECastException("Parameter 1 to " + getName() + " must be a closure.", t); } c = ((CClosure) args[0]); @@ -139,7 +139,7 @@ public Boolean runAsync() { public Mixed exec(Target t, final Environment environment, Mixed... args) throws ConfigRuntimeException { final CClosure c; String queue = null; - if(!(args[0] instanceof CClosure)) { + if(!(args[0].isInstanceOf(CClosure.class))) { throw new CRECastException("Parameter 1 to " + getName() + " must be a closure.", t); } c = ((CClosure) args[0]); diff --git a/src/main/java/com/laytonsmith/core/functions/ExtensionMeta.java b/src/main/java/com/laytonsmith/core/functions/ExtensionMeta.java index 9c8a2b36a..dcfc961db 100644 --- a/src/main/java/com/laytonsmith/core/functions/ExtensionMeta.java +++ b/src/main/java/com/laytonsmith/core/functions/ExtensionMeta.java @@ -109,7 +109,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil throw new ConfigCompileException(getName() + " can only accept one argument", t); } - if(!(children.get(0).getData() instanceof CString)) { + if(!(children.get(0).getData().isInstanceOf(CString.class))) { throw new ConfigCompileException(getName() + " can only accept hardcoded string values", t); } @@ -186,7 +186,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil throw new ConfigCompileException(getName() + " can only accept one argument", t); } - if(!(children.get(0).getData() instanceof CString)) { + if(!(children.get(0).getData().isInstanceOf(CString.class))) { throw new ConfigCompileException(getName() + " can only accept hardcoded string values", t); } @@ -256,7 +256,7 @@ public Set optimizationOptions() { public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { if(children.size() != 1) { throw new ConfigCompileException(getName() + " can only accept one argument", t); - } else if(!(children.get(0).getData() instanceof CString)) { + } else if(!(children.get(0).getData().isInstanceOf(CString.class))) { throw new ConfigCompileException(getName() + " can only accept hardcoded string values", t); } else { return new ParseTree(this.exec(t, null, children.get(0).getData()), children.get(0).getFileOptions()); diff --git a/src/main/java/com/laytonsmith/core/functions/FileHandling.java b/src/main/java/com/laytonsmith/core/functions/FileHandling.java index f1fd5441d..0c187817f 100644 --- a/src/main/java/com/laytonsmith/core/functions/FileHandling.java +++ b/src/main/java/com/laytonsmith/core/functions/FileHandling.java @@ -245,7 +245,7 @@ public Mixed exec(final Target t, final Environment environment, Mixed... args) startup(); final String file = args[0].val(); final CClosure callback; - if(!(args[1] instanceof CClosure)) { + if(!(args[1].isInstanceOf(CClosure.class))) { throw new CRECastException("Expected paramter 2 of " + getName() + " to be a closure!", t); } else { callback = ((CClosure) args[1]); diff --git a/src/main/java/com/laytonsmith/core/functions/InventoryManagement.java b/src/main/java/com/laytonsmith/core/functions/InventoryManagement.java index bf2f72f60..751728ea8 100644 --- a/src/main/java/com/laytonsmith/core/functions/InventoryManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/InventoryManagement.java @@ -701,7 +701,7 @@ public MSVersion since() { @Override public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { - if(children.size() > 0 && children.get(children.size() - 1).getData() instanceof CString) { + if(children.size() > 0 && children.get(children.size() - 1).getData().isInstanceOf(CString.class)) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The string item format in " + getName() + " is deprecated.", t); } return null; @@ -809,7 +809,7 @@ public MSVersion since() { @Override public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { - if(children.size() > 0 && children.get(children.size() - 1).getData() instanceof CString) { + if(children.size() > 0 && children.get(children.size() - 1).getData().isInstanceOf(CString.class)) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The string item format in " + getName() + " is deprecated.", t); } return null; @@ -877,7 +877,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi itemOffset = 1; } } else if(args.length == 3) { - if(args[0] instanceof CString) { // we assume player here, apparently + if(args[0].isInstanceOf(CString.class)) { // we assume player here, apparently itemOffset = 1; } } else if(args.length == 4) { @@ -926,7 +926,7 @@ public MSVersion since() { public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { if(children.size() > 2 || children.size() == 2 - && (children.get(1).getData() instanceof CString || children.get(1).getData() instanceof CInt)) { + && (children.get(1).getData().isInstanceOf(CString.class) || children.get(1).getData().isInstanceOf(CInt.class))) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The string item format in " + getName() + " is deprecated.", t); } return null; @@ -1045,7 +1045,7 @@ public MSVersion since() { public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { if(children.size() > 2 || children.size() == 2 - && (children.get(1).getData() instanceof CString || children.get(1).getData() instanceof CInt)) { + && (children.get(1).getData().isInstanceOf(CString.class) || children.get(1).getData().isInstanceOf(CInt.class))) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The string item format in " + getName() + " is deprecated.", t); } return null; @@ -1112,7 +1112,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi itemOffset = 1; } } else if(args.length == 3) { - if(args[0] instanceof CString) { // we assume player here, apparently + if(args[0].isInstanceOf(CString.class)) { // we assume player here, apparently itemOffset = 1; } } else if(args.length == 4) { @@ -1159,7 +1159,7 @@ public MSVersion since() { public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { if(children.size() > 2 || children.size() == 2 - && (children.get(1).getData() instanceof CString || children.get(1).getData() instanceof CInt)) { + && (children.get(1).getData().isInstanceOf(CString.class) || children.get(1).getData().isInstanceOf(CInt.class))) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The string item format in " + getName() + " is deprecated.", t); } return null; @@ -1276,7 +1276,7 @@ public MSVersion since() { public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { if(children.size() > 2 || children.size() == 2 - && (children.get(1).getData() instanceof CString || children.get(1).getData() instanceof CInt)) { + && (children.get(1).getData().isInstanceOf(CString.class) || children.get(1).getData().isInstanceOf(CInt.class))) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "The string item format in " + getName() + " is deprecated.", t); } return null; @@ -2584,7 +2584,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime int size = 54; String title = null; if(args.length > 1) { - if(args[1] instanceof CNumber) { + if(args[1].isInstanceOf(CNumber.class)) { size = Static.getInt32(args[1], t); if(size < 9) { size = 9; // minimum diff --git a/src/main/java/com/laytonsmith/core/functions/Marquee.java b/src/main/java/com/laytonsmith/core/functions/Marquee.java index d6932f1f0..b02f14344 100644 --- a/src/main/java/com/laytonsmith/core/functions/Marquee.java +++ b/src/main/java/com/laytonsmith/core/functions/Marquee.java @@ -68,7 +68,7 @@ public Mixed exec(final Target t, Environment environment, Mixed... args) throws text = args[1 + offset].val(); stringWidth = Static.getInt32(args[2 + offset], t); delayTime = Static.getInt32(args[3 + offset], t); - if(args[4 + offset] instanceof CClosure) { + if(args[4 + offset].isInstanceOf(CClosure.class)) { callback = ((CClosure) args[4 + offset]); } else { throw new CRECastException("Expected argument " + (4 + offset + 1) + " to be a closure, but was not.", t); diff --git a/src/main/java/com/laytonsmith/core/functions/Math.java b/src/main/java/com/laytonsmith/core/functions/Math.java index 6c543eb9d..ea4bbb0ff 100644 --- a/src/main/java/com/laytonsmith/core/functions/Math.java +++ b/src/main/java/com/laytonsmith/core/functions/Math.java @@ -523,7 +523,7 @@ protected static Mixed doIncrementDecrement(ParseTree[] nodes, } long delta = Static.getInt(cdelta, t); //First, error check, then get the old value, and store it in temp. - if(!(array instanceof CArray) && !(array instanceof ArrayAccess)) { + if(!(array instanceof CArray) && !(array.isInstanceOf(ArrayAccess.class))) { //Let's just evaluate this like normal with array_get, so it will //throw the appropriate exception. new ArrayHandling.array_get().exec(t, env, array, index); @@ -539,7 +539,7 @@ protected static Mixed doIncrementDecrement(ParseTree[] nodes, Mixed value = myArray.get(index, t); //Alright, now let's actually perform the increment, and store that in the array. - if(value instanceof CInt) { + if(value.isInstanceOf(CInt.class)) { CInt newVal; if(inc) { newVal = new CInt(Static.getInt(value, t) + delta, t); @@ -552,7 +552,7 @@ protected static Mixed doIncrementDecrement(ParseTree[] nodes, } else { return value; } - } else if(value instanceof CDouble) { + } else if(value.isInstanceOf(CDouble.class)) { CDouble newVal; if(inc) { newVal = new CDouble(Static.getDouble(value, t) + delta, t); @@ -1186,7 +1186,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { - if(args[0] instanceof CInt) { + if(args[0].isInstanceOf(CInt.class)) { return new CInt(java.lang.Math.abs(Static.getInt(args[0], t)), t); } else { return new CDouble(java.lang.Math.abs(Static.getDouble(args[0], t)), t); @@ -2463,7 +2463,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { - if(args[0] instanceof CInt) { + if(args[0].isInstanceOf(CInt.class)) { return new CInt(-(Static.getInt(args[0], t)), t); } else { return new CDouble(-(Static.getDouble(args[0], t)), t); diff --git a/src/main/java/com/laytonsmith/core/functions/Meta.java b/src/main/java/com/laytonsmith/core/functions/Meta.java index 795fdf1de..8ea5331b1 100644 --- a/src/main/java/com/laytonsmith/core/functions/Meta.java +++ b/src/main/java/com/laytonsmith/core/functions/Meta.java @@ -859,7 +859,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { CString s; - if(args[0] instanceof CString) { + if(args[0].isInstanceOf(CString.class)) { s = (CString) args[0]; } else { s = new CString(args[0].val(), t); diff --git a/src/main/java/com/laytonsmith/core/functions/Minecraft.java b/src/main/java/com/laytonsmith/core/functions/Minecraft.java index d033265dc..085fb8ffb 100644 --- a/src/main/java/com/laytonsmith/core/functions/Minecraft.java +++ b/src/main/java/com/laytonsmith/core/functions/Minecraft.java @@ -99,7 +99,7 @@ public Integer[] numArgs() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws CancelCommandException, ConfigRuntimeException { - if(args[0] instanceof CInt) { + if(args[0].isInstanceOf(CInt.class)) { return new CInt(Static.getInt(args[0], t), t); } String c = args[0].val(); @@ -211,7 +211,7 @@ public Boolean runAsync() { public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { int i = -1; int i2 = -1; - if(args[0] instanceof CString) { + if(args[0].isInstanceOf(CString.class)) { //We also accept item notation if(args[0].val().contains(":")) { String[] split = args[0].val().split(":"); @@ -377,7 +377,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil if(children.size() < 1) { return null; } - if(children.get(0).getData() instanceof CString && children.get(0).getData().val().contains(":") + if(children.get(0).getData().isInstanceOf(CString.class) && children.get(0).getData().val().contains(":") || ArgumentValidation.isNumber(children.get(0).getData())) { MSLog.GetLogger().w(MSLog.Tags.DEPRECATION, "Numeric ids are deprecated in max_stack_size()", t); } @@ -477,7 +477,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil return null; } Mixed effect = children.get(1).getData(); - if(effect instanceof CString) { + if(effect.isInstanceOf(CString.class)) { String effectName = effect.val().split(":")[0].toUpperCase(); try { MCEffect.valueOf(effectName); diff --git a/src/main/java/com/laytonsmith/core/functions/MobManagement.java b/src/main/java/com/laytonsmith/core/functions/MobManagement.java index f38a95eb9..a2e27c74b 100644 --- a/src/main/java/com/laytonsmith/core/functions/MobManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/MobManagement.java @@ -711,7 +711,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime MCLivingEntity mob = Static.getLivingEntity(args[0], t); MCPotionEffectType type = null; - if(args[1] instanceof CString) { + if(args[1].isInstanceOf(CString.class)) { try { type = MCPotionEffectType.valueOf(args[1].val().toUpperCase()); } catch (IllegalArgumentException ex) { diff --git a/src/main/java/com/laytonsmith/core/functions/Objects.java b/src/main/java/com/laytonsmith/core/functions/Objects.java index 8d635fbcf..1fee418c9 100644 --- a/src/main/java/com/laytonsmith/core/functions/Objects.java +++ b/src/main/java/com/laytonsmith/core/functions/Objects.java @@ -167,7 +167,7 @@ private Mixed evaluateString(ParseTree data, Target t) { if(data.getData() instanceof CNull) { return CNull.NULL; } - if(!(data.getData() instanceof CString)) { + if(!(data.getData().isInstanceOf(CString.class))) { throw new CREClassDefinitionError("Expected a string, but found " + data.getData() + " instead", t); } return data.getData(); diff --git a/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java b/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java index d1c0b30ec..79d8e721a 100644 --- a/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java @@ -1395,7 +1395,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime } } else { //if it's a number, we are setting F. Otherwise, it's a getter for the MCPlayer specified. - if(!(args[0] instanceof CInt)) { + if(!(args[0].isInstanceOf(CInt.class))) { MCPlayer p2 = Static.GetPlayer(args[0], t); l = p2.getLocation(); } @@ -2180,7 +2180,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime MCPlayer m = Static.GetPlayer(args[0].val(), t); MCPotionEffectType type = null; - if(args[1] instanceof CString) { + if(args[1].isInstanceOf(CString.class)) { try { type = MCPotionEffectType.valueOf(args[1].val().toUpperCase()); } catch (IllegalArgumentException ex) { @@ -3314,7 +3314,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi ticks = args[0]; } int tick = 0; - if(ticks instanceof CBoolean) { + if(ticks.isInstanceOf(CBoolean.class)) { boolean value = ((CBoolean) ticks).getBoolean(); if(value) { tick = 20; diff --git a/src/main/java/com/laytonsmith/core/functions/Reflection.java b/src/main/java/com/laytonsmith/core/functions/Reflection.java index b47e72198..34dfc0c37 100644 --- a/src/main/java/com/laytonsmith/core/functions/Reflection.java +++ b/src/main/java/com/laytonsmith/core/functions/Reflection.java @@ -210,14 +210,18 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime Set> enums = ClassDiscovery.getDefaultInstance().getClassesWithAnnotationThatExtend(MEnum.class, Enum.class); Set> dEnums = ClassDiscovery.getDefaultInstance().getClassesWithAnnotationThatExtend(MDynamicEnum.class, DynamicEnum.class); if(args.length == 1) { - //No name provided - for(ClassMirror e : enums) { - String name = (String) e.getAnnotation(MEnum.class).getValue("value"); - a.push(CClassType.get(name), t); - } - for(ClassMirror d : dEnums) { - String name = (String) d.getAnnotation(MDynamicEnum.class).getValue("value"); - a.push(CClassType.get(name), t); + try { + //No name provided + for(ClassMirror e : enums) { + String name = (String) e.getAnnotation(MEnum.class).getValue("value"); + a.push(CClassType.get(FullyQualifiedClassName.forNativeEnum(e.loadClass())), t); + } + for(ClassMirror d : dEnums) { + String name = (String) d.getAnnotation(MDynamicEnum.class).getValue("value"); + a.push(CClassType.get(FullyQualifiedClassName.forFullyQualifiedClass(name)), t); + } + } catch (ClassNotFoundException ex) { + throw new Error(ex); } } else if(args.length == 2) { FullyQualifiedClassName enumName = FullyQualifiedClassName.forName(args[1].val(), t, env); diff --git a/src/main/java/com/laytonsmith/core/functions/ResourceManager.java b/src/main/java/com/laytonsmith/core/functions/ResourceManager.java index 6ac8e2287..9c69f31fd 100644 --- a/src/main/java/com/laytonsmith/core/functions/ResourceManager.java +++ b/src/main/java/com/laytonsmith/core/functions/ResourceManager.java @@ -205,7 +205,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { - if(args[0] instanceof CResource) { + if(args[0].isInstanceOf(CResource.class)) { CResource resource = (CResource) args[0]; if(RESOURCES.containsKey(resource.getId())) { RESOURCES.remove(resource.getId()); diff --git a/src/main/java/com/laytonsmith/core/functions/SQL.java b/src/main/java/com/laytonsmith/core/functions/SQL.java index b29551af3..7e81d3017 100644 --- a/src/main/java/com/laytonsmith/core/functions/SQL.java +++ b/src/main/java/com/laytonsmith/core/functions/SQL.java @@ -195,15 +195,15 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi continue; } try { - if(params[i] instanceof CInt) { + if(params[i].isInstanceOf(CInt.class)) { ps.setLong(i + 1, Static.getInt(params[i], t)); - } else if(params[i] instanceof CDouble) { + } else if(params[i].isInstanceOf(CDouble.class)) { ps.setDouble(i + 1, (Double) Static.getDouble(params[i], t)); - } else if(params[i] instanceof CString) { + } else if(params[i].isInstanceOf(CString.class)) { ps.setString(i + 1, (String) params[i].val()); - } else if(params[i] instanceof CByteArray) { + } else if(params[i].isInstanceOf(CByteArray.class)) { ps.setBytes(i + 1, ((CByteArray) params[i]).asByteArrayCopy()); - } else if(params[i] instanceof CBoolean) { + } else if(params[i].isInstanceOf(CBoolean.class)) { ps.setBoolean(i + 1, ArgumentValidation.getBoolean(params[i], t)); } else { throw new CRECastException("The type " + params[i].getClass().getSimpleName() @@ -326,7 +326,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil + " must use concatenation, and you promise you know what you're doing, you" + " can use " + new unsafe_query().getName() + "() to supress this warning.", t); } - } else if(queryData instanceof CString) { + } else if(queryData.isInstanceOf(CString.class)) { //It's a hard coded query, so we can double check parameter lengths and other things String query = queryData.val(); int count = 0; @@ -347,7 +347,7 @@ public ParseTree optimizeDynamic(Target t, Environment env, List chil //Profile validation will simply ensure that the profile stated is listed in the profiles, //and that a connection can in fact be made. //Also need to figure out how to validate a prepared statement. -// if(children.get(0).isConst() && children.get(0).getData() instanceof CString){ +// if(children.get(0).isConst() && children.get(0).getData().isInstanceOf(CString.class)){ // if(true){ //Prefs.verifyQueries() // String profileName = children.get(0).getData().val(); // SQLProfiles.Profile profile = null; @@ -478,7 +478,7 @@ public Boolean runAsync() { public Mixed exec(final Target t, final Environment environment, Mixed... args) throws ConfigRuntimeException { startup(); Mixed arg = args[args.length - 1]; - if(!(arg instanceof CClosure)) { + if(!(arg.isInstanceOf(CClosure.class))) { throw new CRECastException("The last argument to " + getName() + " must be a closure.", t); } final CClosure closure = ((CClosure) arg); diff --git a/src/main/java/com/laytonsmith/core/functions/Sandbox.java b/src/main/java/com/laytonsmith/core/functions/Sandbox.java index 9b61f4312..6cab27e0d 100644 --- a/src/main/java/com/laytonsmith/core/functions/Sandbox.java +++ b/src/main/java/com/laytonsmith/core/functions/Sandbox.java @@ -603,7 +603,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi } byte[] content; - if(!(args[1] instanceof CByteArray)) { + if(!(args[1].isInstanceOf(CByteArray.class))) { content = args[1].val().getBytes(Charset.forName("UTF-8")); } else { content = ArgumentValidation.getByteArray(args[1], t).asByteArrayCopy(); diff --git a/src/main/java/com/laytonsmith/core/functions/Scheduling.java b/src/main/java/com/laytonsmith/core/functions/Scheduling.java index 8ee0efe21..87934ee83 100644 --- a/src/main/java/com/laytonsmith/core/functions/Scheduling.java +++ b/src/main/java/com/laytonsmith/core/functions/Scheduling.java @@ -275,7 +275,7 @@ public Mixed exec(final Target t, final Environment environment, Mixed... args) offset = 1; delay = Static.getInt(args[1], t); } - if(!(args[1 + offset] instanceof CClosure)) { + if(!(args[1 + offset].isInstanceOf(CClosure.class))) { throw new CRECastException(getName() + " expects a closure to be sent as the second argument", t); } final CClosure c = (CClosure) args[1 + offset]; @@ -364,7 +364,7 @@ public Boolean runAsync() { public Mixed exec(final Target t, final Environment environment, Mixed... args) throws ConfigRuntimeException { final TaskManager taskManager = environment.getEnv(GlobalEnv.class).GetTaskManager(); long time = Static.getInt(args[0], t); - if(!(args[1] instanceof CClosure)) { + if(!(args[1].isInstanceOf(CClosure.class))) { throw new CRECastException(getName() + " expects a closure to be sent as the second argument", t); } final CClosure c = (CClosure) args[1]; @@ -796,10 +796,10 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { //First things first, check the format of the arguments. - if(!(args[0] instanceof CString)) { + if(!(args[0].isInstanceOf(CString.class))) { throw new CRECastException("Expected string for argument 1 in " + getName(), t); } - if(!(args[1] instanceof CClosure)) { + if(!(args[1].isInstanceOf(CClosure.class))) { throw new CRECastException("Expected closure for argument 2 in " + getName(), t); } CronFormat format = validateFormat(args[0].val(), t); @@ -1127,7 +1127,7 @@ public Set optimizationOptions() { @Override public ParseTree optimizeDynamic(Target t, Environment env, List children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException { if(children.get(0).isConst()) { - if(children.get(0).getData() instanceof CString) { + if(children.get(0).getData().isInstanceOf(CString.class)) { validateFormat(children.get(0).getData().val(), t); } } diff --git a/src/main/java/com/laytonsmith/core/functions/StringHandling.java b/src/main/java/com/laytonsmith/core/functions/StringHandling.java index 07bf32b13..eba891bd1 100644 --- a/src/main/java/com/laytonsmith/core/functions/StringHandling.java +++ b/src/main/java/com/laytonsmith/core/functions/StringHandling.java @@ -634,7 +634,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws CancelCommandException, ConfigRuntimeException { - if(args[0] instanceof Sizeable) { + if(args[0].isInstanceOf(Sizeable.class)) { return new CInt(((Sizeable) args[0]).size(), t); } else { return new CInt(args[0].val().length(), t); @@ -696,7 +696,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws CancelCommandException, ConfigRuntimeException { - if(!(args[0] instanceof CString)) { + if(!(args[0].isInstanceOf(CString.class))) { throw new CREFormatException(this.getName() + " expects a string as first argument, but type " + args[0].typeof() + " was found.", t); } @@ -759,7 +759,7 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment env, Mixed... args) throws CancelCommandException, ConfigRuntimeException { - if(!(args[0] instanceof CString)) { + if(!(args[0].isInstanceOf(CString.class))) { throw new CREFormatException(this.getName() + " expects a string as first argument, but type " + args[0].typeof() + " was found.", t); } @@ -2477,10 +2477,10 @@ public Boolean runAsync() { @Override public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { - if(args[0] instanceof CSecureString) { + if(args[0].isInstanceOf(CSecureString.class)) { CSecureString secure = ArgumentValidation.getObject(args[0], t, CSecureString.class); return secure.getDecryptedCharCArray(); - } else if(args[0] instanceof CString) { + } else if(args[0].isInstanceOf(CString.class)) { CArray array = new CArray(Target.UNKNOWN, args[0].val().length()); for(char c : args[0].val().toCharArray()) { array.push(new CString(c, t), t); diff --git a/src/main/java/com/laytonsmith/core/functions/Threading.java b/src/main/java/com/laytonsmith/core/functions/Threading.java index 3d9f49e90..17ddba45c 100644 --- a/src/main/java/com/laytonsmith/core/functions/Threading.java +++ b/src/main/java/com/laytonsmith/core/functions/Threading.java @@ -72,7 +72,7 @@ public Boolean runAsync() { @Override public Mixed exec(final Target t, final Environment environment, Mixed... args) throws ConfigRuntimeException { String id = args[0].val(); - if(!(args[1] instanceof CClosure)) { + if(!(args[1].isInstanceOf(CClosure.class))) { throw new CRECastException("Expected closure for arg 2", t); } final CClosure closure = (CClosure) args[1]; diff --git a/src/main/java/com/laytonsmith/core/functions/Weather.java b/src/main/java/com/laytonsmith/core/functions/Weather.java index 2d208228d..247148e09 100644 --- a/src/main/java/com/laytonsmith/core/functions/Weather.java +++ b/src/main/java/com/laytonsmith/core/functions/Weather.java @@ -141,9 +141,9 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime MCWorld w = null; int duration = -1; if(args.length == 2) { - if(args[1] instanceof CString) { + if(args[1].isInstanceOf(CString.class)) { w = Static.getServer().getWorld(args[1].val()); - } else if(args[1] instanceof CInt) { + } else if(args[1].isInstanceOf(CInt.class)) { duration = Static.getInt32(args[1], t); } else { throw new CREFormatException("", t); diff --git a/src/main/java/com/laytonsmith/core/functions/Web.java b/src/main/java/com/laytonsmith/core/functions/Web.java index 390ed5a7d..1b3a307d1 100644 --- a/src/main/java/com/laytonsmith/core/functions/Web.java +++ b/src/main/java/com/laytonsmith/core/functions/Web.java @@ -231,7 +231,7 @@ public Mixed exec(final Target t, final Environment environment, Mixed... args) final boolean binary; final String textEncoding; boolean useDefaultHeaders = true; - if(args[1] instanceof CClosure) { + if(args[1].isInstanceOf(CClosure.class)) { success = (CClosure) args[1]; error = null; arrayJar = null; @@ -304,7 +304,7 @@ public Mixed exec(final Target t, final Environment environment, Mixed... args) } settings.setComplexParameters(mparams); } else { - if(csettings.get("params", t) instanceof CByteArray) { + if(csettings.get("params", t).isInstanceOf(CByteArray.class)) { CByteArray b = (CByteArray) csettings.get("params", t); settings.setRawParameter(b.asByteArrayCopy()); } else { @@ -327,7 +327,7 @@ public Mixed exec(final Target t, final Environment environment, Mixed... args) } //Only required parameter if(csettings.containsKey("success")) { - if(csettings.get("success", t) instanceof CClosure) { + if(csettings.get("success", t).isInstanceOf(CClosure.class)) { success = (CClosure) csettings.get("success", t); } else { throw new CRECastException("Expecting the success parameter to be a closure.", t); @@ -336,7 +336,7 @@ public Mixed exec(final Target t, final Environment environment, Mixed... args) throw new CRECastException("Missing the success parameter, which is required.", t); } if(csettings.containsKey("error")) { - if(csettings.get("error", t) instanceof CClosure) { + if(csettings.get("error", t).isInstanceOf(CClosure.class)) { error = (CClosure) csettings.get("error", t); } else { throw new CRECastException("Expecting the error parameter to be a closure.", t); @@ -373,7 +373,7 @@ public Mixed exec(final Target t, final Environment environment, Mixed... args) } if(csettings.containsKey("trustStore")) { Mixed trustStore = csettings.get("trustStore", t); - if(trustStore instanceof CBoolean && ArgumentValidation.getBoolean(trustStore, t) == false) { + if(trustStore.isInstanceOf(CBoolean.class) && ArgumentValidation.getBoolean(trustStore, t) == false) { settings.setDisableCertChecking(true); } else if(trustStore instanceof CArray) { CArray trustStoreA = ((CArray) trustStore); @@ -843,7 +843,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi String body = ArgumentValidation.getItemFromArray(options, "body", t, new CString("", t)).val(); Mixed cto = ArgumentValidation.getItemFromArray(options, "to", t, null); CArray to; - if(cto instanceof CString) { + if(cto.isInstanceOf(CString.class)) { to = new CArray(t); to.push(cto, t); } else { @@ -1029,9 +1029,9 @@ public String getName() { * @return */ private Object getContent(Mixed c, Target t) { - if(c instanceof CString) { + if(c.isInstanceOf(CString.class)) { return c.val(); - } else if(c instanceof CByteArray) { + } else if(c.isInstanceOf(CByteArray.class)) { CByteArray cb = (CByteArray) c; return cb.asByteArrayCopy(); } else { diff --git a/src/main/java/com/laytonsmith/core/functions/World.java b/src/main/java/com/laytonsmith/core/functions/World.java index c7c3809d2..bdce7c6f4 100644 --- a/src/main/java/com/laytonsmith/core/functions/World.java +++ b/src/main/java/com/laytonsmith/core/functions/World.java @@ -913,7 +913,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime creator.type(type).environment(environment); } if((args.length >= 4) && !(args[3] instanceof CNull)) { - if(args[3] instanceof CInt) { + if(args[3].isInstanceOf(CInt.class)) { creator.seed(Static.getInt(args[3], t)); } else { creator.seed(args[3].val().hashCode()); diff --git a/src/main/java/com/laytonsmith/core/functions/bash/BashPlatformResolver.java b/src/main/java/com/laytonsmith/core/functions/bash/BashPlatformResolver.java index 75707d22c..52ad6b27d 100644 --- a/src/main/java/com/laytonsmith/core/functions/bash/BashPlatformResolver.java +++ b/src/main/java/com/laytonsmith/core/functions/bash/BashPlatformResolver.java @@ -13,7 +13,7 @@ public class BashPlatformResolver implements PlatformResolver { @Override public String outputConstant(Mixed c) { - if(c instanceof CString) { + if(c.isInstanceOf(CString.class)) { return "\"" + c.val() + "\""; } else if(c instanceof CArray) { throw new RuntimeException("Not implemented yet"); 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 edbd84224..9bbfda594 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixedInterfaceRunner.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixedInterfaceRunner.java @@ -116,7 +116,7 @@ public CClassType getContainingClass() { */ @Override public final CClassType typeof() { - return CClassType.get(getName()); + return Construct.typeof(this); } @Override 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 c7bbf21d7..b9a9acbde 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccess.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccess.java @@ -14,7 +14,7 @@ public interface ArrayAccess extends Mixed { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.ArrayAccess"); + public static final CClassType TYPE = CClassType.get(ArrayAccess.class); /** * Return the mixed at this location. This should throw an exception if the index does not exist. This method will 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 0e1811a45..8074cdd2a 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/Booleanish.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/Booleanish.java @@ -13,7 +13,7 @@ public interface Booleanish extends Mixed { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.Booleanish"); + public static final CClassType TYPE = CClassType.get(Booleanish.class); /** * Returns true if this value is a trueish value. Each implementation is free to define this as they wish. In diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/Iterable.java b/src/main/java/com/laytonsmith/core/natives/interfaces/Iterable.java index 47c6fefa4..87a739b8c 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/Iterable.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/Iterable.java @@ -15,6 +15,6 @@ public interface Iterable extends ArrayAccess, Sizeable { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.Iterable"); + public static final CClassType TYPE = CClassType.get(Iterable.class); } 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 3db5f383e..a2620caaf 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java @@ -39,7 +39,7 @@ public abstract class MEnumType implements Mixed, com.laytonsmith.core.natives.i @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.enum"); + public static final CClassType TYPE = CClassType.get(MEnumType.class); /** * Generates a new MEnumType subclass. 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 89c04bb3c..dea7020f1 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java @@ -20,7 +20,7 @@ public interface Mixed extends Cloneable, Documentation { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.mixed"); + public static final CClassType TYPE = CClassType.get(Mixed.class); public String val(); 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 9755241b3..33cee2f9c 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/Sizeable.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/Sizeable.java @@ -10,7 +10,7 @@ public interface Sizeable extends Mixed { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.Sizeable"); + public static final CClassType TYPE = CClassType.get(Sizeable.class); /** * Returns the size of this object. diff --git a/src/main/java/com/laytonsmith/core/natives/interfaces/ValueType.java b/src/main/java/com/laytonsmith/core/natives/interfaces/ValueType.java index 814e7b417..52017d232 100644 --- a/src/main/java/com/laytonsmith/core/natives/interfaces/ValueType.java +++ b/src/main/java/com/laytonsmith/core/natives/interfaces/ValueType.java @@ -22,7 +22,7 @@ public interface ValueType extends Mixed { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final CClassType TYPE = CClassType.get("ms.lang.ValueType"); + public static final CClassType TYPE = CClassType.get(ValueType.class); /** * Returns a duplicated value of this object. The duplicate MUST be equals(), and it MUST NOT be ref_equals(). The diff --git a/src/test/java/com/laytonsmith/core/constructs/EnumTest.java b/src/test/java/com/laytonsmith/core/constructs/EnumTest.java index 42f817864..bce411f22 100644 --- a/src/test/java/com/laytonsmith/core/constructs/EnumTest.java +++ b/src/test/java/com/laytonsmith/core/constructs/EnumTest.java @@ -59,7 +59,7 @@ public void testEnumTypeIsFound() throws ClassNotFoundException { @Test public void testEnumTypeValueIsCorrect() throws ClassNotFoundException { MEnumType t = NativeTypeList.getNativeEnumType(FullyQualifiedClassName - .forFullyQualifiedClass("ms.lang.ArraySortType")); + .forNativeEnum(CArray.ArraySortType.class)); MEnumTypeValue v = t.values().get(0); assertEquals(0, v.ordinal()); assertEquals("REGULAR", v.name());