diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/AssertIsValid.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/AssertIsValid.java index 2df7449a3c..1827b1df34 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/AssertIsValid.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/AssertIsValid.java @@ -1,11 +1,13 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mcassertstatements._ast.ASTAssertStatement; import de.monticore.statements.mcassertstatements._cocos.MCAssertStatementsASTAssertStatementCoCo; import de.monticore.types.check.SymTypeExpression; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; public class AssertIsValid implements MCAssertStatementsASTAssertStatementCoCo { @@ -17,27 +19,46 @@ public class AssertIsValid implements MCAssertStatementsASTAssertStatementCoCo { public static final String ERROR_CODE_2 = "0xA0902"; public static final String ERROR_MSG_FORMAT_2 = "Assert-statement must not be of void type."; - + TypeCalculator typeCheck; - - public AssertIsValid(TypeCalculator typeCheck){ - + + /** + * @deprecated use default constructor + */ + @Deprecated + public AssertIsValid(TypeCalculator typeCheck) { this.typeCheck = typeCheck; - } - + @Override public void check(ASTAssertStatement node) { + Preconditions.checkNotNull(node); + + SymTypeExpression assertion; + + if (typeCheck != null) { + // support deprecated behavior + assertion = typeCheck.typeOf(node.getAssertion()); + } else { + assertion = TypeCheck3.typeOf(node.getAssertion()); + } - SymTypeExpression result = typeCheck.typeOf(node.getAssertion()); - - if(!TypeCheck.isBoolean(result)){ + if(!SymTypeRelations.isBoolean(assertion)){ Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.getAssertion().get_SourcePositionStart()); } - + if(node.isPresentMessage()) { - result = typeCheck.typeOf(node.getMessage()); - if (!TypeCheck.isVoid(result)) { + + SymTypeExpression message; + + if (typeCheck != null) { + // support deprecated behavior + message = typeCheck.typeOf(node.getMessage()); + } else { + message = TypeCheck3.typeOf(node.getMessage()); + } + + if (message.isVoidType()) { Log.error(ERROR_CODE_2 + ERROR_MSG_FORMAT_2, node.getMessage().get_SourcePositionStart()); } } diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/CatchIsValid.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/CatchIsValid.java index c54acbe333..cafcfec350 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/CatchIsValid.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/CatchIsValid.java @@ -1,30 +1,32 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mcexceptionstatements._ast.ASTCatchClause; import de.monticore.statements.mcexceptionstatements._cocos.MCExceptionStatementsASTCatchClauseCoCo; import de.monticore.types.check.SymTypeExpression; import de.monticore.types.check.SymTypeExpressionFactory; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; import de.se_rwth.commons.logging.Log; public class CatchIsValid implements MCExceptionStatementsASTCatchClauseCoCo { - TypeCalculator typeCheck; - public static final String ERROR_CODE = "0xA0903"; public static final String ERROR_MSG_FORMAT = "Parameter in catch-statement has to be throwable or subtype of it."; - - public CatchIsValid(TypeCalculator typeCheck){ - - this.typeCheck = typeCheck; - - } - + + /** + * @deprecated use default constructor + */ + @Deprecated + public CatchIsValid(TypeCalculator typeCheck) { } + + public CatchIsValid() { } + @Override public void check(ASTCatchClause node) { + Preconditions.checkNotNull(node); SymTypeExpression throwable = SymTypeExpressionFactory.createTypeObject("java.lang.Throwable", node.getEnclosingScope()); @@ -33,7 +35,7 @@ public void check(ASTCatchClause node) { SymTypeExpression result = SymTypeExpressionFactory.createTypeObject(name, node.getEnclosingScope()); - if (!TypeCheck.isSubtypeOf(result, throwable)) { + if (!SymTypeRelations.isSubTypeOf(result, throwable)) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } } diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/DoWhileConditionHasBooleanType.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/DoWhileConditionHasBooleanType.java index 51ee53d5c0..84374dfedd 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/DoWhileConditionHasBooleanType.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/DoWhileConditionHasBooleanType.java @@ -1,33 +1,50 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mccommonstatements._ast.ASTDoWhileStatement; import de.monticore.statements.mccommonstatements._cocos.MCCommonStatementsASTDoWhileStatementCoCo; import de.monticore.types.check.SymTypeExpression; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; public class DoWhileConditionHasBooleanType implements MCCommonStatementsASTDoWhileStatementCoCo { - + + @Deprecated TypeCalculator typeCheck; - + public static final String ERROR_CODE = "0xA0905"; - + public static final String ERROR_MSG_FORMAT = "Condition in do-statement must be a boolean expression."; - - public DoWhileConditionHasBooleanType(TypeCalculator typeCheck){ + + /** + * @deprecated use default constructor + */ + @Deprecated + public DoWhileConditionHasBooleanType(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } - + + public DoWhileConditionHasBooleanType() { } + @Override public void check(ASTDoWhileStatement node) { - - SymTypeExpression result = typeCheck.typeOf(node.getCondition()); - - if(!TypeCheck.isBoolean(result)){ + Preconditions.checkNotNull(node); + + SymTypeExpression result; + + if (typeCheck != null) { + // support deprecated behavior + result = typeCheck.typeOf(node.getCondition()); + } else { + result = TypeCheck3.typeOf(node.getCondition()); + } + + if (!SymTypeRelations.isBoolean(result)) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } - + } } \ No newline at end of file diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ExpressionStatementIsValid.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ExpressionStatementIsValid.java index 829942cc54..38a71d8c47 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ExpressionStatementIsValid.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ExpressionStatementIsValid.java @@ -22,8 +22,7 @@ public ExpressionStatementIsValid(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } - public ExpressionStatementIsValid() { - } + public ExpressionStatementIsValid() { } @Deprecated protected TypeCalculator getTypeCheck() { @@ -31,13 +30,14 @@ protected TypeCalculator getTypeCheck() { } @Override - public void check(ASTExpressionStatement statement) { - Preconditions.checkNotNull(statement); - if(typeCheck != null) { - // support deprecated behavior - this.getTypeCheck().typeOf(statement.getExpression()); + public void check(ASTExpressionStatement node) { + Preconditions.checkNotNull(node); + + if (typeCheck != null) { + // support deprecated behavior + this.getTypeCheck().typeOf(node.getExpression()); } else { - TypeCheck3.typeOf(statement.getExpression()); + TypeCheck3.typeOf(node.getExpression()); } } } diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForConditionHasBooleanType.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForConditionHasBooleanType.java index 8a28908b3c..95768e3c51 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForConditionHasBooleanType.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForConditionHasBooleanType.java @@ -1,38 +1,54 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mccommonstatements._ast.ASTCommonForControl; import de.monticore.statements.mccommonstatements._ast.ASTForStatement; import de.monticore.statements.mccommonstatements._cocos.MCCommonStatementsASTForStatementCoCo; import de.monticore.types.check.SymTypeExpression; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; public class ForConditionHasBooleanType implements MCCommonStatementsASTForStatementCoCo { - + + @Deprecated TypeCalculator typeCheck; - + public static final String ERROR_CODE = "0xA0906"; - + public static final String ERROR_MSG_FORMAT = "Condition of for-loop must be a boolean expression."; - - public ForConditionHasBooleanType(TypeCalculator typeCheck){ + + /** + * @deprecated use default constructor + */ + @Deprecated + public ForConditionHasBooleanType(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } - + + public ForConditionHasBooleanType() { } + @Override public void check(ASTForStatement node) { + Preconditions.checkNotNull(node); // todo replace with typedispatcher as soon as issues are fixed - if(!(node.getForControl() instanceof ASTCommonForControl)) { + if (!(node.getForControl() instanceof ASTCommonForControl)) { return; } - SymTypeExpression result = typeCheck.typeOf(((ASTCommonForControl)node.getForControl()).getCondition()); - - if(!TypeCheck.isBoolean(result)){ + SymTypeExpression result; + + if (typeCheck != null) { + // support deprecated behavior + result = typeCheck.typeOf(((ASTCommonForControl) node.getForControl()).getCondition()); + } else { + result = TypeCheck3.typeOf(((ASTCommonForControl) node.getForControl()).getCondition()); + } + + if (!SymTypeRelations.isBoolean(result)) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } - } } \ No newline at end of file diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForEachIsValid.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForEachIsValid.java index 456b7b38db..15950fe625 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForEachIsValid.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ForEachIsValid.java @@ -1,35 +1,53 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mccommonstatements._ast.ASTEnhancedForControl; import de.monticore.statements.mccommonstatements._cocos.MCCommonStatementsASTEnhancedForControlCoCo; import de.monticore.types.check.SymTypeExpression; import de.monticore.types.check.SymTypeExpressionFactory; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; public class ForEachIsValid implements MCCommonStatementsASTEnhancedForControlCoCo { + @Deprecated TypeCalculator typeCheck; public static final String ERROR_CODE = "0xA0907 "; public static final String ERROR_MSG_FORMAT = "For-each loop expression must be an array of subtype of list."; + /** + * @deprecated use default constructor + */ + @Deprecated public ForEachIsValid(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } + public ForEachIsValid() { } + @Override public void check(ASTEnhancedForControl node) { + Preconditions.checkNotNull(node); + + SymTypeExpression expression; + + if (typeCheck != null) { + // support deprecated behavior + expression = typeCheck.typeOf(node.getExpression()); + } else { + expression = TypeCheck3.typeOf(node.getExpression()); + } - SymTypeExpression expression = typeCheck.typeOf(node.getExpression()); SymTypeExpression arrays = SymTypeExpressionFactory.createTypeObject("java.util.Arrays", node.getEnclosingScope()); SymTypeExpression lists = SymTypeExpressionFactory.createTypeObject("java.lang.Iterable", node.getEnclosingScope()); - if (!TypeCheck.isSubtypeOf(expression, arrays)) { - if (!TypeCheck.isSubtypeOf(expression, lists)) { + if (!SymTypeRelations.isSubTypeOf(expression, arrays)) { + if (!SymTypeRelations.isSubTypeOf(expression, lists)) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } } diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/IfConditionHasBooleanType.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/IfConditionHasBooleanType.java index 4e4864e99a..44165eec9c 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/IfConditionHasBooleanType.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/IfConditionHasBooleanType.java @@ -1,32 +1,49 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mccommonstatements._ast.ASTIfStatement; import de.monticore.statements.mccommonstatements._cocos.MCCommonStatementsASTIfStatementCoCo; import de.monticore.types.check.SymTypeExpression; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; public class IfConditionHasBooleanType implements MCCommonStatementsASTIfStatementCoCo { - + + @Deprecated TypeCalculator typeCheck; - + public static final String ERROR_CODE = "0xA0909"; - + public static final String ERROR_MSG_FORMAT = " Condition in if-statement must be a boolean expression."; - - public IfConditionHasBooleanType(TypeCalculator typeCheck){ + + /** + * @deprecated use default constructor + */ + @Deprecated + public IfConditionHasBooleanType(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } - + + public IfConditionHasBooleanType() { } + //JLS3 14.9-1 @Override public void check(ASTIfStatement node) { - - SymTypeExpression result = typeCheck.typeOf(node.getCondition()); - - if(!TypeCheck.isBoolean(result)){ + Preconditions.checkNotNull(node); + + SymTypeExpression result; + + if (typeCheck != null) { + // support deprecated behavior + result = typeCheck.typeOf(node.getCondition()); + } else { + result = TypeCheck3.typeOf(node.getCondition()); + } + + if (!SymTypeRelations.isBoolean(result)) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } } diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ResourceInTryStatementCloseable.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ResourceInTryStatementCloseable.java index f34a4039a8..6eef2379b5 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ResourceInTryStatementCloseable.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ResourceInTryStatementCloseable.java @@ -1,34 +1,54 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mcexceptionstatements._ast.ASTTryLocalVariableDeclaration; import de.monticore.statements.mcexceptionstatements._ast.ASTTryStatement3; import de.monticore.statements.mcexceptionstatements._cocos.MCExceptionStatementsASTTryStatement3CoCo; import de.monticore.types.check.SymTypeExpression; import de.monticore.types.check.SymTypeExpressionFactory; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; public class ResourceInTryStatementCloseable implements MCExceptionStatementsASTTryStatement3CoCo { - + + @Deprecated TypeCalculator typeCheck; - + public static final String ERROR_CODE = "0xA0920"; - + public static final String ERROR_MSG_FORMAT = " Resource in try-statement must be closeable or subtype of it."; - - public ResourceInTryStatementCloseable(TypeCalculator typeCheck){ + + /** + * @deprecated use default constructor + */ + @Deprecated + public ResourceInTryStatementCloseable(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } - + + public ResourceInTryStatementCloseable() { } + @Override public void check(ASTTryStatement3 node) { - + Preconditions.checkNotNull(node); + SymTypeExpression closeable = SymTypeExpressionFactory.createTypeObject("java.io.Closeable", node.getEnclosingScope()); - - for (ASTTryLocalVariableDeclaration dec: node.getTryLocalVariableDeclarationList()){ - if (!TypeCheck.isSubtypeOf(typeCheck.typeOf(dec.getExpression()), closeable)) { + + for (ASTTryLocalVariableDeclaration dec : node.getTryLocalVariableDeclarationList()) { + + SymTypeExpression expression; + + if (typeCheck != null) { + // support deprecated behavior + expression = typeCheck.typeOf(dec.getExpression()); + } else { + expression = TypeCheck3.typeOf(dec.getExpression()); + } + + if (!SymTypeRelations.isSubTypeOf(expression, closeable)) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } } diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/SwitchStatementValid.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/SwitchStatementValid.java index 3af28a3fff..b513563088 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/SwitchStatementValid.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/SwitchStatementValid.java @@ -1,46 +1,57 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; -import de.monticore.expressions.commonexpressions._ast.ASTFieldAccessExpression; -import de.monticore.statements.mccommonstatements.MCCommonStatementsMill; +import com.google.common.base.Preconditions; import de.monticore.statements.mccommonstatements._ast.ASTSwitchStatement; import de.monticore.statements.mccommonstatements._cocos.MCCommonStatementsASTSwitchStatementCoCo; -import de.monticore.symbols.basicsymbols.BasicSymbolsMill; -import de.monticore.symbols.basicsymbols._symboltable.TypeSymbolSurrogate; import de.monticore.symbols.oosymbols.OOSymbolsMill; -import de.monticore.symbols.oosymbols._symboltable.IOOSymbolsScope; -import de.monticore.symbols.oosymbols._symboltable.OOTypeSymbol; import de.monticore.types.check.SymTypeExpression; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; -import java.util.Optional; - public class SwitchStatementValid implements MCCommonStatementsASTSwitchStatementCoCo { + @Deprecated TypeCalculator typeCheck; public static final String ERROR_CODE = "0xA0917"; public static final String ERROR_MSG_FORMAT = - "Switch expression in the switch-statement must be " + - "char, byte, short, int, Character, Byte, Short, " + - "Integer, or an enum type."; + "Switch expression in the switch-statement must be " + + "char, byte, short, int, Character, Byte, Short, " + + "Integer, or an enum type."; + /** + * @deprecated use default constructor + */ + @Deprecated public SwitchStatementValid(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } + public SwitchStatementValid() { + this(null); + } + //JLS3 14.11 @Override public void check(ASTSwitchStatement node) { + Preconditions.checkNotNull(node); - SymTypeExpression result = typeCheck.typeOf(node.getExpression()); + SymTypeExpression result; + + if (typeCheck != null) { + // support deprecated behavior + result = typeCheck.typeOf(node.getExpression()); + } else { + result = TypeCheck3.typeOf(node.getExpression()); + } - if (!(typeCheck.isChar(result) || typeCheck.isByte(result) - || typeCheck.isShort(result) || typeCheck.isInt(result) - || isEnumMember(result))) { + if (!(SymTypeRelations.isChar(result) || SymTypeRelations.isByte(result) + || SymTypeRelations.isShort(result) || SymTypeRelations.isInt(result) + || isEnumMember(result))) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/SynchronizedArgIsReftype.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/SynchronizedArgIsReftype.java index c7aa422bbd..54d5f7ffb0 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/SynchronizedArgIsReftype.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/SynchronizedArgIsReftype.java @@ -1,30 +1,47 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mcsynchronizedstatements._ast.ASTSynchronizedStatement; import de.monticore.statements.mcsynchronizedstatements._cocos.MCSynchronizedStatementsASTSynchronizedStatementCoCo; import de.monticore.types.check.SymTypeExpression; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; public class SynchronizedArgIsReftype implements MCSynchronizedStatementsASTSynchronizedStatementCoCo { - + + @Deprecated TypeCalculator typeCheck; - + public static final String ERROR_CODE = "0xA0918 "; - + public static final String ERROR_MSG_FORMAT = "Expression in synchronized-statement must have a reference type."; - - public SynchronizedArgIsReftype(TypeCalculator typeCheck){ + + /** + * @deprecated use default constructor + */ + @Deprecated + public SynchronizedArgIsReftype(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } - + + public SynchronizedArgIsReftype() { } + @Override public void check(ASTSynchronizedStatement node) { - - SymTypeExpression result = typeCheck.typeOf(node.getExpression()); - - if(!result.isObjectType()) { + Preconditions.checkNotNull(node); + + SymTypeExpression result; + + if (typeCheck != null) { + // support deprecated behavior + result = typeCheck.typeOf(node.getExpression()); + } else { + result = TypeCheck3.typeOf(node.getExpression()); + } + + if (!result.isObjectType()) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } } diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ThrowIsValid.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ThrowIsValid.java index 66e1266b1b..863f7412a5 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ThrowIsValid.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/ThrowIsValid.java @@ -1,35 +1,54 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mcexceptionstatements._ast.ASTThrowStatement; import de.monticore.statements.mcexceptionstatements._cocos.MCExceptionStatementsASTThrowStatementCoCo; import de.monticore.types.check.SymTypeExpression; import de.monticore.types.check.SymTypeExpressionFactory; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; -public class ThrowIsValid implements MCExceptionStatementsASTThrowStatementCoCo{ - +public class ThrowIsValid implements MCExceptionStatementsASTThrowStatementCoCo { + + @Deprecated TypeCalculator typeCheck; - + public static final String ERROR_CODE = "0xA0918"; - + public static final String ERROR_MSG_FORMAT = " Exception in throw-statement must be Throwable or subtype of it."; - - public ThrowIsValid(TypeCalculator typeCheck){ + + /** + * @deprecated use default constructor + */ + @Deprecated + public ThrowIsValid(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } - + + public ThrowIsValid() { } + //JLS3 14.18-1 @Override public void check(ASTThrowStatement node) { - + Preconditions.checkNotNull(node); + SymTypeExpression throwable = SymTypeExpressionFactory.createTypeObject("java.lang.Throwable", node.getEnclosingScope()); - - if(!TypeCheck.isSubtypeOf(typeCheck.typeOf(node.getExpression()),throwable)){ + + SymTypeExpression expression; + + if (typeCheck != null) { + // support deprecated behavior + expression = typeCheck.typeOf(node.getExpression()); + } else { + expression = TypeCheck3.typeOf(node.getExpression()); + } + + if (!SymTypeRelations.isSubTypeOf(expression, throwable)) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } - + } } \ No newline at end of file diff --git a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/WhileConditionHasBooleanType.java b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/WhileConditionHasBooleanType.java index 2407f902ac..cb0dfcf33a 100644 --- a/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/WhileConditionHasBooleanType.java +++ b/monticore-grammar/src/main/java/de/monticore/statements/mccommonstatements/cocos/WhileConditionHasBooleanType.java @@ -1,31 +1,49 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.statements.mccommonstatements.cocos; +import com.google.common.base.Preconditions; import de.monticore.statements.mccommonstatements._ast.ASTWhileStatement; import de.monticore.statements.mccommonstatements._cocos.MCCommonStatementsASTWhileStatementCoCo; import de.monticore.types.check.SymTypeExpression; -import de.monticore.types.check.TypeCheck; import de.monticore.types.check.TypeCalculator; +import de.monticore.types3.SymTypeRelations; +import de.monticore.types3.TypeCheck3; import de.se_rwth.commons.logging.Log; public class WhileConditionHasBooleanType implements MCCommonStatementsASTWhileStatementCoCo { - + + @Deprecated TypeCalculator typeCheck; - + public static final String ERROR_CODE = "0xA0919"; - + public static final String ERROR_MSG_FORMAT = "Condition in while-statement must be a boolean expression."; - - public WhileConditionHasBooleanType(TypeCalculator typeCheck){ + + /** + * @deprecated use default constructor + */ + @Deprecated + public WhileConditionHasBooleanType(TypeCalculator typeCheck) { this.typeCheck = typeCheck; } - + + public WhileConditionHasBooleanType() { } + //JLS3 14.12-1 @Override public void check(ASTWhileStatement node) { - SymTypeExpression result = typeCheck.typeOf(node.getCondition()); - - if(!TypeCheck.isBoolean(result)){ + Preconditions.checkNotNull(node); + + SymTypeExpression result; + + if (typeCheck != null) { + // support deprecated behavior + result = typeCheck.typeOf(node.getCondition()); + } else { + result = TypeCheck3.typeOf(node.getCondition()); + } + + if (!SymTypeRelations.isBoolean(result)) { Log.error(ERROR_CODE + ERROR_MSG_FORMAT, node.get_SourcePositionStart()); } } diff --git a/monticore-grammar/src/test/java/de/monticore/statements/cocos/AssertIsValidTest.java b/monticore-grammar/src/test/java/de/monticore/statements/cocos/AssertIsValidTest.java index 8925e97f07..c4e42803e3 100644 --- a/monticore-grammar/src/test/java/de/monticore/statements/cocos/AssertIsValidTest.java +++ b/monticore-grammar/src/test/java/de/monticore/statements/cocos/AssertIsValidTest.java @@ -18,9 +18,6 @@ import java.io.IOException; import java.util.Optional; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class AssertIsValidTest { protected TestMCAssertStatementsCoCoChecker checker; @@ -45,7 +42,7 @@ public void checkValid(String expressionString) throws IOException { Log.getFindings().clear(); checker.checkAll(optAST.get()); Assertions.assertTrue(Log.getFindings().isEmpty()); - + } public void checkInvalid(String expressionString) throws IOException { @@ -61,19 +58,15 @@ public void checkInvalid(String expressionString) throws IOException { @Test public void testValid() throws IOException { - checkValid("assert 5 >= 0;"); checkValid("assert !(true||false)&&(5<6);"); - checkInvalid("assert 5 >= 0: 1+1;"); - + checkValid("assert 5 >= 0: 1+1;"); } @Test public void testInvalid() throws IOException { - checkInvalid("assert 4;"); checkInvalid("assert 'c';"); - } } \ No newline at end of file