mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-19 11:49:05 +00:00
- Continued writing on the IC2 integration code
- Implemented advanced recipes on <*> values - Removed unused ZenScript classes - Continued work on any values - Moved documentation generation to buildSrc - Started work on a jar merging task - Added toString implementation to ingredients - Added stack count to ICraftingInventory - Fixed imports - Added logCommand to the logger to log command output - Implemented memory script provider to load scripts received from the server - Added exception handling for script execution - First attempt at creating a transformer to generate a list of ZenClass and ZenExpansion classes - Added console commands (reload, names, liquids, inventory, hand, oredict) - Added general logic - Fixed item ingredients for wildcard sizes - Implemented selective recipe removal - Fixed null recipe results - Started implementation of player-specific recipes - Removed redundant IC2 mod copy - Other minor fixes
This commit is contained in:
1 parent
f3ea7f7831
commit
489347558f
124 files changed
+3942
-419
No files matched your search
+2
-1
@@ -4,13 +4,14 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.symbols;
|
||||
package stanhebben.zenscript;
|
||||
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.IZenErrorLogger;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.compiler.TypeRegistry;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -29,7 +29,6 @@ import stanhebben.zenscript.definitions.ParsedFunctionArgument;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.statements.Statement;
|
||||
import stanhebben.zenscript.statements.StatementReturn;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolArgument;
|
||||
import stanhebben.zenscript.symbols.SymbolZenStaticMethod;
|
||||
@@ -79,30 +78,9 @@ public class ZenModule {
|
||||
for (ZenParsedFile script : scripts) {
|
||||
ClassWriter clsScript = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
clsScript.visitSource(script.getFileName(), null);
|
||||
EnvironmentClass environmentScript = new EnvironmentClass(clsScript, environmentGlobal);
|
||||
EnvironmentClass environmentScript = new EnvironmentClass(clsScript, script.getEnvironment());
|
||||
|
||||
clsScript.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, script.getClassName(), null, internal(Object.class), new String[] {internal(Runnable.class)});
|
||||
for (Import imprt : script.getImports()) {
|
||||
List<String> name = imprt.getName();
|
||||
IPartialExpression value = environmentGlobal.getValue(name.get(0), imprt.getPosition());
|
||||
for (int i = 1; i < name.size(); i++) {
|
||||
IPartialExpression member = value.getMember(imprt.getPosition(), environmentGlobal, name.get(i));
|
||||
if (member == null) {
|
||||
environmentGlobal.error(imprt.getPosition(), StringUtil.join(name, ".") + " not found");
|
||||
break;
|
||||
}
|
||||
value = member;
|
||||
}
|
||||
IZenSymbol symbol = value.toSymbol();
|
||||
if (symbol == null) {
|
||||
environmentGlobal.error(imprt.getPosition(), StringUtil.join(name, ".") + " is not a valid import");
|
||||
} else {
|
||||
environmentScript.putValue(
|
||||
imprt.getRename() == null
|
||||
? name.get(name.size() - 1)
|
||||
: imprt.getRename(), value.toSymbol());
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, ParsedFunction> function : script.getFunctions().entrySet()) {
|
||||
ParsedFunction fn = function.getValue();
|
||||
@@ -180,7 +158,7 @@ public class ZenModule {
|
||||
* @return compiled module
|
||||
* @throws IOException if the file could not be read
|
||||
*/
|
||||
public static ZenModule compileScriptFile(File single, IZenCompileEnvironment environment) throws IOException {
|
||||
public static ZenModule compileScriptFile(File single, IZenCompileEnvironment environment, ClassLoader baseClassLoader) throws IOException {
|
||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
ClassNameGenerator nameGen = new ClassNameGenerator();
|
||||
EnvironmentGlobal environmentGlobal = new EnvironmentGlobal(
|
||||
@@ -214,7 +192,7 @@ public class ZenModule {
|
||||
output.close();
|
||||
}
|
||||
|
||||
return new ZenModule(classes);
|
||||
return new ZenModule(classes, baseClassLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,7 +205,11 @@ public class ZenModule {
|
||||
* @return compiled module
|
||||
* @throws IOException if the file could not be read properly
|
||||
*/
|
||||
public static ZenModule compileZip(File file, String subdir, IZenCompileEnvironment environment) throws IOException {
|
||||
public static ZenModule compileZip(
|
||||
File file,
|
||||
String subdir,
|
||||
IZenCompileEnvironment environment,
|
||||
ClassLoader baseClassLoader) throws IOException {
|
||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
ClassNameGenerator nameGen = new ClassNameGenerator();
|
||||
EnvironmentGlobal environmentGlobal = new EnvironmentGlobal(
|
||||
@@ -269,7 +251,7 @@ public class ZenModule {
|
||||
output.close();
|
||||
}
|
||||
|
||||
return new ZenModule(classes);
|
||||
return new ZenModule(classes, baseClassLoader);
|
||||
}
|
||||
|
||||
private final Map<String, byte[]> classes;
|
||||
@@ -281,9 +263,9 @@ public class ZenModule {
|
||||
*
|
||||
* @param classes
|
||||
*/
|
||||
public ZenModule(Map<String, byte[]> classes) {
|
||||
public ZenModule(Map<String, byte[]> classes, ClassLoader baseClassLoader) {
|
||||
this.classes = classes;
|
||||
classLoader = new MyClassLoader();
|
||||
classLoader = new MyClassLoader(baseClassLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,10 +323,14 @@ public class ZenModule {
|
||||
* Custom class loader. Loads classes from this module.
|
||||
*/
|
||||
private class MyClassLoader extends ClassLoader {
|
||||
private MyClassLoader(ClassLoader baseClassLoader) {
|
||||
super(baseClassLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
if (classes.containsKey(name)) {
|
||||
return this.defineClass(name, classes.get(name), 0, classes.get(name).length);
|
||||
return defineClass(name, classes.get(name), 0, classes.get(name).length);
|
||||
}
|
||||
|
||||
return super.findClass(name);
|
||||
|
||||
@@ -5,11 +5,15 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static stanhebben.zenscript.ZenTokener.*;
|
||||
import stanhebben.zenscript.compiler.EnvironmentScript;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.definitions.Import;
|
||||
import stanhebben.zenscript.definitions.ParsedFunction;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.statements.Statement;
|
||||
import stanhebben.zenscript.symbols.SymbolType;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
|
||||
/**
|
||||
* Contains a parsed file.
|
||||
@@ -32,6 +36,7 @@ public class ZenParsedFile {
|
||||
private final List<Import> imports;
|
||||
private final Map<String, ParsedFunction> functions;
|
||||
private final List<Statement> statements;
|
||||
private final IEnvironmentGlobal environmentScript;
|
||||
|
||||
/**
|
||||
* Constructs and parses a given file.
|
||||
@@ -48,6 +53,7 @@ public class ZenParsedFile {
|
||||
imports = new ArrayList<Import>();
|
||||
functions = new HashMap<String, ParsedFunction>();
|
||||
statements = new ArrayList<Statement>();
|
||||
environmentScript = new EnvironmentScript(environment);
|
||||
|
||||
tokener.setFile(this);
|
||||
|
||||
@@ -74,20 +80,55 @@ public class ZenParsedFile {
|
||||
imports.add(new Import(start.getPosition(), importName, rename));
|
||||
}
|
||||
|
||||
for (Import imprt : imports) {
|
||||
List<String> name = imprt.getName();
|
||||
IPartialExpression type = null;
|
||||
|
||||
StringBuilder nameSoFar = new StringBuilder();
|
||||
|
||||
for (String part : name) {
|
||||
if (type == null) {
|
||||
nameSoFar.append(part);
|
||||
type = environment.getValue(part, imprt.getPosition());
|
||||
if (type == null) {
|
||||
environment.error(imprt.getPosition(), "could not find package " + type);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
nameSoFar.append('.').append(part);
|
||||
type = type.getMember(imprt.getPosition(), environment, part);
|
||||
if (type == null) {
|
||||
environment.error(imprt.getPosition(), "could not find type or package " + nameSoFar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
environmentScript.putValue(imprt.getRename(), type.toSymbol());
|
||||
} else {
|
||||
environmentScript.putValue(imprt.getRename(), new SymbolType(ZenType.ANY));
|
||||
}
|
||||
}
|
||||
|
||||
while (tokener.hasNext()) {
|
||||
Token next = tokener.peek();
|
||||
if (next.getType() == T_FUNCTION) {
|
||||
ParsedFunction function = ParsedFunction.parse(tokener, environment);
|
||||
ParsedFunction function = ParsedFunction.parse(tokener, environmentScript);
|
||||
if (functions.containsKey(function.getName())) {
|
||||
environment.error(function.getPosition(), "function " + function.getName() + " already exists");
|
||||
}
|
||||
functions.put(function.getName(), function);
|
||||
} else {
|
||||
statements.add(Statement.read(tokener, environment));
|
||||
statements.add(Statement.read(tokener, environmentScript));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnvironmentGlobal getEnvironment() {
|
||||
return environmentScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the output classname for this file.
|
||||
*
|
||||
|
||||
@@ -8,7 +8,6 @@ import stanhebben.zenscript.parser.CompiledDFA;
|
||||
import stanhebben.zenscript.parser.NFA;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.parser.TokenStream;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
|
||||
/**
|
||||
* A tokener is capable of splitting a single file into tokens. It's intended
|
||||
@@ -96,6 +95,7 @@ public class ZenTokener extends TokenStream {
|
||||
private static final String[] REGEXPS = {
|
||||
"#[^\n]*\n",
|
||||
"//[^\n]*\n",
|
||||
"/\\*[^\\*]*(\\*^/[^\\*]*)*\\*/",
|
||||
"[ \t\r\n]*",
|
||||
"[a-zA-Z_][a-zA-Z_0-9]*",
|
||||
"\\-?(0|[1-9][0-9]*)\\.[0-9]+([eE][\\+\\-]?[0-9]+)?",
|
||||
@@ -147,6 +147,7 @@ public class ZenTokener extends TokenStream {
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
T_ID,
|
||||
T_FLOATVALUE,
|
||||
T_INTVALUE,
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import stanhebben.zenscript.IZenErrorLogger;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolLocal;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolLocal;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.compiler;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class EnvironmentScript implements IEnvironmentGlobal {
|
||||
private final IEnvironmentGlobal parent;
|
||||
private final Map<String, IZenSymbol> imports;
|
||||
|
||||
public EnvironmentScript(IEnvironmentGlobal parent) {
|
||||
this.parent = parent;
|
||||
imports = new HashMap<String, IZenSymbol>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenCompileEnvironment getEnvironment() {
|
||||
return parent.getEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeExpansion getExpansion(String name) {
|
||||
return parent.getExpansion(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String makeClassName() {
|
||||
return parent.makeClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsClass(String name) {
|
||||
return parent.containsClass(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putClass(String name, byte[] data) {
|
||||
parent.putClass(name, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getValue(String name, ZenPosition position) {
|
||||
if (imports.containsKey(name)) {
|
||||
return imports.get(name).instance(position);
|
||||
} else {
|
||||
return parent.getValue(name, position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String name, IZenSymbol value) {
|
||||
imports.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType getType(Type type) {
|
||||
return parent.getType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(ZenPosition position, String message) {
|
||||
parent.error(position, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(ZenPosition position, String message) {
|
||||
parent.warning(position, message);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ package stanhebben.zenscript.compiler;
|
||||
import stanhebben.zenscript.IZenErrorLogger;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
|
||||
@@ -33,6 +33,6 @@ public class Import {
|
||||
}
|
||||
|
||||
public String getRename() {
|
||||
return rename;
|
||||
return rename == null ? name.get(name.size() - 1) : rename;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.docs;
|
||||
|
||||
import com.sun.javadoc.MethodDoc;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenCasterDoc {
|
||||
private final MethodDoc method;
|
||||
|
||||
public ZenCasterDoc(MethodDoc method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public MethodDoc getMethod() {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.docs;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenClassDoc {
|
||||
private final ClassDoc cls;
|
||||
private final String name;
|
||||
private final List<ZenExpansionDoc> expansions;
|
||||
|
||||
public ZenClassDoc(ClassDoc cls, String name) {
|
||||
this.cls = cls;
|
||||
this.name = name;
|
||||
expansions = new ArrayList<ZenExpansionDoc>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ClassDoc getDoc() {
|
||||
return cls;
|
||||
}
|
||||
|
||||
public void addExpansion(ZenExpansionDoc expansion) {
|
||||
expansions.add(expansion);
|
||||
}
|
||||
|
||||
public List<ZenExpansionDoc> getExpansions() {
|
||||
return expansions;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.docs;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenExpansionDoc {
|
||||
private final ClassDoc cls;
|
||||
private final String type;
|
||||
|
||||
public ZenExpansionDoc(ClassDoc cls, String type) {
|
||||
this.cls = cls;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public ClassDoc getDoc() {
|
||||
return cls;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.docs;
|
||||
|
||||
import com.sun.javadoc.MethodDoc;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenMethodDoc {
|
||||
private final String name;
|
||||
private final MethodDoc method;
|
||||
private final List<ZenParameterDoc> parameters;
|
||||
|
||||
public ZenMethodDoc(String name, MethodDoc method, List<ZenParameterDoc> parameters) {
|
||||
this.name = name;
|
||||
this.method = method;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public MethodDoc getDoc() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public List<ZenParameterDoc> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.docs;
|
||||
|
||||
import com.sun.javadoc.MethodDoc;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenOperatorDoc {
|
||||
private final String operator;
|
||||
private final MethodDoc method;
|
||||
|
||||
public ZenOperatorDoc(String operator, MethodDoc method) {
|
||||
this.operator = operator;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
public MethodDoc getMethod() {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.docs;
|
||||
|
||||
import com.sun.javadoc.AnnotationDesc;
|
||||
import com.sun.javadoc.Parameter;
|
||||
import com.sun.javadoc.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenParameterDoc {
|
||||
private boolean optional;
|
||||
private final String name;
|
||||
private final Type type;
|
||||
|
||||
public ZenParameterDoc(Parameter parameter) {
|
||||
optional = false;
|
||||
name = parameter.name();
|
||||
type = parameter.type();
|
||||
|
||||
for (AnnotationDesc annotation : parameter.annotations()) {
|
||||
if (annotation.annotationType().qualifiedName().equals("stanhebben.zenscript.annotations.Optional")) {
|
||||
optional = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOptional() {
|
||||
return optional;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.docs;
|
||||
|
||||
import com.sun.javadoc.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenPropertyDoc {
|
||||
private Type type;
|
||||
private String name;
|
||||
private boolean canGet;
|
||||
private boolean canSet;
|
||||
private String[] comment;
|
||||
|
||||
public ZenPropertyDoc(String name, Type type) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isCanGet() {
|
||||
return canGet;
|
||||
}
|
||||
|
||||
public void setCanGet(boolean canGet) {
|
||||
this.canGet = canGet;
|
||||
}
|
||||
|
||||
public boolean isCanSet() {
|
||||
return canSet;
|
||||
}
|
||||
|
||||
public void setCanSet(boolean canSet) {
|
||||
this.canSet = canSet;
|
||||
}
|
||||
|
||||
public String[] getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String[] comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
@@ -1,666 +0,0 @@
|
||||
package stanhebben.zenscript.docs;
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import com.sun.javadoc.AnnotationDesc;
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.LanguageVersion;
|
||||
import com.sun.javadoc.MethodDoc;
|
||||
import com.sun.javadoc.Parameter;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import com.sun.javadoc.Type;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.util.StringUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* Example usage: (from minetweaker API source dir):
|
||||
*
|
||||
* javadoc -doclet stanhebben.zenscript.docs.ZenScriptDoclet -docletpath ..\..\..\..\ZenScript\build\classes\main -cp ..\..\..\..\ZenScript\build\libs\ZenScript.jar -sourcepath . -subpackages minetweaker
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class ZenScriptDoclet {
|
||||
public static boolean start(RootDoc root) {
|
||||
ClassDoc[] classes = root.classes();
|
||||
List<ZenClassDoc> documentedClasses = new ArrayList<ZenClassDoc>();
|
||||
List<ZenExpansionDoc> expansionClasses = new ArrayList<ZenExpansionDoc>();
|
||||
|
||||
for (int i = 0; i < classes.length; ++i) {
|
||||
ClassDoc cls = classes[i];
|
||||
|
||||
for (AnnotationDesc annotation : cls.annotations()) {
|
||||
//String fullName = annotation.annotationType().containingPackage().name() + '.' + annotation.annotationType().name();
|
||||
String fullName = annotation.annotationType().qualifiedName();
|
||||
if (fullName.equals("stanhebben.zenscript.annotations.ZenClass")) {
|
||||
documentedClasses.add(new ZenClassDoc(cls, (String) (annotation.elementValues()[0].value().value())));
|
||||
} else if (fullName.equals("stanhebben.zenscript.annotations.ZenExpansion")) {
|
||||
expansionClasses.add(new ZenExpansionDoc(cls, (String) (annotation.elementValues()[0].value().value())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, ZenClassDoc> classesByName = new HashMap<String, ZenClassDoc>();
|
||||
Map<String, ZenClassDoc> classesByJavaName = new HashMap<String, ZenClassDoc>();
|
||||
|
||||
for (ZenClassDoc documentedClass : documentedClasses) {
|
||||
classesByName.put(documentedClass.getName(), documentedClass);
|
||||
classesByJavaName.put(documentedClass.getDoc().qualifiedName(), documentedClass);
|
||||
}
|
||||
for (ZenExpansionDoc expansion : expansionClasses) {
|
||||
if (classesByName.containsKey(expansion.getType())) {
|
||||
classesByName.get(expansion.getType()).addExpansion(expansion);
|
||||
} else {
|
||||
if (expansion.getType().endsWith("]")) {
|
||||
String baseName = expansion.getType().substring(0, expansion.getType().lastIndexOf('['));
|
||||
if (classesByName.containsKey(baseName)) {
|
||||
classesByName.get(baseName).addExpansion(expansion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Number of classes to document: " + classesByName.size());
|
||||
File output = new File("../../../build/zendoc");
|
||||
if (!output.exists()) output.mkdirs();
|
||||
|
||||
String packageList = buildPackageList(documentedClasses);
|
||||
|
||||
for (ZenClassDoc doc : classesByName.values()) {
|
||||
try {
|
||||
File outputDoc = new File(output, doc.getName().replace('.', '/') + ".html");
|
||||
File outputDocParent = outputDoc.getParentFile();
|
||||
if (!outputDocParent.exists()) outputDocParent.mkdirs();
|
||||
|
||||
Writer writer = new BufferedWriter(new FileWriter(outputDoc));
|
||||
|
||||
String simpleName = doc.getName().substring(doc.getName().lastIndexOf('.') + 1);
|
||||
|
||||
writer.append("<!DOCTYPE html>");
|
||||
writer.append("<html><head>");
|
||||
writer.append("<title>ZenDoc : " + simpleName + "</title>");
|
||||
writer.append("<link rel=\"stylesheet\" href=\"/css/bootstrap.min.css\" />");
|
||||
writer.append("<link rel=\"stylesheet\" href=\"/css/bootstrap-theme.css\" />");
|
||||
writer.append("<link rel=\"stylesheet\" href=\"/css/font-awesome.min.css\" />");
|
||||
writer.append("</head><body>");
|
||||
writer.append("<div class=\"container\"><div class=\"row\">");
|
||||
writer.append(packageList);
|
||||
writer.append("<div class=\"col-md-9\">");
|
||||
|
||||
String pkgName = doc.getName().substring(0, doc.getName().lastIndexOf('.'));
|
||||
writer.append("<div class=\"class-package-name\">");
|
||||
writer.append(pkgName);
|
||||
writer.append("</div>");
|
||||
|
||||
// output class or interface contents
|
||||
writer.append("<h1>");
|
||||
if (doc.getDoc().isInterface()) {
|
||||
writer.append("Interface ");
|
||||
} else {
|
||||
writer.append("Class ");
|
||||
}
|
||||
|
||||
writer.append(doc.getDoc().name()).append("</h1>");
|
||||
if (doc.getDoc().interfaces().length > 0) {
|
||||
writer.append("<div class=\"implemented-interfaces\">implements ");
|
||||
boolean first = true;
|
||||
for (Type itype : doc.getDoc().interfaceTypes()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
writer.append(", ");
|
||||
}
|
||||
|
||||
outputType(writer, itype, classesByJavaName);
|
||||
}
|
||||
writer.append("</div>");
|
||||
}
|
||||
|
||||
writer.append("<hr />");
|
||||
writer.append("<div class=\"documentation-class\">");
|
||||
|
||||
for (String p : StringUtil.splitParagraphs(doc.getDoc().commentText())) {
|
||||
writer.append("<p>");
|
||||
writer.append(p);
|
||||
writer.append("</p>");
|
||||
}
|
||||
|
||||
writer.append("</div>");
|
||||
|
||||
|
||||
if (doc.getDoc().isInterface() && doc.getDoc().methods().length == 1) {
|
||||
// functional interface
|
||||
writer.append("<h2>Functional interface</h2>");
|
||||
|
||||
MethodDoc method = doc.getDoc().methods()[0];
|
||||
writer.append("<div class=\"functional-interface-signature\">");
|
||||
writer.append("function (");
|
||||
|
||||
boolean first = true;
|
||||
for (Parameter parameter : method.parameters()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
writer.append(", ");
|
||||
}
|
||||
ZenParameterDoc paramdoc = new ZenParameterDoc(parameter);
|
||||
writer.append(paramdoc.getName());
|
||||
writer.append(" as ");
|
||||
outputType(writer, paramdoc.getType(), classesByJavaName);
|
||||
}
|
||||
writer.append(") as ");
|
||||
outputType(writer, method.returnType(), classesByJavaName);
|
||||
writer.append("</div>");
|
||||
|
||||
String[] comment = StringUtil.splitParagraphs(method.commentText());
|
||||
for (String line : comment) {
|
||||
writer.append("<p>");
|
||||
writer.append(line);
|
||||
writer.append("</p>");
|
||||
}
|
||||
} else {
|
||||
writer.append("<h2>Member Overview</h2>");
|
||||
|
||||
// collect members
|
||||
|
||||
LinkedHashMap<String, ZenPropertyDoc> instanceProperties = new LinkedHashMap<String, ZenPropertyDoc>();
|
||||
LinkedHashMap<String, ZenPropertyDoc> staticProperties = new LinkedHashMap<String, ZenPropertyDoc>();
|
||||
List<ZenMethodDoc> instanceMethods = new ArrayList<ZenMethodDoc>();
|
||||
List<ZenMethodDoc> staticMethods = new ArrayList<ZenMethodDoc>();
|
||||
List<ZenOperatorDoc> operators = new ArrayList<ZenOperatorDoc>();
|
||||
List<ZenCasterDoc> casters = new ArrayList<ZenCasterDoc>();
|
||||
|
||||
for (MethodDoc method : doc.getDoc().methods()) {
|
||||
for (AnnotationDesc annotation : method.annotations()) {
|
||||
String fullName = annotation.annotationType().qualifiedName();
|
||||
|
||||
if (fullName.equals("stanhebben.zenscript.annotations.ZenMethod")
|
||||
|| fullName.equals("stanhebben.zenscript.annotations.ZenMethodStatic")) {
|
||||
String name = annotation.elementValues().length > 0
|
||||
? (String) (annotation.elementValues()[0].value().value())
|
||||
: "";
|
||||
|
||||
if (name.length() == 0) {
|
||||
name = method.name();
|
||||
}
|
||||
|
||||
List<ZenParameterDoc> parameters = new ArrayList<ZenParameterDoc>();
|
||||
for (Parameter parameter : method.parameters()) {
|
||||
parameters.add(new ZenParameterDoc(parameter));
|
||||
}
|
||||
|
||||
if (method.isStatic()) {
|
||||
staticMethods.add(new ZenMethodDoc(name, method, parameters));
|
||||
} else {
|
||||
instanceMethods.add(new ZenMethodDoc(name, method, parameters));
|
||||
}
|
||||
} else if (fullName.equals("stanhebben.zenscript.annotations.ZenGetter")) {
|
||||
String name = annotation.elementValues().length > 0
|
||||
? (String) (annotation.elementValues()[0].value().value())
|
||||
: "";
|
||||
|
||||
if (name.length() == 0) {
|
||||
name = method.name();
|
||||
}
|
||||
|
||||
Type type = method.returnType();
|
||||
String[] comment = StringUtil.splitParagraphs(method.commentText());
|
||||
|
||||
if (!method.isStatic()) {
|
||||
if (instanceProperties.containsKey(name)) {
|
||||
ZenPropertyDoc property = instanceProperties.get(name);
|
||||
property.setCanGet(true);
|
||||
property.setComment(comment);
|
||||
} else {
|
||||
ZenPropertyDoc property = new ZenPropertyDoc(name, type);
|
||||
property.setCanGet(true);
|
||||
property.setComment(comment);
|
||||
instanceProperties.put(name, property);
|
||||
}
|
||||
} else {
|
||||
if (staticProperties.containsKey(name)) {
|
||||
ZenPropertyDoc property = staticProperties.get(name);
|
||||
property.setCanGet(true);
|
||||
property.setComment(comment);
|
||||
} else {
|
||||
ZenPropertyDoc property = new ZenPropertyDoc(name, type);
|
||||
property.setCanGet(true);
|
||||
property.setComment(comment);
|
||||
staticProperties.put(name, property);
|
||||
}
|
||||
}
|
||||
} else if (fullName.equals("stanhebben.zenscript.annotations.ZenSetter")) {
|
||||
String name = annotation.elementValues().length > 0
|
||||
? (String) (annotation.elementValues()[0].value().value())
|
||||
: "";
|
||||
|
||||
if (name.length() == 0) {
|
||||
name = method.name();
|
||||
}
|
||||
|
||||
Type type = method.parameters()[0].type();
|
||||
String[] comment = StringUtil.splitParagraphs(method.commentText());
|
||||
|
||||
if (!method.isStatic()) {
|
||||
if (instanceProperties.containsKey(name)) {
|
||||
ZenPropertyDoc property = instanceProperties.get(name);
|
||||
property.setCanSet(true);
|
||||
} else {
|
||||
ZenPropertyDoc property = new ZenPropertyDoc(name, type);
|
||||
property.setCanGet(true);
|
||||
property.setComment(comment);
|
||||
instanceProperties.put(name, property);
|
||||
}
|
||||
} else {
|
||||
if (staticProperties.containsKey(name)) {
|
||||
ZenPropertyDoc property = staticProperties.get(name);
|
||||
property.setCanSet(true);
|
||||
} else {
|
||||
ZenPropertyDoc property = new ZenPropertyDoc(name, type);
|
||||
property.setCanGet(true);
|
||||
property.setComment(comment);
|
||||
staticProperties.put(name, property);
|
||||
}
|
||||
}
|
||||
} else if (fullName.equals("stanhebben.zenscript.annotations.ZenOperator")) {
|
||||
String operator = annotation.elementValues()[0].value().value().toString();
|
||||
operators.add(new ZenOperatorDoc(operator, method));
|
||||
} else if (fullName.equals("stanhebben.zenscript.annotations.ZenCaster")) {
|
||||
casters.add(new ZenCasterDoc(method));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ZenExpansionDoc expansion : doc.getExpansions()) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (!staticProperties.isEmpty()) {
|
||||
writer.append("<div class=\"panel panel-info panel-memberlist\">");
|
||||
writer.append("<div class=\"panel-heading\">Static Properties</div>");
|
||||
writer.append("<div class=\"panel-body\">");
|
||||
writer.append("<table class=\"table table-properties table-bordered\"><tbody>");
|
||||
|
||||
String[] names = new String[staticProperties.size()];
|
||||
int namei = 0;
|
||||
for (String name : staticProperties.keySet()) {
|
||||
names[namei++] = name;
|
||||
}
|
||||
Arrays.sort(names);
|
||||
|
||||
for (String name : names) {
|
||||
ZenPropertyDoc property = staticProperties.get(name);
|
||||
|
||||
writer.append("<tr>");
|
||||
writer.append("<td class=\"property-type\">");
|
||||
outputType(writer, property.getType(), classesByJavaName);
|
||||
writer.append("</td>");
|
||||
writer.append("<td>");
|
||||
writer.append("<div class=\"property-name\">");
|
||||
if (!property.isCanSet()) writer.append("<span class=\"fa fa-lock\" style=\"color: #ccc;\" title=\"cannot be set\"></span> ");
|
||||
writer.append("<a href=\"#property-staticvalue\">")
|
||||
.append(property.getName())
|
||||
.append("</a></div>");
|
||||
if (property.getComment() != null && property.getComment().length > 0) {
|
||||
writer.append("<div class=\"property-intro\">")
|
||||
.append(property.getComment()[0])
|
||||
.append("</div>");
|
||||
}
|
||||
writer.append("</td></tr>");
|
||||
}
|
||||
|
||||
writer.append("</tbody></table></div></div>");
|
||||
}
|
||||
|
||||
if (!instanceProperties.isEmpty()) {
|
||||
writer.append("<div class=\"panel panel-info panel-memberlist\">");
|
||||
writer.append("<div class=\"panel-heading\">Properties</div>");
|
||||
writer.append("<div class=\"panel-body\">");
|
||||
writer.append("<table class=\"table table-properties table-bordered\"><tbody>");
|
||||
|
||||
String[] names = new String[instanceProperties.size()];
|
||||
int namei = 0;
|
||||
for (String name : instanceProperties.keySet()) {
|
||||
names[namei++] = name;
|
||||
}
|
||||
Arrays.sort(names);
|
||||
|
||||
for (String name : names) {
|
||||
ZenPropertyDoc property = instanceProperties.get(name);
|
||||
|
||||
writer.append("<tr>");
|
||||
writer.append("<td class=\"property-type\">");
|
||||
outputType(writer, property.getType(), classesByJavaName);
|
||||
writer.append("</td>");
|
||||
writer.append("<td>");
|
||||
writer.append("<div class=\"property-name\">");
|
||||
if (!property.isCanSet()) writer.append("<span class=\"fa fa-lock\" style=\"color: #ccc;\" title=\"cannot be set\"></span> ");
|
||||
writer.append("<a href=\"#property-staticvalue\">")
|
||||
.append(property.getName())
|
||||
.append("</a></div>");
|
||||
if (property.getComment() != null && property.getComment().length > 0) {
|
||||
writer.append("<div class=\"property-intro\">")
|
||||
.append(property.getComment()[0])
|
||||
.append("</div>");
|
||||
}
|
||||
writer.append("</td></tr>");
|
||||
}
|
||||
|
||||
writer.append("</tbody></table></div></div>");
|
||||
}
|
||||
|
||||
if (!staticMethods.isEmpty()) {
|
||||
writer.append("<div class=\"panel panel-info panel-memberlist\">");
|
||||
writer.append("<div class=\"panel-heading\">Static Methods</div>");
|
||||
writer.append("<div class=\"panel-body\">");
|
||||
writer.append("<table class=\"table table-properties table-bordered\"><tbody>");
|
||||
|
||||
for (ZenMethodDoc method : staticMethods) {
|
||||
writer.append("<tr>");
|
||||
writer.append("<td class=\"property-type\">");
|
||||
outputType(writer, method.getDoc().returnType(), classesByJavaName);
|
||||
writer.append("</td>");
|
||||
writer.append("<td>");
|
||||
writer.append("<div class=\"property-name\">");
|
||||
writer.append("<a href=\"#property-staticvalue\">")
|
||||
.append(method.getName())
|
||||
.append("</a>(");
|
||||
boolean first = true;
|
||||
|
||||
for (ZenParameterDoc param : method.getParameters()) {
|
||||
if (param.isOptional()) writer.append("<span class=\"param-optional\">");
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
writer.append(", ");
|
||||
}
|
||||
writer.append(param.getName());
|
||||
writer.append(" as ");
|
||||
outputType(writer, param.getType(), classesByJavaName);
|
||||
}
|
||||
writer.append(")</div>");
|
||||
|
||||
String[] comment = StringUtil.splitParagraphs(method.getDoc().commentText());
|
||||
if (comment.length > 0) {
|
||||
writer.append("<div class=\"property-intro\">")
|
||||
.append(comment[0])
|
||||
.append("</div>");
|
||||
}
|
||||
writer.append("</td></tr>");
|
||||
}
|
||||
|
||||
writer.append("</tbody></table></div></div>");
|
||||
}
|
||||
|
||||
if (!instanceMethods.isEmpty()) {
|
||||
writer.append("<div class=\"panel panel-info panel-memberlist\">");
|
||||
writer.append("<div class=\"panel-heading\">Methods</div>");
|
||||
writer.append("<div class=\"panel-body\">");
|
||||
writer.append("<table class=\"table table-properties table-bordered\"><tbody>");
|
||||
|
||||
for (ZenMethodDoc method : instanceMethods) {
|
||||
writer.append("<tr>");
|
||||
writer.append("<td class=\"property-type\">");
|
||||
outputType(writer, method.getDoc().returnType(), classesByJavaName);
|
||||
writer.append("</td>");
|
||||
writer.append("<td>");
|
||||
writer.append("<div class=\"property-name\">");
|
||||
writer.append("<a href=\"#property-staticvalue\">")
|
||||
.append(method.getName())
|
||||
.append("</a>(");
|
||||
boolean first = true;
|
||||
|
||||
for (ZenParameterDoc param : method.getParameters()) {
|
||||
if (param.isOptional()) writer.append("<span class=\"param-optional\">");
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
writer.append(", ");
|
||||
}
|
||||
writer.append(param.getName());
|
||||
writer.append(" as ");
|
||||
outputType(writer, param.getType(), classesByJavaName);
|
||||
}
|
||||
writer.append(")</div>");
|
||||
|
||||
String[] comment = StringUtil.splitParagraphs(method.getDoc().commentText());
|
||||
if (comment.length > 0) {
|
||||
writer.append("<div class=\"property-intro\">")
|
||||
.append(comment[0])
|
||||
.append("</div>");
|
||||
}
|
||||
writer.append("</td></tr>");
|
||||
}
|
||||
|
||||
writer.append("</tbody></table></div></div>");
|
||||
}
|
||||
|
||||
if (!operators.isEmpty()) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (!casters.isEmpty()) {
|
||||
writer.append("<div class=\"panel panel-info panel-memberlist\">");
|
||||
writer.append("<div class=\"panel-heading\">Casters</div>");
|
||||
writer.append("<div class=\"panel-body\">");
|
||||
writer.append("<table class=\"table table-properties table-bordered\"><tbody>");
|
||||
|
||||
for (ZenCasterDoc caster : casters) {
|
||||
writer.append("<tr>");
|
||||
writer.append("<td>");
|
||||
writer.append("<div class=\"property-name\">");
|
||||
writer.append("as <a href=\"#property-staticvalue\">");
|
||||
outputTypeRaw(writer, caster.getMethod().returnType(), classesByJavaName);
|
||||
writer.append("</a></div>");
|
||||
|
||||
String[] comment = StringUtil.splitParagraphs(caster.getMethod().commentText());
|
||||
if (comment.length > 0) {
|
||||
writer.append("<div class=\"property-intro\">")
|
||||
.append(comment[0])
|
||||
.append("</div>");
|
||||
}
|
||||
writer.append("</td></tr>");
|
||||
}
|
||||
|
||||
writer.append("</tbody></table></div></div>");
|
||||
}
|
||||
}
|
||||
|
||||
writer.append("</div></div></div>");
|
||||
writer.append("<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>");
|
||||
writer.append("<script src=\"/js/bootstrap.min.js\"></script>");
|
||||
writer.append("<script type=\"application/javascript\">");
|
||||
writer.append("$('#collapse-");
|
||||
writer.append(pkgName.replace('.', '-'));
|
||||
writer.append("').collapse('show');");
|
||||
writer.append("</script>");
|
||||
writer.append("</body></html>");
|
||||
writer.close();
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: Without this method present and returning LanguageVersion.JAVA_1_5,
|
||||
* Javadoc will not process generics because it assumes LanguageVersion.JAVA_1_1
|
||||
* @return language version (hard coded to LanguageVersion.JAVA_1_5)
|
||||
*/
|
||||
public static LanguageVersion languageVersion() {
|
||||
return LanguageVersion.JAVA_1_5;
|
||||
}
|
||||
|
||||
private static String buildPackageList(List<ZenClassDoc> classes) {
|
||||
// collect package list
|
||||
Map<String, List<ZenClassDoc>> packages = new HashMap<String, List<ZenClassDoc>>();
|
||||
for (ZenClassDoc cls : classes) {
|
||||
String pkg = cls.getName().substring(0, cls.getName().lastIndexOf('.'));
|
||||
if (packages.containsKey(pkg)) {
|
||||
packages.get(pkg).add(cls);
|
||||
} else {
|
||||
ArrayList<ZenClassDoc> classList = new ArrayList<ZenClassDoc>();
|
||||
classList.add(cls);
|
||||
packages.put(pkg, classList);
|
||||
}
|
||||
}
|
||||
|
||||
String[] packageSorted = new String[packages.size()];
|
||||
int packageIndex = 0;
|
||||
for (String packageName : packages.keySet()) {
|
||||
packageSorted[packageIndex++] = packageName;
|
||||
}
|
||||
Arrays.sort(packageSorted);
|
||||
|
||||
// output data
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("<div class=\"col-md-3\">");
|
||||
output.append("<div class=\"panel panel-group\"><div class=\"panel-body\">");
|
||||
output.append("<div class=\"panel-heading\"><h3>Packages</h3></div>");
|
||||
output.append("<div class=\"panel-scroll\">");
|
||||
|
||||
for (int i = 0; i < packageSorted.length; i++) {
|
||||
String pkgId = extractId(packageSorted[i]);
|
||||
String pkgDir = "/doc/" + packageSorted[i].replace('.', '/');
|
||||
|
||||
output.append("<div class=\"panel panel-default\">");
|
||||
output.append("<div class=\"panel-heading\"><h4 class=\"panel-title package-title\">");
|
||||
output.append("<a data-toggle=\"collapse\" data-parent=\"#accordion\" href=\"#collapse-")
|
||||
.append(pkgId)
|
||||
.append("\"><span class=\"glyphicon glyphicon-th-large\"></span> ")
|
||||
.append(packageSorted[i])
|
||||
.append("</a>");
|
||||
output.append("</h4></div>");
|
||||
|
||||
output.append("<div id=\"collapse-")
|
||||
.append(pkgId)
|
||||
.append("\" class=\"panel-collapse collapse\">");
|
||||
output.append("<div class=\"panel-body\">");
|
||||
|
||||
// assemble lists
|
||||
List<String> interfaceNames = new ArrayList<String>();
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
|
||||
for (ZenClassDoc cls : packages.get(packageSorted[i])) {
|
||||
if (cls.getDoc().isInterface()) {
|
||||
interfaceNames.add(cls.getDoc().name());
|
||||
} else {
|
||||
classNames.add(cls.getDoc().name());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(interfaceNames);
|
||||
Collections.sort(classNames);
|
||||
|
||||
if (!interfaceNames.isEmpty()) {
|
||||
output.append("<h4 class=\"interfaces-title\">Interfaces</h4>");
|
||||
output.append("<table class=\"table table-classes\"><tbody>");
|
||||
|
||||
for (String ifaceName : interfaceNames) {
|
||||
output.append("<tr><td><a href=\"")
|
||||
.append(pkgDir).append('/').append(ifaceName).append(".html")
|
||||
.append("\">")
|
||||
.append(ifaceName)
|
||||
.append("</a></td></tr>");
|
||||
}
|
||||
|
||||
output.append("</tbody></table>");
|
||||
}
|
||||
|
||||
if (!classNames.isEmpty()) {
|
||||
output.append("<h4 class=\"classes-title\">Classes</h4>");
|
||||
output.append("<table class=\"table table-classes\"><tbody>");
|
||||
|
||||
for (String className : classNames) {
|
||||
output.append("<tr><td><a href=\"")
|
||||
.append(pkgDir).append('/').append(className).append(".html")
|
||||
.append("\">")
|
||||
.append(className)
|
||||
.append("</a></td></tr>");
|
||||
}
|
||||
|
||||
output.append("</tbody></table>");
|
||||
}
|
||||
|
||||
output.append("</div></div></div>");
|
||||
}
|
||||
|
||||
output.append("</div></div></div></div>");
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private static String extractId(String pkg) {
|
||||
return pkg.replace('.', '-');
|
||||
}
|
||||
|
||||
private static void outputType(Writer output, Type type, Map<String, ZenClassDoc> javaClasses) throws IOException {
|
||||
if (javaClasses.containsKey(type.qualifiedTypeName())) {
|
||||
ZenClassDoc doc = javaClasses.get(type.qualifiedTypeName());
|
||||
output.append("<a href=\"");
|
||||
output.append(makeLink(doc.getName()));
|
||||
output.append("\">");
|
||||
output.append(doc.getName().substring(doc.getName().lastIndexOf('.') + 1));
|
||||
output.append("</a>");
|
||||
} else if (type.qualifiedTypeName().equals("java.util.List")) {
|
||||
Type base = type.asParameterizedType().typeArguments()[0];
|
||||
outputType(output, base, javaClasses);
|
||||
output.append("[]");
|
||||
} else if (type.qualifiedTypeName().equals("java.util.Map")) {
|
||||
Type key = type.asParameterizedType().typeArguments()[0];
|
||||
Type value = type.asParameterizedType().typeArguments()[1];
|
||||
outputType(output, value, javaClasses);
|
||||
output.append('[');
|
||||
outputType(output, key, javaClasses);
|
||||
output.append(']');
|
||||
} else if (type.qualifiedTypeName().equals("java.lang.String")) {
|
||||
output.append("string");
|
||||
} else {
|
||||
output.append(type.qualifiedTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
private static void outputTypeRaw(Writer output, Type type, Map<String, ZenClassDoc> javaClasses) throws IOException {
|
||||
if (javaClasses.containsKey(type.qualifiedTypeName())) {
|
||||
ZenClassDoc doc = javaClasses.get(type.qualifiedTypeName());
|
||||
output.append(doc.getName().substring(doc.getName().lastIndexOf('.') + 1));
|
||||
} else if (type.qualifiedTypeName().equals("java.util.List")) {
|
||||
Type base = type.asParameterizedType().typeArguments()[0];
|
||||
outputTypeRaw(output, base, javaClasses);
|
||||
output.append("[]");
|
||||
} else if (type.qualifiedTypeName().equals("java.util.Map")) {
|
||||
Type key = type.asParameterizedType().typeArguments()[0];
|
||||
Type value = type.asParameterizedType().typeArguments()[1];
|
||||
outputTypeRaw(output, value, javaClasses);
|
||||
output.append('[');
|
||||
outputTypeRaw(output, key, javaClasses);
|
||||
output.append(']');
|
||||
} else if (type.qualifiedTypeName().equals("java.lang.String")) {
|
||||
output.append("string");
|
||||
} else {
|
||||
output.append(type.qualifiedTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
private static String makeLink(String className) {
|
||||
return "/doc/" + className.replace('.', '/') + ".html";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.expression.partial;
|
||||
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.expression.ExpressionInvalid;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolType;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class PartialType implements IPartialExpression {
|
||||
private final ZenPosition position;
|
||||
private final ZenType type;
|
||||
|
||||
public PartialType(ZenPosition position, ZenType type) {
|
||||
this.position = position;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression eval(IEnvironmentGlobal environment) {
|
||||
environment.error(position, "cannot use type as expression");
|
||||
return new ExpressionInvalid(position, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression assign(ZenPosition position, IEnvironmentGlobal environment, Expression other) {
|
||||
environment.error(position, "cannot assign to a type");
|
||||
return new ExpressionInvalid(position, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, String name) {
|
||||
return type.getStaticMember(position, environment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
||||
environment.error(position, "cannot call a type");
|
||||
return new ExpressionInvalid(position, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol toSymbol() {
|
||||
return new SymbolType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType toType(IEnvironmentGlobal environment) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
+2
@@ -20,6 +20,8 @@ public class ParsedExpressionValue extends ParsedExpression {
|
||||
public ParsedExpressionValue(ZenPosition position, IPartialExpression value) {
|
||||
super(position);
|
||||
|
||||
if (value == null) throw new IllegalArgumentException("value cannot be null");
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.ZenTypeBool;
|
||||
import stanhebben.zenscript.symbols.IZenNamespace;
|
||||
import stanhebben.zenscript.util.MethodOutput;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.symbols;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public interface IZenEnvironment {
|
||||
public Object getValue(byte[] key);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.symbols;
|
||||
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public interface IZenNamespace {
|
||||
public IZenCompileEnvironment getEnvironment();
|
||||
|
||||
public IPartialExpression getValue(String name, ZenPosition position);
|
||||
|
||||
public void putValue(String name, IZenSymbol value);
|
||||
}
|
||||
@@ -22,10 +22,17 @@ import stanhebben.zenscript.util.ZenPosition;
|
||||
public class SymbolPackage implements IZenSymbol {
|
||||
private final HashMap<String, IZenSymbol> members;
|
||||
|
||||
public SymbolPackage() {
|
||||
private final String name;
|
||||
|
||||
public SymbolPackage(String name) {
|
||||
this.name = name;
|
||||
members = new HashMap<String, IZenSymbol>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Map<String, IZenSymbol> getPackages() {
|
||||
return members;
|
||||
}
|
||||
@@ -38,7 +45,14 @@ public class SymbolPackage implements IZenSymbol {
|
||||
String[] parts = StringUtil.split(name, '.');
|
||||
String[] pkgParts = Arrays.copyOf(parts, parts.length - 1);
|
||||
SymbolPackage pkgCurrent = this;
|
||||
String pkgName = null;
|
||||
for (String part : pkgParts) {
|
||||
if (pkgName == null) {
|
||||
pkgName = part;
|
||||
} else {
|
||||
pkgName = pkgName + '.' + part;
|
||||
}
|
||||
|
||||
if (pkgCurrent.members.containsKey(part)) {
|
||||
IZenSymbol member = pkgCurrent.members.get(part);
|
||||
if (member instanceof SymbolPackage) {
|
||||
@@ -48,12 +62,13 @@ public class SymbolPackage implements IZenSymbol {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
SymbolPackage child = new SymbolPackage();
|
||||
SymbolPackage child = new SymbolPackage(pkgName);
|
||||
pkgCurrent.members.put(part, child);
|
||||
pkgCurrent = child;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Adding " + parts[parts.length - 1] + " to package " + pkgCurrent.getName() + "(" + symbol + ")");
|
||||
if (pkgCurrent.members.containsKey(parts[parts.length - 1])) {
|
||||
errors.error(null, parts[parts.length - 1] + " is already defined in that package");
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.symbols;
|
||||
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.expression.partial.PartialType;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class SymbolType implements IZenSymbol {
|
||||
private final ZenType type;
|
||||
|
||||
public SymbolType(ZenType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
return new PartialType(position, type);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.symbols;
|
||||
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class ZenNamespaceLocal implements IZenNamespace {
|
||||
private final IZenNamespace parent;
|
||||
private final Map<String, IZenSymbol> values;
|
||||
|
||||
public ZenNamespaceLocal(IZenNamespace parent) {
|
||||
this.parent = parent;
|
||||
this.values = new HashMap<String, IZenSymbol>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenCompileEnvironment getEnvironment() {
|
||||
return parent.getEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getValue(String name, ZenPosition position) {
|
||||
if (values.containsKey(name)) {
|
||||
return values.get(name).instance(position);
|
||||
} else {
|
||||
return parent.getValue(name, position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String name, IZenSymbol value) {
|
||||
values.put(name, value);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.symbols;
|
||||
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class ZenNamespaceScript implements IZenNamespace {
|
||||
private final IZenCompileEnvironment environment;
|
||||
private final Map<String, IZenSymbol> values;
|
||||
|
||||
public ZenNamespaceScript(IZenCompileEnvironment environment) {
|
||||
this.environment = environment;
|
||||
this.values = new HashMap<String, IZenSymbol>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenCompileEnvironment getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getValue(String name, ZenPosition position) {
|
||||
if (values.containsKey(name)) {
|
||||
return values.get(name).instance(position);
|
||||
} else {
|
||||
IZenSymbol symbol = environment.getGlobal(name);
|
||||
if (symbol == null) {
|
||||
return null;
|
||||
} else {
|
||||
return symbol.instance(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String name, IZenSymbol value) {
|
||||
values.put(name, value);
|
||||
}
|
||||
}
|
||||
@@ -80,12 +80,27 @@ public abstract class ZenType {
|
||||
base = STRING;
|
||||
break;
|
||||
case ZenTokener.T_ID:
|
||||
base = ANY;
|
||||
|
||||
StringBuilder typeName = new StringBuilder();
|
||||
typeName.append(next.getValue());
|
||||
IPartialExpression partial = environment.getValue(next.getValue(), next.getPosition());
|
||||
while (parser.optional(ZenTokener.T_DOT) != null) {
|
||||
typeName.append('.');
|
||||
|
||||
Token member = parser.required(ZenTokener.T_ID, "identifier expected");
|
||||
typeName.append(member.getValue());
|
||||
partial = partial.getMember(member.getPosition(), environment, member.getValue());
|
||||
|
||||
if (partial == null) {
|
||||
environment.error(member.getPosition(), "could not find type " + typeName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (partial != null) {
|
||||
base = partial.toType(environment);
|
||||
System.out.println("Parsed type " + base.getName());
|
||||
}
|
||||
base = partial.toType(environment);
|
||||
break;
|
||||
default:
|
||||
throw new ParseException(next, "Unknown type: " + next.getValue());
|
||||
|
||||
@@ -140,12 +140,14 @@ public class ZenTypeAny extends ZenType {
|
||||
|
||||
@Override
|
||||
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, IPartialExpression value, String name) {
|
||||
return null;
|
||||
environment.error(position, "any values not yet supported");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getStaticMember(ZenPosition position, IEnvironmentGlobal environment, String name) {
|
||||
return null;
|
||||
environment.error(position, "any values not yet supported");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,7 +157,7 @@ public class ZenTypeAny extends ZenType {
|
||||
|
||||
@Override
|
||||
public boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
|
||||
return true; // true or not?
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,15 @@ public abstract class ZenTypeArray extends ZenType {
|
||||
|
||||
@Override
|
||||
public final boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
|
||||
return equals(type) || canCastExpansion(environment, type);
|
||||
if (equals(type) || canCastExpansion(environment, type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type instanceof ZenTypeArray) {
|
||||
return base.canCastImplicit(((ZenTypeArray) type).base, environment);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.type;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Type;
|
||||
import stanhebben.zenscript.annotations.CompareType;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.compiler.ITypeRegistry;
|
||||
import stanhebben.zenscript.compiler.TypeRegistry;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.expression.ExpressionInvalid;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallVirtual;
|
||||
import stanhebben.zenscript.expression.ExpressionNull;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.MethodOutput;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
import static stanhebben.zenscript.util.ZenTypeUtil.signature;
|
||||
import stanhebben.zenscript.value.IntRange;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenTypeIntRange extends ZenType {
|
||||
public static final ZenTypeIntRange INSTANCE = new ZenTypeIntRange();
|
||||
|
||||
private final JavaMethod methodFrom;
|
||||
private final JavaMethod methodTo;
|
||||
|
||||
private ZenTypeIntRange() {
|
||||
ITypeRegistry dummy = new TypeRegistry();
|
||||
methodFrom = JavaMethod.get(dummy, IntRange.class, "getFrom");
|
||||
methodTo = JavaMethod.get(dummy, IntRange.class, "getTo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression unary(ZenPosition position, IEnvironmentGlobal environment, Expression value, OperatorType operator) {
|
||||
environment.error(position, "cannot apply unary operators on int ranges");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression binary(ZenPosition position, IEnvironmentGlobal environment, Expression left, Expression right, OperatorType operator) {
|
||||
environment.error(position, "cannot apply binary operators on int ranges");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression trinary(ZenPosition position, IEnvironmentGlobal environment, Expression first, Expression second, Expression third, OperatorType operator) {
|
||||
environment.error(position, "cannot apply ternary operators on int ranges");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression compare(ZenPosition position, IEnvironmentGlobal environment, Expression left, Expression right, CompareType type) {
|
||||
environment.error(position, "cannot compare int ranges");
|
||||
return new ExpressionInvalid(position, BOOL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, IPartialExpression value, String name) {
|
||||
if (name.equals("from")) {
|
||||
return new ExpressionJavaCallVirtual(position, methodFrom, value.eval(environment));
|
||||
} else if (name.equals("to")) {
|
||||
return new ExpressionJavaCallVirtual(position, methodTo, value.eval(environment));
|
||||
} else {
|
||||
environment.error(position, "no such member " + name + " in int range");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getStaticMember(ZenPosition position, IEnvironmentGlobal environment, String name) {
|
||||
environment.error(position, "int ranges don't have static members");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression call(ZenPosition position, IEnvironmentGlobal environment, Expression receiver, Expression... arguments) {
|
||||
environment.error(position, "int ranges cannot be called");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, Expression value, ZenType type) {
|
||||
if (type == this) {
|
||||
return value;
|
||||
}
|
||||
|
||||
environment.error(position, "cannot cast int ranges to any other type");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenIterator makeIterator(int numValues, IEnvironmentMethod methodOutput) {
|
||||
if (numValues == 1) {
|
||||
return new IntRangeIterator(methodOutput);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
|
||||
return type == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCastExplicit(ZenType type, IEnvironmentGlobal environment) {
|
||||
return type == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class toJavaClass() {
|
||||
return IntRange.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type toASMType() {
|
||||
return Type.getType(IntRange.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSignature() {
|
||||
return signature(IntRange.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPointer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType type) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "int..";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression defaultValue(ZenPosition position) {
|
||||
return new ExpressionNull(position);
|
||||
}
|
||||
|
||||
private class IntRangeIterator implements IZenIterator {
|
||||
private final IEnvironmentMethod method;
|
||||
|
||||
public IntRangeIterator(IEnvironmentMethod methodOutput) {
|
||||
this.method = methodOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compileStart(int[] locals) {
|
||||
MethodOutput output = method.getOutput();
|
||||
|
||||
output.dup(); // copy IntRange reference
|
||||
output.invoke(methodFrom);
|
||||
output.storeInt(locals[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compilePreIterate(int[] locals, Label exit) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compilePostIterate(int[] locals, Label exit, Label repeat) {
|
||||
MethodOutput output = method.getOutput();
|
||||
|
||||
output.dup(); // copy IntRange reference
|
||||
output.invoke(methodTo);
|
||||
|
||||
output.loadInt(locals[0]);
|
||||
output.iinc(locals[0]);
|
||||
output.dup();
|
||||
output.storeInt(locals[0]);
|
||||
|
||||
output.ifICmpGT(repeat);
|
||||
output.goTo(exit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compileEnd() {
|
||||
method.getOutput().pop(); // remove IntRange reference
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType getType(int i) {
|
||||
return INT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,7 +412,7 @@ public class ZenTypeNative extends ZenType {
|
||||
|
||||
@Override
|
||||
public String getSignature() {
|
||||
return cls.getName();
|
||||
return signature(cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,7 +429,9 @@ public class ZenTypeNative extends ZenType {
|
||||
*/
|
||||
private static boolean canCastImplicit(Class cls, ZenType type) {
|
||||
if (isEqual(cls, type)) return true;
|
||||
if (canCastImplicit(cls.getSuperclass(), type)) return true;
|
||||
if (cls.getSuperclass() != null) {
|
||||
if (canCastImplicit(cls.getSuperclass(), type)) return true;
|
||||
}
|
||||
for (Class iface : cls.getInterfaces()) {
|
||||
if (canCastImplicit(iface, type)) return true;
|
||||
}
|
||||
@@ -458,7 +460,7 @@ public class ZenTypeNative extends ZenType {
|
||||
}
|
||||
|
||||
private static String getSignature(Class cls) {
|
||||
String signature = cls.getName();
|
||||
String signature = signature(cls);
|
||||
if (Number.class.isAssignableFrom(cls)) {
|
||||
if (cls == Byte.class) {
|
||||
signature = "B";
|
||||
|
||||
@@ -16,6 +16,7 @@ import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import static stanhebben.zenscript.util.StringUtil.methodMatchingError;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,7 @@ public class ZenExpandMember {
|
||||
System.arraycopy(values, 0, newValues, 1, values.length);
|
||||
JavaMethod method = JavaMethod.select(true, methods, environment, newValues);
|
||||
if (method == null) {
|
||||
environment.error(position, "no matching method found");
|
||||
environment.error(position, methodMatchingError(methods, values));
|
||||
return new ExpressionInvalid(position);
|
||||
} else {
|
||||
return method.callStatic(position, environment, newValues);
|
||||
@@ -133,7 +134,7 @@ public class ZenExpandMember {
|
||||
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
||||
JavaMethod method = JavaMethod.select(true, methods, environment, values);
|
||||
if (method == null) {
|
||||
environment.error(position, "no matching method found");
|
||||
environment.error(position, methodMatchingError(methods, values));
|
||||
return new ExpressionInvalid(position);
|
||||
} else {
|
||||
return method.callStatic(position, environment, values);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class JavaMethod {
|
||||
Method method = cls.getMethod(name, parameterTypes);
|
||||
return new JavaMethod(cls, method, types);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new RuntimeException("method not found", ex);
|
||||
throw new RuntimeException("method " + name + " not found in class " + cls.getName(), ex);
|
||||
} catch (SecurityException ex) {
|
||||
throw new RuntimeException("method retrieval not permitted", ex);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import stanhebben.zenscript.expression.ExpressionInvalid;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import static stanhebben.zenscript.util.StringUtil.methodMatchingError;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
@@ -91,7 +92,7 @@ public class ZenNativeMember {
|
||||
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
||||
JavaMethod method = JavaMethod.select(false, methods, environment, values);
|
||||
if (method == null) {
|
||||
environment.error(position, "no matching method found");
|
||||
environment.error(position, methodMatchingError(methods, values));
|
||||
return new ExpressionInvalid(position);
|
||||
} else {
|
||||
return method.callVirtual(position, environment, value.eval(environment), values);
|
||||
@@ -137,7 +138,7 @@ public class ZenNativeMember {
|
||||
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
||||
JavaMethod method = JavaMethod.select(true, methods, environment, values);
|
||||
if (method == null) {
|
||||
environment.error(position, "no matching method found");
|
||||
environment.error(position, methodMatchingError(methods, values));
|
||||
return new ExpressionInvalid(position);
|
||||
} else {
|
||||
return method.callStatic(position, environment, values);
|
||||
|
||||
@@ -26,6 +26,7 @@ public class MethodOutput {
|
||||
private final LocalVariablesSorter visitor;
|
||||
|
||||
public MethodOutput(ClassVisitor cls, int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
System.out.println("Method output: " + name + descriptor);
|
||||
MethodVisitor methodVisitor = cls.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
visitor = new LocalVariablesSorter(access, descriptor, methodVisitor);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
package stanhebben.zenscript.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -42,6 +45,39 @@ public class StringUtil {
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* If a set of methods is available and none matches, this method creates
|
||||
* a suitable message.
|
||||
*
|
||||
* @param methods matching methods
|
||||
* @param arguments calling arguments
|
||||
* @return return value
|
||||
*/
|
||||
public static String methodMatchingError(List<JavaMethod> methods, Expression... arguments) {
|
||||
if (methods.isEmpty()) {
|
||||
return "no method with that name available";
|
||||
} else {
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (methods.size() == 1) {
|
||||
message.append("a method ");
|
||||
} else {
|
||||
message.append(methods.size()).append(" methods ");
|
||||
}
|
||||
message.append("available but none matches the parameters (");
|
||||
boolean first = true;
|
||||
for (Expression value : arguments) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
message.append(", ");
|
||||
}
|
||||
message.append(value.getType().toString());
|
||||
}
|
||||
message.append(")");
|
||||
return message.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string in parts, given a specified delimiter.
|
||||
|
||||
@@ -37,6 +37,6 @@ public class ZenPosition {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString(line) + ":" + offset;
|
||||
return (file == null ? "?" : file.getFileName()) + " - " + Integer.toString(line) + ":" + offset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.value;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class IntRange {
|
||||
private final int from;
|
||||
private final int to;
|
||||
|
||||
public IntRange(int from, int to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public int getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public int getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package stanhebben.zenscript.value.builtin;
|
||||
import java.util.Iterator;
|
||||
import stanhebben.zenscript.ZenRuntimeException;
|
||||
import stanhebben.zenscript.value.IAny;
|
||||
import stanhebben.zenscript.value.IntRange;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -82,8 +83,7 @@ public class AnyByte implements IAny {
|
||||
|
||||
@Override
|
||||
public IAny range(IAny value) {
|
||||
//return new AnyIntRange(this.value, value.asInt());
|
||||
return null; // TODO
|
||||
return new AnyIntRange(new IntRange(this.value, value.asInt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,7 +117,7 @@ public class AnyByte implements IAny {
|
||||
|
||||
@Override
|
||||
public IAny call(IAny... values) {
|
||||
throw new ZenRuntimeException("cannot index a byte value");
|
||||
throw new ZenRuntimeException("cannot call a byte value");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.value.builtin;
|
||||
|
||||
import java.util.Iterator;
|
||||
import stanhebben.zenscript.ZenRuntimeException;
|
||||
import stanhebben.zenscript.value.IAny;
|
||||
import stanhebben.zenscript.value.IntRange;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class AnyInt implements IAny {
|
||||
public static AnyInt valueOf(byte value) {
|
||||
return new AnyInt(value);
|
||||
}
|
||||
|
||||
private final int value;
|
||||
|
||||
public AnyInt(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny not() {
|
||||
return new AnyInt(~value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny neg() {
|
||||
return new AnyInt(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny add(IAny value) {
|
||||
return new AnyInt(this.value + value.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny sub(IAny value) {
|
||||
return new AnyInt(this.value - value.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny cat(IAny value) {
|
||||
return new AnyString(Integer.toString(this.value) + value.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny mul(IAny value) {
|
||||
return new AnyInt(this.value * value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny div(IAny value) {
|
||||
return new AnyInt(this.value / value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny mod(IAny value) {
|
||||
return new AnyInt(this.value % value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny and(IAny value) {
|
||||
return new AnyInt(this.value & value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny or(IAny value) {
|
||||
return new AnyInt(this.value | value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny xor(IAny value) {
|
||||
return new AnyInt(this.value ^ value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny range(IAny value) {
|
||||
return new AnyIntRange(new IntRange(this.value, value.asInt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IAny value) {
|
||||
return Integer.compare(this.value, value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IAny value) {
|
||||
throw new ZenRuntimeException("int has no in operator");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny member(String value) {
|
||||
if (value.equals("abs")) {
|
||||
return new AnyInt(Math.abs(this.value));
|
||||
} else {
|
||||
throw new ZenRuntimeException("no such member in int: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny indexGet(IAny key) {
|
||||
throw new ZenRuntimeException("cannot index an int value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexSet(IAny key, IAny value) {
|
||||
throw new ZenRuntimeException("cannot index an int value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny call(IAny... values) {
|
||||
throw new ZenRuntimeException("cannot call an int value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new ZenRuntimeException("cannot convert an int to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T as(Class<T> cls) {
|
||||
throw new ZenRuntimeException("cannot convert a byte to an object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAny> iteratorSingle() {
|
||||
throw new ZenRuntimeException("cannot iterate over a byte value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAny[]> iteratorMulti(int n) {
|
||||
throw new ZenRuntimeException("cannot iterate over a byte value");
|
||||
}
|
||||
}
|
||||
@@ -7,107 +7,126 @@
|
||||
package stanhebben.zenscript.value.builtin;
|
||||
|
||||
import java.util.Iterator;
|
||||
import stanhebben.zenscript.ZenRuntimeException;
|
||||
import stanhebben.zenscript.value.IAny;
|
||||
import stanhebben.zenscript.value.IntRange;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class AnyIntRange implements IAny {
|
||||
private IntRange value;
|
||||
|
||||
public AnyIntRange(IntRange value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny not() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot invert an int range");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny neg() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot negate an int range");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny add(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot add int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny sub(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot subtract int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny cat(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot concatenate int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny mul(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot multiply int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny div(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot divide int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny mod(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot perform modulo on int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny and(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot perform and on int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny or(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot perform or on int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny xor(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot perform xor on int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny range(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Already a range!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot compare ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
int ivalue = value.asInt();
|
||||
return ivalue >= this.value.getFrom() && ivalue < this.value.getTo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny member(String value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
if (value.equals("from")) {
|
||||
return new AnyInt(this.value.getFrom());
|
||||
} else if (value.equals("to")) {
|
||||
return new AnyInt(this.value.getTo());
|
||||
} else {
|
||||
throw new ZenRuntimeException("No member " + value + " in int range");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny indexGet(IAny key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
int ivalue = key.asInt();
|
||||
if (ivalue < value.getTo() - value.getFrom()) {
|
||||
return new AnyInt(this.value.getFrom() + ivalue);
|
||||
} else {
|
||||
throw new ArrayIndexOutOfBoundsException("int range index out of bounds: " + ivalue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexSet(IAny key, IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot modify int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny call(IAny... values) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot call int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot cast int range to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,5 +178,4 @@ public class AnyIntRange implements IAny {
|
||||
public Iterator<IAny[]> iteratorMulti(int n) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user