|
@@ -21,6 +21,7 @@ import org.eclipse.emf.ecore.EClass;
|
|
|
import org.eclipse.emf.ecore.EObject;
|
|
|
import org.eclipse.xtext.validation.Check;
|
|
|
import org.eclipse.xtext.validation.CheckType;
|
|
|
+import org.eclipse.xtext.validation.ComposedChecks;
|
|
|
import org.yakindu.base.expressions.expressions.Argument;
|
|
|
import org.yakindu.base.expressions.expressions.ArgumentExpression;
|
|
|
import org.yakindu.base.expressions.expressions.AssignmentExpression;
|
|
@@ -31,22 +32,15 @@ import org.yakindu.base.expressions.expressions.FeatureCall;
|
|
|
import org.yakindu.base.expressions.expressions.PostFixUnaryExpression;
|
|
|
import org.yakindu.base.types.AnnotatableElement;
|
|
|
import org.yakindu.base.types.Annotation;
|
|
|
-import org.yakindu.base.types.ComplexType;
|
|
|
-import org.yakindu.base.types.GenericElement;
|
|
|
import org.yakindu.base.types.Operation;
|
|
|
import org.yakindu.base.types.Parameter;
|
|
|
import org.yakindu.base.types.Property;
|
|
|
-import org.yakindu.base.types.Type;
|
|
|
-import org.yakindu.base.types.TypeParameter;
|
|
|
-import org.yakindu.base.types.TypeSpecifier;
|
|
|
-import org.yakindu.base.types.TypesPackage;
|
|
|
import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
|
|
|
-import org.yakindu.base.types.typesystem.ITypeSystem;
|
|
|
import org.yakindu.base.types.validation.IValidationIssueAcceptor;
|
|
|
+import org.yakindu.base.types.validation.TypesJavaValidator;
|
|
|
|
|
|
import com.google.common.base.Predicate;
|
|
|
import com.google.common.collect.Iterables;
|
|
|
-import com.google.common.collect.Sets;
|
|
|
import com.google.inject.Inject;
|
|
|
|
|
|
/**
|
|
@@ -54,57 +48,12 @@ import com.google.inject.Inject;
|
|
|
* @author andreas muelder - Initial contribution and API
|
|
|
*
|
|
|
*/
|
|
|
+@ComposedChecks(validators = { TypesJavaValidator.class })
|
|
|
public class ExpressionsJavaValidator extends org.yakindu.base.expressions.validation.AbstractExpressionsJavaValidator
|
|
|
implements IValidationIssueAcceptor {
|
|
|
|
|
|
- public static final String WARNING_IS_RAW_CODE = "WarningRaw";
|
|
|
- public static final String WARNING_IS_RAW_MSG = "%s is a raw type. References to generic type %s should be parameterized.";
|
|
|
-
|
|
|
- public static final String ERROR_NOT_GENERIC_CODE = "TypeNotGeneric";
|
|
|
- public static final String ERROR_NOT_GENERIC_MSG = "The type %s is not generic; it cannot be parameterized with arguments %s.";
|
|
|
-
|
|
|
- public static final String ERROR_ARGUMENTED_SPECIFIER_INCORRECT_ARGUMENT_NR_CODE = "IncorrectNrOfArguments";
|
|
|
- public static final String ERROR_ARGUMENTED_SPECIFIER_INCORRECT_ARGUMENT_NR_MSG = "Incorrect number of arguments for type %s; it cannot be parameterized with arguments %s.";
|
|
|
-
|
|
|
- public static final String ERROR_BOUND_MISSMATCH_CODE = "TypeParameterBoundMissmatch";
|
|
|
- public static final String ERROR_BOUND_MISSMATCH_MSG = "Bound mismatch: The type %s is not a valid substitute for the bounded parameter %s of the type %s.";
|
|
|
-
|
|
|
- public static final String ERROR_DUPLICATE_TYPE_PARAMETER_CODE = "DuplicateTypeParameter";
|
|
|
- public static final String ERROR_DUPLICATE_TYPE_PARAMETER_MSG = "Duplicate type parameter %s.";
|
|
|
-
|
|
|
- public static final String ERROR_CYCLE_DETECTED_CODE = "TypeExtendsItself";
|
|
|
- public static final String ERROR_CYCLE_DETECTED_MSG = "Cycle detected: the type %s cannot extend itself.";
|
|
|
-
|
|
|
- public static final String ERROR_DUPLICATE_PARAMETER_ASSIGNMENT_CODE = "ErrorDuplicateParameterAssignment";
|
|
|
- public static final String ERROR_DUPLICATE_PARAMETER_ASSIGNMENT_MSG = "Duplicate assignment to parameter '%s'.";
|
|
|
-
|
|
|
- public static final String ERROR_ASSIGNMENT_TO_CONST_CODE = "AssignmentToConst";
|
|
|
- public static final String ERROR_ASSIGNMENT_TO_CONST_MSG = "Assignment to constant not allowed.";
|
|
|
-
|
|
|
- public static final String ERROR_LEFT_HAND_ASSIGNMENT_CODE = "LeftHandAssignment";
|
|
|
- public static final String ERROR_LEFT_HAND_ASSIGNMENT_MSG = "The left-hand side of an assignment must be a variable.";
|
|
|
-
|
|
|
- public static final String ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE = "WrongNrOfArgs";
|
|
|
- public static final String ERROR_WRONG_NUMBER_OF_ARGUMENTS_MSG = "Wrong number of arguments, expected %s .";
|
|
|
-
|
|
|
- public static final String ERROR_VAR_ARGS_LAST_CODE = "VarArgsMustBeLast";
|
|
|
- public static final String ERROR_VAR_ARGS_LAST_MSG = "The variable argument type must be the last argument.";
|
|
|
-
|
|
|
- public static final String ERROR_WRONG_ANNOTATION_TARGET_CODE = "WrongAnnotationTarget";
|
|
|
- public static final String ERROR_WRONG_ANNOTATION_TARGET_MSG = "Annotation '%s' can not be applied on %s .";
|
|
|
-
|
|
|
- public static final String ERROR_OPTIONAL_MUST_BE_LAST_CODE = "OptionalParametersLast";
|
|
|
- public static final String ERROR_OPTIONAL_MUST_BE_LAST_MSG = "Required parameters must not be defined after optional parameters.";
|
|
|
-
|
|
|
- public static final String POSTFIX_ONLY_ON_VARIABLES_CODE = "PostfixOnlyOnVariables";
|
|
|
- public static final String POSTFIX_ONLY_ON_VARIABLES_MSG = "Invalid argument to operator '++/--'";
|
|
|
-
|
|
|
- @Inject
|
|
|
- private GenericsPrettyPrinter printer;
|
|
|
@Inject
|
|
|
private ITypeSystemInferrer typeInferrer;
|
|
|
- @Inject
|
|
|
- private ITypeSystem typeSystem;
|
|
|
|
|
|
@Check
|
|
|
public void checkExpression(Expression expression) {
|
|
@@ -127,6 +76,9 @@ public class ExpressionsJavaValidator extends org.yakindu.base.expressions.valid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static final String POSTFIX_ONLY_ON_VARIABLES_CODE = "PostfixOnlyOnVariables";
|
|
|
+ public static final String POSTFIX_ONLY_ON_VARIABLES_MSG = "Invalid argument to operator '++/--'";
|
|
|
+
|
|
|
@Check
|
|
|
public void checkPostFixOperatorOnlyOnVariables(PostFixUnaryExpression expression) {
|
|
|
if (!(expression.getOperand() instanceof ElementReferenceExpression)
|
|
@@ -135,94 +87,8 @@ public class ExpressionsJavaValidator extends org.yakindu.base.expressions.valid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Check
|
|
|
- public void checkIsRaw(TypeSpecifier typedElement) {
|
|
|
- Type type = typedElement.getType();
|
|
|
- if (!(type instanceof GenericElement))
|
|
|
- return;
|
|
|
- EList<TypeParameter> typeParameter = ((GenericElement) type).getTypeParameters();
|
|
|
- if (typedElement.getTypeArguments().size() == 0 && typeParameter.size() > 0) {
|
|
|
- String s1 = typedElement.getType().getName();
|
|
|
- String s2 = s1 + printer.concatTypeParameter(typeParameter);
|
|
|
- warning(String.format(WARNING_IS_RAW_MSG, s1, s2), typedElement, TypesPackage.Literals.TYPE_SPECIFIER__TYPE,
|
|
|
- WARNING_IS_RAW_CODE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Check
|
|
|
- public void checkTypedElementNotGeneric(TypeSpecifier typedElement) {
|
|
|
- if (typedElement.getTypeArguments().size() > 0 && ((!(typedElement.getType() instanceof GenericElement))
|
|
|
- || ((GenericElement) typedElement.getType()).getTypeParameters().size() == 0)) {
|
|
|
- String s1 = typedElement.getType().getName();
|
|
|
- String s2 = printer.concatTypeArguments(typedElement.getTypeArguments());
|
|
|
- error(String.format(ERROR_NOT_GENERIC_MSG, s1, s2), typedElement,
|
|
|
- TypesPackage.Literals.TYPE_SPECIFIER__TYPE, ERROR_NOT_GENERIC_CODE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Check
|
|
|
- public void checkNofArguments(TypeSpecifier typedElement) {
|
|
|
- if (!(typedElement.getType() instanceof GenericElement)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- GenericElement type = (GenericElement) typedElement.getType();
|
|
|
- EList<TypeParameter> typeParameter = type.getTypeParameters();
|
|
|
- if (typedElement.getTypeArguments().size() > 0
|
|
|
- && (typedElement.getTypeArguments().size() != typeParameter.size()) && typeParameter.size() > 0) {
|
|
|
- String s1 = type.getName() + printer.concatTypeParameter(typeParameter);
|
|
|
- String s2 = printer.concatTypeArguments(typedElement.getTypeArguments());
|
|
|
- error(String.format(ERROR_ARGUMENTED_SPECIFIER_INCORRECT_ARGUMENT_NR_MSG, s1, s2), typedElement,
|
|
|
- TypesPackage.Literals.TYPE_SPECIFIER__TYPE, ERROR_ARGUMENTED_SPECIFIER_INCORRECT_ARGUMENT_NR_CODE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Check
|
|
|
- public void checkDuplicateTypeParameter(GenericElement type) {
|
|
|
- Set<String> names = Sets.newHashSet();
|
|
|
- EList<TypeParameter> typeParameter = type.getTypeParameters();
|
|
|
- for (TypeParameter param : typeParameter) {
|
|
|
- String name = param.getName();
|
|
|
- if (names.contains(name)) {
|
|
|
- error(String.format(ERROR_DUPLICATE_TYPE_PARAMETER_MSG, name), type,
|
|
|
- TypesPackage.Literals.GENERIC_ELEMENT__TYPE_PARAMETERS, ERROR_DUPLICATE_TYPE_PARAMETER_CODE);
|
|
|
- }
|
|
|
- names.add(name);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Check
|
|
|
- public void checkTypeParameterBounds(TypeSpecifier typedElement) {
|
|
|
- if (!(typedElement.getType() instanceof GenericElement)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- GenericElement type = (GenericElement) typedElement.getType();
|
|
|
- EList<TypeParameter> typeParameter = type.getTypeParameters();
|
|
|
- if (typedElement.getTypeArguments().size() == 0
|
|
|
- || (typedElement.getTypeArguments().size() != typeParameter.size()))
|
|
|
- return;
|
|
|
- for (int i = 0; i < typeParameter.size(); i++) {
|
|
|
- TypeParameter parameter = typeParameter.get(i);
|
|
|
- if (parameter.getBound() != null) {
|
|
|
- Type argument = typedElement.getTypeArguments().get(i).getType();
|
|
|
- if (!typeSystem.isSuperType(argument, parameter.getBound())) {
|
|
|
- error(String.format(ERROR_BOUND_MISSMATCH_MSG, argument.getName(), (parameter.getBound()).getName(),
|
|
|
- type.getName()), typedElement, TypesPackage.Literals.TYPE_SPECIFIER__TYPE_ARGUMENTS, i,
|
|
|
- ERROR_BOUND_MISSMATCH_CODE);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Check
|
|
|
- public void checkTypeNotExtendsItself(ComplexType type) {
|
|
|
- EList<Type> superTypes = type.getSuperTypes();
|
|
|
- for (Type superType : superTypes) {
|
|
|
- if (superType.equals(type)) {
|
|
|
- error(String.format(ERROR_CYCLE_DETECTED_MSG, type.getName()), type,
|
|
|
- TypesPackage.Literals.TYPE__SUPER_TYPES, ERROR_CYCLE_DETECTED_CODE);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ public static final String ERROR_DUPLICATE_PARAMETER_ASSIGNMENT_CODE = "ErrorDuplicateParameterAssignment";
|
|
|
+ public static final String ERROR_DUPLICATE_PARAMETER_ASSIGNMENT_MSG = "Duplicate assignment to parameter '%s'.";
|
|
|
|
|
|
@Check
|
|
|
public void checkDuplicateParameterAssignment(ArgumentExpression exp) {
|
|
@@ -240,6 +106,9 @@ public class ExpressionsJavaValidator extends org.yakindu.base.expressions.valid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static final String ERROR_ASSIGNMENT_TO_CONST_CODE = "AssignmentToConst";
|
|
|
+ public static final String ERROR_ASSIGNMENT_TO_CONST_MSG = "Assignment to constant not allowed.";
|
|
|
+
|
|
|
@Check(CheckType.FAST)
|
|
|
public void checkAssignmentToFinalVariable(AssignmentExpression exp) {
|
|
|
Expression varRef = exp.getVarRef();
|
|
@@ -256,6 +125,9 @@ public class ExpressionsJavaValidator extends org.yakindu.base.expressions.valid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static final String ERROR_LEFT_HAND_ASSIGNMENT_CODE = "LeftHandAssignment";
|
|
|
+ public static final String ERROR_LEFT_HAND_ASSIGNMENT_MSG = "The left-hand side of an assignment must be a variable.";
|
|
|
+
|
|
|
@Check(CheckType.FAST)
|
|
|
public void checkLeftHandAssignment(final AssignmentExpression expression) {
|
|
|
Expression varRef = expression.getVarRef();
|
|
@@ -294,6 +166,9 @@ public class ExpressionsJavaValidator extends org.yakindu.base.expressions.valid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static final String ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE = "WrongNrOfArgs";
|
|
|
+ public static final String ERROR_WRONG_NUMBER_OF_ARGUMENTS_MSG = "Wrong number of arguments, expected %s .";
|
|
|
+
|
|
|
protected void assertOperationArguments(Operation operation, List<Expression> args) {
|
|
|
EList<Parameter> parameters = operation.getParameters();
|
|
|
List<Parameter> optionalParameters = filterOptionalParameters(parameters);
|
|
@@ -305,10 +180,6 @@ public class ExpressionsJavaValidator extends org.yakindu.base.expressions.valid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param parameters
|
|
|
- * @return
|
|
|
- */
|
|
|
protected List<Parameter> filterOptionalParameters(EList<Parameter> parameters) {
|
|
|
List<Parameter> optionalParameters = new ArrayList<>();
|
|
|
for (Parameter p : parameters) {
|
|
@@ -319,13 +190,8 @@ public class ExpressionsJavaValidator extends org.yakindu.base.expressions.valid
|
|
|
return optionalParameters;
|
|
|
}
|
|
|
|
|
|
- @Check(CheckType.FAST)
|
|
|
- public void checkVarArgParameterIsLast(Operation operation) {
|
|
|
- if (operation.isVariadic() && operation.getVarArgIndex() != operation.getParameters().size() - 1) {
|
|
|
- error(ERROR_VAR_ARGS_LAST_MSG, operation.getParameters().get(operation.getVarArgIndex()), null,
|
|
|
- ERROR_VAR_ARGS_LAST_CODE);
|
|
|
- }
|
|
|
- }
|
|
|
+ public static final String ERROR_WRONG_ANNOTATION_TARGET_CODE = "WrongAnnotationTarget";
|
|
|
+ public static final String ERROR_WRONG_ANNOTATION_TARGET_MSG = "Annotation '%s' can not be applied on %s .";
|
|
|
|
|
|
@Check(CheckType.FAST)
|
|
|
public void checkAnnotationTarget(final AnnotatableElement element) {
|
|
@@ -347,18 +213,4 @@ public class ExpressionsJavaValidator extends org.yakindu.base.expressions.valid
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Check(CheckType.FAST)
|
|
|
- public void checkOptionalArgumentsAreLast(Operation op) {
|
|
|
- boolean foundOptional = false;
|
|
|
- for (Parameter p : op.getParameters()) {
|
|
|
- if (foundOptional && !p.isOptional()) {
|
|
|
- error(ERROR_OPTIONAL_MUST_BE_LAST_MSG, p, null, ERROR_OPTIONAL_MUST_BE_LAST_CODE);
|
|
|
- }
|
|
|
- if (p.isOptional()) {
|
|
|
- foundOptional = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|