this.replaceMethodCode.append(
spaces + "// remove obsolete connections...\n"
);
for(ConnectionContainer conn : leftConnections) {
AbstractRuleOperator parentOp = conn.getParent();
AbstractRuleOperator childOp = conn.getChild();
String parentName = this.getJumpOverName(parentOp, false);
String childName = this.getJumpOverName(childOp, true);
String opIDLabel = conn.getOpIDLabel();
boolean hasLabel = conn.getIsActive() && !opIDLabel.equals("");
StringBuffer labelBrackets = new StringBuffer();
String succeedingString = null;
int dim = 0;
StringBuffer arrayAccess = new StringBuffer();
switch(conn.getMode()) {
case ALL_PRECEDING:
dim = this.variableList_left.get(childName).getDimension();
if(hasLabel) {
for(int i = 0; i <= dim; i += 1) {
labelBrackets.append("[]");
}
this.replaceMethodCode.append(
spaces + "int" + labelBrackets + " _label_" + opIDLabel + " = null;\n" +
"\n"
);
}
for(int i = 0; i < dim; i += 1) {
if(hasLabel) {
labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());
this.replaceMethodCode.append(
spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + childName + ".length]" + labelBrackets + ";\n" +
"\n"
);
}
this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < this." + childName + ".length; this._dim_" + i + " += 1) {\n");
arrayAccess.append("[this._dim_" + i + "]");
spaces.append(" ");
}
succeedingString = (conn.getIsActive() && conn.getOpID() != -1) ? "new OperatorIDTuple(this." + childName + arrayAccess + ", " + conn.getOpID() + ")" : "this." + childName + arrayAccess;
if(hasLabel) {
labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());
this.replaceMethodCode.append(
spaces + "int _label_" + opIDLabel + "_count" + " = 0;\n" +
spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + parentName + arrayAccess + ".length]" + labelBrackets + ";\n" +
"\n"
);
}
this.replaceMethodCode.append(spaces + "for(" + parentOp.getClassType().getOpClass().getName() + " _parent : this." + parentName + arrayAccess + ") {\n");
if(hasLabel) {
this.replaceMethodCode.append(
spaces + " _label_" + opIDLabel + arrayAccess + "[_label_" + opIDLabel + "_count] = _parent.getOperatorIDTuple(this." + childName + arrayAccess + ").getId();\n" +
spaces + " _label_" + opIDLabel + "_count += 1;\n" +
"\n"
);
}
this.replaceMethodCode.append(
spaces + " _parent.removeSucceedingOperator(" + succeedingString + ");\n" +
spaces + " this." + childName + arrayAccess + ".removePrecedingOperator(_parent);\n" +
spaces + "}\n" +
"\n"
);
break;
case ALL_SUCCEEDING:
dim = this.variableList_left.get(parentName).getDimension();
if(hasLabel) {
for(int i = 0; i <= dim; i += 1) {
labelBrackets.append("[]");
}
this.replaceMethodCode.append(
spaces + "int" + labelBrackets + " _label_" + opIDLabel + " = null;\n" +
"\n"
);
}
for(int i = 0; i < dim; i += 1) {
if(hasLabel) {
labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());
this.replaceMethodCode.append(
spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + childName + ".length]" + labelBrackets + ";\n" +
"\n"
);
}
this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < this." + parentName + ".length; this._dim_" + i + " += 1) {\n");
arrayAccess.append("[this._dim_" + i + "]");
spaces.append(" ");
}
succeedingString = (conn.getIsActive() && conn.getOpID() != -1) ? "new OperatorIDTuple(_child, " + conn.getOpID() + ")" : "_child";
if(hasLabel) {
labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());
this.replaceMethodCode.append(
spaces + "int _label_" + opIDLabel + "_count = 0;\n" +
spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + childName + arrayAccess + ".length]" + labelBrackets + ";\n" +
"\n"
);
}
this.replaceMethodCode.append(spaces + "for(" + childOp.getClassType().getOpClass().getName() + " _child : this." + childName + arrayAccess + ") {\n");
if(hasLabel) {
this.replaceMethodCode.append(
spaces + " _label_" + opIDLabel + arrayAccess + "[_label_" + opIDLabel + "_count] = this." + parentName + arrayAccess + ".getOperatorIDTuple(_child).getId();\n" +
spaces + " _label_" + opIDLabel + "_count += 1;\n" +
"\n"
);
}
this.replaceMethodCode.append(
spaces + " this." + parentName + arrayAccess + ".removeSucceedingOperator(" + succeedingString + ");\n" +
spaces + " _child.removePrecedingOperator(this." + parentName + arrayAccess + ");\n" +
spaces + "}\n" +
"\n"
);
break;
default:
dim = this.variableList_left.get(parentName).getDimension();
if(hasLabel) {
for(int i = 0; i <= dim; i += 1) {
labelBrackets.append("[]");
}
this.replaceMethodCode.append(
spaces + "int" + labelBrackets + " _label_" + opIDLabel + " = null;\n" +
"\n"
);
}
for(int i = 0; i < dim; i += 1) {
if(hasLabel) {
labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());
this.replaceMethodCode.append(
spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + childName + ".length]" + labelBrackets + ";\n" +
"\n"
);
}
this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < this." + parentName + ".length; this._dim_" + i + " += 1) {\n");
arrayAccess.append("[this._dim_" + i + "]");
spaces.append(" ");
}
succeedingString = (conn.getIsActive() && conn.getOpID() != -1) ? "new OperatorIDTuple(this." + childName + arrayAccess + ", " + conn.getOpID() + ")" : "this." + childName + arrayAccess;
if(hasLabel) {
labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());
this.replaceMethodCode.append(
spaces + " _label_" + opIDLabel + arrayAccess + " = this." + parentName + arrayAccess + ".getOperatorIDTuple(this." + childName + arrayAccess + ").getId();\n" +
"\n"
);
}
this.replaceMethodCode.append(
spaces + "this." + parentName + arrayAccess + ".removeSucceedingOperator(" + succeedingString + ");\n" +
spaces + "this." + childName + arrayAccess + ".removePrecedingOperator(this." + parentName + arrayAccess + ");\n"
);
break;
}
for(int i = 0; i < dim; i += 1) {
spaces.delete(spaces.length()-4, spaces.length());
this.replaceMethodCode.append(spaces + "}\n");
}
}
// --- remove all connections that only occur on the left side - end ---
// --- add operators that only occur on the right side - begin ---
this.replaceMethodCode.append(
"\n" +
spaces + "// add new operators...\n"
);
for(String opName : rightOperators) {
AbstractRuleOperator op = rightOperatorsMap.get(opName);
String opClass = op.getClassType().getOpClass().getName();
VariableContainer vc = variableList_right.get(opName);
int dim = vc.getDimension();
StringBuffer arrayAccess = new StringBuffer();
for(int i = 0; i < dim; i += 1) {
arrayAccess.append("[]");
}
this.replaceMethodCode.append(spaces + opClass + arrayAccess + " " + opName + " = null;\n");
arrayAccess = new StringBuffer();
for(int i = 0; i < dim; i += 1) {
this.replaceMethodCode.append(
vc.initiate_next_dimension(spaces, i, this.getOpName(vc.getCountProvider(), rightOperators, true) + arrayAccess + ".length", false) +
"\n" +
spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < " + opName + arrayAccess + ".length; this._dim_" + i + " += 1) {\n"
);
spaces.append(" ");
arrayAccess.append("[this._dim_" + i + "]");
}
this.replaceMethodCode.append(spaces + opName + arrayAccess + " = new " + opClass + "();\n");
if(this.generateStartMap) {
this.replaceMethodCode.append(spaces + "this.addNodeToStartNodeMap(" + opName + arrayAccess + ", _startNodes);\n");
}
for(int i = 0; i < dim; i += 1) {
spaces.delete(spaces.length()-4, spaces.length());
this.replaceMethodCode.append(spaces + "}\n");
}
}
this.replaceMethodCode.append("\n");
// --- add operators that only occur on the right side - end ---
// --- add connections that only occur on the right side - begin ---
this.replaceMethodCode.append(
"\n" +
spaces + "// add new connections...\n"
);
for(ConnectionContainer conn : rightConnections) {
AbstractRuleOperator parentOp = conn.getParent();
AbstractRuleOperator childOp = conn.getChild();
String parentName = this.getOpName(parentOp, rightOperators, false);
String childName = this.getOpName(childOp, rightOperators, true);
VariableContainer parentVC = variableList_right.get(this.getJumpOverName(parentOp, false));
VariableContainer childVC = variableList_right.get(this.getJumpOverName(childOp, true));
String opIDLabel = conn.getOpIDLabel();
boolean hasLabel = conn.getIsActive() && !opIDLabel.equals("");
int dim = 0;
StringBuffer arrayAccess = new StringBuffer();
String succeedingString = "";
switch(conn.getMode()) {
case ALL_PRECEDING:
dim = childVC.getDimension();
for(int i = 0; i < dim; i += 1) {
this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < " + childName + ".length; this._dim_" + i + " += 1) {\n");
arrayAccess.append("[this._dim_" + i + "]");
spaces.append(" ");
}
if(conn.getIsActive()) {
if(hasLabel) {
succeedingString = "new OperatorIDTuple(" + childName + arrayAccess + ", _label_" + conn.getOpIDLabel() + arrayAccess + "[_label_" + opIDLabel + "_count])";
this.replaceMethodCode.append(
spaces + "_label_" + opIDLabel + "_count = 0;\n" +
"\n"
);
}
else {
succeedingString = "new OperatorIDTuple(" + childName + arrayAccess + ", " + conn.getOpID() + ")";
}
}
else {
succeedingString = childName + arrayAccess;
}
this.replaceMethodCode.append(
spaces + "for(" + parentOp.getClassType().getOpClass().getName() + " _parent : " + parentName + arrayAccess + ") {\n" +
spaces + " _parent.addSucceedingOperator(" + succeedingString + ");\n" +
spaces + " " + childName + arrayAccess + ".addPrecedingOperator(_parent);\n"
);
if(hasLabel) {
this.replaceMethodCode.append(
"\n" +
spaces + " _label_" + opIDLabel + "_count += 1;\n"
);
}
this.replaceMethodCode.append(
spaces + "}\n" +
"\n"
);
break;
case ALL_SUCCEEDING:
dim = parentVC.getDimension();
for(int i = 0; i < dim; i += 1) {
this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < " + parentName + ".length; this._dim_" + i + " += 1) {\n");
arrayAccess.append("[this._dim_" + i + "]");
spaces.append(" ");
}
if(conn.getIsActive()) {
if(hasLabel) {
succeedingString = "new OperatorIDTuple(_child, _label_" + conn.getOpIDLabel() + arrayAccess + "[_label_" + opIDLabel + "_count])";
this.replaceMethodCode.append(
spaces + "_label_" + opIDLabel + "_count = 0;\n" +
"\n"
);
}
else {
succeedingString = "new OperatorIDTuple(_child, " + conn.getOpID() + ")";
}
}
else {
succeedingString = "_child";
}
this.replaceMethodCode.append(
spaces + "for(" + childOp.getClassType().getOpClass().getName() + " _child : " + childName + arrayAccess + ") {\n" +
spaces + " " + parentName + arrayAccess + ".addSucceedingOperator(" + succeedingString + ");\n" +
spaces + " _child.addPrecedingOperator(" + parentName + arrayAccess + ");\n"
);
if(hasLabel) {