mirror of
				https://gitee.com/BDWare/cp.git
				synced 2025-06-12 10:44:02 +00:00 
			
		
		
		
	support interface
This commit is contained in:
		
							parent
							
								
									7e8076e075
								
							
						
					
					
						commit
						eb91d17982
					
				| @ -14,8 +14,9 @@ public abstract class AnnotationProcessor { | |||||||
|             FunctionNode functionNode) throws Exception { |             FunctionNode functionNode) throws Exception { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     public void processInterface(AnnotationNode anno, ContractNode contractNode, |     public void processInterface(AnnotationNode anno, ContractNode contractNode, | ||||||
|                                 InterfaceNode functionNode) throws Exception { |             InterfaceNode functionNode) throws Exception { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -34,8 +34,7 @@ public class YJSCompiler { | |||||||
|     ContractNode contract; |     ContractNode contract; | ||||||
|     private static final Logger LOGGER = LogManager.getLogger(YJSCompiler.class); |     private static final Logger LOGGER = LogManager.getLogger(YJSCompiler.class); | ||||||
| 
 | 
 | ||||||
|     public YJSCompiler() { |     public YJSCompiler() {} | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     public static ScriptFunction compileWithGlobal(Source source, Global global, Context context) { |     public static ScriptFunction compileWithGlobal(Source source, Global global, Context context) { | ||||||
|         Global oldGlobal = Context.getGlobal(); |         Global oldGlobal = Context.getGlobal(); | ||||||
| @ -56,7 +55,7 @@ public class YJSCompiler { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private static Context makeContext(final InputStream in, final OutputStream out, |     private static Context makeContext(final InputStream in, final OutputStream out, | ||||||
|                                        final OutputStream err) { |             final OutputStream err) { | ||||||
|         final PrintStream pout = |         final PrintStream pout = | ||||||
|                 out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); |                 out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); | ||||||
|         final PrintStream perr = |         final PrintStream perr = | ||||||
| @ -68,7 +67,7 @@ public class YJSCompiler { | |||||||
|         final ErrorManager errors = new ErrorManager(werr); |         final ErrorManager errors = new ErrorManager(werr); | ||||||
|         // Set up options. |         // Set up options. | ||||||
|         final Options options = new Options("nashorn", werr); |         final Options options = new Options("nashorn", werr); | ||||||
|         options.process(new String[]{}); |         options.process(new String[] {}); | ||||||
|         // detect scripting mode by any source's first character being '#' |         // detect scripting mode by any source's first character being '#' | ||||||
|         options.set("persistent.code.cache", true); |         options.set("persistent.code.cache", true); | ||||||
|         options.set("print.code", "true"); |         options.set("print.code", "true"); | ||||||
| @ -121,7 +120,7 @@ public class YJSCompiler { | |||||||
|         Set<String> todo = new HashSet<>(); |         Set<String> todo = new HashSet<>(); | ||||||
|         Set<String> allEntries = new HashSet<>(); |         Set<String> allEntries = new HashSet<>(); | ||||||
|         Enumeration<? extends ZipEntry> iter = zf.entries(); |         Enumeration<? extends ZipEntry> iter = zf.entries(); | ||||||
|         for (; iter.hasMoreElements(); ) { |         for (; iter.hasMoreElements();) { | ||||||
|             ZipEntry ele = iter.nextElement(); |             ZipEntry ele = iter.nextElement(); | ||||||
|             if (ele != null) |             if (ele != null) | ||||||
|                 allEntries.add(ele.getName()); |                 allEntries.add(ele.getName()); | ||||||
| @ -140,7 +139,8 @@ public class YJSCompiler { | |||||||
|                 String cnPath = entry.getName(); |                 String cnPath = entry.getName(); | ||||||
|                 int i = cnPath.lastIndexOf("/"); |                 int i = cnPath.lastIndexOf("/"); | ||||||
|                 String cnDir = ""; |                 String cnDir = ""; | ||||||
|                 if (i != -1) cnDir = cnPath.substring(0, i); |                 if (i != -1) | ||||||
|  |                     cnDir = cnPath.substring(0, i); | ||||||
|                 czb.put(str, cn); |                 czb.put(str, cn); | ||||||
|                 for (ImportNode in : cn.getImports()) { |                 for (ImportNode in : cn.getImports()) { | ||||||
|                     String path = in.getPath(); |                     String path = in.getPath(); | ||||||
| @ -155,9 +155,10 @@ public class YJSCompiler { | |||||||
|                 if (allEntries.contains(str)) |                 if (allEntries.contains(str)) | ||||||
|                     toParse.add(str); |                     toParse.add(str); | ||||||
|                 else { |                 else { | ||||||
|                     //TODO parse manifest.json first? |                     // TODO parse manifest.json first? | ||||||
|                     for (String entry : allEntries) |                     for (String entry : allEntries) | ||||||
|                         if (!czb.containsPath(entry) && entry.startsWith(str) && entry.endsWith(".yjs")) { |                         if (!czb.containsPath(entry) && entry.startsWith(str) | ||||||
|  |                                 && entry.endsWith(".yjs")) { | ||||||
|                             toParse.add(entry); |                             toParse.add(entry); | ||||||
|                         } |                         } | ||||||
|                 } |                 } | ||||||
| @ -181,7 +182,7 @@ public class YJSCompiler { | |||||||
|                 + " function getGlobal () { return Global; }}"; |                 + " function getGlobal () { return Global; }}"; | ||||||
|         czb.put(globalBeanName + ".yjs", |         czb.put(globalBeanName + ".yjs", | ||||||
|                 compile(new ByteArrayInputStream( |                 compile(new ByteArrayInputStream( | ||||||
|                                 globalBeanContract.getBytes(StandardCharsets.UTF_8)), |                         globalBeanContract.getBytes(StandardCharsets.UTF_8)), | ||||||
|                         globalBeanName + ".yjs")); |                         globalBeanName + ".yjs")); | ||||||
|         LOGGER.info("--compile-- " + globalBeanName); |         LOGGER.info("--compile-- " + globalBeanName); | ||||||
|         czb.setMergedContractNode(); |         czb.setMergedContractNode(); | ||||||
|  | |||||||
| @ -18,9 +18,10 @@ public class DOOP extends AnnotationProcessor { | |||||||
|         functionNode.setIsDoipOperation(true); |         functionNode.setIsDoipOperation(true); | ||||||
|         functionNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode)); |         functionNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode)); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void processInterface(AnnotationNode anno, ContractNode contractNode, |     public void processInterface(AnnotationNode anno, ContractNode contractNode, | ||||||
|                                 InterfaceNode interfaceNode) throws Exception { |             InterfaceNode interfaceNode) throws Exception { | ||||||
|         interfaceNode.setIsDoipOperation(true); |         interfaceNode.setIsDoipOperation(true); | ||||||
|         interfaceNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode)); |         interfaceNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode)); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -15,9 +15,10 @@ public class Join extends AnnotationProcessor { | |||||||
|         // 增加标记,在ContractNode中记录Join相关的函数和Join规则 |         // 增加标记,在ContractNode中记录Join相关的函数和Join规则 | ||||||
|         functionNode.setJoinInfo(JoinInfo.create(anno, contractNode)); |         functionNode.setJoinInfo(JoinInfo.create(anno, contractNode)); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void processInterface(AnnotationNode anno, ContractNode contractNode, |     public void processInterface(AnnotationNode anno, ContractNode contractNode, | ||||||
|                                 InterfaceNode interfaceNode) { |             InterfaceNode interfaceNode) { | ||||||
|         interfaceNode.setJoinInfo(JoinInfo.create(anno, contractNode)); |         interfaceNode.setJoinInfo(JoinInfo.create(anno, contractNode)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -13,9 +13,10 @@ public class Route extends AnnotationProcessor { | |||||||
|             FunctionNode functionNode) { |             FunctionNode functionNode) { | ||||||
|         functionNode.setRouteInfo(RouteInfo.create(anno, contractNode)); |         functionNode.setRouteInfo(RouteInfo.create(anno, contractNode)); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void processInterface(AnnotationNode anno, ContractNode contractNode, |     public void processInterface(AnnotationNode anno, ContractNode contractNode, | ||||||
|                                 InterfaceNode interfaceNode) { |             InterfaceNode interfaceNode) { | ||||||
|         interfaceNode.setRouteInfo(RouteInfo.create(anno, contractNode)); |         interfaceNode.setRouteInfo(RouteInfo.create(anno, contractNode)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user