Search in sources :

Example 21 with MagikType

use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.

the class MethodArgumentParameterTypeCheckTest method testArgumentTypeMatches.

@Test
void testArgumentTypeMatches() {
    final String code = "integer.m1(:symbol)";
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
    final AbstractType symbolType = typeKeeper.getType(GlobalReference.of("sw:symbol"));
    final Parameter param1 = new Parameter("p1", Parameter.Modifier.NONE, symbolType);
    integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "m1()", List.of(param1), null, ExpressionResult.UNDEFINED);
    final MagikTypedCheck check = new MethodArgumentParameterTypedCheck();
    final List<MagikIssue> checkResults = this.runCheck(code, typeKeeper, check);
    assertThat(checkResults).isEmpty();
}
Also used : MagikTypedCheck(nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) Parameter(nl.ramsolutions.sw.magik.analysis.typing.types.Parameter) MagikIssue(nl.ramsolutions.sw.magik.checks.MagikIssue) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Test(org.junit.jupiter.api.Test)

Example 22 with MagikType

use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.

the class MethodArgumentParameterTypeCheckTest method testArgumentTypeNotMatches.

@Test
void testArgumentTypeNotMatches() {
    final String code = "integer.m1(1)";
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
    final AbstractType symbolType = typeKeeper.getType(GlobalReference.of("sw:symbol"));
    final Parameter param1 = new Parameter("p1", Parameter.Modifier.NONE, symbolType);
    integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "m1()", List.of(param1), null, ExpressionResult.UNDEFINED);
    final MagikTypedCheck check = new MethodArgumentParameterTypedCheck();
    final List<MagikIssue> checkResults = this.runCheck(code, typeKeeper, check);
    assertThat(checkResults).hasSize(1);
}
Also used : MagikTypedCheck(nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) Parameter(nl.ramsolutions.sw.magik.analysis.typing.types.Parameter) MagikIssue(nl.ramsolutions.sw.magik.checks.MagikIssue) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Test(org.junit.jupiter.api.Test)

Example 23 with MagikType

use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.

the class HoverProviderTest method testProvideHoverMethodDefinitionExemplar.

@Test
void testProvideHoverMethodDefinitionExemplar() {
    // Set up a method.
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType hoverMeType = new SlottedType(GlobalReference.of("user:hover_me_type"));
    hoverMeType.setDoc("type_doc");
    typeKeeper.addType(hoverMeType);
    final String code = "" + "_method hover_me_type.method()\n" + "_endmethod";
    // On 'hover_me_type'.
    final Position position = new Position(0, 10);
    // Hover and test.
    final Hover hover = this.provideHover(code, position, typeKeeper);
    final MarkupContent content = hover.getContents().getRight();
    assertThat(content.getKind()).isEqualTo(MarkupKind.MARKDOWN);
    assertThat(content.getValue()).contains("hover_me_type");
    assertThat(content.getValue()).contains("type_doc");
}
Also used : SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MarkupContent(org.eclipse.lsp4j.MarkupContent) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Test(org.junit.jupiter.api.Test)

Example 24 with MagikType

use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.

the class HoverProviderTest method testProvideHoverType.

@Test
void testProvideHoverType() {
    // Set up a method.
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType symbolType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:symbol"));
    symbolType.setDoc("type_doc");
    final String code = "" + "_method a.b\n" + "    _local var << :symbol\n" + "    var.hover_me()\n" + "_endmethod";
    // On `var`.
    final Position position = new Position(2, 4);
    // Hover and test.
    final Hover hover = this.provideHover(code, position, typeKeeper);
    final MarkupContent content = hover.getContents().getRight();
    assertThat(content.getKind()).isEqualTo(MarkupKind.MARKDOWN);
    assertThat(content.getValue()).contains("symbol");
    assertThat(content.getValue()).contains("type_doc");
}
Also used : Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MarkupContent(org.eclipse.lsp4j.MarkupContent) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Test(org.junit.jupiter.api.Test)

Example 25 with MagikType

use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.

the class ImplementationProviderTest method testProvideImplementation.

@Test
void testProvideImplementation() {
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
    integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), EMPTY_LOCATION, "implementation()", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
    final URI uri = URI.create("tests://unittest");
    final String code = "" + "_method object.b\n" + "    1.implementation()\n" + "_endmethod";
    final MagikTypedFile magikFile = new MagikTypedFile(uri, code, typeKeeper);
    final org.eclipse.lsp4j.Position position = new org.eclipse.lsp4j.Position(1, 10);
    final ImplementationProvider provider = new ImplementationProvider();
    final List<org.eclipse.lsp4j.Location> implementations = provider.provideImplementations(magikFile, position);
    assertThat(implementations).containsOnly(Lsp4jConversion.locationToLsp4j(EMPTY_LOCATION));
}
Also used : Position(nl.ramsolutions.sw.magik.analysis.Position) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) URI(java.net.URI) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) ImplementationProvider(nl.ramsolutions.sw.magik.languageserver.implementation.ImplementationProvider) MagikTypedFile(nl.ramsolutions.sw.magik.MagikTypedFile) Location(nl.ramsolutions.sw.magik.analysis.Location) Test(org.junit.jupiter.api.Test)

Aggregations

MagikType (nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)64 Test (org.junit.jupiter.api.Test)47 AstNode (com.sonar.sslr.api.AstNode)33 ExpressionResult (nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult)32 MagikTypedFile (nl.ramsolutions.sw.magik.MagikTypedFile)28 ITypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)22 AbstractType (nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType)20 TypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper)18 SlottedType (nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType)17 GlobalReference (nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference)16 Method (nl.ramsolutions.sw.magik.analysis.typing.types.Method)14 Location (nl.ramsolutions.sw.magik.analysis.Location)10 IntrinsicType (nl.ramsolutions.sw.magik.analysis.typing.types.IntrinsicType)10 Parameter (nl.ramsolutions.sw.magik.analysis.typing.types.Parameter)9 Position (org.eclipse.lsp4j.Position)9 IndexedType (nl.ramsolutions.sw.magik.analysis.typing.types.IndexedType)8 Path (java.nio.file.Path)7 URI (java.net.URI)6 Collections (java.util.Collections)5 EnumSet (java.util.EnumSet)5