refactor extract routerInfo and joinInfo

This commit is contained in:
CaiHQ 2023-03-27 16:10:59 +08:00
parent 3fb7b5c7c2
commit fdd5848989
3 changed files with 53 additions and 2 deletions

View File

@ -52,7 +52,7 @@ dependencies {
}
group = "org.bdware.sc"
version = "1.6.6"
version = "1.6.7"
tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)

View File

@ -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<FunctionNode> 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());
}
}
}

View File

@ -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;
}
}