- Removed the Transformer classes as transformation-based class detection is too slow

- Finished the RegisterZenClassesTask and applied it to the API & Mod support projects
- Started work on the events API
- Added a mod.info file
- Added mods detection API
This commit is contained in:
Stan Hebben committed 2014-06-25 11:54:08 +02:00
1 parent 8b00ce34b6
commit 0c535134c5
106 files changed
+2111 -444

No files matched your search

@@ -33,6 +33,7 @@ import stanhebben.zenscript.util.ZenPosition;
* @author Stan Hebben
*/
public class TypeExpansion {
private final String type;
private final Map<String, ZenExpandMember> members;
private final Map<String, ZenExpandMember> staticMembers;
private final List<ZenExpandCaster> casters;
@@ -43,8 +44,12 @@ public class TypeExpansion {
/**
* Creates an empty type expansion. Use the expand method to register the
* actual expansions.
*
* @param type type name
*/
public TypeExpansion() {
public TypeExpansion(String type) {
this.type = type;
members = new HashMap<String, ZenExpandMember>();
staticMembers = new HashMap<String, ZenExpandMember>();
casters = new ArrayList<ZenExpandCaster>();
@@ -76,7 +81,7 @@ public class TypeExpansion {
String name = getterAnnotation.value().length() == 0 ? method.getName() : getterAnnotation.value();
if (!members.containsKey(name)) {
members.put(name, new ZenExpandMember());
members.put(name, new ZenExpandMember(type, name));
}
members.get(name).setGetter(new JavaMethod(cls, method, types));
} else if (annotation instanceof ZenSetter) {
@@ -85,7 +90,7 @@ public class TypeExpansion {
String name = setterAnnotation.value().length() == 0 ? method.getName() : setterAnnotation.value();
if (!members.containsKey(name)) {
members.put(name, new ZenExpandMember());
members.put(name, new ZenExpandMember(type, name));
}
members.get(name).setSetter(new JavaMethod(cls, method, types));
} else if (annotation instanceof ZenOperator) {
@@ -140,7 +145,7 @@ public class TypeExpansion {
methodName = methodAnnotation.value();
}
if (!members.containsKey(methodName)) {
members.put(methodName, new ZenExpandMember());
members.put(methodName, new ZenExpandMember(type, methodName));
}
members.get(methodName).addMethod(new JavaMethod(cls, method, types));
} else if (annotation instanceof ZenMethodStatic) {
@@ -150,7 +155,7 @@ public class TypeExpansion {
methodName = methodAnnotation.value();
}
if (!staticMembers.containsKey(methodName)) {
staticMembers.put(methodName, new ZenExpandMember());
staticMembers.put(methodName, new ZenExpandMember(type, methodName));
}
staticMembers.get(methodName).addMethod(new JavaMethod(cls, method, types));
}
@@ -93,8 +93,8 @@ public class ZenTokener extends TokenStream {
public static final int T_IMPORT = 160;
private static final String[] REGEXPS = {
"#[^\n]*\n",
"//[^\n]*\n",
"#[^\n]*[\n\\e]",
"//[^\n]*[\n\\e]",
"/\\*[^\\*]*(\\*^/[^\\*]*)*\\*/",
"[ \t\r\n]*",
"[a-zA-Z_][a-zA-Z_0-9]*",
@@ -296,9 +296,9 @@ public class NFA {
out.add(i);
}
} else {
char from = processChar(stream);
int from = processChar(stream);
if (stream.optional('-')) {
char to = processChar(stream);
int to = processChar(stream);
for (int i = from; i <= to; i++) {
out.add(i);
}
@@ -309,8 +309,9 @@ public class NFA {
}
/* Processes a single character */
private char processChar(CharStream stream) {
private int processChar(CharStream stream) {
if (stream.optional('\\')) {
if (stream.optional('e')) return -1;
if (stream.optional('r')) return '\r';
if (stream.optional('n')) return '\n';
if (stream.optional('t')) return '\t';
@@ -216,6 +216,10 @@ public class TokenStream implements Iterator<Token> {
if (state == 0) throw new TokenException(line, lineOffset, (char)nextChar);
next = process(new Token(value.toString(), dfa.finals[state], new ZenPosition(file, tLine, tLineOffset)));
} else {
if (nextChar < 0 && value.length() == 0) {
return; // happens on comments at the end of files
}
System.out.println("Value: " + value.length() + " characters: " + value);
throw new TokenException(line, lineOffset, (char)nextChar);
}
} catch (IOException ex) {
@@ -24,10 +24,17 @@ import stanhebben.zenscript.util.ZenPosition;
* @author Stan
*/
public class ZenExpandMember {
private final String type;
private final String name;
private JavaMethod getter;
private JavaMethod setter;
private final List<JavaMethod> methods = new ArrayList<JavaMethod>();
public ZenExpandMember(String type, String name) {
this.type = type;
this.name = name;
}
public IPartialExpression instance(ZenPosition position, IEnvironmentGlobal environment, IPartialExpression value) {
return new InstanceGetValue(position, value);
}
@@ -37,16 +44,16 @@ public class ZenExpandMember {
}
public void setGetter(JavaMethod getter) {
if (getter != null) {
throw new RuntimeException("already have a getter");
if (this.getter != null) {
throw new RuntimeException(type + "." + name + " already has a getter");
} else {
this.getter = getter;
}
}
public void setSetter(JavaMethod setter) {
if (setter != null) {
throw new RuntimeException("already have a setter");
if (this.setter != null) {
throw new RuntimeException(type + "." + name + " already has a setter");
} else {
this.setter = setter;
}
@@ -0,0 +1,32 @@
package stanhebben.zenscript.util;
import java.util.Iterator;
/**
*
* @author Stan Hebben
*/
public abstract class MappingIterator<T, U> implements Iterator<U> {
private final Iterator<T> iterator;
public MappingIterator(Iterator<T> iterator) {
this.iterator = iterator;
}
public abstract U map(T value);
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public U next() {
return map(iterator.next());
}
@Override
public void remove() {
iterator.remove();
}
}