From fdd584898900a12cf8d17d41b75c6ceda6aa4ae9 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Mon, 27 Mar 2023 16:10:59 +0800 Subject: [PATCH] refactor extract routerInfo and joinInfo --- build.gradle | 2 +- .../base/org/bdware/sc/node/ContractNode.java | 46 ++++++++++++++++++- .../base/org/bdware/sc/node/FunctionNode.java | 7 +++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 6fc6f9a..af65dce 100644 --- a/build.gradle +++ b/build.gradle @@ -52,7 +52,7 @@ dependencies { } group = "org.bdware.sc" -version = "1.6.6" +version = "1.6.7" tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE) diff --git a/src/main/base/org/bdware/sc/node/ContractNode.java b/src/main/base/org/bdware/sc/node/ContractNode.java index 86bf0ea..3cae6bd 100644 --- a/src/main/base/org/bdware/sc/node/ContractNode.java +++ b/src/main/base/org/bdware/sc/node/ContractNode.java @@ -1,8 +1,12 @@ package org.bdware.sc.node; +import com.google.gson.JsonObject; import org.antlr.v4.runtime.CommonTokenStream; -import org.bdware.doip.codec.operations.BasicOperations; +import org.bdware.sc.bean.DoipOperationInfo; +import org.bdware.sc.bean.JoinInfo; +import org.bdware.sc.bean.RouteInfo; import org.bdware.sc.event.REvent.REventSemantics; +import org.bdware.sc.util.JsonUtil; import java.util.*; @@ -182,6 +186,14 @@ public class ContractNode { return yjsType; } + public boolean hasDoipModule() { + if (functions != null) + for (FunctionNode node : functions) { + if (node.getDoipOperationInfo() != null) return true; + } + return false; + } + public void setYjsType(YjsType yjsType1) { this.yjsType = yjsType1; } @@ -197,4 +209,36 @@ public class ContractNode { public void resetContractName(String name) { contractName = name; } + + public void maintainRouteJoinInfo(JsonObject methodRouteInfoMap, JsonObject methodJoinInfoMap, JsonObject dependentFunctions) { + // all functions存了ContractNode中,所有的FunctionNode + List allFunctions = getFunctions(); + for (FunctionNode functionNode : allFunctions) { + AnnotationNode doopAnnotation = functionNode.getAnnotation("DOOP"); + DoipOperationInfo doipOperationInfo = functionNode.getDoipOperationInfo(); + if (doopAnnotation != null && doipOperationInfo != null) { + RouteInfo routeInfo = functionNode.getRouteInfo(); + JoinInfo joinInfo = functionNode.getJoinInfo(); + if (routeInfo != null) { + packSourceFunctionAndDependentFunctions(getFunction(routeInfo.funcName), dependentFunctions); + methodRouteInfoMap.add(doipOperationInfo.operationName, JsonUtil.parseObjectAsJsonObject(routeInfo)); + } + if (joinInfo != null) { + packSourceFunctionAndDependentFunctions(getFunction(joinInfo.joinCountFuncName), dependentFunctions); + packSourceFunctionAndDependentFunctions(getFunction(joinInfo.joinFuncName), dependentFunctions); + methodJoinInfoMap.add(doipOperationInfo.operationName, JsonUtil.parseObjectAsJsonObject(joinInfo)); + } + } + } + } + + public void packSourceFunctionAndDependentFunctions(FunctionNode sourceFunctionNode, JsonObject functions) { + if (sourceFunctionNode == null) return; + functions.addProperty(sourceFunctionNode.functionName, sourceFunctionNode.plainText()); + // find all dependent functions to the "functions" struct + for (String dependentFunctionName : sourceFunctionNode.getDependentFunctions()) { + FunctionNode dependentFunctionNode = getFunction(dependentFunctionName); + functions.addProperty(dependentFunctionName, dependentFunctionNode.plainText()); + } + } } diff --git a/src/main/base/org/bdware/sc/node/FunctionNode.java b/src/main/base/org/bdware/sc/node/FunctionNode.java index 173b79d..2c01602 100644 --- a/src/main/base/org/bdware/sc/node/FunctionNode.java +++ b/src/main/base/org/bdware/sc/node/FunctionNode.java @@ -295,4 +295,11 @@ public class FunctionNode extends Script { public void setFunctionName(String functionName) { this.functionName = functionName; } + + public AnnotationNode getAnnotation(String annotationName) { + for (AnnotationNode node : annotations) + if (node.getType() != null && node.getType().equals(annotationName)) + return node; + return null; + } }