Search in sources :

Example 26 with MagikType

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

the class MagikPreIndexer method handleDefinition.

private void handleDefinition(final MixinDefinition definition) {
    final GlobalReference globalRef = definition.getGlobalReference();
    this.ensurePackage(globalRef);
    final MagikType magikType = new IntrinsicType(globalRef);
    this.typeKeeper.addType(magikType);
    LOGGER.debug("Indexed mixin: {}", magikType);
}
Also used : IntrinsicType(nl.ramsolutions.sw.magik.analysis.typing.types.IntrinsicType) GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)

Example 27 with MagikType

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

the class MagikPreIndexer method handleDefinition.

private void handleDefinition(final SlottedExemplarDefinition definition) {
    final GlobalReference globalRef = definition.getGlobalReference();
    this.ensurePackage(globalRef);
    final MagikType magikType = new SlottedType(globalRef);
    this.typeKeeper.addType(magikType);
    LOGGER.debug("Indexed slotted exemplar: {}", magikType);
}
Also used : SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)

Example 28 with MagikType

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

the class CompletionProviderTest method testMethodCompletionBare.

@Test
void testMethodCompletionBare() {
    final String code = "" + "_method a.b\n" + "    1.\n" + "_endmethod";
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
    integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "find_me()", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
    // On '.'.
    final Position position = new Position(1, 6);
    final List<CompletionItem> completions = this.getCompletions(code, typeKeeper, position);
    assertThat(completions).hasSize(1);
    final CompletionItem item = completions.get(0);
    assertThat(item.getKind()).isEqualTo(CompletionItemKind.Method);
    assertThat(item.getInsertText()).isEqualTo("find_me()");
    assertThat(item.getLabel()).isEqualTo("find_me()");
    assertThat(item.getDetail()).isEqualTo("sw:integer");
}
Also used : Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Test(org.junit.jupiter.api.Test)

Example 29 with MagikType

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

the class CompletionProviderTest method testMethodCompletionSelf.

@Test
void testMethodCompletionSelf() {
    final String code = "" + "_method a.b\n" + "    _self.\n" + "_endmethod";
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType aType = new SlottedType(GlobalReference.of("user:a"));
    typeKeeper.addType(aType);
    aType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "find_me()", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
    // On '.'.
    final Position position = new Position(1, 10);
    final List<CompletionItem> completions = this.getCompletions(code, typeKeeper, position);
    assertThat(completions).hasSize(1);
    final CompletionItem item = completions.get(0);
    assertThat(item.getKind()).isEqualTo(CompletionItemKind.Method);
    assertThat(item.getInsertText()).isEqualTo("find_me()");
    assertThat(item.getLabel()).isEqualTo("find_me()");
    assertThat(item.getDetail()).isEqualTo("user:a");
}
Also used : SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Test(org.junit.jupiter.api.Test)

Example 30 with MagikType

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

the class CompletionProviderTest method testMethodCompletionExisting.

@Test
void testMethodCompletionExisting() {
    final String code = "" + "_method a.b\n" + "    1.fi\n" + "_endmethod";
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
    integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "find_me()", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
    // On 'i'.
    final Position position = new Position(1, 8);
    final List<CompletionItem> completions = this.getCompletions(code, typeKeeper, position);
    assertThat(completions).hasSize(1);
    final CompletionItem item = completions.get(0);
    assertThat(item.getKind()).isEqualTo(CompletionItemKind.Method);
    assertThat(item.getInsertText()).isEqualTo("find_me()");
    assertThat(item.getLabel()).isEqualTo("find_me()");
    assertThat(item.getDetail()).isEqualTo("sw:integer");
}
Also used : Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) 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