-
Notifications
You must be signed in to change notification settings - Fork 27
Error logging if subcomponent is of primitive type #203
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
Merged
TomBursch
merged 43 commits into
MontiCore:dev
from
vanol21:error-logging-by-primitive-type-subcomponent
Dec 19, 2025
Merged
Changes from 14 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
db76c8b
add error logging when the optional is empty
vanol21 35f5340
update
vanol21 769887d
test
vanol21 64ee378
test
vanol21 b53a9c1
test
vanol21 c78843a
test
vanol21 6c4ccd3
test
vanol21 1473ba0
add SynthesizeCompKindFromMCBasicTypesTest
vanol21 96f2dda
add enclosingscope
vanol21 004feaa
test update with ComponentSymbolsWithExpressionsAndMCBasicTypesMill
vanol21 e98f0c9
update
vanol21 5ca409c
update
vanol21 8a516da
add further Tests
vanol21 222d1c4
add further Tests
vanol21 7c5545b
nach MCAssertions umstellen
vanol21 6d24ca4
minor
vanol21 26e0727
extend MCAssertions with assertNotHasFindingStartingWith
vanol21 a0c4439
initialisation process for Typecheck3, delete comments
vanol21 6e87082
initialisation process for Typecheck3, delete commented code
vanol21 8ea1ea6
Merge remote-tracking branch 'origin/error-logging-by-primitive-type-…
vanol21 da458bb
Merge branch 'dev' into error-logging-by-primitive-type-subcomponent
TomBursch 202943c
Update Tests
TomBursch 68e9b48
Merge branch 'dev' into error-logging-by-primitive-type-subcomponent
TomBursch 2aba5e6
Remove MCAssertions change
TomBursch 1347e89
Fix SynthesizeComponentFromMCBasicTypesTest for qualified names
vanol21 ebf61ff
refractor SynthesizeComponentFromMCSimpleGenericTypesTest
vanol21 0480ad0
refractor SynthesizeComponentFromMCSimpleGenericTypesTest
vanol21 e7904db
refractor SynthesizeComponentFromMCSimpleGenericTypesTest
vanol21 ec02e9b
clean
vanol21 0c577e6
parameterize shouldHandleMCQualifiedTypeTest
vanol21 ed89d62
reduce and parameterized Tests
vanol21 07147ed
clean
vanol21 33f0cdb
minor
vanol21 27308b1
minor
vanol21 464fb32
MCTypeFacade nutzen
vanol21 f5a9612
MCTypeFacade nutzen
vanol21 8c5872a
clean
vanol21 14dd210
clean
vanol21 f8bb79b
clean
vanol21 d2870e9
refractor
vanol21 ab5bf6e
clean
vanol21 054f514
Merge branch 'dev' into error-logging-by-primitive-type-subcomponent
TomBursch f073b2d
Cleanup
TomBursch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ore-grammar/src/test/grammars/de/monticore/types/ComponentSymbolsWithMCBasicTypesTest.mc4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /* (c) https://github.com/MontiCore/monticore */ | ||
|
|
||
| package de.monticore.types; | ||
|
|
||
| component grammar ComponentSymbolsWithMCBasicTypesTest extends | ||
| de.monticore.symbols.CompSymbols, | ||
| de.monticore.symbols.OOSymbols, | ||
| de.monticore.types.MCBasicTypes, | ||
| de.monticore.types.MCSimpleGenericTypes { | ||
| } |
82 changes: 82 additions & 0 deletions
82
monticore-grammar/src/test/java/de/monticore/types/check/ISynthesizeComponentTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* (c) https://github.com/MontiCore/monticore */ | ||
| package de.monticore.types.check; | ||
|
|
||
| import de.monticore.expressions.combineexpressionswithliterals.CombineExpressionsWithLiteralsMill; | ||
| import de.monticore.expressions.combineexpressionswithliterals._parser.CombineExpressionsWithLiteralsParser; | ||
| import de.monticore.types.componentsymbolswithmcbasictypestest.ComponentSymbolsWithMCBasicTypesTestMill; | ||
| import de.monticore.types.mcbasictypes._ast.ASTMCType; | ||
| import de.monticore.symbols.compsymbols._symboltable.ComponentTypeSymbol; | ||
| import de.se_rwth.commons.logging.Finding; | ||
| import de.se_rwth.commons.logging.Log; | ||
| import de.se_rwth.commons.logging.LogStub; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.Assertions; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public class ISynthesizeComponentTest { | ||
|
|
||
| private CombineExpressionsWithLiteralsParser parser; | ||
|
|
||
| @BeforeAll | ||
| public static void beforeAll() { | ||
| LogStub.init(); | ||
| Log.enableFailQuick(false); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| Log.clearFindings(); | ||
|
|
||
| parser = CombineExpressionsWithLiteralsMill.parser(); | ||
|
|
||
| ComponentSymbolsWithMCBasicTypesTestMill.reset(); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.init(); | ||
| } | ||
|
|
||
| @Test | ||
| public void synthesizesCompKind_forResolvableComponentTypeSymbol() throws Exception { | ||
| ComponentTypeSymbol typeA = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder() | ||
| .setName("A") | ||
| .setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope()) | ||
| .build(); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.globalScope().add(typeA); | ||
| typeA.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope()); | ||
|
|
||
| ASTMCType ast = parser.parse_StringMCType("A").orElseThrow(); | ||
| ast.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope()); | ||
|
|
||
| FullSynthesizeCompKindFromMCBasicTypes synth = new FullSynthesizeCompKindFromMCBasicTypes(); | ||
|
|
||
| Log.clearFindings(); | ||
| Optional<CompKindExpression> res = synth.synthesize(ast); | ||
| List<Finding> findings = Log.getFindings(); | ||
| boolean hasD0104 = findings.stream().anyMatch(f -> f.getMsg() != null && f.getMsg().contains("0xD0104")); | ||
| Assertions.assertTrue(res.isPresent()); | ||
| Assertions.assertFalse(hasD0104, "Did not expect central error 0xD0104"); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldLogCentralError_whenPrimitiveType() throws Exception { | ||
| ASTMCType astDouble = parser.parse_StringMCType("double").orElseThrow(); | ||
|
|
||
| FullSynthesizeCompKindFromMCBasicTypes synth = new FullSynthesizeCompKindFromMCBasicTypes(); | ||
|
|
||
| Log.clearFindings(); | ||
| Optional<CompKindExpression> result = synth.synthesize(astDouble); | ||
|
|
||
| Assertions.assertTrue(result.isEmpty(), "Expected no CompKindExpression for primitive 'double'"); | ||
|
|
||
| List<Finding> findings = Log.getFindings(); | ||
| Assertions.assertFalse(findings.isEmpty(), "Expected at least one finding when synthesis fails for primitive 'double'"); | ||
|
|
||
| boolean found = findings.stream().anyMatch(f -> { | ||
| String m = f.getMsg(); | ||
| return m != null && (m.contains("0xD0104")); | ||
| }); | ||
| Assertions.assertTrue(found, "Expected a central finding containing 0xD0104"); | ||
| } | ||
| } |
169 changes: 169 additions & 0 deletions
169
...ammar/src/test/java/de/monticore/types/check/SynthesizeComponentFromMCBasicTypesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /* (c) https://github.com/MontiCore/monticore */ | ||
| package de.monticore.types.check; | ||
|
|
||
| import de.monticore.symbols.compsymbols._symboltable.ComponentTypeSymbol; | ||
| import de.monticore.types.MCBasicTypesTest; | ||
| import de.monticore.types.componentsymbolswithmcbasictypestest.ComponentSymbolsWithMCBasicTypesTestMill; | ||
| import de.monticore.types.componentsymbolswithmcbasictypestest._visitor.ComponentSymbolsWithMCBasicTypesTestTraverser; | ||
| import de.monticore.types.mcbasictypes._ast.ASTMCQualifiedType; | ||
| import de.monticore.types.mcbasictypes._ast.ASTMCVoidType; | ||
| import de.se_rwth.commons.logging.Log; | ||
| import de.se_rwth.commons.logging.LogStub; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class SynthesizeComponentFromMCBasicTypesTest extends MCBasicTypesTest { | ||
|
|
||
| @BeforeAll | ||
| public static void beforeAll() { | ||
| LogStub.init(); | ||
| Log.enableFailQuick(false); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| Log.clearFindings(); | ||
|
|
||
| ComponentSymbolsWithMCBasicTypesTestMill.reset(); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.init(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldHandleMCQualifiedType() { | ||
| // Given | ||
| // First build some component type symbols which we refer to with the qualified type | ||
| String normalCompName = "Comp1"; | ||
| ComponentTypeSymbol normalComp = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder() | ||
| .setName(normalCompName) | ||
| .setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope()) | ||
| .build(); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.globalScope().add(normalComp); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.globalScope().addSubScope(normalComp.getSpannedScope()); | ||
|
|
||
| String qualifiedCompName = "Comp2"; | ||
| ComponentTypeSymbol qualifiedComp = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder() | ||
| .setName(qualifiedCompName) | ||
| .setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope()) | ||
| .build(); | ||
|
|
||
| String multipleNormalCompName = "Comp3"; | ||
| ComponentTypeSymbol multipleNormalComp1 = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder() | ||
| .setName(multipleNormalCompName) | ||
| .setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope()) | ||
| .build(); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.globalScope().add(multipleNormalComp1); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.globalScope().addSubScope(multipleNormalComp1.getSpannedScope()); | ||
| ComponentTypeSymbol multipleNormalComp2 = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder() | ||
| .setName(multipleNormalCompName) | ||
| .setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope()) | ||
| .build(); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.globalScope().add(multipleNormalComp2); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.globalScope().addSubScope(multipleNormalComp2.getSpannedScope()); | ||
|
|
||
| String nameOfQualCompScope = "scoop"; | ||
| var scopeOfQualComp = ComponentSymbolsWithMCBasicTypesTestMill.scope(); | ||
| scopeOfQualComp.setName(nameOfQualCompScope); | ||
| scopeOfQualComp.add(qualifiedComp); | ||
| scopeOfQualComp.addSubScope(qualifiedComp.getSpannedScope()); | ||
| ComponentSymbolsWithMCBasicTypesTestMill.globalScope().addSubScope(scopeOfQualComp); | ||
|
|
||
| // Now build the qualified type | ||
| ASTMCQualifiedType astNormalComp = ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedTypeBuilder() | ||
| .setMCQualifiedName(ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedNameBuilder() | ||
| .addParts(normalCompName) | ||
| .build()) | ||
| .build(); | ||
| ASTMCQualifiedType astQualComp = ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedTypeBuilder() | ||
| .setMCQualifiedName(ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedNameBuilder() | ||
| .addParts(nameOfQualCompScope) | ||
| .addParts(qualifiedCompName) | ||
| .build()) | ||
| .build(); | ||
| ASTMCQualifiedType astMultiNormalComp = ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedTypeBuilder() | ||
| .setMCQualifiedName(ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedNameBuilder() | ||
| .addParts(multipleNormalCompName) | ||
| .build()) | ||
| .build(); | ||
| astNormalComp.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope()); | ||
| astQualComp.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope()); | ||
| astMultiNormalComp.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope()); | ||
|
|
||
| CompKindCheckResult result4normal = new CompKindCheckResult(); | ||
| CompKindCheckResult result4qual = new CompKindCheckResult(); | ||
| CompKindCheckResult result4multi = new CompKindCheckResult(); | ||
| SynthesizeCompKindFromMCBasicTypes synth4normal = new SynthesizeCompKindFromMCBasicTypes(result4normal); | ||
| SynthesizeCompKindFromMCBasicTypes synth4qual = new SynthesizeCompKindFromMCBasicTypes(result4qual); | ||
| SynthesizeCompKindFromMCBasicTypes synth4multi = new SynthesizeCompKindFromMCBasicTypes(result4multi); | ||
|
|
||
| // When | ||
| synth4normal.handle(astNormalComp); | ||
| synth4qual.handle(astQualComp); | ||
| synth4multi.handle(astMultiNormalComp); | ||
|
|
||
| // Then | ||
| Assertions.assertTrue(result4normal.getResult().isPresent()); | ||
| Assertions.assertTrue(result4qual.getResult().isPresent()); | ||
| Assertions.assertTrue(result4multi.getResult().isPresent()); | ||
|
|
||
| Assertions.assertEquals(normalComp, result4normal.getResult().get().getTypeInfo()); | ||
| Assertions.assertEquals(qualifiedComp, result4qual.getResult().get().getTypeInfo()); | ||
| Assertions.assertTrue( | ||
| result4multi.getResult().get().getTypeInfo().equals(multipleNormalComp1) | ||
| || result4multi.getResult().get().getTypeInfo().equals(multipleNormalComp2)); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotHandleMCQualifiedType() { | ||
| // Given | ||
| ASTMCQualifiedType astNormalComp = ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedTypeBuilder() | ||
| .setMCQualifiedName(ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedNameBuilder() | ||
| .addParts("Foo") | ||
| .build()) | ||
| .build(); | ||
| ASTMCQualifiedType astQualComp = | ||
| ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedTypeBuilder() | ||
| .setMCQualifiedName(ComponentSymbolsWithMCBasicTypesTestMill.mCQualifiedNameBuilder() | ||
| .addParts("qual") | ||
| .addParts("Foo") | ||
| .build()) | ||
| .build(); | ||
| astNormalComp.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope()); | ||
| astQualComp.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope()); | ||
|
|
||
| CompKindCheckResult result4normal = new CompKindCheckResult(); | ||
| CompKindCheckResult result4qual = new CompKindCheckResult(); | ||
| SynthesizeCompKindFromMCBasicTypes synth4normal = new SynthesizeCompKindFromMCBasicTypes(result4normal); | ||
| SynthesizeCompKindFromMCBasicTypes synth4qual = new SynthesizeCompKindFromMCBasicTypes(result4qual); | ||
|
|
||
| // When | ||
| synth4normal.handle(astNormalComp); | ||
| synth4qual.handle(astQualComp); | ||
|
|
||
| // Then | ||
| Assertions.assertFalse(result4normal.getResult().isPresent()); | ||
| Assertions.assertFalse(result4qual.getResult().isPresent()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotHandleVoidType() { | ||
| // Given | ||
| ASTMCVoidType voidType = ComponentSymbolsWithMCBasicTypesTestMill.mCVoidTypeBuilder().build(); | ||
| CompKindCheckResult resultWrapper = new CompKindCheckResult(); | ||
| SynthesizeCompKindFromMCBasicTypes synth = new SynthesizeCompKindFromMCBasicTypes(resultWrapper); | ||
|
|
||
| // Attach a traverser to the synth, as we do not override the handle method and thus the synth tries to traverse the | ||
| // AST. In the end this should result in an empty synth result, however, if we do not attach a traverser, this will | ||
| // Result in an error instead. | ||
| ComponentSymbolsWithMCBasicTypesTestTraverser traverser = ComponentSymbolsWithMCBasicTypesTestMill.traverser(); | ||
| traverser.setMCBasicTypesHandler(synth); | ||
|
|
||
| // When | ||
| synth.handle(voidType); | ||
|
|
||
| // Then | ||
| Assertions.assertFalse(resultWrapper.getResult().isPresent()); | ||
| Assertions.assertTrue(Log.getFindings().isEmpty()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.