CoCo for defs and usages having the same type - #147
Conversation
adriancostin-sd
left a comment
There was a problem hiding this comment.
Remember to rebase/merge the main branch into yours and whenever you are working on an issue just create a fresh branch not together with other previous issues. Also update the PR description
| .anyMatch(t -> node.getEnclosingScope() | ||
| .resolvePartDef(t.getSuperTypes(0).printType()) | ||
| .isPresent()); |
There was a problem hiding this comment.
| .anyMatch(t -> node.getEnclosingScope() | |
| .resolvePartDef(t.getSuperTypes(0).printType()) | |
| .isPresent()); | |
| .flatMap(t -> getSuperTypesList()) | |
| .map(t -> ((ISysMLv2Scope)t.getEnclosingScope()).resolvePartDef(t.printType())) | |
| .allMatch(t -> t.isPresent()) |
The idea is, if it has a typing then see if it is the right definition, therefore allMatch
| /* node.getSymbol().getTypesList().stream() | ||
| .filter(t -> !(t.getTypeInfo() instanceof PartDef2TypeSymbolAdapter))// This type actually came from a part def | ||
| .forEach(t -> Log.error( | ||
| "0xCOCO001 Part usages must be typed by part definitions, but found: " | ||
| + t.print(), | ||
| node.get_SourcePositionStart(), | ||
| node.get_SourcePositionEnd()));*/ | ||
| } |
There was a problem hiding this comment.
| /* node.getSymbol().getTypesList().stream() | |
| .filter(t -> !(t.getTypeInfo() instanceof PartDef2TypeSymbolAdapter))// This type actually came from a part def | |
| .forEach(t -> Log.error( | |
| "0xCOCO001 Part usages must be typed by part definitions, but found: " | |
| + t.print(), | |
| node.get_SourcePositionStart(), | |
| node.get_SourcePositionEnd()));*/ | |
| } |
| checker.addCoCo((SysMLPartsASTPortUsageCoCo) new DefsAndUsagesHaveTheSameTypeCoCo()); | ||
| Log.enableFailQuick(false); | ||
| checker.checkAll((ASTSysMLv2Node) as.getAstNode()); | ||
| System.out.println("HERE:" + Log.getFindings()); |
There was a problem hiding this comment.
| System.out.println("HERE:" + Log.getFindings()); |
This pollutes the output
| "packages.sysml", | ||
| "imports.sysml", | ||
| "ports.sysml", | ||
| "parts.sysml", | ||
| "states.sysml", | ||
| "parallel_states.sysml", | ||
| "actions.sysml", | ||
| "items.sysml", | ||
| "assert.sysml", | ||
| "constraints.sysml", | ||
| "requirements.sysml", | ||
| "streams.sysml", | ||
| "refinement.sysml", | ||
| "cardinalities.sysml", | ||
| "connections.sysml", | ||
| "collections.sysml", | ||
| "StateDecomposition1.sysml", | ||
| "FlowConectionInterfaceExample.sysml", | ||
| "StateActions.sysml", | ||
| "ConditionalSuccessionExample-1.sysml" | ||
| "example.sysml" | ||
| //"packages.sysml", | ||
| // "imports.sysml", | ||
| //"ports.sysml", | ||
| // "parts.sysml", | ||
| // "states.sysml", | ||
| //"parallel_states.sysml", | ||
| //"actions.sysml", | ||
| // "items.sysml", | ||
| // "assert.sysml", | ||
| // "constraints.sysml", | ||
| // "requirements.sysml", | ||
| // "streams.sysml", | ||
| // "refinement.sysml", | ||
| // "cardinalities.sysml", | ||
| // "connections.sysml", | ||
| // "collections.sysml", | ||
| // "StateDecomposition1.sysml", | ||
| // "FlowConectionInterfaceExample.sysml", | ||
| // "StateActions.sysml", | ||
| // "ConditionalSuccessionExample-1.sysml" |
|
|
||
|
|
||
|
|
||
|
|
| standard library package AnalysisTooling { | ||
| private import ScalarValues::*; | ||
|
|
||
| metadata def ToolExecution { | ||
| attribute toolName : String; | ||
| attribute uri : String; | ||
| } | ||
| metadata def ToolVariable { | ||
| attribute name : String; | ||
| } | ||
| } |
There was a problem hiding this comment.
where is this coming from?
There was a problem hiding this comment.
i think i copied it from the release notes to test standard library types for attributes, but I can delete it, it is not essential.
There was a problem hiding this comment.
revert the test completely
There was a problem hiding this comment.
revert this test as well and merge the main branch into yours
6d8d266 to
66ca8c5
Compare
| public void init() { | ||
| tool.init(); | ||
| Log.init(); | ||
|
|
|
|
||
| static SysMLv2Tool tool; | ||
|
|
||
|
|
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
|
|
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.Disabled; | ||
|
|
||
|
|
| assertThat(ast).isPresent(); | ||
| assertThat(Log.getFindings()).isEmpty(); | ||
| } | ||
|
|
There was a problem hiding this comment.
dont delete lines without a reason
| //"imports.sysml", | ||
| "imports.sysml", | ||
| "ports.sysml", | ||
| //"parts.sysml", | ||
| //"states.sysml", | ||
| "parts.sysml", | ||
| "states.sysml", | ||
| "parallel_states.sysml", | ||
| //"actions.sysml", | ||
| "actions.sysml", | ||
| "items.sysml", | ||
| "assert.sysml", | ||
| //"constraints.sysml", | ||
| "constraints.sysml", | ||
| "requirements.sysml", | ||
| //"streams.sysml", | ||
| //"streamsFilter.sysml", | ||
| //"refinement.sysml", | ||
| "streams.sysml", | ||
| "streamsFilter.sysml", | ||
| "refinement.sysml", | ||
| "cardinalities.sysml", | ||
| "connections.sysml", | ||
| //"collections.sysml", | ||
| "collections.sysml", | ||
| "StateDecomposition1.sysml", | ||
| //"FlowConectionInterfaceExample.sysml", | ||
| "FlowConectionInterfaceExample.sysml", | ||
| "StateActions.sysml", | ||
| "ConditionalSuccessionExample-1.sysml" |
There was a problem hiding this comment.
Leave them commented out until we fix the parser in another PR
There was a problem hiding this comment.
Revert these changes please.
| } | ||
|
|
||
| @Test | ||
| public void testInvalid() throws IOException { |
There was a problem hiding this comment.
rename to shouldReportError
| } | ||
|
|
||
| @Test | ||
| public void testValid() throws IOException { |
There was a problem hiding this comment.
rename to shouldNotReportError
|
|
||
| @Test | ||
| public void testInvalid() throws IOException { | ||
| var as = process("attribute def P; attribute d: P;"); |
There was a problem hiding this comment.
in this case the def should have another type to detect an error
Implemented:
DefsAndUsagesHaveTheSameTypeCoCo.java: a coco that checks if defs and usages have the same type. Contains 4 check() functions, one for each of part, port, enum and attribute. Attributes can be typed both by 'attribute' and by standard library types
DefsAndUsagesHaveTheSameTypeTest: tests if the def and usage within the given model have the same type