From 12f8e71d69316f93b55fee05e6b88a1a022d1022 Mon Sep 17 00:00:00 2001 From: Marita Breuer Date: Mon, 21 Aug 2023 12:58:52 +0200 Subject: [PATCH 1/3] refactor modifier isAbstract --- monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 | 1 - .../src/main/grammars/de/monticore/symbols/OOSymbols.mc4 | 1 + .../monticore/symbols/oosymbols/_symboltable/MethodSymbol.java | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 b/monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 index e672ac8c96..670d3382c4 100644 --- a/monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 +++ b/monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 @@ -41,7 +41,6 @@ symbol JavaMethod extends Method = Name; symbolrule JavaMethod = exceptions: de.monticore.types.check.SymTypeExpression* annotations: de.monticore.types.check.SymTypeExpression* - isAbstract: boolean isSynchronized: boolean isNative:boolean isStrictfp: boolean diff --git a/monticore-grammar/src/main/grammars/de/monticore/symbols/OOSymbols.mc4 b/monticore-grammar/src/main/grammars/de/monticore/symbols/OOSymbols.mc4 index 9d60bb4aa4..a18843f41b 100644 --- a/monticore-grammar/src/main/grammars/de/monticore/symbols/OOSymbols.mc4 +++ b/monticore-grammar/src/main/grammars/de/monticore/symbols/OOSymbols.mc4 @@ -97,6 +97,7 @@ component grammar OOSymbols extends BasicSymbols { isPrivate: boolean isProtected: boolean isPublic: boolean + isAbstract: boolean isStatic: boolean isFinal: boolean ; diff --git a/monticore-grammar/src/main/java/de/monticore/symbols/oosymbols/_symboltable/MethodSymbol.java b/monticore-grammar/src/main/java/de/monticore/symbols/oosymbols/_symboltable/MethodSymbol.java index 82404a9f3f..f9809f094b 100644 --- a/monticore-grammar/src/main/java/de/monticore/symbols/oosymbols/_symboltable/MethodSymbol.java +++ b/monticore-grammar/src/main/java/de/monticore/symbols/oosymbols/_symboltable/MethodSymbol.java @@ -29,6 +29,7 @@ public MethodSymbol deepClone() { clone.setIsPrivate(this.isPrivate); clone.setIsProtected(this.isProtected); clone.setIsPublic(this.isPublic); + clone.setIsAbstract(this.isAbstract); if (isPresentAstNode()) { clone.setAstNode(this.getAstNode()); } From e4e5b6e7d90df53cd74d0aac6b73ca1f7ff7f1c2 Mon Sep 17 00:00:00 2001 From: Marita Breuer Date: Mon, 28 Aug 2023 08:33:34 +0200 Subject: [PATCH 2/3] add test --- .../oosymbols/_symboltable/OOSymbolsModifierTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/monticore-grammar/src/test/java/de/monticore/symbols/oosymbols/_symboltable/OOSymbolsModifierTest.java b/monticore-grammar/src/test/java/de/monticore/symbols/oosymbols/_symboltable/OOSymbolsModifierTest.java index f5ae8cecb1..483ab9d607 100644 --- a/monticore-grammar/src/test/java/de/monticore/symbols/oosymbols/_symboltable/OOSymbolsModifierTest.java +++ b/monticore-grammar/src/test/java/de/monticore/symbols/oosymbols/_symboltable/OOSymbolsModifierTest.java @@ -114,6 +114,13 @@ public void testMethodSymbolModifier() { assertFalse(symbol.isIsPublic()); assertFalse(symbol.isIsPrivate()); assertFalse(symbol.isIsProtected()); + + assertFalse(symbol.isAbstract); + + symbol.setIsAbstract(true); + + assertTrue(symbol.isAbstract); + } } From 78977343fef4995779708e3526194ffda6e9e35e Mon Sep 17 00:00:00 2001 From: Marita Breuer Date: Tue, 29 Aug 2023 09:51:18 +0200 Subject: [PATCH 3/3] add CloneTest --- .../oosymbols/_symboltable/FieldSymbol.java | 1 + .../oosymbols/_symboltable/CloneTest.java | 97 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 monticore-grammar/src/test/java/de/monticore/symbols/oosymbols/_symboltable/CloneTest.java diff --git a/monticore-grammar/src/main/java/de/monticore/symbols/oosymbols/_symboltable/FieldSymbol.java b/monticore-grammar/src/main/java/de/monticore/symbols/oosymbols/_symboltable/FieldSymbol.java index 0db418177d..69455fde38 100644 --- a/monticore-grammar/src/main/java/de/monticore/symbols/oosymbols/_symboltable/FieldSymbol.java +++ b/monticore-grammar/src/main/java/de/monticore/symbols/oosymbols/_symboltable/FieldSymbol.java @@ -29,6 +29,7 @@ public FieldSymbol deepClone(){ clone.setIsStatic(this.isStatic); clone.setIsFinal(this.isFinal); clone.setIsDerived(this.isDerived); + clone.setIsReadOnly(this.isReadOnly); if(isPresentAstNode()) { clone.setAstNode(this.getAstNode()); } diff --git a/monticore-grammar/src/test/java/de/monticore/symbols/oosymbols/_symboltable/CloneTest.java b/monticore-grammar/src/test/java/de/monticore/symbols/oosymbols/_symboltable/CloneTest.java new file mode 100644 index 0000000000..f6236ac70d --- /dev/null +++ b/monticore-grammar/src/test/java/de/monticore/symbols/oosymbols/_symboltable/CloneTest.java @@ -0,0 +1,97 @@ +/* (c) https://github.com/MontiCore/monticore */ +package de.monticore.symbols.oosymbols._symboltable; + +import de.monticore.symbols.basicsymbols.BasicSymbolsMill; +import de.monticore.symbols.oosymbols.OOSymbolsMill; +import de.monticore.symboltable.modifiers.BasicAccessModifier; +import de.monticore.symboltable.modifiers.CompoundAccessModifier; +import de.monticore.symboltable.modifiers.StaticAccessModifier; +import de.monticore.types.check.DefsTypeBasic; +import de.monticore.types.check.SymTypeExpressionFactory; +import de.se_rwth.commons.logging.Log; +import de.se_rwth.commons.logging.LogStub; +import org.junit.Before; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class CloneTest { + + protected IOOSymbolsScope symbolTable; + + @Before + public void init(){ + LogStub.init(); + Log.enableFailQuick(false); + + OOSymbolsMill.reset(); + OOSymbolsMill.init(); + BasicSymbolsMill.initializePrimitives(); + + symbolTable = OOSymbolsMill.scope(); + + //FieldSymbols + FieldSymbol bar = DefsTypeBasic.field("bar", SymTypeExpressionFactory.createPrimitive("int")); + bar.setIsPublic(true); + bar.setIsStatic(true); + bar.setIsReadOnly(true); + bar.setIsFinal(true); + bar.setIsDerived(true); + symbolTable.add(bar); + + //MethodSymbols + MethodSymbol foo = DefsTypeBasic.method("foo", SymTypeExpressionFactory.createPrimitive("int")); + foo.setIsPublic(true); + foo.setIsStatic(true); + foo.setIsAbstract(true); + foo.setIsMethod(true); + foo.setIsElliptic(true); + symbolTable.add(foo); + + } + + + @Test + public void testMethod(){ + List methodsAllInclusion = symbolTable.resolveMethodMany("foo"); + assertEquals(1, methodsAllInclusion.size()); + + MethodSymbol methodSymbol = methodsAllInclusion.get(0); + MethodSymbol cloneSymbol = methodSymbol.deepClone(); + + assertEquals(methodSymbol.getName(), cloneSymbol.getName()); + assertEquals(methodSymbol.getParameterList().size(), cloneSymbol.getParameterList().size()); + assertEquals(methodSymbol.isIsMethod(), cloneSymbol.isIsMethod()); + assertEquals(methodSymbol.isIsPrivate(), cloneSymbol.isIsPrivate()); + assertEquals(methodSymbol.isIsPublic(), cloneSymbol.isIsPublic()); + assertEquals(methodSymbol.isIsProtected(), cloneSymbol.isIsProtected()); + assertEquals(methodSymbol.isIsAbstract(), cloneSymbol.isIsAbstract()); + assertEquals(methodSymbol.isIsStatic(), cloneSymbol.isIsStatic()); + assertEquals(methodSymbol.isIsFinal(), cloneSymbol.isIsFinal()); + assertEquals(methodSymbol.isIsElliptic(), cloneSymbol.isIsElliptic()); + assertEquals(methodSymbol.isIsConstructor(), cloneSymbol.isIsConstructor()); + assertEquals(methodSymbol.getType().asPrimitive().getPrimitiveName(), cloneSymbol.getType().asPrimitive().getPrimitiveName()); + } + + @Test + public void testField(){ + List fieldsAllInclusion = symbolTable.resolveFieldMany("bar"); + assertEquals(1, fieldsAllInclusion.size()); + + FieldSymbol fieldSymbol = fieldsAllInclusion.get(0); + FieldSymbol cloneSymbol = fieldSymbol.deepClone(); + + assertEquals(fieldSymbol.getName(), cloneSymbol.getName()); + assertEquals(fieldSymbol.getType().asPrimitive().getPrimitiveName(), cloneSymbol.getType().asPrimitive().getPrimitiveName()); + assertEquals(fieldSymbol.isIsFinal(), cloneSymbol.isIsFinal()); + assertEquals(fieldSymbol.isIsPrivate(), cloneSymbol.isIsPrivate()); + assertEquals(fieldSymbol.isIsProtected(), cloneSymbol.isIsProtected()); + assertEquals(fieldSymbol.isIsPublic(), cloneSymbol.isIsPublic()); + assertEquals(fieldSymbol.isIsStatic(), cloneSymbol.isIsStatic()); + assertEquals(fieldSymbol.isIsDerived(), cloneSymbol.isIsDerived()); + assertEquals(fieldSymbol.isIsReadOnly(), cloneSymbol.isIsReadOnly()); + } + +}