diff --git a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java index f7c137e..7227785 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java @@ -21,117 +21,91 @@ private static final String FORMULA_CHANNEL_NODE = "fc"; private static final String IO_CHANNEL_NODE = "ioc"; - /** - * -------------------------------------------------------------------------------- - * [Constructor] - * /**-------------------------------------------------------------------------------- - * - * @param stream - */ public ParserDTRAM(final TokenStream stream) { super(stream); } - /** - * -------------------------------------------------------------------------------- - * - * @param reader - */ public ParserDTRAM(final BufferedReader reader) { super(reader); } - /** - * -------------------------------------------------------------------------------- - * [public] - * /**-------------------------------------------------------------------------------- - * - * @param reader - * @throws WrongJsonExpression - * @throws ExpectedColon - */ public DataTransferModel doParseModel() throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefOrSubKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment, ExpectedModel, ExpectedGeometry, ExpectedRightCurlyBracket, WrongPathExpression, WrongJsonExpression, ExpectedColon { - DataTransferModel model = getParsedModel(); - return model; + return getParsedModel(); } - /** - * -------------------------------------------------------------------------------- - * - * @param graph - */ public void doParseGeometry(mxGraph graph) throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefOrSubKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment, ExpectedModel, ExpectedGeometry, ExpectedNode, ExpectedResource, ExpectedFormulaChannel, ExpectedIoChannel { - parseGeometry(graph); } - /** - * -------------------------------------------------------------------------------- - * [private] - * /**-------------------------------------------------------------------------------- - * - * @param stream - * @throws WrongJsonExpression - * @throws ExpectedColon - */ - private DataTransferModel getParsedModel() throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefOrSubKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment, ExpectedModel, ExpectedGeometry, ExpectedRightCurlyBracket, WrongPathExpression, WrongJsonExpression, ExpectedColon { - - if (!stream.hasNext()) throw new NullPointerException(); - + private DataTransferModel getParsedModel() throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefOrSubKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment, ExpectedModel, ExpectedRightCurlyBracket, WrongPathExpression, WrongJsonExpression, ExpectedColon { + if (!stream.hasNext()) { + throw new NullPointerException(); + } String modelKeyword = stream.next(); - if (!modelKeyword.equals(MODEL_GROUP)) throw new ExpectedModel(stream.getLine()); - if (!stream.hasNext()) throw new ExpectedModel(stream.getLine()); + if (!modelKeyword.equals(MODEL_GROUP)) { + throw new ExpectedModel(stream.getLine()); + } + if (!stream.hasNext()) { + throw new ExpectedModel(stream.getLine()); + } String leftBracket = stream.next(); - if (!leftBracket.equals(LEFT_CURLY_BRACKET)) throw new ExpectedLeftCurlyBracket(stream.getLine()); + if (!leftBracket.equals(LEFT_CURLY_BRACKET)) { + throw new ExpectedLeftCurlyBracket(stream.getLine()); + } DataTransferModel model = parseDataFlowModel(); String rightBracket = stream.next(); - if (!rightBracket.equals(RIGHT_CURLY_BRACKET)) throw new ExpectedRightBracket(stream.getLine()); + if (!rightBracket.equals(RIGHT_CURLY_BRACKET)) { + throw new ExpectedRightBracket(stream.getLine()); + } return model; } - /** - * -------------------------------------------------------------------------------- - * change graph's geometries from "DTRAM" file. - * - * @param stream - * @param graph - */ - private void parseGeometry(mxGraph graph) throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefOrSubKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment, ExpectedModel, ExpectedGeometry, ExpectedNode, ExpectedResource, ExpectedFormulaChannel, ExpectedIoChannel { + private void parseGeometry(mxGraph graph) throws ExpectedRightBracket, ExpectedLeftCurlyBracket, ExpectedAssignment, ExpectedGeometry, ExpectedNode { + if (!doesMatchToKeyword(stream.next(), GEOMETRY_GROUP)) { + throw new ExpectedGeometry(stream.getLine()); + } - if (!doesMatchToKeyword(stream.next(), GEOMETRY_GROUP)) throw new ExpectedGeometry(stream.getLine()); - - if (!doesMatchToKeyword(stream.next(), LEFT_CURLY_BRACKET)) + if (!doesMatchToKeyword(stream.next(), LEFT_CURLY_BRACKET)) { throw new ExpectedLeftCurlyBracket(stream.getLine()); + } String node = stream.next(); while (node.equals(GEOMETRY_NODE)) { String rOrFcOrIocOrC = stream.next(); - if (!rOrFcOrIocOrC.equals(RESOURCE_NODE) && !rOrFcOrIocOrC.equals(FORMULA_CHANNEL_NODE) && !rOrFcOrIocOrC.equals(CHANNEL_NODE) && !rOrFcOrIocOrC.equals(IO_CHANNEL_NODE)) + if (!rOrFcOrIocOrC.equals(RESOURCE_NODE) && !rOrFcOrIocOrC.equals(FORMULA_CHANNEL_NODE) && !rOrFcOrIocOrC.equals(CHANNEL_NODE) && !rOrFcOrIocOrC.equals(IO_CHANNEL_NODE)) { throw new ExpectedNode(stream.getLine()); - + } String name = stream.next(); - if (!doesMatchToKeyword(stream.next(), COLON)) throw new ExpectedAssignment(stream.getLine()); + if (!doesMatchToKeyword(stream.next(), COLON)) { + throw new ExpectedAssignment(stream.getLine()); + } String x = stream.next(); int xC = Integer.parseInt(x); // C = Coordinate(x,y,w,h) - if (!doesMatchToKeyword(stream.next(), COMMA)) throw new ExpectedAssignment(stream.getLine()); + if (!doesMatchToKeyword(stream.next(), COMMA)) { + throw new ExpectedAssignment(stream.getLine()); + } String y = stream.next(); int yC = Integer.parseInt(y); - if (!doesMatchToKeyword(stream.next(), COMMA)) throw new ExpectedAssignment(stream.getLine()); + if (!doesMatchToKeyword(stream.next(), COMMA)) { + throw new ExpectedAssignment(stream.getLine()); + } String w = stream.next(); int wC = Integer.parseInt(w); - if (!doesMatchToKeyword(stream.next(), COMMA)) throw new ExpectedAssignment(stream.getLine()); + if (!doesMatchToKeyword(stream.next(), COMMA)) { + throw new ExpectedAssignment(stream.getLine()); + } String h = stream.next(); int hC = Integer.parseInt(h); @@ -139,15 +113,18 @@ Object root = graph.getDefaultParent(); mxIGraphModel graphModel = graph.getModel(); for (int i = 0; i < graph.getModel().getChildCount(root); i++) { - Object cell = graph.getModel().getChildAt(root, i); - if (!graph.getModel().isVertex(cell)) continue; + if (!graph.getModel().isVertex(cell)) { + continue; + } mxGeometry geom = (mxGeometry) ((mxCell) cell).getGeometry().clone(); mxGraphView view = graph.getView(); mxCellState state = view.getState(cell); - if (!name.equals(state.getLabel())) continue; + if (!name.equals(state.getLabel())) { + continue; + } geom.setX(xC); geom.setY(yC); @@ -156,8 +133,8 @@ node = stream.next(); } - if (!node.equals(RIGHT_CURLY_BRACKET)) throw new ExpectedRightBracket(stream.getLine()); + if (!node.equals(RIGHT_CURLY_BRACKET)) { + throw new ExpectedRightBracket(stream.getLine()); + } } } - -