Skip to content

CoCo for defs and usages having the same type - #147

Open
Deni1593 wants to merge 7 commits into
masterfrom
fixing-grammars-issue-119
Open

CoCo for defs and usages having the same type#147
Deni1593 wants to merge 7 commits into
masterfrom
fixing-grammars-issue-119

Conversation

@Deni1593

@Deni1593 Deni1593 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

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

@adriancostin-sd adriancostin-sd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +26 to +28
.anyMatch(t -> node.getEnclosingScope()
.resolvePartDef(t.getSuperTypes(0).printType())
.isPresent());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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

Comment on lines +36 to +43
/* 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()));*/
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* 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());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
System.out.println("HERE:" + Log.getFindings());

This pollutes the output

Comment on lines +42 to +62
"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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

Comment on lines +70 to +73




Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

Comment on lines +1 to +11
standard library package AnalysisTooling {
private import ScalarValues::*;

metadata def ToolExecution {
attribute toolName : String;
attribute uri : String;
}
metadata def ToolVariable {
attribute name : String;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this coming from?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert the test completely

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this test as well and merge the main branch into yours

@Deni1593
Deni1593 force-pushed the fixing-grammars-issue-119 branch from 6d8d266 to 66ca8c5 Compare August 21, 2026 09:38
@Deni1593 Deni1593 changed the title Possible grammar fix for imports.sysml CoCo for defs and usages having the same type Aug 21, 2026
public void init() {
tool.init();
Log.init();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


static SysMLv2Tool tool;


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


import static org.assertj.core.api.Assertions.assertThat;


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

assertThat(ast).isPresent();
assertThat(Log.getFindings()).isEmpty();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont delete lines without a reason

Comment on lines -47 to 63
//"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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave them commented out until we fix the parser in another PR

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert these changes please.

}

@Test
public void testInvalid() throws IOException {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to shouldReportError

}

@Test
public void testValid() throws IOException {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to shouldNotReportError


@Test
public void testInvalid() throws IOException {
var as = process("attribute def P; attribute d: P;");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case the def should have another type to detect an error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants