use of nl.ramsolutions.sw.magik.analysis.typing.types.CombinedType in project magik-tools by StevenLooman.
the class LocalTypeReasoner method walkPostSuper.
@Override
protected void walkPostSuper(final AstNode node) {
// Determine which type we are.
final AbstractType methodOwnerType = this.getMethodOwnerType(node);
if (methodOwnerType == UndefinedType.INSTANCE) {
LOGGER.debug("Unknown type for node: {}", node);
return;
}
// Find specified super, if given.
final AstNode identifierNode = node.getFirstChild(MagikGrammar.IDENTIFIER);
final String identifier = identifierNode != null ? identifierNode.getTokenValue() : null;
final AbstractType superType;
if (identifier != null) {
superType = methodOwnerType.getParents().stream().filter(parentType -> {
final String fullTypeName = parentType.getFullName();
final String typeName = fullTypeName.split(":")[1];
return identifier.equals(typeName);
}).findAny().orElse(null);
} else {
superType = methodOwnerType.getParents().stream().reduce(CombinedType::combine).orElse(null);
}
if (superType == null) {
return;
}
final ExpressionResult result = new ExpressionResult(superType);
this.assignAtom(node, result);
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.CombinedType in project magik-tools by StevenLooman.
the class LocalTypeReasonerTest method testLoopResultOptional.
@Test
void testLoopResultOptional() {
final String code = "" + "_method object.test\n" + " _return _for i _over 1.upto(10)\n" + " _loop\n" + " _if a\n" + " _then\n" + " _leave _with i\n" + " _endif\n" + " _endloop\n" + "_endmethod\n";
// Set up TypeKeeper/TypeReasoner.
final TypeKeeper typeKeeper = new TypeKeeper();
final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "upto()", Collections.emptyList(), null, new ExpressionResult(), new ExpressionResult(integerType));
// 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 CombinedType resultType = (CombinedType) result.get(0, null);
assertThat(resultType).isNotNull();
assertThat(resultType.getFullName()).isEqualTo("sw:integer|sw:unset");
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.CombinedType in project magik-tools by StevenLooman.
the class TypeMatcherTest method testCombinedTypeNotMatchesCombinedType.
@Test
void testCombinedTypeNotMatchesCombinedType() {
final AbstractType type = new CombinedType(new IntrinsicType(GlobalReference.of("sw:type1")), new IntrinsicType(GlobalReference.of("sw:type2")));
final AbstractType criterium = new CombinedType(new IntrinsicType(GlobalReference.of("sw:type2")), new IntrinsicType(GlobalReference.of("sw:type3")));
final boolean matches = TypeMatcher.typeMatches(type, criterium);
assertThat(matches).isFalse();
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.CombinedType in project magik-tools by StevenLooman.
the class TypeMatcherTest method testCombinedTypeMatchesCombinedType.
@Test
void testCombinedTypeMatchesCombinedType() {
final AbstractType type = new CombinedType(new IntrinsicType(GlobalReference.of("sw:type1")), new IntrinsicType(GlobalReference.of("sw:type2")));
final AbstractType criterium = new CombinedType(new IntrinsicType(GlobalReference.of("sw:type1")), new IntrinsicType(GlobalReference.of("sw:type2")), new IntrinsicType(GlobalReference.of("sw:type3")));
final boolean matches = TypeMatcher.typeMatches(type, criterium);
assertThat(matches).isTrue();
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.CombinedType in project magik-tools by StevenLooman.
the class TypeMatcherTest method testTypeNotMatchesCombinedType.
@Test
void testTypeNotMatchesCombinedType() {
final AbstractType type = new IntrinsicType(GlobalReference.of("sw:type3"));
final AbstractType criterium = new CombinedType(new IntrinsicType(GlobalReference.of("sw:type1")), new IntrinsicType(GlobalReference.of("sw:type2")));
final boolean matches = TypeMatcher.typeMatches(type, criterium);
assertThat(matches).isFalse();
}
Aggregations