Commit 3730f3c9 authored by baueko's avatar baueko

did some cleanup

parent b27412cb
......@@ -4,19 +4,17 @@ import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import de.in.tum.www2.cup.Position;
public class JavaCompiler {
public static ASTNode parseJava(String blob, CodeBlock codeblock) {
public static ASTNode parseJava(String userCode, CodeBlock codeblock) {
ASTParser parser = ASTParser.newParser(AST.JLS8);
ASTNode node;
parser.setEnvironment(new String[] { "" }, new String[] { "" }, new String[] { "UTF-8" }, true);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setUnitName("TODO: Edit name");
parser.setUnitName("DummyClass");
parser.setResolveBindings(true);
String tokkenblob = "";
String dummyClass = "";
final String DUMMY_CLASS_DEF = "public class DummyClass\n{";
final String RWING = "}";
......@@ -28,51 +26,36 @@ public class JavaCompiler {
switch (codeblock.getBt()) {
case Action:
case Parser:
tokkenblob = DUMMY_CLASS_DEF + blob + RWING;
parser.setSource(tokkenblob.toCharArray());
node = parser.createAST(null);
node.accept(new LocalVariableDetector());
dummyClass = DUMMY_CLASS_DEF + userCode + RWING;
break;
case Init:
case Scan:
tokkenblob = DUMMY_CLASS_DEF + DUMMY_METHOD_DEF + DUMMY_METHOD_ARGS_END + blob + DUMMY_METHOD_END
dummyClass = DUMMY_CLASS_DEF + DUMMY_METHOD_DEF + DUMMY_METHOD_ARGS_END + userCode + DUMMY_METHOD_END
+ DUMMY_CLASS_DEF_END;
parser.setSource(tokkenblob.toCharArray());
node = parser.createAST(null);
node.accept(new LocalVariableDetector());
break;
case ActionCode:
ActionCodeBlock block = (ActionCodeBlock) codeblock;
tokkenblob = DUMMY_CLASS_DEF + DUMMY_METHOD_DEF;
tokkenblob += block.getReturnType() + " RESULT";
dummyClass = DUMMY_CLASS_DEF + DUMMY_METHOD_DEF;
// do we need a return type?
dummyClass += block.getReturnType() + " RESULT";
for (LabeledProductionSymbolRef l : block.getVariables()) {
tokkenblob += ", " + l.getDatatype() + " " + l.label;
tokkenblob += ", " + "Object" + " " + l.label + "xleft"; // TODO Object should really be a Location
tokkenblob += ", " + "Object" + " " + l.label + "xright"; // TODO Object should really be a Location
tokkenblob += ", " + "int" + " " + l.label + "left";
tokkenblob += ", " + "int" + " " + l.label + "right";
Position left = l.getBegin();
Position right = l.getEnd();
// xleft, xright
System.out.println(left + " to " + right);
dummyClass += ", " + l.getDatatype() + " " + l.label;
dummyClass += ", " + "Object" + " " + l.label + "xleft"; // TODO Object should really be a Location
dummyClass += ", " + "Object" + " " + l.label + "xright"; // TODO Object should really be a Location
dummyClass += ", " + "int" + " " + l.label + "left";
dummyClass += ", " + "int" + " " + l.label + "right";
}
tokkenblob += DUMMY_METHOD_ARGS_END + "\n\t\t";
// action code
tokkenblob += blob;
tokkenblob += DUMMY_METHOD_END + DUMMY_CLASS_DEF_END;
parser.setSource(tokkenblob.toCharArray());
node = parser.createAST(null);
node.accept(new LocalVariableDetector());
dummyClass += DUMMY_METHOD_ARGS_END + "\n\t\t";
dummyClass += userCode;
dummyClass += DUMMY_METHOD_END + DUMMY_CLASS_DEF_END;
break;
default:
throw new UnsupportedOperationException("java parsing not implemented: unknown blocktype");
}
parser.setSource(dummyClass.toCharArray());
node = parser.createAST(null);
node.accept(new LocalVariableDetector());
return node;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment