use of nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult in project magik-tools by StevenLooman.
the class LocalTypeReasonerTest method testReasonMethodMultiReturnSame.
@Test
void testReasonMethodMultiReturnSame() {
final String code = "" + "_package sw\n" + "_method object.test\n" + " _return 1\n" + " _return 2\n" + "_endmethod\n";
// Set up TypeKeeper/TypeReasoner.
final TypeKeeper typeKeeper = new TypeKeeper();
// Do analysis.
final MagikTypedFile magikFile = this.createMagikFile(code, typeKeeper);
final LocalTypeReasoner reasoner = magikFile.getTypeReasoner();
// Assert user:object.test type determined.
final AstNode topNode = magikFile.getTopNode();
final AstNode methodNode = topNode.getFirstChild(MagikGrammar.METHOD_DEFINITION);
final ExpressionResult result = reasoner.getNodeType(methodNode);
assertThat(result.size()).isEqualTo(1);
final AbstractType resultType = (AbstractType) result.get(0, null);
assertThat(resultType).isNotNull();
assertThat(resultType.getFullName()).isEqualTo("sw:integer");
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult in project magik-tools by StevenLooman.
the class LocalTypeReasonerTest method testSelfNewInit.
@Test
void testSelfNewInit() {
final String code = "" + "_method object.test\n" + " _return rope.new()\n" + "_endmethod\n";
// Set up TypeKeeper/TypeReasoner.
final TypeKeeper typeKeeper = new TypeKeeper();
final MagikType ropeType = new SlottedType(GlobalReference.of("sw:rope"));
typeKeeper.addType(ropeType);
ropeType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "new()", Collections.emptyList(), null, new ExpressionResult(SelfType.INSTANCE));
// Do analysis.
final MagikTypedFile magikFile = this.createMagikFile(code, typeKeeper);
final LocalTypeReasoner reasoner = magikFile.getTypeReasoner();
// Assert user:object.test type determined.
final AstNode topNode = magikFile.getTopNode();
final AstNode methodNode = topNode.getFirstChild(MagikGrammar.METHOD_DEFINITION);
final ExpressionResult result = reasoner.getNodeType(methodNode);
assertThat(result.size()).isEqualTo(1);
final MagikType resultType = (MagikType) result.get(0, null);
assertThat(resultType).isNotNull();
assertThat(resultType.getFullName()).isEqualTo("sw:rope");
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult in project magik-tools by StevenLooman.
the class LocalTypeReasonerTest method testSelf.
// region: self
@Test
void testSelf() {
final String code = "" + "_package sw\n" + "_method object.test\n" + " _return _self.test1\n" + "_endmethod\n";
// Set up TypeKeeper/TypeReasoner.
final TypeKeeper typeKeeper = new TypeKeeper();
final MagikType objectType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:object"));
objectType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "test1", Collections.emptyList(), null, new ExpressionResult(SelfType.INSTANCE));
// Do analysis.
final MagikTypedFile magikFile = this.createMagikFile(code, typeKeeper);
final LocalTypeReasoner reasoner = magikFile.getTypeReasoner();
// Assert user:object.test type determined.
final AstNode topNode = magikFile.getTopNode();
final AstNode methodNode = topNode.getFirstChild(MagikGrammar.METHOD_DEFINITION);
final ExpressionResult result = reasoner.getNodeType(methodNode);
assertThat(result.size()).isEqualTo(1);
final SelfType resultType = (SelfType) result.get(0, null);
assertThat(resultType).isNotNull();
assertThat(resultType.getFullName()).isEqualTo(SelfType.SERIALIZED_NAME);
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult in project magik-tools by StevenLooman.
the class LocalTypeReasonerTest method testGatherParameters.
@Test
void testGatherParameters() {
final String code = "" + "_method object.test(_gather args)\n" + "_endmethod\n";
// Set up TypeKeeper/TypeReasoner.
final TypeKeeper typeKeeper = new TypeKeeper();
// Do analysis.
final MagikTypedFile magikFile = this.createMagikFile(code, typeKeeper);
final LocalTypeReasoner reasoner = magikFile.getTypeReasoner();
// Assert user:object.test type determined.
final AstNode topNode = magikFile.getTopNode();
final AstNode parameterNode = topNode.getFirstDescendant(MagikGrammar.PARAMETER);
final ExpressionResult result = reasoner.getNodeType(parameterNode);
final MagikType resultType = (MagikType) result.get(0, null);
assertThat(resultType).isNotNull();
assertThat(resultType.getFullName()).isEqualTo("sw:simple_vector");
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult in project magik-tools by StevenLooman.
the class LocalTypeReasonerTest method testMultipleAssignmentStatement.
@Test
void testMultipleAssignmentStatement() {
final String code = "" + "_method object.test\n" + " (a, b) << (2, 3)\n" + " _return b\n" + "_endmethod\n";
// Set up TypeKeeper/TypeReasoner.
final TypeKeeper typeKeeper = new TypeKeeper();
// Do analysis.
final MagikTypedFile magikFile = this.createMagikFile(code, typeKeeper);
final LocalTypeReasoner reasoner = magikFile.getTypeReasoner();
// Assert user:object.test type determined.
final AstNode topNode = magikFile.getTopNode();
final AstNode methodNode = topNode.getFirstChild(MagikGrammar.METHOD_DEFINITION);
final ExpressionResult result = reasoner.getNodeType(methodNode);
assertThat(result.size()).isEqualTo(1);
final MagikType resultType = (MagikType) result.get(0, null);
assertThat(resultType).isNotNull();
assertThat(resultType.getFullName()).isEqualTo("sw:integer");
}
Aggregations