Commit de8a36a4 authored by Christoph Richter's avatar Christoph Richter
Browse files

ChainOfResponsibility: Ensure to start at top of the chain

parent 9b9d7b81
Pipeline #63661 failed with stage
in 26 seconds
...@@ -11,15 +11,19 @@ public abstract class BaseMathFunctionFixerHandler extends BaseChainOfResponsibi ...@@ -11,15 +11,19 @@ public abstract class BaseMathFunctionFixerHandler extends BaseChainOfResponsibi
protected abstract void doFixMathFunction(MathExpressionSymbol symbol, BluePrintCPP bluePrintCPP); protected abstract void doFixMathFunction(MathExpressionSymbol symbol, BluePrintCPP bluePrintCPP);
public void handleFixMathFunction(MathExpressionSymbol symbol, BluePrintCPP bluePrintCPP) { private void handleFixMathFunction(MathExpressionSymbol symbol, BluePrintCPP bluePrintCPP) {
if (canFixMathSymbol(symbol)) { if (canFixMathSymbol(symbol)) {
doFixMathFunction(symbol, bluePrintCPP); doFixMathFunction(symbol, bluePrintCPP);
} else if (getSuccessor() != null) { } else if (getSuccessor() != null) {
getSuccessor().handleFixMathFunction(symbol, bluePrintCPP); ((BaseMathFunctionFixerHandler) getSuccessor()).handleFixMathFunction(symbol, bluePrintCPP);
} else { } else {
Log.info(symbol.getTextualRepresentation(), "Symbol:"); Log.info(symbol.getTextualRepresentation(), "Symbol:");
Log.debug(getRole(), "Case not handled!"); Log.debug(getRole(), "Case not handled!");
} }
} }
public void chainHandleFixMathFunction(MathExpressionSymbol symbol, BluePrintCPP bluePrintCPP) {
((BaseMathFunctionFixerHandler) getChainStart()).handleFixMathFunction(symbol, bluePrintCPP);
}
} }
...@@ -112,7 +112,7 @@ public class MathFunctionFixer extends BaseMathFunctionFixerHandler { ...@@ -112,7 +112,7 @@ public class MathFunctionFixer extends BaseMathFunctionFixerHandler {
} }
public static void fixMathFunctions(MathExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) { public static void fixMathFunctions(MathExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) {
getInstance().doFixMathFunction(mathExpressionSymbol, bluePrintCPP); getInstance().chainHandleFixMathFunction(mathExpressionSymbol, bluePrintCPP);
} }
public static void fixMathFunctions(MathPreOperatorExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) { public static void fixMathFunctions(MathPreOperatorExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) {
......
...@@ -17,12 +17,12 @@ public abstract class BaseExecuteMethodGeneratorHandler extends BaseChainOfRespo ...@@ -17,12 +17,12 @@ public abstract class BaseExecuteMethodGeneratorHandler extends BaseChainOfRespo
protected abstract String doGenerateExecuteCode(MathExpressionSymbol symbol, List<String> includeStrings); protected abstract String doGenerateExecuteCode(MathExpressionSymbol symbol, List<String> includeStrings);
public String handleGenerateExecuteCode(MathExpressionSymbol symbol, List<String> includeStrings) { private String handleGenerateExecuteCode(MathExpressionSymbol symbol, List<String> includeStrings) {
String result = ""; String result = "";
if (canHandleSymbol(symbol)) { if (canHandleSymbol(symbol)) {
result = doGenerateExecuteCode(symbol, includeStrings); result = doGenerateExecuteCode(symbol, includeStrings);
} else if (getSuccessor() != null) { } else if (getSuccessor() != null) {
result = getSuccessor().handleGenerateExecuteCode(symbol, includeStrings); result = ((BaseExecuteMethodGeneratorHandler) getSuccessor()).handleGenerateExecuteCode(symbol, includeStrings);
} else { } else {
Log.info(symbol.getTextualRepresentation(), "Symbol:"); Log.info(symbol.getTextualRepresentation(), "Symbol:");
Log.debug(getRole(), "Case not handled!"); Log.debug(getRole(), "Case not handled!");
...@@ -30,4 +30,8 @@ public abstract class BaseExecuteMethodGeneratorHandler extends BaseChainOfRespo ...@@ -30,4 +30,8 @@ public abstract class BaseExecuteMethodGeneratorHandler extends BaseChainOfRespo
return result; return result;
} }
public String chainHandleGenerateExecuteCode(MathExpressionSymbol symbol, List<String> includeStrings) {
return ((BaseExecuteMethodGeneratorHandler) getChainStart()).handleGenerateExecuteCode(symbol, includeStrings);
}
} }
...@@ -101,7 +101,7 @@ public class ExecuteMethodGenerator extends BaseExecuteMethodGeneratorHandler { ...@@ -101,7 +101,7 @@ public class ExecuteMethodGenerator extends BaseExecuteMethodGeneratorHandler {
} }
public static String generateExecuteCode(MathExpressionSymbol mathExpressionSymbol, List<String> includeStrings) { public static String generateExecuteCode(MathExpressionSymbol mathExpressionSymbol, List<String> includeStrings) {
return getInstance().handleGenerateExecuteCode(mathExpressionSymbol, includeStrings); return getInstance().chainHandleGenerateExecuteCode(mathExpressionSymbol, includeStrings);
} }
/** /**
......
...@@ -7,14 +7,28 @@ package de.monticore.lang.monticar.pattern; ...@@ -7,14 +7,28 @@ package de.monticore.lang.monticar.pattern;
*/ */
public abstract class BaseChainOfResponsibility<T> { public abstract class BaseChainOfResponsibility<T> {
private T successor = null; private BaseChainOfResponsibility<T> predecessor = null;
public T getSuccessor() { private BaseChainOfResponsibility<T> successor = null;
public BaseChainOfResponsibility<T> getSuccessor() {
return successor; return successor;
} }
public void setSuccessor(T successor) { protected BaseChainOfResponsibility<T> getPredecessor() {
return predecessor;
}
public void setSuccessor(BaseChainOfResponsibility<T> successor) {
this.successor = successor; this.successor = successor;
successor.predecessor = this;
}
protected BaseChainOfResponsibility<T> getChainStart() {
if (predecessor == null)
return this;
else
return predecessor.getChainStart();
} }
public abstract String getRole(); public abstract String getRole();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment