Skip to content
Permalink
Browse files

Use isInstanceOf everywhere.

This changes the code everwhere to use .isInstanceof instead of instanceof, since
this is needed for user objects to work. However, the code is *incredibly* slow,
so much so that RandomTests takes 60 seconds on my computer. I added some caches,
but that didn't really work well enough either. So the next thought is to add this
to the jarInfo perhaps, but even still, once user classes are added,that will increase
startup time even more, so I think this has to be solved in a more general way. I think
the next step is to very closely examine the code path of isInstanceOf, and see what
steps are there today, and figure up if any can be removed, replaced with more efficient
mechanisms, or at least further cached.

This will serve as the basis of the continued work on objects, but until this is fixed,
it utterly kills the runtime performance, and simply cannot be merged in to master.
  • Loading branch information...
LadyCailin committed Apr 4, 2019
1 parent b1ad039 commit 0865c21dc5f936b7b2c070cf9b7a98b936412dc3
Showing with 362 additions and 283 deletions.
  1. +14 −0 src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassDiscovery.java
  2. +1 −1 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCCommand.java
  3. +4 −4 src/main/java/com/laytonsmith/core/ArgumentValidation.java
  4. +3 −1 src/main/java/com/laytonsmith/core/MainSandbox.java
  5. +1 −1 src/main/java/com/laytonsmith/core/Method.java
  6. +17 −17 src/main/java/com/laytonsmith/core/ObjectGenerator.java
  7. +9 −3 src/main/java/com/laytonsmith/core/Static.java
  8. +3 −1 src/main/java/com/laytonsmith/core/compiler/OptimizationUtilities.java
  9. +13 −6 src/main/java/com/laytonsmith/core/constructs/CArray.java
  10. +1 −1 src/main/java/com/laytonsmith/core/constructs/CBareString.java
  11. +1 −1 src/main/java/com/laytonsmith/core/constructs/CBoolean.java
  12. +3 −3 src/main/java/com/laytonsmith/core/constructs/CByteArray.java
  13. +9 −3 src/main/java/com/laytonsmith/core/constructs/CClassType.java
  14. +2 −2 src/main/java/com/laytonsmith/core/constructs/CClosure.java
  15. +1 −1 src/main/java/com/laytonsmith/core/constructs/CDecimal.java
  16. +1 −1 src/main/java/com/laytonsmith/core/constructs/CDouble.java
  17. +1 −1 src/main/java/com/laytonsmith/core/constructs/CIClosure.java
  18. +1 −1 src/main/java/com/laytonsmith/core/constructs/CInt.java
  19. +3 −2 src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java
  20. +1 −1 src/main/java/com/laytonsmith/core/constructs/CNull.java
  21. +1 −1 src/main/java/com/laytonsmith/core/constructs/CNumber.java
  22. +1 −1 src/main/java/com/laytonsmith/core/constructs/CPackage.java
  23. +1 −1 src/main/java/com/laytonsmith/core/constructs/CPrimitive.java
  24. +1 −1 src/main/java/com/laytonsmith/core/constructs/CResource.java
  25. +1 −1 src/main/java/com/laytonsmith/core/constructs/CSecureString.java
  26. +1 −1 src/main/java/com/laytonsmith/core/constructs/CSlice.java
  27. +1 −1 src/main/java/com/laytonsmith/core/constructs/CString.java
  28. +1 −1 src/main/java/com/laytonsmith/core/constructs/CVoid.java
  29. +11 −9 src/main/java/com/laytonsmith/core/constructs/Construct.java
  30. +20 −1 src/main/java/com/laytonsmith/core/constructs/NativeTypeList.java
  31. +17 −17 src/main/java/com/laytonsmith/core/events/drivers/BlockEvents.java
  32. +5 −5 src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java
  33. +5 −5 src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java
  34. +1 −1 src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java
  35. +1 −1 src/main/java/com/laytonsmith/core/events/drivers/VehicleEvents.java
  36. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java
  37. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityException.java
  38. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityTypeException.java
  39. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREBindException.java
  40. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CRECastException.java
  41. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREClassDefinitionError.java
  42. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREEnchantmentException.java
  43. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREError.java
  44. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREEventException.java
  45. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREException.java
  46. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREFormatException.java
  47. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREIOException.java
  48. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREIllegalArgumentException.java
  49. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREIncludeException.java
  50. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREIndexOverflowException.java
  51. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientArgumentsException.java
  52. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientPermissionException.java
  53. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidPluginException.java
  54. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidProcedureException.java
  55. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidWorldException.java
  56. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CRELengthException.java
  57. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CRENotFoundException.java
  58. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CRENullPointerException.java
  59. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREOAuthException.java
  60. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREPlayerOfflineException.java
  61. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginChannelException.java
  62. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginInternalException.java
  63. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CRERangeException.java
  64. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREReadOnlyException.java
  65. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CRESQLException.java
  66. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREScoreboardException.java
  67. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CRESecurityException.java
  68. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREShellException.java
  69. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREStackOverflowError.java
  70. +14 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREThrowable.java
  71. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnageableMobException.java
  72. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnsupportedOperationException.java
  73. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREUntameableMobException.java
  74. +2 −2 src/main/java/com/laytonsmith/core/functions/AbstractFunction.java
  75. +14 −13 src/main/java/com/laytonsmith/core/functions/ArrayHandling.java
  76. +4 −4 src/main/java/com/laytonsmith/core/functions/BasicLogic.java
  77. +2 −2 src/main/java/com/laytonsmith/core/functions/BossBar.java
  78. +1 −1 src/main/java/com/laytonsmith/core/functions/Cmdline.java
  79. +2 −2 src/main/java/com/laytonsmith/core/functions/Commands.java
  80. +2 −2 src/main/java/com/laytonsmith/core/functions/Compiler.java
  81. +3 −3 src/main/java/com/laytonsmith/core/functions/Crypto.java
  82. +25 −24 src/main/java/com/laytonsmith/core/functions/DataHandling.java
  83. +2 −2 src/main/java/com/laytonsmith/core/functions/Debug.java
  84. +1 −1 src/main/java/com/laytonsmith/core/functions/Echoes.java
  85. +2 −2 src/main/java/com/laytonsmith/core/functions/Enchantments.java
  86. +1 −1 src/main/java/com/laytonsmith/core/functions/EntityManagement.java
  87. +4 −4 src/main/java/com/laytonsmith/core/functions/Environment.java
  88. +3 −3 src/main/java/com/laytonsmith/core/functions/Exceptions.java
  89. +2 −2 src/main/java/com/laytonsmith/core/functions/ExecutionQueue.java
  90. +3 −3 src/main/java/com/laytonsmith/core/functions/ExtensionMeta.java
  91. +1 −1 src/main/java/com/laytonsmith/core/functions/FileHandling.java
  92. +9 −9 src/main/java/com/laytonsmith/core/functions/InventoryManagement.java
  93. +1 −1 src/main/java/com/laytonsmith/core/functions/Marquee.java
  94. +5 −5 src/main/java/com/laytonsmith/core/functions/Math.java
  95. +1 −1 src/main/java/com/laytonsmith/core/functions/Meta.java
  96. +4 −4 src/main/java/com/laytonsmith/core/functions/Minecraft.java
  97. +1 −1 src/main/java/com/laytonsmith/core/functions/MobManagement.java
  98. +1 −1 src/main/java/com/laytonsmith/core/functions/Objects.java
  99. +3 −3 src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
  100. +14 −8 src/main/java/com/laytonsmith/core/functions/Reflection.java
  101. +1 −1 src/main/java/com/laytonsmith/core/functions/ResourceManager.java
  102. +8 −8 src/main/java/com/laytonsmith/core/functions/SQL.java
  103. +1 −1 src/main/java/com/laytonsmith/core/functions/Sandbox.java
  104. +5 −5 src/main/java/com/laytonsmith/core/functions/Scheduling.java
  105. +5 −5 src/main/java/com/laytonsmith/core/functions/StringHandling.java
  106. +1 −1 src/main/java/com/laytonsmith/core/functions/Threading.java
  107. +2 −2 src/main/java/com/laytonsmith/core/functions/Weather.java
  108. +8 −8 src/main/java/com/laytonsmith/core/functions/Web.java
  109. +1 −1 src/main/java/com/laytonsmith/core/functions/World.java
  110. +1 −1 src/main/java/com/laytonsmith/core/functions/bash/BashPlatformResolver.java
  111. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/AbstractMixedInterfaceRunner.java
  112. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccess.java
  113. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/Booleanish.java
  114. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/Iterable.java
  115. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java
  116. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java
  117. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/Sizeable.java
  118. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/ValueType.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<Class<? extends Annotation>, Set<ConstructorMirror<?>>> constructorAnnotationCache = new HashMap<>();
private final Map<Pair<Class<? extends Annotation>, Class<?>>, Set<ClassMirror<?>>>
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 boolean doesClassExtend(ClassMirror<?> subClass, Class<?> superClass) {
*/
@SuppressWarnings("unchecked")
public <T> Set<ClassMirror<? extends T>> getClassesWithAnnotationThatExtend(Class<? extends Annotation> annotation, Class<T> superClass) {
Pair<Class<? extends Annotation>, 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<ClassMirror<? extends T>>)(Object) classesWithAnnotationThatExtendCache.get(id);
}
Set<ClassMirror<? extends T>> mirrors = new HashSet<>();
for(ClassMirror<?> c : getClassesWithAnnotation(annotation)) {
if(doesClassExtend(c, superClass)) {
@@ -728,6 +741,7 @@ public boolean doesClassExtend(ClassMirror<?> subClass, Class<?> superClass) {
// ourselves here.
mirrors.add(new ClassMirror<>(superClass));
}
classesWithAnnotationThatExtendCache.put(id, (Set<ClassMirror<?>>)(Object)mirrors);
return mirrors;
}

@@ -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) {
@@ -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;
@@ -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");
}

@@ -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;
@@ -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<String> 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 CArray enchants(Map<MCEnchantment, Integer> map, 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);
@@ -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 {
@@ -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) {
@@ -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<Mixed>, 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<Mixed> array;
@@ -622,11 +624,11 @@ private static CArray deepClone(CArray array, Target t, ArrayList<CArray[]> 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<ObjectModifier> getObjectModifiers() {
return EnumSet.of(ObjectModifier.FINAL);
}

@Override
public CClassType[] getSuperclasses() {
return new CClassType[]{Mixed.TYPE};
@@ -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);
@@ -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;

Oops, something went wrong.

0 comments on commit 0865c21

Please sign in to comment.
You can’t perform that action at this time.