format all the things!

This commit is contained in:
jaredlll08 committed 2015-08-31 19:15:35 +02:00
1 parent 54ec75fd3d
commit b36c6dade6
377 files changed
+6833 -6772

No files matched your search

@@ -56,7 +56,7 @@ public class AnyClassWriter {
public static final IJavaMethod METHOD_GETNUMBERTYPE = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "getNumberType");
public static final IJavaMethod METHOD_ITERATORSINGLE = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "iteratorSingle");
public static final IJavaMethod METHOD_ITERATORMULTI = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "iteratorMulti", int.class);
private static final String SIG_ANY = "()" + signature(IAny.class);
private static final String SIG_ANY_ANY = "(" + signature(IAny.class) + ")" + signature(IAny.class);
private static final String SIG_ANY_INT = "(" + signature(IAny.class) + ")I";
@@ -66,9 +66,10 @@ public class AnyClassWriter {
private static final String SIG_STRING_ANYARRAY_ANY = "(" + signature(String.class) + signature(IAny[].class) + ")" + signature(IAny.class);
private static final String SIG_ANY_ANY_VOID = "(" + signature(IAny.class) + signature(IAny.class) + ")V";
private static final String SIG_ANYARRAY_ANY = "(" + signature(IAny[].class) + ")" + signature(IAny.class);
private AnyClassWriter() {}
private AnyClassWriter() {
}
public static byte[] construct(IAnyDefinition definition, String name, Type asmType) {
try {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
@@ -366,7 +367,7 @@ public class AnyClassWriter {
writer,
Opcodes.ACC_PUBLIC,
"iteratorSingle",
"()" + signature(Iterator.class),
"()" + signature(Iterator.class),
"()Ljava/util/Iterator<Lstanhebben/zenscript/value/IAny;>;",
null);
outputIteratorSingle.start();
@@ -395,17 +396,12 @@ public class AnyClassWriter {
definition.defineHashCode(outputHashCode);
outputHashCode.end();
/*MethodOutput outputEquals = new MethodOutput(
writer,
Opcodes.ACC_PUBLIC,
"equals",
"(Ljava/lang/Object;)Z",
null,
null);
outputEquals.enableDebug();
outputEquals.start();
definition.defineEquals(outputEquals);
outputEquals.end();*/
/*
* MethodOutput outputEquals = new MethodOutput( writer,
* Opcodes.ACC_PUBLIC, "equals", "(Ljava/lang/Object;)Z", null,
* null); outputEquals.enableDebug(); outputEquals.start();
* definition.defineEquals(outputEquals); outputEquals.end();
*/
writer.visitEnd();
return writer.toByteArray();
@@ -413,30 +409,33 @@ public class AnyClassWriter {
throw new RuntimeException("Could not construct any class for " + name, ex);
}
}
public static void throwUnsupportedException(MethodOutput output, String fromType, String operation) {
// throw new UnsupportedOperationException(fromType + " does not support the " + operation + " operator");
// throw new UnsupportedOperationException(fromType +
// " does not support the " + operation + " operator");
output.newObject(UnsupportedOperationException.class);
output.dup();
output.constant(fromType + " does not support the " + operation + " operator");
output.construct(UnsupportedOperationException.class, String.class);
output.aThrow();
}
public static void throwCastException(MethodOutput output, String fromType, String toType) {
// throw new ClassCastException("Cannot cast " + fromType + " to " + [local:Class].getName())
// throw new ClassCastException("Cannot cast " + fromType + " to " +
// [local:Class].getName())
output.newObject(ClassCastException.class);
output.dup();
output.constant("Cannot cast " + fromType + " to " + toType);
output.construct(ClassCastException.class, String.class);
output.aThrow();
}
public static void throwCastException(MethodOutput output, String fromType, int local) {
// throw new ClassCastException("Cannot cast " + fromType + " to " + [local:Class].getName())
// throw new ClassCastException("Cannot cast " + fromType + " to " +
// [local:Class].getName())
output.newObject(ClassCastException.class);
output.dup();
output.newObject(StringBuilder.class);
output.dup();
output.construct(StringBuilder.class);
@@ -446,7 +445,7 @@ public class AnyClassWriter {
output.invokeVirtual(Class.class, "getName", String.class);
output.invokeVirtual(StringBuilder.class, "append", StringBuilder.class, String.class);
output.invokeVirtual(StringBuilder.class, "toString", String.class);
output.construct(ClassCastException.class, String.class);
output.aThrow();
}
@@ -14,78 +14,78 @@ import org.objectweb.asm.ClassVisitor;
*/
public interface IAnyDefinition {
public void defineMembers(ClassVisitor output);
public void defineStaticCanCastImplicit(MethodOutput output);
public void defineStaticAs(MethodOutput output);
public void defineNot(MethodOutput output);
public void defineNeg(MethodOutput output);
public void defineAdd(MethodOutput output);
public void defineSub(MethodOutput output);
public void defineCat(MethodOutput output);
public void defineMul(MethodOutput output);
public void defineDiv(MethodOutput output);
public void defineMod(MethodOutput output);
public void defineAnd(MethodOutput output);
public void defineOr(MethodOutput output);
public void defineXor(MethodOutput output);
public void defineRange(MethodOutput output);
public void defineCompareTo(MethodOutput output);
public void defineContains(MethodOutput output);
public void defineMemberGet(MethodOutput output);
public void defineMemberSet(MethodOutput output);
public void defineMemberCall(MethodOutput output);
public void defineIndexGet(MethodOutput output);
public void defineIndexSet(MethodOutput output);
public void defineCall(MethodOutput output);
public void defineAsBool(MethodOutput output);
public void defineAsByte(MethodOutput output);
public void defineAsShort(MethodOutput output);
public void defineAsInt(MethodOutput output);
public void defineAsLong(MethodOutput output);
public void defineAsFloat(MethodOutput output);
public void defineAsDouble(MethodOutput output);
public void defineAsString(MethodOutput output);
public void defineAs(MethodOutput output);
public void defineIs(MethodOutput output);
public void defineGetNumberType(MethodOutput output);
public void defineIteratorSingle(MethodOutput output);
public void defineIteratorMulti(MethodOutput output);
public void defineEquals(MethodOutput output);
public void defineHashCode(MethodOutput output);
}
@@ -8,11 +8,11 @@ import java.util.Iterator;
*/
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
File diff suppressed because it is too large. Load diff
@@ -16,8 +16,9 @@ import stanhebben.zenscript.type.natives.IJavaMethod;
* @author Stanneke
*/
public class StringUtil {
private StringUtil() {}
private StringUtil() {
}
public static String join(String[] values, String separator) {
StringBuilder result = new StringBuilder();
boolean first = true;
@@ -31,7 +32,7 @@ public class StringUtil {
}
return result.toString();
}
public static String join(Iterable<String> values, String separator) {
StringBuilder result = new StringBuilder();
boolean first = true;
@@ -45,10 +46,10 @@ public class StringUtil {
}
return result.toString();
}
/**
* If a set of methods is available and none matches, this method creates
* a suitable message.
* If a set of methods is available and none matches, this method creates a
* suitable message.
*
* @param methods matching methods
* @param arguments calling arguments
@@ -78,29 +79,30 @@ public class StringUtil {
return message.toString();
}
}
/**
* Splits a string in parts, given a specified delimiter.
*
* @param value string to be split
* @param delimiter delimiter
* @return
*/
public static String[] split(String value, char delimiter) {
if (value == null) return null;
/**
* Splits a string in parts, given a specified delimiter.
*
* @param value string to be split
* @param delimiter delimiter
* @return
*/
public static String[] split(String value, char delimiter) {
if (value == null)
return null;
ArrayList<String> result = new ArrayList<String>();
int start = 0;
outer: for (int i = 0; i < value.length(); i++) {
if (value.charAt(i) == delimiter) {
result.add(value.substring(start, i));
start = i + 1;
}
}
result.add(value.substring(start));
return result.toArray(new String[result.size()]);
}
int start = 0;
outer: for (int i = 0; i < value.length(); i++) {
if (value.charAt(i) == delimiter) {
result.add(value.substring(start, i));
start = i + 1;
}
}
result.add(value.substring(start));
return result.toArray(new String[result.size()]);
}
/**
* Processes a doc comment into paragraphs.
*
@@ -127,10 +129,10 @@ public class StringUtil {
if (current.length() > 0) {
output.add(current.toString());
}
return output.toArray(new String[output.size()]);
}
// ########################
// ### String utilities ###
// ########################
@@ -186,14 +188,14 @@ public class StringUtil {
* what about \[IDIOT JAVA PREPROCESSOR]u?
*
* @param oldstr
* @return
* @return
*/
public static String unescapeString(String oldstr) {
if ((oldstr.charAt(0) != '"' || oldstr.charAt(oldstr.length() - 1) != '"')
&& (oldstr.charAt(0) != '\'' || oldstr.charAt(oldstr.length() - 1) != '\'')) {
// TODO: error
//throw new TweakerExecuteException("Not a valid string constant: "
// + oldstr);
// throw new TweakerExecuteException("Not a valid string constant: "
// + oldstr);
}
oldstr = oldstr.substring(1, oldstr.length() - 1);
@@ -232,252 +234,252 @@ public class StringUtil {
switch (cp) {
case 'r':
newstr.append('\r');
break; /* switch */
case 'r':
newstr.append('\r');
break; /* switch */
case 'n':
newstr.append('\n');
break; /* switch */
case 'n':
newstr.append('\n');
break; /* switch */
case 'f':
newstr.append('\f');
break; /* switch */
case 'f':
newstr.append('\f');
break; /* switch */
/* PASS a \b THROUGH!! */
case 'b':
newstr.append("\\b");
break; /* switch */
/* PASS a \b THROUGH!! */
case 'b':
newstr.append("\\b");
break; /* switch */
case 't':
newstr.append('\t');
break; /* switch */
case 't':
newstr.append('\t');
break; /* switch */
case 'a':
newstr.append('\007');
break; /* switch */
case 'a':
newstr.append('\007');
break; /* switch */
case 'e':
newstr.append('\033');
break; /* switch */
/*
* A "control" character is what you get when you xor its codepoint
* with '@'==64. This only makes sense for ASCII, and may not yield
* a "control" character after all.
*
* Strange but true: "\c{" is ";", "\c}" is "=", etc.
*/
case 'c': {
if (++i == oldstr.length()) {
// TODO: error
//throw new TweakerExecuteException("trailing \\c");
}
cp = oldstr.codePointAt(i);
/*
* don't need to grok surrogates, as next line blows them up
*/
if (cp > 0x7f) {
// TODO: error
//throw new TweakerExecuteException(
// "expected ASCII after \\c");
}
newstr.append(Character.toChars(cp ^ 64));
break; /* switch */
}
case '8':
case '9':
// TODO: error
//throw new TweakerExecuteException("illegal octal digit");
/* NOTREACHED */
case 'e':
newstr.append('\033');
break; /* switch */
/*
* may be 0 to 2 octal digits following this one so back up one
* for fallthrough to next case; unread this digit and fall
* through to next case.
* A "control" character is what you get when you xor its
* codepoint with '@'==64. This only makes sense for ASCII, and
* may not yield a "control" character after all.
*
* Strange but true: "\c{" is ";", "\c}" is "=", etc.
*/
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
--i;
/* FALLTHROUGH */
/*
* Can have 0, 1, or 2 octal digits following a 0 this permits
* larger values than octal 377, up to octal 777.
*/
case '0': {
if (i + 1 == oldstr.length()) {
/* found \0 at end of string */
newstr.append(Character.toChars(0));
case 'c': {
if (++i == oldstr.length()) {
// TODO: error
// throw new TweakerExecuteException("trailing \\c");
}
cp = oldstr.codePointAt(i);
/*
* don't need to grok surrogates, as next line blows them up
*/
if (cp > 0x7f) {
// TODO: error
// throw new TweakerExecuteException(
// "expected ASCII after \\c");
}
newstr.append(Character.toChars(cp ^ 64));
break; /* switch */
}
i++;
int digits = 0;
int j;
for (j = 0; j <= 2; j++) {
if (i + j == oldstr.length()) {
break; /* for */
}
/* safe because will unread surrogate */
int ch = oldstr.charAt(i + j);
if (ch < '0' || ch > '7') {
break; /* for */
}
digits++;
}
if (digits == 0) {
--i;
newstr.append('\0');
break; /* switch */
}
int value = 0;
try {
value = Integer
.parseInt(oldstr.substring(i, i + digits), 8);
} catch (NumberFormatException nfe) {
// TODO: error
//throw new TweakerExecuteException(
// "invalid octal value for \\0 escape");
}
newstr.append(Character.toChars(value));
i += digits - 1;
break; /* switch */
} /* end case '0' */
case 'x': {
if (i + 2 > oldstr.length()) {
case '8':
case '9':
// TODO: error
//throw new TweakerExecuteException(
// "string too short for \\x escape");
}
i++;
boolean saw_brace = false;
if (oldstr.charAt(i) == '{') {
/* ^^^^^^ ok to ignore surrogates here */
i++;
saw_brace = true;
}
int j;
for (j = 0; j < 8; j++) {
if (!saw_brace && j == 2) {
break; /* for */
}
// throw new TweakerExecuteException("illegal octal digit");
/* NOTREACHED */
/*
* ASCII test also catches surrogates
* may be 0 to 2 octal digits following this one so back up
* one for fallthrough to next case; unread this digit and
* fall through to next case.
*/
int ch = oldstr.charAt(i + j);
if (ch > 127) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
--i;
/* FALLTHROUGH */
/*
* Can have 0, 1, or 2 octal digits following a 0 this
* permits larger values than octal 377, up to octal 777.
*/
case '0': {
if (i + 1 == oldstr.length()) {
/* found \0 at end of string */
newstr.append(Character.toChars(0));
break; /* switch */
}
i++;
int digits = 0;
int j;
for (j = 0; j <= 2; j++) {
if (i + j == oldstr.length()) {
break; /* for */
}
/* safe because will unread surrogate */
int ch = oldstr.charAt(i + j);
if (ch < '0' || ch > '7') {
break; /* for */
}
digits++;
}
if (digits == 0) {
--i;
newstr.append('\0');
break; /* switch */
}
int value = 0;
try {
value = Integer
.parseInt(oldstr.substring(i, i + digits), 8);
} catch (NumberFormatException nfe) {
// TODO: error
//throw new TweakerExecuteException(
// "illegal non-ASCII hex digit in \\x escape");
// throw new TweakerExecuteException(
// "invalid octal value for \\0 escape");
}
newstr.append(Character.toChars(value));
i += digits - 1;
break; /* switch */
} /* end case '0' */
if (saw_brace && ch == '}') {
break; /* for */
}
if (!((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'))) {
case 'x': {
if (i + 2 > oldstr.length()) {
// TODO: error
//throw new TweakerExecuteException(String.format(
// "illegal hex digit #%d '%c' in \\x", ch, ch));
// throw new TweakerExecuteException(
// "string too short for \\x escape");
}
i++;
boolean saw_brace = false;
if (oldstr.charAt(i) == '{') {
/* ^^^^^^ ok to ignore surrogates here */
i++;
saw_brace = true;
}
int j;
for (j = 0; j < 8; j++) {
}
if (j == 0) {
// TODO: error
//throw new TweakerExecuteException(
// "empty braces in \\x{} escape");
}
int value = 0;
try {
value = Integer.parseInt(oldstr.substring(i, i + j), 16);
} catch (NumberFormatException nfe) {
// TODO: error
//throw new TweakerExecuteException(
// "invalid hex value for \\x escape");
}
newstr.append(Character.toChars(value));
if (saw_brace) {
j++;
}
i += j - 1;
break; /* switch */
}
if (!saw_brace && j == 2) {
break; /* for */
}
case 'u': {
if (i + 4 > oldstr.length()) {
// TODO: error
//throw new TweakerExecuteException(
// "string too short for \\u escape");
}
i++;
int j;
for (j = 0; j < 4; j++) {
/* this also handles the surrogate issue */
if (oldstr.charAt(i + j) > 127) {
/*
* ASCII test also catches surrogates
*/
int ch = oldstr.charAt(i + j);
if (ch > 127) {
// TODO: error
// throw new TweakerExecuteException(
// "illegal non-ASCII hex digit in \\x escape");
}
if (saw_brace && ch == '}') {
break; /* for */
}
if (!((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'))) {
// TODO: error
// throw new TweakerExecuteException(String.format(
// "illegal hex digit #%d '%c' in \\x", ch, ch));
}
}
if (j == 0) {
// TODO: error
//throw new TweakerExecuteException(
// "illegal non-ASCII hex digit in \\u escape");
// throw new TweakerExecuteException(
// "empty braces in \\x{} escape");
}
}
int value = 0;
try {
value = Integer.parseInt(oldstr.substring(i, i + j), 16);
} catch (NumberFormatException nfe) {
// TODO: error
//throw new TweakerExecuteException(
// "invalid hex value for \\u escape");
}
newstr.append(Character.toChars(value));
i += j - 1;
break; /* switch */
}
case 'U': {
if (i + 8 > oldstr.length()) {
// TODO: error
//throw new TweakerExecuteException(
// "string too short for \\U escape");
}
i++;
int j;
for (j = 0; j < 8; j++) {
/* this also handles the surrogate issue */
if (oldstr.charAt(i + j) > 127) {
int value = 0;
try {
value = Integer.parseInt(oldstr.substring(i, i + j), 16);
} catch (NumberFormatException nfe) {
// TODO: error
//throw new TweakerExecuteException(
// "illegal non-ASCII hex digit in \\U escape");
// throw new TweakerExecuteException(
// "invalid hex value for \\x escape");
}
newstr.append(Character.toChars(value));
if (saw_brace) {
j++;
}
i += j - 1;
break; /* switch */
}
int value = 0;
try {
value = Integer.parseInt(oldstr.substring(i, i + j), 16);
} catch (NumberFormatException nfe) {
// TODO: error
//throw new TweakerExecuteException(
// "invalid hex value for \\U escape");
}
newstr.append(Character.toChars(value));
i += j - 1;
break; /* switch */
}
default:
newstr.append('\\');
newstr.append(Character.toChars(cp));
/*
* say(String.format(
* "DEFAULT unrecognized escape %c passed through", cp));
*/
break; /* switch */
case 'u': {
if (i + 4 > oldstr.length()) {
// TODO: error
// throw new TweakerExecuteException(
// "string too short for \\u escape");
}
i++;
int j;
for (j = 0; j < 4; j++) {
/* this also handles the surrogate issue */
if (oldstr.charAt(i + j) > 127) {
// TODO: error
// throw new TweakerExecuteException(
// "illegal non-ASCII hex digit in \\u escape");
}
}
int value = 0;
try {
value = Integer.parseInt(oldstr.substring(i, i + j), 16);
} catch (NumberFormatException nfe) {
// TODO: error
// throw new TweakerExecuteException(
// "invalid hex value for \\u escape");
}
newstr.append(Character.toChars(value));
i += j - 1;
break; /* switch */
}
case 'U': {
if (i + 8 > oldstr.length()) {
// TODO: error
// throw new TweakerExecuteException(
// "string too short for \\U escape");
}
i++;
int j;
for (j = 0; j < 8; j++) {
/* this also handles the surrogate issue */
if (oldstr.charAt(i + j) > 127) {
// TODO: error
// throw new TweakerExecuteException(
// "illegal non-ASCII hex digit in \\U escape");
}
}
int value = 0;
try {
value = Integer.parseInt(oldstr.substring(i, i + j), 16);
} catch (NumberFormatException nfe) {
// TODO: error
// throw new TweakerExecuteException(
// "invalid hex value for \\U escape");
}
newstr.append(Character.toChars(value));
i += j - 1;
break; /* switch */
}
default:
newstr.append('\\');
newstr.append(Character.toChars(cp));
/*
* say(String.format(
* "DEFAULT unrecognized escape %c passed through", cp));
*/
break; /* switch */
}
saw_backslash = false;
@@ -16,27 +16,28 @@ public class ZenPosition {
private final ZenParsedFile file;
private final int line;
private final int offset;
public ZenPosition(ZenParsedFile file, int line, int offset) {
if (file != null && line <= 0) throw new IllegalArgumentException("Line must be positive");
if (file != null && line <= 0)
throw new IllegalArgumentException("Line must be positive");
this.file = file;
this.line = line;
this.offset = offset;
}
public ZenParsedFile getFile() {
return file;
}
public int getLine() {
return line;
}
public int getLineOffset() {
return offset;
}
@Override
public String toString() {
return (file == null ? "?" : file.getFileName()) + ":" + Integer.toString(line);
@@ -18,9 +18,9 @@ import stanhebben.zenscript.compiler.TypeRegistry;
*/
public class ZenTypeUtil {
public static final ITypeRegistry EMPTY_REGISTRY = new TypeRegistry();
private static final Map<String, String> SIGNATURE_MAP;
static {
SIGNATURE_MAP = new HashMap<String, String>();
SIGNATURE_MAP.put(boolean.class.getName(), "Z");
@@ -33,7 +33,7 @@ public class ZenTypeUtil {
SIGNATURE_MAP.put(char.class.getName(), "C");
SIGNATURE_MAP.put(void.class.getName(), "V");
}
public static String signature(Class<?> cls) {
if (SIGNATURE_MAP.containsKey(cls.getName())) {
return SIGNATURE_MAP.get(cls.getName());
@@ -45,11 +45,11 @@ public class ZenTypeUtil {
return signature;
}
}
public static String internal(Class<?> cls) {
return cls.getName().replace('.', '/');
}
public static String descriptor(Method method) {
StringBuilder output = new StringBuilder();
output.append('(');