use of org.yakindu.base.expressions.expressions.ElementReferenceExpression 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));
}
}
}
use of org.yakindu.base.expressions.expressions.ElementReferenceExpression in project statecharts by Yakindu.
the class STextJavaValidator method checkValueOfNoEvent.
@Check(CheckType.FAST)
public void checkValueOfNoEvent(EventValueReferenceExpression exp) {
Expression eventExpr = exp.getValue();
EObject element = null;
if (eventExpr instanceof ElementReferenceExpression) {
element = ((ElementReferenceExpression) eventExpr).getReference();
} else if (eventExpr instanceof FeatureCall) {
element = ((FeatureCall) eventExpr).getFeature();
}
if (element != null && (!(element instanceof Event))) {
String elementName = "";
if (element instanceof NamedElement) {
elementName = "'" + ((NamedElement) element).getName() + "' ";
}
error(elementName + "is no event.", StextPackage.Literals.EVENT_VALUE_REFERENCE_EXPRESSION__VALUE, 0, VALUE_OF_REQUIRES_EVENT);
}
}
use of org.yakindu.base.expressions.expressions.ElementReferenceExpression in project statecharts by Yakindu.
the class SGenSemanticHighlightingCalculator method provideHighlightingFor.
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
if (resource == null || resource.getParseResult() == null)
return;
TreeIterator<EObject> allContents = resource.getAllContents();
while (allContents.hasNext()) {
final EObject object = allContents.next();
if (object instanceof GeneratorEntry) {
GeneratorEntry entry = (GeneratorEntry) object;
List<INode> nodes = NodeModelUtils.findNodesForFeature(entry, SGenPackage.Literals.GENERATOR_ENTRY__CONTENT_TYPE);
List<INode> features = NodeModelUtils.findNodesForFeature(entry, SGenPackage.Literals.GENERATOR_ENTRY__FEATURES);
for (INode node : nodes) {
if (node instanceof LeafNode && !((LeafNode) node).isHidden()) {
acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), DefaultHighlightingConfiguration.KEYWORD_ID);
}
}
for (INode node : features) {
if (node.getSemanticElement() instanceof FeatureConfigurationImpl) {
FeatureConfigurationImpl feature = (FeatureConfigurationImpl) node.getSemanticElement();
DeprecatableElement deprecatableElement = feature.getType();
if (deprecatableElement != null && deprecatableElement.isDeprecated()) {
acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), SGenHighlightingConfiguration.DEPRECATION);
}
}
}
// allContents.prune();
} else if (object instanceof ElementReferenceExpression && !((ElementReferenceExpression) object).getReference().eIsProxy()) {
List<INode> nodes = NodeModelUtils.findNodesForFeature(object, ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE);
for (INode node : nodes) {
String name = ((Property) ((ElementReferenceExpression) object).getReference()).getName();
switch(name) {
case SCT_VERSION_VAR:
case SHA256:
case SCTFILE:
case TIMESTAMP_VAR:
case USER_VAR:
case HOSTNAME_VAR:
acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), DefaultHighlightingConfiguration.KEYWORD_ID);
}
}
}
}
}
Aggregations