Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package emulator.editor;
- import static emulator.memory.Memory.Access.StructureAccess.simpleStructureAccess;
- import java.net.*;
- import java.util.*;
- import javax.lang.model.element.TypeElement;
- import javax.tools.*;
- import com.sun.source.tree.CompilationUnitTree;
- import com.sun.tools.javac.api.JavacTaskImpl;
- import com.sun.tools.javac.code.*;
- import com.sun.tools.javac.code.Symbol.ClassSymbol;
- import com.sun.tools.javac.comp.*;
- import com.sun.tools.javac.tree.*;
- import com.sun.tools.javac.tree.JCTree.JCClassDecl;
- import com.sun.tools.javac.tree.JCTree.JCExpression;
- import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
- import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
- import com.sun.tools.javac.util.Context;
- import emulator.code.*;
- import emulator.code.Code.Decl;
- import emulator.code.Operation.OperationType;
- import emulator.editor.Context.*;
- import emulator.editor.Export.*;
- import emulator.memory.*;
- import emulator.memory.Memory.Access;
- import emulator.memory.Memory.Access.StackAccess;
- public class Import {
- // preliminary: java only
- public static final LinkedHashMap<Class, ImportDef> javaImportDef = new LinkedHashMap<Class, ImportDef>();
- public static void initJavaImport() {
- // Structure
- javaImportDef.put(JCTree.JCCompilationUnit.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- assert false;
- }
- }
- ));
- javaImportDef.put(JCTree.JCImport.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCMethodDecl.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- JCTree.JCMethodDecl jctree1 = (JCTree.JCMethodDecl) importContext.jctree;
- {
- Code code1 = importContext.parent.return1 = new Code();
- code1.operationType = Operation.OperationType.Control.OP_SEQUENCE;
- code1.propertyList.put(new Identifier.Property("function"), null);
- //code1.paramList.put(key, value); // param decl
- //code1.linkedList.add(e)
- code1.title = jctree1.name.toString();
- importDecl(jctree1.body, context, javaImport, importContext, code1);
- assert importContext.return1 != null;
- CodeOut.initList(context, code1.codeList, new Identifier.Property("code"));
- Structure.List.Vector access1 = (Structure.List.Vector) Memory.Process.resolveExecuteItem(context.process, code1.codeList.get(new Identifier.Property("code")))[0];
- int next = Memory.Process.appendData(context.process, new StackAccess(context.stackContext.stackId.control, 0), new Object[] { importContext.return1 });
- access1.set(new Identifier.Property("index", 0), new Object[] { simpleStructureAccess(context.stackContext.stackId.control, new Identifier.Property("index", next)) });
- }
- }
- }
- ));
- javaImportDef.put(JCTree.JCCatch.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCTypeParameter.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.TypeBoundKind.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCModifiers.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- // Statement
- javaImportDef.put(JCTree.JCClassDecl.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- JCTree.JCClassDecl jctree1 = (JCTree.JCClassDecl) importContext.jctree;
- // create new type and add to type list
- // check nested class environment
- //System.out.println("JCClassDecl SYM " + jctree1.sym);
- {
- String[] package1 = jctree1.sym.fullname.toString().split("\\.");
- Structure.Type type = new Structure.Type();
- type.typeId = new Identifier.Type(context.process.processId.programId, package1);
- type.enclosingTypeId = importContext.type != null ? importContext.type.typeId : null;
- /*if(jctree1.extending != null) {
- jctree1.extending.type.tsym.
- String[] package1 = jctree1.extending.type.tsym.fullname.toString().split("\\.");
- type.extendsList.append(new Object[] { new Identifier.Type(context.process.processId.programId, package1) });
- }*/
- Memory.Process.setData(context.process, simpleStructureAccess(context.stackContext.stackId.type, new Identifier.Property(type.typeId)), new Object[] { type });
- for(JCTree jctree2 : jctree1.defs) {
- importTypeMember(jctree2, context, javaImport, importContext, type);
- if(jctree2 instanceof JCVariableDecl) {
- }
- else if(jctree2 instanceof JCMethodDecl) {
- assert importContext.return1 != null;
- JCTree.JCMethodDecl jctree3 = (JCTree.JCMethodDecl) jctree2;
- assert !type.codeList.containsKey(new Identifier.Property(jctree3.name.toString()));
- int next = Memory.Process.appendData(context.process, new StackAccess(context.stackContext.stackId.control, 0), new Object[] { importContext.return1 });
- type.codeList.put(new Identifier.Property(jctree3.name.toString()), simpleStructureAccess(context.stackContext.stackId.control, new Identifier.Property("index", next)));
- }
- else if(jctree2 instanceof JCClassDecl) {
- }
- else {
- assert false;
- }
- }
- }
- }
- }
- ));
- javaImportDef.put(JCTree.JCVariableDecl.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- JCTree.JCVariableDecl jctree1 = (JCTree.JCVariableDecl) importContext.jctree;
- assert importContext.type != null;
- Decl decl = new Decl();
- decl.typing = new Code.Typing();
- /*if(jctree1.vartype.tag == TypeTag.) {
- Access type = getType(jctree1.vartype);
- decl.typing.typingType = Code.Typing.TypingType.CONSTANT;
- }
- else {
- }*/
- decl.initType = Code.Decl.InitType.LITERAL;
- if(importContext.decl != null) { // local vars (thread local)
- //Identifier.Stack stackId = new Identifier.Stack(context.process.processId, context.thread.threadId, importContext.type.typeId, jctree1.name.toString());
- Identifier.Stack stackId = new Identifier.Stack(context.process.processId, context.thread.threadId, null, jctree1.name.toString());
- assert !importContext.decl.declList.containsKey(stackId);
- decl.stackId = stackId;
- importContext.decl.declList.put(decl.stackId, decl);
- }
- else { // type vars (thread global)
- Identifier.Property propertyId = new Identifier.Property(jctree1.name.toString());
- assert !importContext.type.declList.containsKey(propertyId);
- decl.propertyId = propertyId;
- importContext.type.declList.put(decl.propertyId, decl);
- }
- }
- }
- ));
- javaImportDef.put(JCTree.JCSkip.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCBlock.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- JCTree.JCBlock jctree1 = (JCTree.JCBlock) importContext.jctree;
- {
- Code code1 = importContext.parent.return1 = new Code();
- code1.operationType = Operation.OperationType.Control.OP_SEQUENCE;
- CodeOut.initList(context, code1.codeList, new Identifier.Property("code"));
- Structure.List.Vector access1 = (Structure.List.Vector) Memory.Process.resolveExecuteItem(context.process, code1.codeList.get(new Identifier.Property("code")))[0];
- int i = 0;
- int j = 0;
- for(JCTree jctree2 : jctree1.stats) {
- importNoDecl(jctree2, context, javaImport, importContext, code1);
- if(importContext.return1 == null) {
- System.out.println(jctree2.getClass().getSimpleName());
- assert jctree2 instanceof JCVariableDecl;
- }
- else {
- int next = Memory.Process.appendData(context.process, new StackAccess(context.stackContext.stackId.control, 0), new Object[] { importContext.return1 });
- access1.set(new Identifier.Property("index", j++), new Object[] { simpleStructureAccess(context.stackContext.stackId.control, new Identifier.Property("index", next)) });
- }
- i++;
- }
- }
- }
- }
- ));
- javaImportDef.put(JCTree.JCDoWhileLoop.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCWhileLoop.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCForLoop.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCEnhancedForLoop.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCLabeledStatement.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCSwitch.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCCase.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCSynchronized.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCTry.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCIf.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- JCTree.JCIf jctree1 = (JCTree.JCIf) importContext.jctree;
- {
- Code code1 = importContext.parent.return1 = new Code();
- code1.operationType = Operation.OperationType.Control.OP_IF;
- CodeOut.initList(context, code1.dataList, new Identifier.Property("cond"));
- CodeOut.initList(context, code1.codeList, new Identifier.Property("code"));
- Structure.List.Vector access1 = (Structure.List.Vector) Memory.Process.resolveExecuteItem(context.process, code1.dataList.get(new Identifier.Property("cond")))[0];
- Structure.List.Vector access2 = (Structure.List.Vector) Memory.Process.resolveExecuteItem(context.process, code1.codeList.get(new Identifier.Property("code")))[0];
- Code code2 = new Code();
- code2.operationType = Operation.OperationType.Control.OP_SEQUENCE;
- while(jctree1.elsepart instanceof JCTree.JCIf) {
- //access1.append(value);
- //access2.append(value);
- }
- }
- }
- }
- ));
- javaImportDef.put(JCTree.JCExpressionStatement.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- JCTree.JCExpressionStatement jctree1 = (JCTree.JCExpressionStatement) importContext.jctree;
- importPassthrough(jctree1.expr, context, javaImport, importContext);
- assert importContext.return1 != null;
- importContext.parent.return1 = importContext.return1;
- }
- }
- ));
- javaImportDef.put(JCTree.JCBreak.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCContinue.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCReturn.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCThrow.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCAssert.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- // Expression
- javaImportDef.put(JCTree.JCConditional.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCMethodInvocation.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- JCTree.JCMethodInvocation jctree1 = (JCTree.JCMethodInvocation) importContext.jctree;
- {
- Code code1 = importContext.parent.return1 = new Code();
- code1.operationType = Operation.OperationType.Control.OP_ENVIRONMENT;
- //code1.declList
- code1.codeList.put(new Identifier.Property("code"), getAccess(jctree1.meth));
- for(JCTree jctree2 : jctree1.args) {
- importExpression(jctree2, context, javaImport, importContext, code1);
- assert importContext.return1 != null;
- }
- }
- }
- }
- ));
- javaImportDef.put(JCTree.JCNewClass.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCNewArray.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCParens.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCAssign.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCAssignOp.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCUnary.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCBinary.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCTypeCast.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCInstanceOf.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCArrayAccess.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCFieldAccess.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCIdent.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCLiteral.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- JCTree.JCLiteral jctree1 = (JCTree.JCLiteral) importContext.jctree;
- if(!javaImport.literalTable.containsKey(jctree1.value)) {
- int next = Memory.Process.appendData(context.process, new StackAccess(context.stackContext.stackId.constant, 0), new Object[] { jctree1.value });
- javaImport.literalTable.put(jctree1.value, simpleStructureAccess(context.stackContext.stackId.constant, new Identifier.Property("index", next)));
- }
- Code code1 = importContext.parent.return1 = new Code();
- code1.operationType = Operation.OperationType.Expression.OP_ACCESS;
- code1.dataList.put(new Identifier.Property("source"), javaImport.literalTable.get(jctree1.value)); // constant
- code1.propertyList.put(new Identifier.Property("constant"), null);
- }
- }
- ));
- javaImportDef.put(JCTree.JCPrimitiveTypeTree.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCArrayTypeTree.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCTypeApply.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCWildcard.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCAnnotation.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- System.out.println("UNIMPLEMENTED: " + importContext.jctree.getClass().getSimpleName());
- }
- }
- ));
- javaImportDef.put(JCTree.JCErroneous.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- assert false;
- }
- }
- ));
- javaImportDef.put(JCTree.LetExpr.class, new ImportDef(
- new ImportScript() {
- public void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- assert false;
- }
- }
- ));
- }
- public static Access getAccess(JCExpression expression) {
- return null;
- }
- public static Access getType(JCExpression expression) {
- return null;
- }
- public static Type getPrimitive(JCExpression expression) {
- return null;
- }
- public static int logIndent = 0;///
- public static void import1(CodeContext context, JavaImport javaImport, JavaImportContext.JavaImportContextNew importContext) {
- //*
- //System.out.println("import " + jctree.getClass().getSimpleName());
- System.out.print("import ");
- for(int i = logIndent; i > 0; i--)
- System.out.print("+ ");
- System.out.print(importContext.jctree.getClass().getSimpleName());
- System.out.println();
- logIndent++;
- //*/
- if(importContext.parent != null) {
- importContext.parent.return1 = null;
- }
- // TODO general: annotation, comment, ...
- javaImportDef.get(importContext.jctree.getClass()).importScript.exec(context, javaImport, importContext);
- logIndent--;///
- }
- public static void importTypeMember(JCTree jctree, CodeContext context, JavaImport javaImport, JavaImportContext importContext, Structure.Type type) {
- import1(context, javaImport, new JavaImportContext.JavaImportContextNew(importContext, jctree, null, null, type));
- }
- public static void importDecl(JCTree jctree, CodeContext context, JavaImport javaImport, JavaImportContext importContext, Code code) {
- import1(context, javaImport, new JavaImportContext.JavaImportContextNew(importContext, jctree, code, importContext.decl, importContext.type));
- }
- public static void importNoDecl(JCTree jctree, CodeContext context, JavaImport javaImport, JavaImportContext importContext, Code code) {
- import1(context, javaImport, new JavaImportContext.JavaImportContextNew(importContext, jctree, code, code, importContext.type));
- }
- public static void importExpression(JCTree jctree, CodeContext context, JavaImport javaImport, JavaImportContext importContext, Code code) {
- import1(context, javaImport, new JavaImportContext.JavaImportContextNew(importContext, jctree, code, null, importContext.type));
- }
- public static void importPassthrough(JCTree jctree, CodeContext context, JavaImport javaImport, JavaImportContext importContext) {
- import1(context, javaImport, new JavaImportContext.JavaImportContextNew(importContext, jctree, importContext.code, importContext.decl, importContext.type));
- }
- public static class JavaSourceString extends SimpleJavaFileObject {
- public String contents;
- protected JavaSourceString(String classname, String contents) throws URISyntaxException {
- super(new URI(classname), Kind.SOURCE);
- this.contents = contents;
- }
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) {
- return contents;
- }
- }
- public static void importSource(String name, String source, CodeContext context, StackContext stackContext) {
- // TODO set compiler classpath and options
- // TODO handle diagnostic messages
- JavaImport.JavaImportNew javaImport;
- //JavaImportContext.JavaImportContextNew importContext;
- try {
- JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
- StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null);
- Iterable<? extends JavaFileObject> fileObjectList = Arrays.asList(new JavaSourceString(name, source));
- JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fileManager, diagnosticCollector, null, null, fileObjectList);
- com.sun.tools.javac.util.Context javacContext = task.getContext();
- javaImport = new JavaImport.JavaImportNew(javacContext);
- Iterable<? extends CompilationUnitTree> compilationList = task.parse();
- Iterable<? extends TypeElement> typeElementList = task.enter(compilationList);
- List<Diagnostic<? extends JavaFileObject>> diagnosticList = diagnosticCollector.getDiagnostics();
- boolean success = diagnosticList.isEmpty();
- for(Diagnostic<? extends JavaFileObject> diagnostic : diagnosticList) {
- System.out.println(diagnostic);
- //diagnosticCollector.report(diagnostic);
- }
- if(success) {
- for (TypeElement typeElement : typeElementList) {
- //System.out.println("### " + (ClassSymbol) typeElement);
- Env<AttrContext> env = javaImport.enter.getEnv((ClassSymbol) typeElement);
- assert env.tree instanceof JCClassDecl;
- importTypeMember(env.tree, context, javaImport, null, null);
- }
- }
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- public static class ImportDef {
- public ImportScript importScript;
- public ImportDef(ImportScript importScript) {
- this.importScript = importScript;
- };
- }
- public static abstract class ImportScript {
- public abstract void exec(CodeContext context, JavaImport javaImport, JavaImportContext importContext);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement