diff --git a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java index 68e2171..ee95620 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java @@ -10,6 +10,7 @@ import parser.exceptions.*; import java.io.BufferedReader; +import java.util.Objects; public class ParserDTRAM extends Parser { @@ -37,23 +38,25 @@ if (!stream.hasNext()) { throw new NullPointerException(); } + + // Model block keyword String modelKeyword = stream.next(); - if (!modelKeyword.equals(MODEL_GROUP)) { - throw new ExpectedModel(stream.getLine()); - } - if (!stream.hasNext()) { + if (!Objects.equals(modelKeyword, MODEL_GROUP)) { throw new ExpectedModel(stream.getLine()); } + // Block-beginning bracket String leftBracket = stream.next(); - if (!leftBracket.equals(LEFT_CURLY_BRACKET)) { + if (!Objects.equals(leftBracket, LEFT_CURLY_BRACKET)) { throw new ExpectedLeftCurlyBracket(stream.getLine()); } + // Parse data-flow model from a content inside "model" tag DataTransferModel model = parseDataFlowModel(); + // Closing bracket String rightBracket = stream.next(); - if (!rightBracket.equals(RIGHT_CURLY_BRACKET)) { + if (!Objects.equals(rightBracket, RIGHT_CURLY_BRACKET)) { throw new ExpectedRightBracket(stream.getLine()); } @@ -65,51 +68,50 @@ } private void parseGeometry(mxGraph graph) throws ExpectedRightBracket, ExpectedLeftCurlyBracket, ExpectedAssignment, ExpectedGeometry, ExpectedNode { - if (!doesMatchToKeyword(stream.next(), GEOMETRY_GROUP)) { + if (!Objects.equals(stream.next(), GEOMETRY_GROUP)) { throw new ExpectedGeometry(stream.getLine()); } - - if (!doesMatchToKeyword(stream.next(), LEFT_CURLY_BRACKET)) { + if (!Objects.equals(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)) { + String nodeType = stream.next(); + if (!Objects.equals(nodeType, RESOURCE_NODE) && !Objects.equals(nodeType, FORMULA_CHANNEL_NODE) && !Objects.equals(nodeType, CHANNEL_NODE) && !Objects.equals(nodeType, IO_CHANNEL_NODE)) { throw new ExpectedNode(stream.getLine()); } String name = stream.next(); - if (!doesMatchToKeyword(stream.next(), COLON)) { + if (!Objects.equals(stream.next(), COLON)) { throw new ExpectedAssignment(stream.getLine()); } - String x = stream.next(); - int xC = Integer.parseInt(x); // C = Coordinate(x,y,w,h) + // get x position + int x = Integer.parseInt(stream.next()); - if (!doesMatchToKeyword(stream.next(), COMMA)) { + if (!Objects.equals(stream.next(), COMMA)) { throw new ExpectedAssignment(stream.getLine()); } - String y = stream.next(); - int yC = Integer.parseInt(y); + // get y position + int y = Integer.parseInt(stream.next()); - if (!doesMatchToKeyword(stream.next(), COMMA)) { + if (!Objects.equals(stream.next(), COMMA)) { throw new ExpectedAssignment(stream.getLine()); } - String w = stream.next(); - int wC = Integer.parseInt(w); + // get width + int width = Integer.parseInt(stream.next()); - if (!doesMatchToKeyword(stream.next(), COMMA)) { + if (!Objects.equals(stream.next(), COMMA)) { throw new ExpectedAssignment(stream.getLine()); } - String h = stream.next(); - int hC = Integer.parseInt(h); + // get height + int height = Integer.parseInt(stream.next()); + // Find the current target cell and update its geometry Object root = graph.getDefaultParent(); mxIGraphModel graphModel = graph.getModel(); for (int i = 0; i < graph.getModel().getChildCount(root); i++) { @@ -117,8 +119,7 @@ if (!graph.getModel().isVertex(cell)) { continue; } - - mxGeometry geom = (mxGeometry) ((mxCell) cell).getGeometry().clone(); + mxGeometry geometry = (mxGeometry) ((mxCell) cell).getGeometry().clone(); mxGraphView view = graph.getView(); mxCellState state = view.getState(cell); @@ -126,14 +127,17 @@ continue; } - geom.setX(xC); - geom.setY(yC); - graphModel.setGeometry(cell, geom); + geometry.setX(x); + geometry.setY(y); + geometry.setWidth(width); + geometry.setHeight(height); + graphModel.setGeometry(cell, geometry); } + node = stream.next(); } - if (!node.equals(RIGHT_CURLY_BRACKET)) { + if (!Objects.equals(node, RIGHT_CURLY_BRACKET)) { throw new ExpectedRightBracket(stream.getLine()); } }