Search in sources :

Example 6 with ITypeKeeper

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

the class GlobalKnownTypedCheckTest method testUnknownGlobal.

@Test
void testUnknownGlobal() {
    final String code = "" + "abc.m";
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikTypedCheck check = new GlobalKnownTypedCheck();
    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) MagikIssue(nl.ramsolutions.sw.magik.checks.MagikIssue) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Test(org.junit.jupiter.api.Test)

Example 7 with ITypeKeeper

use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper 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 8 with ITypeKeeper

use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper 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 9 with ITypeKeeper

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

the class MethodReturnMatchesDocTypedCheckTest method testTypesMatches.

@Test
void testTypesMatches() {
    final String code = "" + "_method a.b\n" + "  ## @return {integer}\n" + "  _return 1\n" + "_endmethod";
    final MagikTypedCheck check = new MethodReturnMatchesDocTypedCheck();
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final List<MagikIssue> issues = this.runCheck(code, typeKeeper, check);
    assertThat(issues).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) MagikIssue(nl.ramsolutions.sw.magik.checks.MagikIssue) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Test(org.junit.jupiter.api.Test)

Example 10 with ITypeKeeper

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

the class NewDocTypeExistsTypeCheckTest method testSlotUnknownType.

@Test
void testSlotUnknownType() {
    final String code = "" + "_method a.b(p1)\n" + "  ## @param {user:missing_type} p1\n" + "_endmethod";
    final MagikTypedCheck check = new NewDocTypeExistsTypeCheck();
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final List<MagikIssue> issues = this.runCheck(code, typeKeeper, check);
    assertThat(issues).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) MagikIssue(nl.ramsolutions.sw.magik.checks.MagikIssue) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Test(org.junit.jupiter.api.Test)

Aggregations

ITypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)55 TypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper)38 Test (org.junit.jupiter.api.Test)34 AbstractType (nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType)20 MagikType (nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)20 MagikTypedCheck (nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck)18 Position (org.eclipse.lsp4j.Position)17 AstNode (com.sonar.sslr.api.AstNode)14 GlobalReference (nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference)14 MagikTypedFile (nl.ramsolutions.sw.magik.MagikTypedFile)13 MagikIssue (nl.ramsolutions.sw.magik.checks.MagikIssue)13 Method (nl.ramsolutions.sw.magik.analysis.typing.types.Method)12 ExpressionResult (nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult)9 CompletionItem (org.eclipse.lsp4j.CompletionItem)9 URI (java.net.URI)8 List (java.util.List)8 MethodDefinitionNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper)8 LocalTypeReasoner (nl.ramsolutions.sw.magik.analysis.typing.LocalTypeReasoner)8 UndefinedType (nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType)8 MagikGrammar (nl.ramsolutions.sw.magik.api.MagikGrammar)8