From bb71895f6ef3ff67f739526ecf1834d6b8bd15fb Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Wed, 23 Aug 2023 16:00:47 +0800 Subject: [PATCH] feat: support fork annotation --- build.gradle | 2 +- .../base/org/bdware/sc/node/ContractNode.java | 19 ++++++++++++++++- .../base/org/bdware/sc/node/FunctionNode.java | 10 +++++++++ .../org/bdware/sc/node/InterfaceNode.java | 11 ++++++++++ .../entry/org/bdware/sc/bean/ForkInfo.java | 21 +++++++++++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/main/entry/org/bdware/sc/bean/ForkInfo.java diff --git a/build.gradle b/build.gradle index da05bab..db1a9d4 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ dependencies { } group = "org.bdware.sc" -version = "1.7.8" +version = "1.7.9" tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE) task copyLibs(type: Copy) { diff --git a/src/main/base/org/bdware/sc/node/ContractNode.java b/src/main/base/org/bdware/sc/node/ContractNode.java index d2512a8..9970279 100644 --- a/src/main/base/org/bdware/sc/node/ContractNode.java +++ b/src/main/base/org/bdware/sc/node/ContractNode.java @@ -3,6 +3,7 @@ package org.bdware.sc.node; import com.google.gson.JsonObject; import org.antlr.v4.runtime.CommonTokenStream; import org.bdware.sc.bean.DoipOperationInfo; +import org.bdware.sc.bean.ForkInfo; import org.bdware.sc.bean.JoinInfo; import org.bdware.sc.bean.RouteInfo; import org.bdware.sc.event.REvent.REventSemantics; @@ -238,6 +239,7 @@ public class ContractNode { } public void maintainRouteJoinInfo(JsonObject methodRouteInfoMap, JsonObject methodJoinInfoMap, + JsonObject methodForkInfoMap, JsonObject dependentFunctions) { // all functions存了ContractNode中,所有的FunctionNode List allFunctions = getFunctions(); @@ -247,11 +249,12 @@ public class ContractNode { if (doopAnnotation != null && doipOperationInfo != null) { RouteInfo routeInfo = functionNode.getRouteInfo(); JoinInfo joinInfo = functionNode.getJoinInfo(); + ForkInfo forkInfo = functionNode.getForkInfo(); if (routeInfo != null) { packSourceFunctionAndDependentFunctions(getFunction(routeInfo.funcName), dependentFunctions); methodRouteInfoMap.add(doipOperationInfo.operationName, - JsonUtil.parseObjectAsJsonObject(routeInfo)); + JsonUtil.parseObjectAsJsonObject(routeInfo)); } if (joinInfo != null) { packSourceFunctionAndDependentFunctions(getFunction(joinInfo.joinCountFuncName), @@ -261,6 +264,13 @@ public class ContractNode { methodJoinInfoMap.add(doipOperationInfo.operationName, JsonUtil.parseObjectAsJsonObject(joinInfo)); } + if (forkInfo != null) { + packSourceFunctionAndDependentFunctions(getFunction(forkInfo.funcName), + dependentFunctions); + methodForkInfoMap.add(doipOperationInfo.operationName, + JsonUtil.parseObjectAsJsonObject(forkInfo)); + } + } } @@ -270,6 +280,7 @@ public class ContractNode { if (doopAnnotation != null && doipOperationInfo != null) { RouteInfo routeInfo = interfaceNode.getRouteInfo(); JoinInfo joinInfo = interfaceNode.getJoinInfo(); + ForkInfo forkInfo = interfaceNode.getForkInfo(); if (routeInfo != null) { packSourceFunctionAndDependentFunctions(getFunction(routeInfo.funcName), dependentFunctions); @@ -284,6 +295,12 @@ public class ContractNode { methodJoinInfoMap.add(doipOperationInfo.operationName, JsonUtil.parseObjectAsJsonObject(joinInfo)); } + if (forkInfo != null) { + packSourceFunctionAndDependentFunctions(getFunction(forkInfo.funcName), + dependentFunctions); + methodForkInfoMap.add(doipOperationInfo.operationName, + JsonUtil.parseObjectAsJsonObject(routeInfo)); + } } } } diff --git a/src/main/base/org/bdware/sc/node/FunctionNode.java b/src/main/base/org/bdware/sc/node/FunctionNode.java index 22e7a1f..9401075 100644 --- a/src/main/base/org/bdware/sc/node/FunctionNode.java +++ b/src/main/base/org/bdware/sc/node/FunctionNode.java @@ -2,6 +2,7 @@ package org.bdware.sc.node; import com.google.gson.JsonElement; import org.bdware.sc.bean.DoipOperationInfo; +import org.bdware.sc.bean.ForkInfo; import org.bdware.sc.bean.JoinInfo; import org.bdware.sc.bean.RouteInfo; @@ -38,6 +39,7 @@ public class FunctionNode extends Script { private JsonElement homoEncryptConf; private JsonElement homoDecryptConf; public transient Class compiledClazz; + private ForkInfo forkInfo; public FunctionNode(String name, String fileName) { this.functionName = name; @@ -302,4 +304,12 @@ public class FunctionNode extends Script { return node; return null; } + + public void setForkInfo(ForkInfo forkInfo) { + this.forkInfo = forkInfo; + } + + public ForkInfo getForkInfo() { + return forkInfo; + } } diff --git a/src/main/base/org/bdware/sc/node/InterfaceNode.java b/src/main/base/org/bdware/sc/node/InterfaceNode.java index 66cd04d..f38347d 100644 --- a/src/main/base/org/bdware/sc/node/InterfaceNode.java +++ b/src/main/base/org/bdware/sc/node/InterfaceNode.java @@ -1,6 +1,7 @@ package org.bdware.sc.node; import org.bdware.sc.bean.DoipOperationInfo; +import org.bdware.sc.bean.ForkInfo; import org.bdware.sc.bean.JoinInfo; import org.bdware.sc.bean.RouteInfo; @@ -153,4 +154,14 @@ public class InterfaceNode extends Script { return node; return null; } + + private ForkInfo forkInfo; + + public void setForkInfo(ForkInfo forkInfo) { + this.forkInfo = forkInfo; + } + + public ForkInfo getForkInfo() { + return forkInfo; + } } diff --git a/src/main/entry/org/bdware/sc/bean/ForkInfo.java b/src/main/entry/org/bdware/sc/bean/ForkInfo.java new file mode 100644 index 0000000..9ee9267 --- /dev/null +++ b/src/main/entry/org/bdware/sc/bean/ForkInfo.java @@ -0,0 +1,21 @@ +package org.bdware.sc.bean; + +import org.bdware.sc.node.AnnotationNode; +import org.bdware.sc.node.ContractNode; +import org.bdware.sc.util.JsonUtil; + +import java.io.Serializable; + +public class ForkInfo implements Serializable { + public String funcName; + + public static ForkInfo create(AnnotationNode annotationNode, ContractNode contractNode) { + ForkInfo info = new ForkInfo(); + if (annotationNode.getArgs().size() == 1) { + String str = annotationNode.getArgs().get(0); + info = JsonUtil.fromJson(str, ForkInfo.class); + } + System.out.println("[ForkInfo] annotationNode:" + JsonUtil.toJson(annotationNode)); + return info; + } +}