-
Notifications
You must be signed in to change notification settings - Fork 4
CoCo for defs and usages having the same type #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
86f4250
362811a
3c04194
064a8db
66ca8c5
c4e3b33
e6788f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package de.monticore.lang.sysmlv2.cocos; | ||
|
|
||
| import de.monticore.lang.sysmlbasis._ast.ASTSysMLTyping; | ||
| import de.monticore.lang.sysmlparts._ast.ASTAttributeUsage; | ||
| import de.monticore.lang.sysmlparts._ast.ASTEnumUsage; | ||
| import de.monticore.lang.sysmlparts._ast.ASTPartUsage; | ||
| import de.monticore.lang.sysmlparts._ast.ASTPortUsage; | ||
| import de.monticore.lang.sysmlparts._cocos.SysMLPartsASTAttributeUsageCoCo; | ||
| import de.monticore.lang.sysmlparts._cocos.SysMLPartsASTEnumUsageCoCo; | ||
| import de.monticore.lang.sysmlparts._cocos.SysMLPartsASTPartUsageCoCo; | ||
| import de.monticore.lang.sysmlparts._cocos.SysMLPartsASTPortUsageCoCo; | ||
| import de.monticore.lang.sysmlparts.symboltable.adapters.EnumDef2TypeSymbolAdapter; | ||
| import de.monticore.lang.sysmlparts.symboltable.adapters.PartDef2TypeSymbolAdapter; | ||
| import de.monticore.lang.sysmlparts.symboltable.adapters.PortDef2TypeSymbolAdapter; | ||
| import de.monticore.lang.sysmlv2._symboltable.ISysMLv2Scope; | ||
| import de.se_rwth.commons.logging.Log; | ||
|
|
||
| public class DefsAndUsagesHaveTheSameTypeCoCo | ||
| implements SysMLPartsASTPartUsageCoCo, SysMLPartsASTPortUsageCoCo, | ||
| SysMLPartsASTAttributeUsageCoCo, SysMLPartsASTEnumUsageCoCo { | ||
|
|
||
| @Override | ||
| public void check(ASTPartUsage node) { | ||
| boolean ok = node.getSpecializationList().stream() | ||
| .filter(t -> t instanceof ASTSysMLTyping) | ||
| .flatMap(t -> ((ASTSysMLTyping) t).getSuperTypesList().stream()) | ||
| .map(t -> ((ISysMLv2Scope)t.getEnclosingScope()).resolvePartDef(t.printType())) | ||
| .allMatch(t -> t.isPresent()); | ||
|
|
||
|
|
||
| if (!ok) { | ||
| Log.error("0xCOCO002 No valid PartDef found for ASTSysMLTyping", | ||
| node.get_SourcePositionStart()); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void check(ASTPortUsage node) { | ||
| boolean ok = node.getSpecializationList().stream() | ||
| .filter(t -> t instanceof ASTSysMLTyping) | ||
| .flatMap(t -> ((ASTSysMLTyping) t).getSuperTypesList().stream()) | ||
| .map(t -> ((ISysMLv2Scope)t.getEnclosingScope()).resolvePortDef(t.printType())) | ||
| .allMatch(t -> t.isPresent()); | ||
|
|
||
| if (!ok) { | ||
| Log.error("0xCOCO002 No valid PortDef found for ASTSysMLTyping", | ||
| node.get_SourcePositionStart()); | ||
| } | ||
|
|
||
| } | ||
| @Override | ||
| public void check(ASTAttributeUsage node) { | ||
|
|
||
| node.getSpecializationList().stream() | ||
| .filter(ASTSysMLTyping.class::isInstance) | ||
| .forEach(t -> { | ||
|
|
||
| String typeName = t.getSuperTypes(0).printType(); | ||
|
|
||
| boolean valid = | ||
| node.getEnclosingScope() | ||
| .resolveAttributeDef(typeName) | ||
| .isPresent() | ||
|
|
||
| || node.getEnclosingScope() | ||
| .resolveType(typeName) | ||
| .filter(type -> | ||
| !(type instanceof PartDef2TypeSymbolAdapter) | ||
| && !(type instanceof PortDef2TypeSymbolAdapter) | ||
| && !(type instanceof EnumDef2TypeSymbolAdapter)) | ||
| .isPresent(); | ||
|
|
||
| if (!valid) { | ||
| Log.error( | ||
| "0xCOCO003 Attribute usages may only be typed by an " | ||
| + "attribute definition or a valid non-SysML type.", | ||
| node.get_SourcePositionStart(), | ||
| node.get_SourcePositionEnd()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void check(ASTEnumUsage node) { | ||
|
adriancostin-sd marked this conversation as resolved.
|
||
| boolean ok = node.getSpecializationList().stream() | ||
| .filter(t -> t instanceof ASTSysMLTyping) | ||
| .flatMap(t -> ((ASTSysMLTyping) t).getSuperTypesList().stream()) | ||
| .map(t -> ((ISysMLv2Scope)t.getEnclosingScope()).resolveEnumDef(t.printType())) | ||
| .allMatch(t -> t.isPresent()); | ||
|
|
||
| if (!ok) { | ||
| Log.error("0xCOCO002 No valid EnumDef found for ASTSysMLTyping", | ||
| node.get_SourcePositionStart()); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package cocos; | ||
|
|
||
| import de.monticore.lang.sysmlparts._cocos.SysMLPartsASTAttributeUsageCoCo; | ||
| import de.monticore.lang.sysmlparts._cocos.SysMLPartsASTEnumUsageCoCo; | ||
| import de.monticore.lang.sysmlparts._cocos.SysMLPartsASTPartUsageCoCo; | ||
| import de.monticore.lang.sysmlparts._cocos.SysMLPartsASTPortUsageCoCo; | ||
| import de.monticore.lang.sysmlparts.symboltable.adapters.EnumDef2TypeSymbolAdapter; | ||
| import de.monticore.lang.sysmlparts.symboltable.adapters.PartDef2TypeSymbolAdapter; | ||
| import de.monticore.lang.sysmlparts.symboltable.adapters.PortDef2TypeSymbolAdapter; | ||
| import de.monticore.lang.sysmlv2.cocos.DefsAndUsagesHaveTheSameTypeCoCo; | ||
| import de.monticore.lang.sysmlv2._ast.ASTSysMLv2Node; | ||
| import de.monticore.lang.sysmlv2._cocos.SysMLv2CoCoChecker; | ||
| import de.se_rwth.commons.logging.Log; | ||
| import de.se_rwth.commons.logging.LogStub; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import symboltable.NervigeSymboltableTests; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
|
|
||
| import static org.assertj.core.api.Assertions.*; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| public class DefsAndUsagesHaveSameTypeTest extends NervigeSymboltableTests{ | ||
|
|
||
| @BeforeEach | ||
| public void clear() { | ||
| LogStub.init(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotReportErrorPort() throws IOException { | ||
| var as = process("port def P; port d: P;"); | ||
| var checker = new SysMLv2CoCoChecker(); | ||
| checker.addCoCo((SysMLPartsASTPortUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| var p = as.resolvePortDef("P"); | ||
| assertTrue(p.isPresent()); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| assertThat(Log.getFindings()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReportErrorPort() throws IOException { | ||
| var as = process("port def P; attribute d: P;"); | ||
|
|
||
| var checker = new SysMLv2CoCoChecker(); | ||
| checker.addCoCo((SysMLPartsASTPortUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| assertThat(Log.getFindings()).isNotEmpty(); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void shouldNotReportErrorPart() throws IOException { | ||
| var as = process("part def P; part d: P;"); | ||
| var checker = new SysMLv2CoCoChecker(); | ||
| checker.addCoCo((SysMLPartsASTPartUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| var p = as.resolvePartDef("P"); | ||
| assertTrue(p.isPresent()); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| assertThat(Log.getFindings()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReportErrorPart() throws IOException { | ||
| var as = process("part def P; attribute d: P;"); | ||
|
|
||
| var checker = new SysMLv2CoCoChecker(); | ||
| checker.addCoCo((SysMLPartsASTPartUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| assertThat(Log.getFindings()).isNotEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotReportErrorEnum() throws IOException { | ||
| var as = process("enum def P; enum d: P;"); | ||
| var checker = new SysMLv2CoCoChecker(); | ||
| checker.addCoCo((SysMLPartsASTEnumUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| var p = as.resolveEnumDef("P"); | ||
| assertTrue(p.isPresent()); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| assertThat(Log.getFindings()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReportErrorEnum() throws IOException { | ||
| var as = process("port def P; attribute d: P;"); | ||
|
|
||
| var checker = new SysMLv2CoCoChecker(); | ||
| checker.addCoCo((SysMLPartsASTEnumUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| assertThat(Log.getFindings()).isNotEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotReportErrorAttribute() throws IOException {// does not work for standard library attributes | ||
| var as = process("attribute def P : String; attribute a : String; "); | ||
| var checker = new SysMLv2CoCoChecker(); | ||
| checker.addCoCo((SysMLPartsASTAttributeUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| var p = as.resolveAttributeDef("P"); | ||
| var p_stlib = as.resolveType("P").filter(type -> | ||
| !(type instanceof PartDef2TypeSymbolAdapter) | ||
| && !(type instanceof PortDef2TypeSymbolAdapter) | ||
| && !(type instanceof EnumDef2TypeSymbolAdapter)); | ||
|
|
||
| assertTrue(p.isPresent() || p_stlib.isPresent()); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| assertThat(Log.getFindings()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReportErrorAttribute() throws IOException { | ||
| var as = process("part def P; attribute a : P;"); | ||
|
|
||
| var checker = new SysMLv2CoCoChecker(); | ||
| checker.addCoCo((SysMLPartsASTAttributeUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| assertThat(Log.getFindings()).isNotEmpty(); | ||
| } | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this test as well and merge the main branch into yours |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -11,13 +11,15 @@ | |||
| import org.junit.jupiter.api.Test; | ||||
| import org.junit.jupiter.api.Disabled; | ||||
|
|
||||
|
|
||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| import java.io.IOException; | ||||
| import java.nio.file.Files; | ||||
| import java.nio.file.Path; | ||||
| import java.util.stream.Collectors; | ||||
|
|
||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
|
|
||||
|
|
||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| /** | ||||
| * Diese Klasse sammelt alle Tests zu den SysML Domain Libraries (abgelegt unter resources). | ||||
| * Ziel ist es die Grammatiken genau so weit aufzubohren, dass die Modelle parsen. | ||||
|
|
@@ -28,6 +30,7 @@ public class DomainLibrariesTest { | |||
|
|
||||
| static SysMLv2Tool tool; | ||||
|
|
||||
|
|
||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| @BeforeAll | ||||
| public static void setup() { | ||||
| tool = new SysMLv2Tool(); | ||||
|
|
@@ -37,6 +40,7 @@ public static void setup() { | |||
| public void init() { | ||||
| tool.init(); | ||||
| Log.init(); | ||||
|
|
||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| } | ||||
|
|
||||
| @Test | ||||
|
|
@@ -152,7 +156,6 @@ public void testFunctionExpression1() throws IOException { | |||
| assertThat(ast).isPresent(); | ||||
| assertThat(Log.getFindings()).isEmpty(); | ||||
| } | ||||
|
|
||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont delete lines without a reason |
||||
| @Disabled | ||||
| @Test | ||||
| public void testParseShapeItems() { | ||||
|
|
||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert the test completely |
Uh oh!
There was an error while loading. Please reload this page.