use of org.drools.core.reteoo.Sink in project drools by kiegroup.
the class InlineFieldReferenceInitHandler method generateInitBody.
private void generateInitBody(BlockStmt initBodyPerPartition, List<NetworkNode> subNodes, int partitionIndex) {
CompilationUnit partitionedCompilationUnit = partitionedNodeInitialisationClasses.get(partitionIndex);
PackageDeclaration partitionedClassPackage = (PackageDeclaration) partitionedCompilationUnit.getChildNodes().get(0);
ClassOrInterfaceDeclaration partitionedClass = (ClassOrInterfaceDeclaration) partitionedCompilationUnit.getChildNodes().get(1);
for (NetworkNode n : subNodes) {
if (n instanceof CanInlineInANC) {
String variableName;
final ClassOrInterfaceType initMethodReturnType;
if (n instanceof AlphaNode) {
variableName = getVariableName((AlphaNode) n);
initMethodReturnType = StaticJavaParser.parseClassOrInterfaceType(getVariableType((AlphaNode) n).getCanonicalName());
} else {
variableName = getVariableName((Sink) n);
initMethodReturnType = StaticJavaParser.parseClassOrInterfaceType(getVariableType((Sink) n).getCanonicalName());
}
String initMethodName = String.format("init%s", variableName);
// We'll need to partition the lambda creation as with too many the compiler crashes
// We'll move it to a separated class
MethodDeclaration initMethod = new MethodDeclaration(nodeList(Modifier.publicModifier(), Modifier.staticModifier()), initMethodName, initMethodReturnType, parametersFromAdditionalFields());
Expression initExpressionForNode = ((CanInlineInANC) n).toANCInlinedForm();
partitionedClass.addMember(initMethod);
BlockStmt initMethodBlock = new BlockStmt();
initMethodBlock.addStatement(new ReturnStmt(initExpressionForNode));
initMethod.setBody(initMethodBlock);
String callInitMethodAndAssignToFieldString = String.format("%s = %s.%s.%s(ctx);", variableName, partitionedClassPackage.getNameAsString(), partitionedClass.getNameAsString(), initMethodName);
initBodyPerPartition.addStatement(parseStatement(callInitMethodAndAssignToFieldString));
}
}
}
use of org.drools.core.reteoo.Sink in project drools by kiegroup.
the class BaseNode method getSinks.
public Sink[] getSinks() {
Sink[] sinks = null;
if (this instanceof EntryPointNode) {
EntryPointNode source = (EntryPointNode) this;
Collection<ObjectTypeNode> otns = source.getObjectTypeNodes().values();
sinks = otns.toArray(new Sink[otns.size()]);
} else if (this instanceof ObjectSource) {
ObjectSource source = (ObjectSource) this;
sinks = source.getObjectSinkPropagator().getSinks();
} else if (this instanceof LeftTupleSource) {
LeftTupleSource source = (LeftTupleSource) this;
sinks = source.getSinkPropagator().getSinks();
}
return sinks;
}
use of org.drools.core.reteoo.Sink in project drools by kiegroup.
the class ReteDiagram method getSinks.
public static Sink[] getSinks(BaseNode node) {
Sink[] sinks = null;
if (node instanceof EntryPointNode) {
EntryPointNode source = (EntryPointNode) node;
Collection<ObjectTypeNode> otns = source.getObjectTypeNodes().values();
sinks = otns.toArray(new Sink[otns.size()]);
} else if (node instanceof ObjectSource) {
ObjectSource source = (ObjectSource) node;
sinks = source.getObjectSinkPropagator().getSinks();
} else if (node instanceof LeftTupleSource) {
LeftTupleSource source = (LeftTupleSource) node;
sinks = source.getSinkPropagator().getSinks();
}
return sinks;
}
use of org.drools.core.reteoo.Sink in project drools by kiegroup.
the class ReteDiagram method visitNodes.
private static void visitNodes(BaseNode node, String ident, Set<Integer> visitedNodesIDs, HashMap<Class<? extends BaseNode>, List<BaseNode>> nodeMap, List<Vertex<BaseNode, BaseNode>> vertexes, Map<Class<? extends BaseNode>, Set<BaseNode>> levelMap, PrintStream out) {
if (!visitedNodesIDs.add(node.getId())) {
return;
}
addToNodeMap(node, nodeMap);
addToLevel(node, levelMap);
Sink[] sinks = getSinks(node);
if (sinks != null) {
for (Sink sink : sinks) {
vertexes.add(Vertex.of(node, (BaseNode) sink));
if (sink instanceof BaseNode) {
visitNodes((BaseNode) sink, ident + " ", visitedNodesIDs, nodeMap, vertexes, levelMap, out);
}
}
}
}
Aggregations