use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.
the class STextJavaValidator method checkValueReferenedBeforeDefined.
@Check(CheckType.NORMAL)
public void checkValueReferenedBeforeDefined(Scope scope) {
EList<Declaration> declarations = scope.getDeclarations();
Set<QualifiedName> defined = Sets.newHashSet();
for (Declaration declaration : declarations) {
if (declaration instanceof VariableDefinition) {
VariableDefinition definition = (VariableDefinition) declaration;
if (!definition.isConst())
return;
Expression initialValue = definition.getInitialValue();
List<Expression> toCheck = Lists.newArrayList(initialValue);
TreeIterator<EObject> eAllContents = initialValue.eAllContents();
while (eAllContents.hasNext()) {
EObject next = eAllContents.next();
if (next instanceof Expression)
toCheck.add((Expression) next);
}
for (Expression expression : toCheck) {
EObject referencedObject = null;
if (expression instanceof FeatureCall)
referencedObject = ((FeatureCall) expression).getFeature();
else if (expression instanceof ElementReferenceExpression)
referencedObject = ((ElementReferenceExpression) expression).getReference();
if (referencedObject instanceof VariableDefinition) {
if (!defined.contains(nameProvider.getFullyQualifiedName(referencedObject)))
error(REFERENCE_CONSTANT_BEFORE_DEFINED, definition, StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
}
}
defined.add(nameProvider.getFullyQualifiedName(definition));
}
}
}
Aggregations