add DO operation and multiple functions mapping relations

This commit is contained in:
haoeliu@foxmail.com 2023-03-12 20:12:55 +08:00
parent d040028463
commit 18b01e3ab0
6 changed files with 14 additions and 9 deletions

View File

@ -63,7 +63,9 @@ public class DebugMain {
= new ResultCallback() {
@Override
public void onResult(String str) {
if(str.contains("Error")) {
LOGGER.error("Some error happens: " + str);
}
LOGGER.info("[PrintCB] " + str);
}
};

View File

@ -10,7 +10,7 @@ public abstract class AnnotationProcessor {
}
public void processFunction(
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) throws Exception {
return;
}
}

View File

@ -188,7 +188,7 @@ public class YJSCompiler {
return czb;
}
public ContractNode compile(InputStream input, String fileName) throws IOException {
public ContractNode compile(InputStream input, String fileName) throws Exception {
// 词法分析
JavaScriptLexer lexer = new JavaScriptLexer(new ANTLRInputStream(input));
lexer.setUseStrictDefault(true);
@ -208,7 +208,7 @@ public class YJSCompiler {
return contract;
}
private void handleAnnotation(ContractNode contractNode) {
private void handleAnnotation(ContractNode contractNode) throws Exception {
for (AnnotationNode node : contract.annotations) {
AnnotationProcessor processor = findProcessor(node);
if (processor != null) {

View File

@ -13,7 +13,7 @@ import org.bdware.sc.node.FunctionNode;
// DOOP is designed for DoipModule which contains specific functions for RepositoryHandler
public class DOOP extends AnnotationProcessor {
@Override
public void processFunction(AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
public void processFunction(AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) throws Exception {
// 通过DOOP注解解析对应的值并放进对应的FunctionNode中
// 注解必须暴露出来昂
functionNode.setIsExport(true);

View File

@ -16,7 +16,6 @@ import org.bdware.sc.bean.ContractRequest;
import org.bdware.sc.boundry.JavaScriptEntry;
import org.bdware.sc.entity.DoipMessagePacker;
import org.bdware.sc.node.FunctionNode;
import org.bdware.sc.util.JsonUtil;
import java.util.HashMap;
import java.util.Map;
@ -41,8 +40,12 @@ public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler
return instance;
}
public void addDoipOperation(FunctionNode function) {
doipFunctionNodeMap.put(function.getDoipOperationInfo().operationName, function);
public void addDoipOperation(FunctionNode function) throws Exception {
String operationName = function.getDoipOperationInfo().operationName;
if (doipFunctionNodeMap.containsKey(operationName)) {
throw new Exception("Contract is wrong: One DO operation maps multiple functions");
}
doipFunctionNodeMap.put(operationName, function);
}
@Override

View File

@ -67,7 +67,7 @@ public class YJSParserTest {
ContractNode cn = compiler.compile(resource, "rrr.yjs");
new DesktopEngine();
System.out.println(new Gson().toJson(cn));
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
}