Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 Nov 6, 2025
35f5340
update
vanol21 Nov 6, 2025
769887d
test
vanol21 Nov 8, 2025
64ee378
test
vanol21 Nov 8, 2025
b53a9c1
test
vanol21 Nov 8, 2025
c78843a
test
vanol21 Nov 10, 2025
6c4ccd3
test
vanol21 Nov 10, 2025
1473ba0
add SynthesizeCompKindFromMCBasicTypesTest
vanol21 Nov 12, 2025
96f2dda
add enclosingscope
vanol21 Nov 12, 2025
004feaa
test update with ComponentSymbolsWithExpressionsAndMCBasicTypesMill
vanol21 Nov 14, 2025
e98f0c9
update
vanol21 Nov 14, 2025
5ca409c
update
vanol21 Nov 14, 2025
8a516da
add further Tests
vanol21 Nov 17, 2025
222d1c4
add further Tests
vanol21 Nov 17, 2025
7c5545b
nach MCAssertions umstellen
vanol21 Dec 7, 2025
6d24ca4
minor
vanol21 Dec 7, 2025
26e0727
extend MCAssertions with assertNotHasFindingStartingWith
vanol21 Dec 7, 2025
a0c4439
initialisation process for Typecheck3, delete comments
vanol21 Dec 7, 2025
6e87082
initialisation process for Typecheck3, delete commented code
vanol21 Dec 7, 2025
8ea1ea6
Merge remote-tracking branch 'origin/error-logging-by-primitive-type-…
vanol21 Dec 7, 2025
da458bb
Merge branch 'dev' into error-logging-by-primitive-type-subcomponent
TomBursch Dec 8, 2025
202943c
Update Tests
TomBursch Dec 8, 2025
68e9b48
Merge branch 'dev' into error-logging-by-primitive-type-subcomponent
TomBursch Dec 8, 2025
2aba5e6
Remove MCAssertions change
TomBursch Dec 8, 2025
1347e89
Fix SynthesizeComponentFromMCBasicTypesTest for qualified names
vanol21 Dec 12, 2025
ebf61ff
refractor SynthesizeComponentFromMCSimpleGenericTypesTest
vanol21 Dec 12, 2025
0480ad0
refractor SynthesizeComponentFromMCSimpleGenericTypesTest
vanol21 Dec 12, 2025
e7904db
refractor SynthesizeComponentFromMCSimpleGenericTypesTest
vanol21 Dec 15, 2025
ec02e9b
clean
vanol21 Dec 15, 2025
0c577e6
parameterize shouldHandleMCQualifiedTypeTest
vanol21 Dec 17, 2025
ed89d62
reduce and parameterized Tests
vanol21 Dec 17, 2025
07147ed
clean
vanol21 Dec 17, 2025
33f0cdb
minor
vanol21 Dec 17, 2025
27308b1
minor
vanol21 Dec 17, 2025
464fb32
MCTypeFacade nutzen
vanol21 Dec 18, 2025
f5a9612
MCTypeFacade nutzen
vanol21 Dec 18, 2025
8c5872a
clean
vanol21 Dec 18, 2025
14dd210
clean
vanol21 Dec 18, 2025
f8bb79b
clean
vanol21 Dec 18, 2025
d2870e9
refractor
vanol21 Dec 19, 2025
ab5bf6e
clean
vanol21 Dec 19, 2025
054f514
Merge branch 'dev' into error-logging-by-primitive-type-subcomponent
TomBursch Dec 19, 2025
f073b2d
Cleanup
TomBursch Dec 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import de.monticore.types.mcbasictypes._ast.ASTMCType;
import de.monticore.types.mcbasictypes._visitor.MCBasicTypesTraverser;
import de.se_rwth.commons.logging.Log;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Optional;
Expand Down Expand Up @@ -30,6 +31,12 @@ public interface ISynthesizeComponent {
default Optional<CompKindExpression> synthesize(@NonNull ASTMCType mcType) {
this.init();
mcType.accept(this.getTraverser());
return this.getResult();
Optional<CompKindExpression> res = this.getResult();
if (res.isEmpty()) {
Log.error(String.format("0xD0104 Cannot resolve component '%s'", mcType.toString()),
mcType.get_SourcePositionStart(), mcType.get_SourcePositionEnd()
);
}
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ public void handle(@NonNull ASTMCQualifiedType node) {
List<ComponentTypeSymbol> comp = enclScope.resolveComponentTypeMany(node.getMCQualifiedName().getQName());

if (comp.isEmpty()) {
Log.error(String.format("0xD0104 Cannot resolve component '%s'", node.getMCQualifiedName().getQName()),
node.get_SourcePositionStart(), node.get_SourcePositionEnd()
);
this.resultWrapper.setResultAbsent();
} else {
CompKindExpression result = new CompKindOfComponentType(comp.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public void handle(@NonNull ASTMCBasicGenericType mcType) {
List<ComponentTypeSymbol> compSym = enclScope.resolveComponentTypeMany(compName);

if (compSym.isEmpty()) {
Log.error(String.format("0xD0104 Cannot resolve component '%s'", mcType.getNameList().stream().reduce("", String::concat)),
mcType.get_SourcePositionStart(), mcType.get_SourcePositionEnd()
);
this.resultWrapper.setResultAbsent();
} else {
if (compSym.size() > 1) {
Expand Down
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 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.types.check;

import de.monticore.runtime.junit.AbstractMCTest;
import de.monticore.runtime.junit.MCAssertions;
import de.monticore.symbols.compsymbols._symboltable.ComponentTypeSymbol;
import de.monticore.types.MCTypeFacade;
import de.monticore.types.componentsymbolswithmcbasictypestest.ComponentSymbolsWithMCBasicTypesTestMill;
import de.monticore.types.mcbasictypes._ast.ASTMCType;
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.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Optional;

public class FullSynthesizeCompKindFromMCBasicTypesTest extends AbstractMCTest {

@BeforeEach
public void setup() {
LogStub.init();
Log.enableFailQuick(false);
Log.clearFindings();

ComponentSymbolsWithMCBasicTypesTestMill.reset();
ComponentSymbolsWithMCBasicTypesTestMill.init();
}

@Test
public void synthesizesCompKind_forResolvableComponentTypeSymbol() {
// Given
ComponentTypeSymbol typeA = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder()
.setName("A")
.setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope())
.build();
ComponentSymbolsWithMCBasicTypesTestMill.globalScope().add(typeA);
typeA.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope());

ASTMCType ast = MCTypeFacade.getInstance().createQualifiedType("A");
ast.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope());

FullSynthesizeCompKindFromMCBasicTypes synth = new FullSynthesizeCompKindFromMCBasicTypes();

// When
Optional<CompKindExpression> res = synth.synthesize(ast);

// Then
Assertions.assertTrue(res.isPresent());
Assertions.assertTrue(res.get().isComponentType());
Assertions.assertEquals(typeA, res.get().getTypeInfo());
}

@Test
public void shouldLogErrorOnPrimitive() {
// Given
ASTMCType ast = MCTypeFacade.getInstance().createIntType();
FullSynthesizeCompKindFromMCBasicTypes synth = new FullSynthesizeCompKindFromMCBasicTypes();

// When
Optional<CompKindExpression> result = synth.synthesize(ast);

// Then
Assertions.assertTrue(result.isEmpty(), "Expected no CompKindExpression for primitive 'int'");
MCAssertions.assertHasFindingStartingWith("0xD0104");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.types.check;

import de.monticore.runtime.junit.AbstractMCTest;
import de.monticore.runtime.junit.MCAssertions;
import de.monticore.symbols.compsymbols._symboltable.ComponentTypeSymbol;
import de.monticore.types.MCTypeFacade;
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.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class SynthesizeComponentFromMCBasicTypesTest extends AbstractMCTest {

@BeforeEach
public void setup() {
LogStub.init();
Log.enableFailQuick(false);
Log.clearFindings();

ComponentSymbolsWithMCBasicTypesTestMill.reset();
ComponentSymbolsWithMCBasicTypesTestMill.init();
}

@ParameterizedTest
@ValueSource(strings = {"Foo", "qual.Foo"})
public void shouldHandleMCQualifiedType(String qualifiedCompName) {
var globalScope = ComponentSymbolsWithMCBasicTypesTestMill.globalScope();

ASTMCQualifiedType ast = MCTypeFacade.getInstance().createQualifiedType(qualifiedCompName);
ast.setEnclosingScope(globalScope);

ComponentTypeSymbol symbol = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder()
.setName(ast.getMCQualifiedName().getBaseName())
.setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope())
.build();

if (qualifiedCompName.equals("qual.Foo")) {
var qualScope = ComponentSymbolsWithMCBasicTypesTestMill.scope();
qualScope.setName("qual");
qualScope.add(symbol);
qualScope.addSubScope(symbol.getSpannedScope());
globalScope.addSubScope(qualScope);
} else {
globalScope.add(symbol);
globalScope.addSubScope(symbol.getSpannedScope());
}

CompKindCheckResult result = new CompKindCheckResult();
SynthesizeCompKindFromMCBasicTypes synth =
new SynthesizeCompKindFromMCBasicTypes(result);

// When
synth.handle(ast);

// Then
Assertions.assertTrue(result.getResult().isPresent());
Assertions.assertTrue(result.getResult().get().isComponentType());
Assertions.assertEquals(symbol, result.getResult().get().getTypeInfo());
}

@Test
public void shouldLogErrorForDuplicateSymbols() {
// Given
ASTMCQualifiedType ast = MCTypeFacade.getInstance().createQualifiedType("Foo");
ast.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope());


ComponentTypeSymbol compSymbol1 = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder()
.setName(ast.getMCQualifiedName().getBaseName())
.setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope())
.build();
ComponentSymbolsWithMCBasicTypesTestMill.globalScope().add(compSymbol1);
ComponentSymbolsWithMCBasicTypesTestMill.globalScope().addSubScope(compSymbol1.getSpannedScope());

ComponentTypeSymbol compSymbol2 = ComponentSymbolsWithMCBasicTypesTestMill.componentTypeSymbolBuilder()
.setName(ast.getMCQualifiedName().getBaseName())
.setSpannedScope(ComponentSymbolsWithMCBasicTypesTestMill.scope())
.build();
ComponentSymbolsWithMCBasicTypesTestMill.globalScope().add(compSymbol2);
ComponentSymbolsWithMCBasicTypesTestMill.globalScope().addSubScope(compSymbol2.getSpannedScope());

CompKindCheckResult result = new CompKindCheckResult();
SynthesizeCompKindFromMCBasicTypes synth = new SynthesizeCompKindFromMCBasicTypes(result);

// When
synth.handle(ast);

// Then
Assertions.assertTrue(result.getResult().isPresent());
Assertions.assertTrue(result.getResult().get().isComponentType());
Assertions.assertEquals(compSymbol1, result.getResult().get().getTypeInfo());
MCAssertions.assertHasFindingStartingWith("0xD0105");
}

@ParameterizedTest
@ValueSource(strings = {"Foo", "qual.Foo"})
public void shouldNotLogErrorForMissingSymbol(String qualifiedName) {
// Given
ASTMCQualifiedType astNormalComp = MCTypeFacade.getInstance().createQualifiedType(qualifiedName);
astNormalComp.setEnclosingScope(ComponentSymbolsWithMCBasicTypesTestMill.globalScope());

CompKindCheckResult result = new CompKindCheckResult();
SynthesizeCompKindFromMCBasicTypes synth4normal = new SynthesizeCompKindFromMCBasicTypes(result);

// When
synth4normal.handle(astNormalComp);

// Then
Assertions.assertFalse(result.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());
}
}
Loading
Loading