mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Fix code style issues
Source: SonarLint :)
This commit is contained in:
parent
84e8cf07f7
commit
d7affc2999
@ -4,6 +4,7 @@ import edu.kit.typicalc.model.term.LambdaTerm;
|
||||
import edu.kit.typicalc.model.term.VarTerm;
|
||||
import edu.kit.typicalc.model.type.TypeAbstraction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -34,8 +35,7 @@ public class TypeInfererLet extends TypeInferer {
|
||||
* @return the constraints needed in the outer inference
|
||||
*/
|
||||
public List<Constraint> getLetConstraints() {
|
||||
return null;
|
||||
// TODO
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package edu.kit.typicalc.model.type;
|
||||
import edu.kit.typicalc.model.UnificationError;
|
||||
import edu.kit.typicalc.util.Result;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Models the type of an abstraction/function.
|
||||
*/
|
||||
@ -127,4 +129,21 @@ public class FunctionType extends Type {
|
||||
public Type getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
FunctionType that = (FunctionType) o;
|
||||
return Objects.equals(parameter, that.parameter) && Objects.equals(output, that.output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(parameter, output);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package edu.kit.typicalc.model.type;
|
||||
import edu.kit.typicalc.model.UnificationError;
|
||||
import edu.kit.typicalc.util.Result;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Models a simple named type.
|
||||
*/
|
||||
@ -108,4 +110,21 @@ public class NamedType extends Type {
|
||||
//TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
NamedType namedType = (NamedType) o;
|
||||
return Objects.equals(name, namedType.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name);
|
||||
}
|
||||
}
|
||||
|
@ -59,24 +59,4 @@ public abstract class Type {
|
||||
* @return the unification steps necessary, or an error if that is impossible
|
||||
*/
|
||||
public abstract Result<UnificationActions, UnificationError> constrainEqualToVariable(TypeVariable type);
|
||||
|
||||
/**
|
||||
* Checks whether this is equal to another Type
|
||||
* @param o the other Type
|
||||
* @return whether this is equal to the other Type or not.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this instanceof NamedType && o instanceof NamedType) {
|
||||
return ((NamedType) o).getName().equals(((NamedType) this).getName());
|
||||
}
|
||||
if (this instanceof TypeVariable && o instanceof TypeVariable) {
|
||||
return ((TypeVariable) o).getIndex() == ((TypeVariable) this).getIndex();
|
||||
}
|
||||
if (this instanceof FunctionType && o instanceof FunctionType) {
|
||||
return (((FunctionType) o).getOutput().equals(((FunctionType) this).getOutput())
|
||||
&& ((FunctionType) o).getParameter().equals(((FunctionType) this).getParameter()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package edu.kit.typicalc.model.type;
|
||||
import edu.kit.typicalc.model.TypeVariableFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Models a type abstraction with its type and the type variables bound by the for-all
|
||||
@ -70,5 +71,20 @@ public class TypeAbstraction {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TypeAbstraction that = (TypeAbstraction) o;
|
||||
return Objects.equals(type, that.type) && Objects.equals(quantifiedVariables, that.quantifiedVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(type, quantifiedVariables);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package edu.kit.typicalc.model.type;
|
||||
import edu.kit.typicalc.model.UnificationError;
|
||||
import edu.kit.typicalc.util.Result;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Models a type variable
|
||||
*/
|
||||
@ -110,4 +112,21 @@ public class TypeVariable extends Type {
|
||||
//TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TypeVariable that = (TypeVariable) o;
|
||||
return index == that.index && kind == that.kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(kind, index);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
@NonNullApi
|
||||
package edu.kit.typicalc.model.type;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
@ -1,7 +1,5 @@
|
||||
package edu.kit.typicalc.view;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
@ -23,17 +21,17 @@ public class TypicalcI18NProvider implements I18NProvider {
|
||||
* Prefix of all language related .property-files
|
||||
*/
|
||||
public static final String LANGUAGE_BUNDLE_PREFIX = "language.translation";
|
||||
|
||||
|
||||
/**
|
||||
* Prefix of general, language independent .property file
|
||||
*/
|
||||
public static final String GENERAL_BUNDLE_PREFIX = "language.general";
|
||||
|
||||
private final ResourceBundle generalBundle = ResourceBundle.getBundle(GENERAL_BUNDLE_PREFIX);
|
||||
|
||||
private final transient ResourceBundle generalBundle = ResourceBundle.getBundle(GENERAL_BUNDLE_PREFIX);
|
||||
|
||||
@Override
|
||||
public List<Locale> getProvidedLocales() {
|
||||
return Collections.unmodifiableList(Arrays.asList(Locale.GERMAN, Locale.ENGLISH));
|
||||
return List.of(Locale.GERMAN, Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,7 +39,7 @@ public class TypicalcI18NProvider implements I18NProvider {
|
||||
if (key == null) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle(LANGUAGE_BUNDLE_PREFIX, locale);
|
||||
String translation;
|
||||
|
||||
@ -52,7 +50,7 @@ public class TypicalcI18NProvider implements I18NProvider {
|
||||
try {
|
||||
translation = this.generalBundle.getString(key);
|
||||
} catch (final MissingResourceException exception) {
|
||||
// this should never be the case
|
||||
// this should never be the case
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
@ -29,31 +29,32 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
private final Button lambdaButton;
|
||||
private final ComboBox<String> inputField;
|
||||
private final Button inferTypeButton;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an InputBar with a Consumer-object to call the inferType()-method in UpperBar.
|
||||
* The current user input is passed as the methods argument.
|
||||
*
|
||||
*
|
||||
* @param callback Consumer to call the inferType()-method in UpperBar
|
||||
*/
|
||||
protected InputBar(final Consumer<String> callback) {
|
||||
infoIcon = new Icon(VaadinIcon.INFO_CIRCLE);
|
||||
// TODO: where is this tooltip supposed to show up?
|
||||
infoTooltip = new Tooltip();
|
||||
initInfoTooltip();
|
||||
infoTooltip.attachToComponent(infoIcon);
|
||||
infoTooltip.setPosition(TooltipPosition.BOTTOM);
|
||||
infoTooltip.setAlignment(TooltipAlignment.TOP);
|
||||
|
||||
|
||||
inputField = new ComboBox<>();
|
||||
initComboBox();
|
||||
lambdaButton = new Button(getTranslation("root.lambda"), event -> onlambdaButtonClick());
|
||||
inferTypeButton = new Button(getTranslation("root.typeInfer"), event -> onTypeInferButtonClick(callback));
|
||||
inferTypeButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||
|
||||
|
||||
add(infoIcon, infoTooltip, lambdaButton, inputField, inferTypeButton);
|
||||
setAlignItems(FlexComponent.Alignment.CENTER);
|
||||
}
|
||||
|
||||
|
||||
private void onTypeInferButtonClick(final Consumer<String> callback) {
|
||||
final Optional<String> currentInput = inputField.getOptionalValue();
|
||||
currentInput.ifPresentOrElse(callback::accept, () -> callback.accept(StringUtils.EMPTY));
|
||||
@ -67,7 +68,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
inputField.setValue(inputBuilder.toString());
|
||||
inputField.focus();
|
||||
}
|
||||
|
||||
|
||||
private void initComboBox() {
|
||||
//TODO remove magic string in this method (used for demo)
|
||||
inputField.setId("inputField");
|
||||
@ -75,7 +76,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
inputField.setAllowCustomValue(true);
|
||||
inputField.setItems("λx.x", "λx.λy.y x", "λx.λy.y (x x)", "let f = λx. g y y in f 3", "(λx.x x) (λx.x x)");
|
||||
inputField.addCustomValueSetListener(event -> inputField.setValue(event.getDetail()));
|
||||
|
||||
|
||||
//TODO seems to be the only solution to "immediately" parse backslash
|
||||
inputField.addValueChangeListener(event -> {
|
||||
if (inputField.getOptionalValue().isPresent()) {
|
||||
|
@ -16,7 +16,7 @@ import edu.kit.typicalc.presenter.Presenter;
|
||||
import edu.kit.typicalc.view.content.typeinferencecontent.TypeInferenceView;
|
||||
|
||||
/**
|
||||
* Contains all the displayed components and builds the applications user interface (UI).
|
||||
* Contains all the displayed components and builds the applications user interface (UI).
|
||||
* Vaadins app layout provides the rough structure of the UI. Using this structure the UI always
|
||||
* consists of an upper bar at the top of the screen and a drawer on the left side of
|
||||
* the screen.
|
||||
|
@ -5,81 +5,85 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import edu.kit.typicalc.model.term.AbsTerm;
|
||||
import edu.kit.typicalc.model.term.AppTerm;
|
||||
import edu.kit.typicalc.model.term.BooleanTerm;
|
||||
//import edu.kit.typicalc.model.term.ConstTerm;
|
||||
import edu.kit.typicalc.model.term.IntegerTerm;
|
||||
import edu.kit.typicalc.model.term.LambdaTerm;
|
||||
import edu.kit.typicalc.model.term.LetTerm;
|
||||
import edu.kit.typicalc.model.term.VarTerm;
|
||||
//import edu.kit.typicalc.model.type.NamedType;
|
||||
import edu.kit.typicalc.util.Result;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class LambdaParserTest {
|
||||
@Test
|
||||
void varTerm() {
|
||||
LambdaParser parser = new LambdaParser("x");
|
||||
Result<LambdaTerm, ParseError> term = parser.parse();
|
||||
System.out.println(term);
|
||||
assertEquals(term.unwrap(), new VarTerm("x"));
|
||||
}
|
||||
@Test
|
||||
void absTerm() {
|
||||
LambdaParser parser = new LambdaParser("λx.x");
|
||||
assertEquals(parser.parse().unwrap(), new AbsTerm(new VarTerm("x"), new VarTerm("x")));
|
||||
}
|
||||
@Test
|
||||
void appTerm() {
|
||||
LambdaParser parser = new LambdaParser("(λx.x)(λx.x)");
|
||||
assertEquals(parser.parse().unwrap(),
|
||||
new AppTerm(new AbsTerm(new VarTerm("x"), new VarTerm("x")),
|
||||
new AbsTerm(new VarTerm("x"), new VarTerm("x"))));
|
||||
}
|
||||
@Test
|
||||
void letTerm() {
|
||||
LambdaParser parser = new LambdaParser("let id = λx.x in id 1");
|
||||
assertEquals(parser.parse().unwrap(),
|
||||
new LetTerm(
|
||||
new VarTerm("id"),
|
||||
new AbsTerm(
|
||||
new VarTerm("x"),
|
||||
new VarTerm("x")
|
||||
),
|
||||
new AppTerm(
|
||||
new VarTerm("id"),
|
||||
new IntegerTerm(1)
|
||||
)
|
||||
));
|
||||
}
|
||||
@Test
|
||||
void complicatedTerm() {
|
||||
LambdaParser parser = new LambdaParser("(λx.λy.x y 5)(λz.z)(true)");
|
||||
assertEquals(parser.parse().unwrap(),
|
||||
new AppTerm(
|
||||
new AppTerm(
|
||||
new AbsTerm(
|
||||
new VarTerm("x"),
|
||||
new AbsTerm(
|
||||
new VarTerm("y"),
|
||||
new AppTerm(
|
||||
new AppTerm(
|
||||
new VarTerm("x"),
|
||||
new VarTerm("y")
|
||||
),
|
||||
new IntegerTerm(5)
|
||||
)
|
||||
)
|
||||
),
|
||||
new AbsTerm(
|
||||
new VarTerm("z"),
|
||||
new VarTerm("z")
|
||||
)
|
||||
),
|
||||
new BooleanTerm(true)
|
||||
));
|
||||
}
|
||||
@Test
|
||||
void miscellaneousTerms() {
|
||||
LambdaParser parser = new LambdaParser("");
|
||||
assertEquals(parser.parse().unwrapError(), ParseError.TOO_FEW_TOKENS);
|
||||
}
|
||||
@Test
|
||||
void varTerm() {
|
||||
LambdaParser parser = new LambdaParser("x");
|
||||
Result<LambdaTerm, ParseError> term = parser.parse();
|
||||
System.out.println(term);
|
||||
assertEquals(new VarTerm("x"), term.unwrap());
|
||||
}
|
||||
@Test
|
||||
void absTerm() {
|
||||
LambdaParser parser = new LambdaParser("λx.x");
|
||||
assertEquals(new AbsTerm(new VarTerm("x"), new VarTerm("x")), parser.parse().unwrap());
|
||||
}
|
||||
@Test
|
||||
void appTerm() {
|
||||
LambdaParser parser = new LambdaParser("(λx.x)(λx.x)");
|
||||
assertEquals(
|
||||
new AppTerm(new AbsTerm(new VarTerm("x"), new VarTerm("x")),
|
||||
new AbsTerm(new VarTerm("x"), new VarTerm("x"))),
|
||||
parser.parse().unwrap()
|
||||
);
|
||||
}
|
||||
@Test
|
||||
void letTerm() {
|
||||
LambdaParser parser = new LambdaParser("let id = λx.x in id 1");
|
||||
assertEquals(
|
||||
new LetTerm(
|
||||
new VarTerm("id"),
|
||||
new AbsTerm(
|
||||
new VarTerm("x"),
|
||||
new VarTerm("x")
|
||||
),
|
||||
new AppTerm(
|
||||
new VarTerm("id"),
|
||||
new IntegerTerm(1)
|
||||
)
|
||||
),
|
||||
parser.parse().unwrap()
|
||||
);
|
||||
}
|
||||
@Test
|
||||
void complicatedTerm() {
|
||||
LambdaParser parser = new LambdaParser("(λx.λy.x y 5)(λz.z)(true)");
|
||||
assertEquals(
|
||||
new AppTerm(
|
||||
new AppTerm(
|
||||
new AbsTerm(
|
||||
new VarTerm("x"),
|
||||
new AbsTerm(
|
||||
new VarTerm("y"),
|
||||
new AppTerm(
|
||||
new AppTerm(
|
||||
new VarTerm("x"),
|
||||
new VarTerm("y")
|
||||
),
|
||||
new IntegerTerm(5)
|
||||
)
|
||||
)
|
||||
),
|
||||
new AbsTerm(
|
||||
new VarTerm("z"),
|
||||
new VarTerm("z")
|
||||
)
|
||||
),
|
||||
new BooleanTerm(true)
|
||||
),
|
||||
parser.parse().unwrap()
|
||||
);
|
||||
}
|
||||
@Test
|
||||
void miscellaneousTerms() {
|
||||
LambdaParser parser = new LambdaParser("");
|
||||
assertEquals(ParseError.TOO_FEW_TOKENS, parser.parse().unwrapError());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.util.HashSet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class LambdaTermTest {
|
||||
class LambdaTermTest {
|
||||
|
||||
private static VarTerm x1;
|
||||
private static VarTerm x2;
|
||||
@ -30,17 +30,17 @@ public class LambdaTermTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeVariablesVarTerm() {
|
||||
void freeVariablesVarTerm() {
|
||||
assertEquals(new HashSet<>(Collections.singletonList(x1)), x1.getFreeVariables());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeVariablesConstTerm() {
|
||||
void freeVariablesConstTerm() {
|
||||
assertEquals(new HashSet<>(), c.getFreeVariables());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeVariablesAbsTerm() {
|
||||
void freeVariablesAbsTerm() {
|
||||
AbsTerm abs1 = new AbsTerm(x1, x2);
|
||||
assertEquals(new HashSet<>(Collections.singletonList(x2)), abs1.getFreeVariables());
|
||||
|
||||
@ -61,7 +61,7 @@ public class LambdaTermTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeVariablesAppTerm() {
|
||||
void freeVariablesAppTerm() {
|
||||
AppTerm app1 = new AppTerm(x1, x1);
|
||||
assertEquals(new HashSet<>(Collections.singletonList(x1)), app1.getFreeVariables());
|
||||
|
||||
@ -79,7 +79,7 @@ public class LambdaTermTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeVariablesLetTerm() {
|
||||
void freeVariablesLetTerm() {
|
||||
LetTerm let1 = new LetTerm(x1, x2, x1);
|
||||
assertEquals(new HashSet<>(Collections.singletonList(x2)), let1.getFreeVariables());
|
||||
|
||||
@ -94,7 +94,7 @@ public class LambdaTermTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeVariablesComplexTerm() {
|
||||
void freeVariablesComplexTerm() {
|
||||
// let x1 = (x2 let x1 = \x2. x2 in x1) in x3 (\x3. x1 x4 \x4. x4)
|
||||
LetTerm let = new LetTerm(x1,
|
||||
new AppTerm(x2, new LetTerm(x1, new AbsTerm(x2, x2), x1)),
|
||||
|
Loading…
Reference in New Issue
Block a user