Skip to content
Snippets Groups Projects
Commit ca9c5d21 authored by dgelessus's avatar dgelessus
Browse files

Update to new B parser exception class

parent e392d2c3
No related branches found
No related tags found
No related merge requests found
Showing
with 32 additions and 30 deletions
...@@ -9,7 +9,7 @@ package de.bmotionstudio.gef.editor.observer; ...@@ -9,7 +9,7 @@ package de.bmotionstudio.gef.editor.observer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute;
...@@ -128,7 +128,7 @@ public class ListenOperationByPredicate extends Observer { ...@@ -128,7 +128,7 @@ public class ListenOperationByPredicate extends Observer {
// addError(control, animation, // addError(control, animation,
// "An error occurred while evaluating. Reason: " // "An error occurred while evaluating. Reason: "
// + e.getMessage()); // + e.getMessage());
} catch (BException e) { } catch (BCompoundException e) {
// addError(control, animation, "Parsing error in: " // addError(control, animation, "Parsing error in: "
// + fPredicate + " Reason: " + e.getMessage()); // + fPredicate + " Reason: " + e.getMessage());
} }
......
...@@ -9,7 +9,7 @@ import java.util.Map; ...@@ -9,7 +9,7 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.model.BControl;
...@@ -213,7 +213,7 @@ public class BMSUtil { ...@@ -213,7 +213,7 @@ public class BMSUtil {
opRandom); opRandom);
} catch (ProBException e) { } catch (ProBException e) {
} catch (BException e) { } catch (BCompoundException e) {
} }
return null; return null;
......
...@@ -14,7 +14,7 @@ import java.util.List; ...@@ -14,7 +14,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.domainobjects.Operation; import de.prob.core.domainobjects.Operation;
import de.prob.core.domainobjects.State; import de.prob.core.domainobjects.State;
...@@ -53,7 +53,7 @@ public final class ConstructTraceCommand implements IComposableCommand { ...@@ -53,7 +53,7 @@ public final class ConstructTraceCommand implements IComposableCommand {
for (String string : predicates) { for (String string : predicates) {
try { try {
evalElement.add(PredicateEvalElement.create(string)); evalElement.add(PredicateEvalElement.create(string));
} catch (BException e) { } catch (BCompoundException e) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Formula must be a predicate: " + string); "Formula must be a predicate: " + string);
} }
......
...@@ -10,7 +10,7 @@ import java.util.ArrayList; ...@@ -10,7 +10,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.ProblemHandler; import de.prob.core.ProblemHandler;
import de.prob.core.domainobjects.Operation; import de.prob.core.domainobjects.Operation;
...@@ -51,7 +51,7 @@ public final class GetOperationByPredicateCommand implements IComposableCommand ...@@ -51,7 +51,7 @@ public final class GetOperationByPredicateCommand implements IComposableCommand
PredicateEvalElement parsedEvalElement = null; PredicateEvalElement parsedEvalElement = null;
try { try {
parsedEvalElement = PredicateEvalElement.create(predicate); parsedEvalElement = PredicateEvalElement.create(predicate);
} catch (BException e) { } catch (BCompoundException e) {
String message = "Fatal error when trying to parse " + predicate String message = "Fatal error when trying to parse " + predicate
+ ". Execution of operation " + name + " aborted."; + ". Execution of operation " + name + " aborted.";
ProblemHandler.raiseCommandException(message); ProblemHandler.raiseCommandException(message);
...@@ -66,7 +66,7 @@ public final class GetOperationByPredicateCommand implements IComposableCommand ...@@ -66,7 +66,7 @@ public final class GetOperationByPredicateCommand implements IComposableCommand
*/ */
public static Operation getOperation(final Animator a, public static Operation getOperation(final Animator a,
final String stateId, final String name, final String predicate) final String stateId, final String name, final String predicate)
throws ProBException, BException { throws ProBException, BCompoundException {
List<Operation> operations = getOperations(a, stateId, name, predicate, List<Operation> operations = getOperations(a, stateId, name, predicate,
1); 1);
...@@ -91,14 +91,14 @@ public final class GetOperationByPredicateCommand implements IComposableCommand ...@@ -91,14 +91,14 @@ public final class GetOperationByPredicateCommand implements IComposableCommand
* @param nrOfSolutions * @param nrOfSolutions
* - maximum number of solutions * - maximum number of solutions
* @return an Operation or null * @return an Operation or null
* @throws BException * @throws BCompoundException
* - if the B predicate contains errors * - if the B predicate contains errors
* @throws ProBException * @throws ProBException
* - if something terrible happens ;-) * - if something terrible happens ;-)
*/ */
public static List<Operation> getOperations(final Animator a, public static List<Operation> getOperations(final Animator a,
final String stateId, final String name, final String predicate, final String stateId, final String name, final String predicate,
final int nrOfSolutions) throws ProBException, BException { final int nrOfSolutions) throws ProBException, BCompoundException {
GetOperationByPredicateCommand executeOperationCommand = new GetOperationByPredicateCommand( GetOperationByPredicateCommand executeOperationCommand = new GetOperationByPredicateCommand(
stateId, name, predicate, nrOfSolutions); stateId, name, predicate, nrOfSolutions);
......
...@@ -19,7 +19,7 @@ import org.osgi.service.prefs.Preferences; ...@@ -19,7 +19,7 @@ import org.osgi.service.prefs.Preferences;
import de.be4.classicalb.core.parser.BParser; import de.be4.classicalb.core.parser.BParser;
import de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader; import de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.be4.classicalb.core.parser.node.Start; import de.be4.classicalb.core.parser.node.Start;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.domainobjects.Operation; import de.prob.core.domainobjects.Operation;
...@@ -154,7 +154,7 @@ public final class LoadClassicalBModelCommand { ...@@ -154,7 +154,7 @@ public final class LoadClassicalBModelCommand {
} catch (IOException e) { } catch (IOException e) {
Logger.notifyUser("IO Error", e); Logger.notifyUser("IO Error", e);
throw new CommandException(e.getLocalizedMessage(), e); throw new CommandException(e.getLocalizedMessage(), e);
} catch (BException e) { } catch (BCompoundException e) {
Logger.notifyUser("Parser Error " + e.getLocalizedMessage(), e); Logger.notifyUser("Parser Error " + e.getLocalizedMessage(), e);
throw new CommandException(e.getLocalizedMessage(), e); throw new CommandException(e.getLocalizedMessage(), e);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package de.prob.core.domainobjects.eval; package de.prob.core.domainobjects.eval;
import de.be4.classicalb.core.parser.BParser; import de.be4.classicalb.core.parser.BParser;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.be4.classicalb.core.parser.node.Start; import de.be4.classicalb.core.parser.node.Start;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.command.EvaluateRawExpressionsCommand; import de.prob.core.command.EvaluateRawExpressionsCommand;
...@@ -30,7 +30,7 @@ public abstract class AbstractEvalElement { ...@@ -30,7 +30,7 @@ public abstract class AbstractEvalElement {
public abstract String getLabel(); public abstract String getLabel();
protected Start parse(final String prefix, final String code) protected Start parse(final String prefix, final String code)
throws BException { throws BCompoundException {
final BParser parser = new BParser(); final BParser parser = new BParser();
final Start modelAst = parser.parse(prefix + code, false); final Start modelAst = parser.parse(prefix + code, false);
return modelAst; return modelAst;
......
...@@ -9,6 +9,7 @@ package de.prob.core.domainobjects.eval; ...@@ -9,6 +9,7 @@ package de.prob.core.domainobjects.eval;
import org.eventb.core.ast.Expression; import org.eventb.core.ast.Expression;
import de.be4.classicalb.core.parser.BParser; import de.be4.classicalb.core.parser.BParser;
import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BException;
import de.be4.classicalb.core.parser.node.AExpressionParseUnit; import de.be4.classicalb.core.parser.node.AExpressionParseUnit;
import de.be4.classicalb.core.parser.node.EOF; import de.be4.classicalb.core.parser.node.EOF;
...@@ -22,10 +23,10 @@ public final class ExpressionEvalElement extends AbstractEvalElement { ...@@ -22,10 +23,10 @@ public final class ExpressionEvalElement extends AbstractEvalElement {
private final String expression; private final String expression;
public static ExpressionEvalElement fromRodin(final Expression expression) public static ExpressionEvalElement fromRodin(final Expression expression)
throws BException { throws BCompoundException {
if (expression == null) { if (expression == null) {
String message = "Expression input must not be null"; String message = "Expression input must not be null";
throw new BException("", new NullPointerException(message)); throw new BCompoundException(new BException("", message, new NullPointerException(message)));
} }
final PExpression expr = TranslationVisitor final PExpression expr = TranslationVisitor
.translateExpression(expression); .translateExpression(expression);
...@@ -35,11 +36,11 @@ public final class ExpressionEvalElement extends AbstractEvalElement { ...@@ -35,11 +36,11 @@ public final class ExpressionEvalElement extends AbstractEvalElement {
} }
public static ExpressionEvalElement create(final String expression) public static ExpressionEvalElement create(final String expression)
throws BException { throws BCompoundException {
return new ExpressionEvalElement(expression); return new ExpressionEvalElement(expression);
} }
public ExpressionEvalElement(final String expression) throws BException { public ExpressionEvalElement(final String expression) throws BCompoundException {
this.expression = expression; this.expression = expression;
parse = parse(BParser.EXPRESSION_PREFIX, expression); parse = parse(BParser.EXPRESSION_PREFIX, expression);
} }
......
...@@ -10,6 +10,7 @@ import org.eventb.core.ast.Predicate; ...@@ -10,6 +10,7 @@ import org.eventb.core.ast.Predicate;
import de.be4.classicalb.core.parser.BParser; import de.be4.classicalb.core.parser.BParser;
import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter; import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter;
import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BException;
import de.be4.classicalb.core.parser.node.AConjunctPredicate; import de.be4.classicalb.core.parser.node.AConjunctPredicate;
import de.be4.classicalb.core.parser.node.ADisjunctPredicate; import de.be4.classicalb.core.parser.node.ADisjunctPredicate;
...@@ -30,10 +31,10 @@ public class PredicateEvalElement extends AbstractEvalElement { ...@@ -30,10 +31,10 @@ public class PredicateEvalElement extends AbstractEvalElement {
private final String predicate; private final String predicate;
public static PredicateEvalElement fromRodin(final Predicate predicate) public static PredicateEvalElement fromRodin(final Predicate predicate)
throws BException { throws BCompoundException {
if (predicate == null) { if (predicate == null) {
String message = "Predicate input must not be null"; String message = "Predicate input must not be null";
throw new BException("", new NullPointerException(message)); throw new BCompoundException(new BException("", message, new NullPointerException(message)));
} }
final PPredicate apred = TranslationVisitor final PPredicate apred = TranslationVisitor
.translatePredicate(predicate); .translatePredicate(predicate);
...@@ -43,11 +44,11 @@ public class PredicateEvalElement extends AbstractEvalElement { ...@@ -43,11 +44,11 @@ public class PredicateEvalElement extends AbstractEvalElement {
} }
public static PredicateEvalElement create(final String predicate) public static PredicateEvalElement create(final String predicate)
throws BException { throws BCompoundException {
return new PredicateEvalElement(predicate); return new PredicateEvalElement(predicate);
} }
private PredicateEvalElement(final String predicate) throws BException { private PredicateEvalElement(final String predicate) throws BCompoundException {
this.predicate = predicate; this.predicate = predicate;
parse = parse(BParser.PREDICATE_PREFIX, predicate); parse = parse(BParser.PREDICATE_PREFIX, predicate);
} }
......
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.command.*; import de.prob.core.command.*;
import de.prob.core.domainobjects.Operation; import de.prob.core.domainobjects.Operation;
...@@ -81,7 +81,7 @@ public class CustomPreconditionInputDialog extends InputDialog { ...@@ -81,7 +81,7 @@ public class CustomPreconditionInputDialog extends InputDialog {
} catch (ProBException e) { } catch (ProBException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (BException e) { } catch (BCompoundException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -14,7 +14,7 @@ import org.eventb.core.ast.IParseResult; ...@@ -14,7 +14,7 @@ import org.eventb.core.ast.IParseResult;
import org.eventb.core.ast.Predicate; import org.eventb.core.ast.Predicate;
import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BCompoundException;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.ProblemHandler; import de.prob.core.ProblemHandler;
import de.prob.core.command.CommandException; import de.prob.core.command.CommandException;
...@@ -64,7 +64,7 @@ public final class GetOperationByPredicateCommand2 implements ...@@ -64,7 +64,7 @@ public final class GetOperationByPredicateCommand2 implements
try { try {
parsedEvalElement = PredicateEvalElement.fromRodin(parsedPredicate); parsedEvalElement = PredicateEvalElement.fromRodin(parsedPredicate);
} catch (BException e) { } catch (BCompoundException e) {
String message = "Fatal error when trying to parse " + predicate String message = "Fatal error when trying to parse " + predicate
+ ". Execution of event " + name + " aborted."; + ". Execution of event " + name + " aborted.";
ProblemHandler.raiseCommandException(message); ProblemHandler.raiseCommandException(message);
...@@ -79,7 +79,7 @@ public final class GetOperationByPredicateCommand2 implements ...@@ -79,7 +79,7 @@ public final class GetOperationByPredicateCommand2 implements
*/ */
public static Operation getOperation(final Animator a, public static Operation getOperation(final Animator a,
final String stateId, final String name, final String predicate) final String stateId, final String name, final String predicate)
throws ProBException, BException { throws ProBException, BCompoundException {
List<Operation> operations = getOperations(a, stateId, name, predicate, List<Operation> operations = getOperations(a, stateId, name, predicate,
1); 1);
...@@ -104,14 +104,14 @@ public final class GetOperationByPredicateCommand2 implements ...@@ -104,14 +104,14 @@ public final class GetOperationByPredicateCommand2 implements
* @param nrOfSolutions * @param nrOfSolutions
* - maximum number of solutions * - maximum number of solutions
* @return an Operation or null * @return an Operation or null
* @throws BException * @throws BCompoundException
* - if the B predicate contains errors * - if the B predicate contains errors
* @throws ProBException * @throws ProBException
* - if something terrible happens ;-) * - if something terrible happens ;-)
*/ */
public static List<Operation> getOperations(final Animator a, public static List<Operation> getOperations(final Animator a,
final String stateId, final String name, final String predicate, final String stateId, final String name, final String predicate,
final int nrOfSolutions) throws ProBException, BException { final int nrOfSolutions) throws ProBException, BCompoundException {
GetOperationByPredicateCommand2 executeOperationCommand = new GetOperationByPredicateCommand2( GetOperationByPredicateCommand2 executeOperationCommand = new GetOperationByPredicateCommand2(
stateId, name, predicate, nrOfSolutions); stateId, name, predicate, nrOfSolutions);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment