From 33ebd0da5378f9eabf27fe9fc9423a5c9f632c6f Mon Sep 17 00:00:00 2001 From: pechoux <romain.pechoux@loria.fr> Date: Thu, 16 Jan 2020 22:52:36 +0100 Subject: [PATCH] syntax error message and comments updated --- src/main/java/complexityparser/Model.java | 5 +---- src/main/java/complexityparser/tos/TOS.java | 14 +++++++------- src/main/java/complexityparser/types/FOTier.java | 10 ++-------- .../types/env/OperatorTypingEnvBuilder.java | 4 ++-- .../java/complexityparser/types/env/TypingEnv.java | 2 +- .../types/tieredtypes/TieredType.java | 2 +- .../typingVisitors/base/BaseStatementVisitor.java | 14 +++++++------- .../typingVisitors/base/BaseVisitor.java | 8 ++++---- src/main/java/view/EditorView.java | 14 ++++++++------ src/main/java/view/MessageView.java | 4 ++++ 10 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/main/java/complexityparser/Model.java b/src/main/java/complexityparser/Model.java index 9be358f..aac7303 100644 --- a/src/main/java/complexityparser/Model.java +++ b/src/main/java/complexityparser/Model.java @@ -139,7 +139,7 @@ public class Model extends Observable { Executes the last pass. Note that this pass call an overload visit method. This is very important as it will not work otherwise first and second pass need to be called with visit() - final pass needs to be called with visit(ParseTree) + final pass needs to be called with visit(ParseTree). */ FinalPass finalPass = new FinalPass(secondPass, tosBuilder, typingListener, token); finalPass.visit(context); @@ -149,11 +149,8 @@ public class Model extends Observable { error = err.toString(); result = finalPass.getResult(); System.out.println("---------------------------------------"); - //optional: Prints the operators list and the TOS to stdout. //usually a good idea for debugging and testing - //but showing bot might create a difficult to read output - System.out.println(TypingEnv.getInstance()); //System.out.println(TOS.getInstance()); //calls update on the Observer objects diff --git a/src/main/java/complexityparser/tos/TOS.java b/src/main/java/complexityparser/tos/TOS.java index 144286a..677bb36 100644 --- a/src/main/java/complexityparser/tos/TOS.java +++ b/src/main/java/complexityparser/tos/TOS.java @@ -36,7 +36,7 @@ import java.util.Stack; /** * Table Of symbols * - * Lists all the program variables and their tier type. + * Lists all the program variables and their tier type for each block. */ public class TOS { @@ -191,7 +191,7 @@ public class TOS { res = b.get(i); if(res == null) { /* - if the current block is a class and the tiered type has not been found + If the current block is a class and the tiered type has not been found (since classes cannot be declared inside other classes) then the parent block is necessarily <root> (and will not contain the searched value). Moreover it also means that it is time to start looking @@ -307,7 +307,7 @@ public class TOS { /** * - * @return a string representation of the tos + * @return a string representation of the tos. */ public String toString() { StringBuilder str = new StringBuilder(); @@ -419,7 +419,7 @@ public class TOS { /** * * @param no - an index. - * @return the parent class block number of the block number of index no. + * @return the parent class block number of the block number of index #no. */ public int getClassBlockNumber(int no) { while (no != -1 && !(array.get(no) instanceof ClassBlock)) { @@ -431,7 +431,7 @@ public class TOS { /** * * @param no - an index. - * @return the number of the parent class for the block number no. + * @return the number of the parent class for the block number #no. */ public int getMotherClassNumber(int no) { if(no == -1) { @@ -453,7 +453,7 @@ public class TOS { * * @param no - an index. * @param cl - an index. - * @return true if the block no is contained inside the class block cl + * @return true if the block of number #no is contained inside the class block #cl. */ public boolean isBlockInClass(int no, int cl) { if(no == -1) { @@ -469,7 +469,7 @@ public class TOS { /** * * @param no - an index. - * @return the name of the class identified by the block number no. + * @return the name of the class identified by the block number #no. */ public String getClassName(int no) { String res = ""; diff --git a/src/main/java/complexityparser/types/FOTier.java b/src/main/java/complexityparser/types/FOTier.java index 03d19c4..cdef4ec 100644 --- a/src/main/java/complexityparser/types/FOTier.java +++ b/src/main/java/complexityparser/types/FOTier.java @@ -22,7 +22,6 @@ import java.util.Objects; public class FOTier { private Tier[] in; -// private Output out; private Tier out; private Tier env; @@ -125,7 +124,7 @@ public class FOTier { /** * - * @return the number of input tiers (arity) of the current operator. + * @return the number of input tiers (arity) of this FOTier. */ public int size() { return in.length; @@ -136,11 +135,6 @@ public class FOTier { return Arrays.toString(in) + " > " + "(" + out + ", " + env + ")"; } - /* @Override - public String toString() { - return "(" + out + ", " + env + ")"; - }*/ - @Override public boolean equals(Object o) { if (this == o) return true; @@ -149,7 +143,7 @@ public class FOTier { return out == output.out && env == output.env; } -//taken directly from former class Output... + @Override public int hashCode() { return Objects.hash(out, env); diff --git a/src/main/java/complexityparser/types/env/OperatorTypingEnvBuilder.java b/src/main/java/complexityparser/types/env/OperatorTypingEnvBuilder.java index 40e36fb..5f858e0 100644 --- a/src/main/java/complexityparser/types/env/OperatorTypingEnvBuilder.java +++ b/src/main/java/complexityparser/types/env/OperatorTypingEnvBuilder.java @@ -37,7 +37,7 @@ public class OperatorTypingEnvBuilder extends OperatorsBaseListener { } /** - * Creates a new FOTierList, updates the attribute latest, and + * Creates a new FOTierList, updates the attribute #latest, and * adds the new object with the operator (or method) name to the TypingEnv #te. * @param ctx - an operator context. */ @@ -54,7 +54,7 @@ public class OperatorTypingEnvBuilder extends OperatorsBaseListener { } /** - * Creates a new entry in the operator latest. + * Creates a new entry in the FOTierList #latest. * @param ctx - a unit context. */ @Override diff --git a/src/main/java/complexityparser/types/env/TypingEnv.java b/src/main/java/complexityparser/types/env/TypingEnv.java index 4b502db..b8446f4 100644 --- a/src/main/java/complexityparser/types/env/TypingEnv.java +++ b/src/main/java/complexityparser/types/env/TypingEnv.java @@ -176,7 +176,7 @@ public class TypingEnv { */ public FOTier checkOverrideMethod(String name, FOTier out, Tier... in) { TOS tos = TOS.getInstance(); - //Only the children needs to be verified since no superclass can be used in case of polymorphism. + //Only the children need to be verified since no superclass can be used in case of polymorphism. return checkOverrideMethod_aux(name, out, in); } diff --git a/src/main/java/complexityparser/types/tieredtypes/TieredType.java b/src/main/java/complexityparser/types/tieredtypes/TieredType.java index 78a104d..b9fe384 100644 --- a/src/main/java/complexityparser/types/tieredtypes/TieredType.java +++ b/src/main/java/complexityparser/types/tieredtypes/TieredType.java @@ -20,7 +20,7 @@ import complexityparser.tos.TOS; import complexityparser.types.Tier; /** - * An abstract class to represent a tiered type + * An abstract class to represent a tiered type. */ public abstract class TieredType { diff --git a/src/main/java/complexityparser/typingVisitors/base/BaseStatementVisitor.java b/src/main/java/complexityparser/typingVisitors/base/BaseStatementVisitor.java index e767562..21c99c3 100644 --- a/src/main/java/complexityparser/typingVisitors/base/BaseStatementVisitor.java +++ b/src/main/java/complexityparser/typingVisitors/base/BaseStatementVisitor.java @@ -109,8 +109,8 @@ public abstract class BaseStatementVisitor extends BaseExpressionVisitor { visit(ctx.parExpression()); setLiteralDefaultTier(getTierType(ctx.parExpression().expression())); //visitChildren(ctx); - //detect recursive calls in each branch and only keep the maximum value - //do the same for while counts + //Detects recursive calls in each branch and only keep the maximum value. + //Does the same for while counts. int recursiveCalls = getRecursiveCallsCount(); int recursiveCallsLocalMax = 0; int whileCount = getWhileCount(); @@ -137,7 +137,7 @@ public abstract class BaseStatementVisitor extends BaseExpressionVisitor { Tier parExpr = getTierType(ctx.parExpression().expression()); Tier env = getEnvironmentType(ctx.parExpression().expression()); Tier res = parExpr; - //type the if statement + //Types the if statement. if(parExpr != Tier.max(parExpr, env)) { res = Tier.None; } @@ -169,7 +169,7 @@ public abstract class BaseStatementVisitor extends BaseExpressionVisitor { Tier parTier = getTierType(par.expression()); Tier env = getEnvironmentType(par.expression()); incrementWhileCount(); - //if the while statement contains recursive calls, the wile statement types (NONE, NONE) + //If the while statement contains recursive calls, the wile statement tier and environment tier are both NONE. Tier res; if(getRecursiveCallsCount() != 0) { res = Tier.None; @@ -216,8 +216,8 @@ public abstract class BaseStatementVisitor extends BaseExpressionVisitor { } /** - * Verifies if a catch clause is valid - * because literals are typed with tier 1 an assignment will type 1 and thus not be a valid catch clause + * Verifies if a catch clause is valid. + * Because literals are typed with tier 1, an assignment will type 1 and thus not be a valid catch clause. * @param ctx - a catch clause context. * @return the tier None (if the block has tier distinct from 0). */ @@ -235,7 +235,7 @@ public abstract class BaseStatementVisitor extends BaseExpressionVisitor { } /** - * Verifies if a finally clause is valid + * Verifies if a finally clause is valid. * @param ctx - a finally block context. * @return the tier of the block. */ diff --git a/src/main/java/complexityparser/typingVisitors/base/BaseVisitor.java b/src/main/java/complexityparser/typingVisitors/base/BaseVisitor.java index e425261..d84a57c 100644 --- a/src/main/java/complexityparser/typingVisitors/base/BaseVisitor.java +++ b/src/main/java/complexityparser/typingVisitors/base/BaseVisitor.java @@ -210,15 +210,15 @@ public abstract class BaseVisitor extends JavaParserBaseVisitor { /** * - * @param ctx - a parse tree - * @return the block index associated with the given tree node + * @param ctx - a parse tree. + * @return the block index associated with the given tree node. */ public Integer getBlockNumber(ParseTree ctx) { return blockNumbers.get(ctx); } /** - * Sets the value of override result + * Sets the value of override result: * if true, * the result value will be overriden on call of putTierType(..) * and a string output will be generated @@ -330,7 +330,7 @@ public abstract class BaseVisitor extends JavaParserBaseVisitor { /** * A helper function to avoid duplicate code and to print the appropriate message - * to the appropirate output (error or standard) + * to the appropirate output (error or standard). * @param rule - the name of the grammar rule. * @param txt - the code associated with the grammar rule. * @param t - the tier type of the rule. diff --git a/src/main/java/view/EditorView.java b/src/main/java/view/EditorView.java index 9661204..90aa5ad 100644 --- a/src/main/java/view/EditorView.java +++ b/src/main/java/view/EditorView.java @@ -53,8 +53,12 @@ public class EditorView extends JPanel { Action action = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { - String code = area.getText(); - m.setCode(code); + try{ + String code = area.getText(); + m.setCode(code); + } catch (IndexOutOfBoundsException e){ + area.setText(area.getText()+" \n !!! Syntax error !!! "); + } } }; updateButton.addActionListener(action); @@ -77,14 +81,12 @@ public class EditorView extends JPanel { String txt = new String(res, StandardCharsets.UTF_8); area.setText(txt); m.setCode(txt); - parent.setTitle(f.toString()); } catch (IOException e) { e.printStackTrace(); } catch (IndexOutOfBoundsException e){ - System.out.println("Syntax error"); - area.setText("Syntax error"); - } + area.setText(area.getText()+" \n !!! Syntax error !!! "); + } } } }); diff --git a/src/main/java/view/MessageView.java b/src/main/java/view/MessageView.java index a5016c5..d2a0ee5 100644 --- a/src/main/java/view/MessageView.java +++ b/src/main/java/view/MessageView.java @@ -29,6 +29,10 @@ public class MessageView extends JScrollPane implements Observer { private JTextArea area; private Model m; + public void setArea(JTextArea area){ + this.area= area; + } + public MessageView(Model m) { m.addObserver(this); this.m = m; -- GitLab