From c78d6b9e0a336a0cf7cb1ee72db95f30aa2e66e5 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Fri, 5 Feb 2021 17:22:43 +0100 Subject: [PATCH] Fix code style issues --- .../edu/kit/typicalc/model/Conclusion.java | 2 +- .../typicalc/model/parser/LambdaLexer.java | 13 ++++++------ .../model/parser/TypeAssumptionParser.java | 1 - .../kit/typicalc/model/step/EmptyStep.java | 9 ++++++++- .../typicalc/model/type/UnificationUtil.java | 2 ++ .../edu/kit/typicalc/view/MathjaxAdapter.java | 5 ++--- .../typicalc/view/content/ControlPanel.java | 1 + .../MathjaxProofTree.java | 5 ----- .../MathjaxUnification.java | 5 ----- .../typeinferencecontent/ShareDialog.java | 3 +-- .../TypeInferenceView.java | 9 +++------ .../typicalc/view/main/ErrorNotification.java | 6 +++--- .../view/main/InferenceRuleField.java | 20 +++++++++---------- .../kit/typicalc/view/main/InfoDialog.java | 9 ++++----- .../edu/kit/typicalc/view/main/InputBar.java | 13 +++++------- .../typicalc/view/main/MathjaxDisplay.java | 5 ----- 16 files changed, 47 insertions(+), 61 deletions(-) diff --git a/src/main/java/edu/kit/typicalc/model/Conclusion.java b/src/main/java/edu/kit/typicalc/model/Conclusion.java index 009627d..5a2e211 100644 --- a/src/main/java/edu/kit/typicalc/model/Conclusion.java +++ b/src/main/java/edu/kit/typicalc/model/Conclusion.java @@ -25,7 +25,7 @@ public class Conclusion { * @param lambdaTerm the lambda term in the conclusion * @param type the type assigned to the lambda term in the conclusion */ - protected Conclusion(Map typeAssumptions, LambdaTerm lambdaTerm, Type type) { + public Conclusion(Map typeAssumptions, LambdaTerm lambdaTerm, Type type) { this.typeAssumptions = typeAssumptions; this.lambdaTerm = lambdaTerm; this.type = type; diff --git a/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java b/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java index d88ff9d..3669e72 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java +++ b/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java @@ -111,20 +111,21 @@ public class LambdaLexer { advance(); return new Result<>(t); default: - if (Character.isLetter(c)) { + // only allow ascii characters in variable names + if (Character.isLetter(c) && (int) c < 128) { int startPos = pos; // identifier StringBuilder sb = new StringBuilder(); do { sb.append(term.charAt(pos)); advance(); - } while (pos < term.length() && Character.isLetterOrDigit(term.charAt(pos))); - String s = sb.toString(); - TokenType type; - // only allow ascii characters in variable names - if (!s.matches("\\A\\p{ASCII}*\\z")) { + } while (pos < term.length() && Character.isLetterOrDigit(term.charAt(pos)) + && (int) term.charAt(pos) < 128); + if (pos < term.length() && (int) term.charAt(pos) >= 128) { return new Result<>(null, ParseError.UNEXPECTED_CHARACTER); } + String s = sb.toString(); + TokenType type; switch (s) { case "let": type = TokenType.LET; diff --git a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java index 36e902e..e2e828b 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java +++ b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java @@ -40,7 +40,6 @@ public class TypeAssumptionParser { } private Result, ParseError> parseType(LambdaLexer lexer, int parenCount) { - // TODO: remove misc. logging Result token = lexer.nextToken(); if (token.isError()) { return new Result<>(token); diff --git a/src/main/java/edu/kit/typicalc/model/step/EmptyStep.java b/src/main/java/edu/kit/typicalc/model/step/EmptyStep.java index 8426d48..1de4e50 100644 --- a/src/main/java/edu/kit/typicalc/model/step/EmptyStep.java +++ b/src/main/java/edu/kit/typicalc/model/step/EmptyStep.java @@ -2,6 +2,10 @@ package edu.kit.typicalc.model.step; import edu.kit.typicalc.model.Conclusion; import edu.kit.typicalc.model.Constraint; +import edu.kit.typicalc.model.term.VarTerm; +import edu.kit.typicalc.model.type.NamedType; + +import java.util.Collections; /** * Empty steps are used if the sub-inference that is started when creating a let step failed and the second premise of @@ -13,7 +17,10 @@ public class EmptyStep extends InferenceStep { * Initializes a new empty step. */ public EmptyStep() { - super(null, null); // TODO + super( + new Conclusion(Collections.emptyMap(), new VarTerm(""), new NamedType("")), + new Constraint(new NamedType(""), new NamedType("")) + ); // TODO: better dummy parameters? } @Override diff --git a/src/main/java/edu/kit/typicalc/model/type/UnificationUtil.java b/src/main/java/edu/kit/typicalc/model/type/UnificationUtil.java index c119b4e..52092d4 100644 --- a/src/main/java/edu/kit/typicalc/model/type/UnificationUtil.java +++ b/src/main/java/edu/kit/typicalc/model/type/UnificationUtil.java @@ -11,6 +11,8 @@ import java.util.Optional; /** * Utility class to avoid unification logic duplication in type methods. + * + * @see Type */ final class UnificationUtil { private UnificationUtil() { } diff --git a/src/main/java/edu/kit/typicalc/view/MathjaxAdapter.java b/src/main/java/edu/kit/typicalc/view/MathjaxAdapter.java index cb584df..d6959e2 100644 --- a/src/main/java/edu/kit/typicalc/view/MathjaxAdapter.java +++ b/src/main/java/edu/kit/typicalc/view/MathjaxAdapter.java @@ -3,13 +3,12 @@ package edu.kit.typicalc.view; /** * Represents an HTML element that uses MathJax and custom JavaScript classes to render its contents. * Provides an interface between Java code and said JavaScript classes. Allows to reveal parts of the - * rendered LaTeX step-by-step. Allows for scaling of the rendered LaTeX. + * rendered LaTeX step-by-step. */ public interface MathjaxAdapter { int getStepCount(); void showStep(int n); - - void scale(double newScaling); + // TODO: document removal of scaling method } diff --git a/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java b/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java index a2eac9f..7bc6f8b 100644 --- a/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java +++ b/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java @@ -23,6 +23,7 @@ public class ControlPanel extends HorizontalLayout { * Sets up buttons with click-listeners that call the corresponding method in the view. * * @param view the view that reacts to the button clicks + * @param focusArea the component key shortcuts should work in */ public ControlPanel(ControlPanelView view, Component focusArea) { firstStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_LEFT), evt -> view.firstStepButton()); diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/MathjaxProofTree.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/MathjaxProofTree.java index bd1704d..9b4098b 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/MathjaxProofTree.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/MathjaxProofTree.java @@ -50,10 +50,5 @@ public class MathjaxProofTree extends LitTemplate implements MathjaxAdapter { public void showStep(int n) { getElement().callJsFunction("showStep", n); } - - @Override - public void scale(double newScaling) { - - } } diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/MathjaxUnification.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/MathjaxUnification.java index 2877560..356f8f9 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/MathjaxUnification.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/MathjaxUnification.java @@ -46,10 +46,5 @@ public class MathjaxUnification extends LitTemplate implements MathjaxAdapter { } getElement().callJsFunction("showStep", n); } - - @Override - public void scale(double newScaling) { - // todo implement - } } diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/ShareDialog.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/ShareDialog.java index 0170d83..d43ad5c 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/ShareDialog.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/ShareDialog.java @@ -14,7 +14,6 @@ import com.vaadin.flow.i18n.LocaleChangeObserver; */ public class ShareDialog extends Dialog implements LocaleChangeObserver { - private final VerticalLayout layout; private final TextField urlField; private final TextField packageField; private final TextArea latexArea; @@ -29,7 +28,7 @@ public class ShareDialog extends Dialog implements LocaleChangeObserver { */ public ShareDialog(String url, String latexPackages, String latexCode) { setWidth(80, Unit.PERCENTAGE); - layout = new VerticalLayout(); + VerticalLayout layout = new VerticalLayout(); layout.setAlignItems(FlexComponent.Alignment.START); layout.setSizeFull(); add(layout); diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java index 2b3c108..82147bb 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/TypeInferenceView.java @@ -31,21 +31,18 @@ public class TypeInferenceView extends VerticalLayout private MathjaxUnification unification; private MathjaxProofTree tree; - private final LatexCreator lc; - private final transient TypeInfererInterface typeInferer; + private final transient LatexCreator lc; private final Div content; - private final ControlPanel controlPanel; - private ShareDialog shareDialog; + private final ShareDialog shareDialog; public TypeInferenceView(TypeInfererInterface typeInferer) { - this.typeInferer = typeInferer; setId(ID); setSizeFull(); addAttachListener(this); lc = new LatexCreator(typeInferer); content = new Div(); content.setId(CONTENT_ID); - controlPanel = new ControlPanel(this, this); + ControlPanel controlPanel = new ControlPanel(this, this); Scroller scroller = new Scroller(content); scroller.setId(SCROLLER_ID); scroller.setScrollDirection(Scroller.ScrollDirection.BOTH); diff --git a/src/main/java/edu/kit/typicalc/view/main/ErrorNotification.java b/src/main/java/edu/kit/typicalc/view/main/ErrorNotification.java index 45602df..11b1cd8 100644 --- a/src/main/java/edu/kit/typicalc/view/main/ErrorNotification.java +++ b/src/main/java/edu/kit/typicalc/view/main/ErrorNotification.java @@ -9,15 +9,15 @@ import com.vaadin.flow.component.orderedlayout.VerticalLayout; public class ErrorNotification extends Notification { - private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = 239587L; + private static final String NOTIFICATION_ID = "errorNotification"; protected ErrorNotification(final String errorMessage) { final VerticalLayout container = new VerticalLayout(); final Span errorSpan = new Span(errorMessage); final Button closeButton = new Button(getTranslation("root.close"), event -> this.close()); - + container.add(errorSpan, closeButton); container.setAlignItems(FlexComponent.Alignment.CENTER); addThemeVariants(NotificationVariant.LUMO_ERROR); diff --git a/src/main/java/edu/kit/typicalc/view/main/InferenceRuleField.java b/src/main/java/edu/kit/typicalc/view/main/InferenceRuleField.java index a984312..bebe876 100644 --- a/src/main/java/edu/kit/typicalc/view/main/InferenceRuleField.java +++ b/src/main/java/edu/kit/typicalc/view/main/InferenceRuleField.java @@ -14,15 +14,15 @@ import com.vaadin.flow.i18n.LocaleChangeObserver; /** * Visual representation of an inference rule. The component is composed of the rule itself (displayed - * in LaTeX rendered by MathJax), the name of the rule and a button to copy the LaTeX-code to the + * in LaTeX rendered by MathJax), the name of the rule and a button to copy the LaTeX-code to the * clipboard. Each InferenceRuleField is displayed in drawer area of the web page. */ @CssImport("./styles/view/main/inference-rule-field.css") @JsModule("./src/copy-to-clipboard.js") public class InferenceRuleField extends VerticalLayout implements LocaleChangeObserver { - + private static final long serialVersionUID = -8551851183297707985L; - + /* * IDs for the imported .css-file */ @@ -30,32 +30,32 @@ public class InferenceRuleField extends VerticalLayout implements LocaleChangeOb private static final String HEADER_ID = "headerField"; private static final String MAIN_ID = "main"; private static final String RULE_NAME_ID = "ruleName"; - + private final String nameKey; private final Button copyButton; private final H4 ruleName; - private final MathjaxDisplay rule; - + /** * Initializes an InferenceRuleField with a key to get the name of the inference rule and the LaTeX-code * for its visual representation. - * + * * @param latex the LaTeX-code * @param nameKey the key to get the name of the inference rule */ protected InferenceRuleField(final String latex, final String nameKey) { this.nameKey = nameKey; - + final HorizontalLayout header = new HorizontalLayout(); header.setId(HEADER_ID); this.ruleName = new H4(getTranslation(nameKey)); ruleName.setId(RULE_NAME_ID); header.add(ruleName); - + final VerticalLayout main = new VerticalLayout(); main.setId(MAIN_ID); this.copyButton = new Button(getTranslation("root.copyLatex"), new Icon(VaadinIcon.CLIPBOARD)); - this.rule = new MathjaxDisplay(latex); //TODO scale, when method implemented + MathjaxDisplay rule = new MathjaxDisplay(latex); //TODO scale, when method implemented + // TODO: scale to what exactly? copyButton.addClickListener(event -> UI.getCurrent().getPage().executeJs("window.copyToClipboard($0)", latex)); main.add(rule, copyButton); add(header, main); diff --git a/src/main/java/edu/kit/typicalc/view/main/InfoDialog.java b/src/main/java/edu/kit/typicalc/view/main/InfoDialog.java index 54814eb..897dc69 100644 --- a/src/main/java/edu/kit/typicalc/view/main/InfoDialog.java +++ b/src/main/java/edu/kit/typicalc/view/main/InfoDialog.java @@ -9,13 +9,12 @@ import com.vaadin.flow.i18n.LocaleChangeEvent; import com.vaadin.flow.i18n.LocaleChangeObserver; /** - * Dialog which contains information on the correct syntax for the users input. + * Dialog which contains information on the correct syntax for the users input. */ @CssImport("./styles/view/main/info-dialog.css") public class InfoDialog extends Dialog implements LocaleChangeObserver { - private static final long serialVersionUID = 2914411566361539614L; - + /* * IDs for the imported .css-file */ @@ -23,7 +22,7 @@ public class InfoDialog extends Dialog implements LocaleChangeObserver { private static final String INFO_CONTENT_ID = "infoContent"; private final H4 heading; - + /** * Creates new InfoDialog. */ @@ -31,7 +30,7 @@ public class InfoDialog extends Dialog implements LocaleChangeObserver { heading = new H4(getTranslation("root.inputSyntax")); HorizontalLayout infoHeader = new HorizontalLayout(heading); infoHeader.setId(INFO_HEADER_ID); - + //TODO fill with content VerticalLayout infoContent = new VerticalLayout(); infoContent.setId(INFO_CONTENT_ID); diff --git a/src/main/java/edu/kit/typicalc/view/main/InputBar.java b/src/main/java/edu/kit/typicalc/view/main/InputBar.java index 2910467..ec56af2 100644 --- a/src/main/java/edu/kit/typicalc/view/main/InputBar.java +++ b/src/main/java/edu/kit/typicalc/view/main/InputBar.java @@ -35,9 +35,6 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { private static final short MAX_INPUT_LENGTH = 1000; - private final Icon infoIcon; - private final Button exampleButton; - private final Button lambdaButton; private final TextField inputField; private final Button inferTypeButton; @@ -48,7 +45,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { * @param callback Consumer to call the inferType()-method in UpperBar */ protected InputBar(final Consumer callback) { - infoIcon = new Icon(VaadinIcon.INFO_CIRCLE); + Icon infoIcon = new Icon(VaadinIcon.INFO_CIRCLE); infoIcon.addClickListener(event -> onInfoIconClick()); inputField = new TextField(); @@ -56,8 +53,8 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { inputField.setClearButtonVisible(true); inputField.setValueChangeMode(ValueChangeMode.EAGER); inputField.addValueChangeListener(event -> onInputFieldValueChange()); - lambdaButton = new Button(getTranslation("root.lambda"), event -> onLambdaButtonClick()); - exampleButton = new Button(getTranslation("root.examplebutton"), event -> onExampleButtonClick()); + Button lambdaButton = new Button(getTranslation("root.lambda"), event -> onLambdaButtonClick()); + Button exampleButton = new Button(getTranslation("root.examplebutton"), event -> onExampleButtonClick()); exampleButton.setId(EXAMPLE_BUTTON_ID); inferTypeButton = new Button(getTranslation("root.typeInfer"), event -> onTypeInferButtonClick(callback)); inferTypeButton.addClickShortcut(Key.ENTER).listenOn(this); @@ -67,10 +64,10 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { add(infoIcon, exampleButton, lambdaButton, inputField, inferTypeButton); setId(INPUT_BAR_ID); } - + /** * Sets the provided string as the value of the inputField and starts the type inference algorithm. - * + * * @param term the provided string */ protected void inferTerm(final String term) { diff --git a/src/main/java/edu/kit/typicalc/view/main/MathjaxDisplay.java b/src/main/java/edu/kit/typicalc/view/main/MathjaxDisplay.java index c99c410..b6ed31d 100644 --- a/src/main/java/edu/kit/typicalc/view/main/MathjaxDisplay.java +++ b/src/main/java/edu/kit/typicalc/view/main/MathjaxDisplay.java @@ -36,10 +36,5 @@ public class MathjaxDisplay extends LitTemplate implements MathjaxAdapter { public void showStep(int n) { // do nothing } - - @Override - public void scale(double newScaling) { - // todo implement - } }