-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
CodeGenUtil.java
38 lines (31 loc) · 1.56 KB
/
CodeGenUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.denizenscript.denizencore.utilities.codegen;
import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.utilities.AsciiMatcher;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import org.objectweb.asm.Type;
public class CodeGenUtil {
public static AsciiMatcher TAG_NAME_PERMITTED = new AsciiMatcher(AsciiMatcher.LETTERS_LOWER + AsciiMatcher.LETTERS_UPPER + AsciiMatcher.DIGITS + "_");
public static final String COMMAND_GEN_PACKAGE = "com/denizenscript/_generated_/commands/";
public static final String TAG_GEN_PACKAGE = "com/denizenscript/_generated_/tags/";
public static final String OBJECT_LOCAL_TYPE = "L" + Type.getInternalName(ObjectTag.class) + ";";
public static DynamicClassLoader loader = new DynamicClassLoader();
public static class DynamicClassLoader extends ClassLoader {
public Class<?> define(String className, byte[] bytecode) {
Class<?> clazz = super.defineClass(className, bytecode, 0, bytecode.length);
resolveClass(clazz);
DenizenCore.implementation.saveClassToLoader(clazz);
return clazz;
}
@Override
public Class<?> findClass(String name) throws ClassNotFoundException {
try {
return Class.forName(name);
}
catch (ClassNotFoundException ex) {
Debug.echoError(ex);
return super.findClass(name);
}
}
}
}