Search in sources :

Example 1 with ElementReferenceExpression

use of org.yakindu.base.expressions.expressions.ElementReferenceExpression in project statecharts by Yakindu.

the class STextProposalProvider method completeKeyword.

/**
 * Validates if a keyword should be viewed by the proposal view.
 *
 * Builds dependent on the ContentAssistContext a list with keywords which
 * shouldn't be displayed by the proposal view.
 */
@Override
public void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
    List<Keyword> suppressKeywords = new ArrayList<Keyword>();
    EObject rootModel = contentAssistContext.getRootModel();
    if (rootModel instanceof TransitionSpecification) {
        suppressKeywords(suppressKeywords, (TransitionSpecification) rootModel);
    } else if (rootModel instanceof SimpleScope) {
        suppressKeywords(suppressKeywords, (SimpleScope) rootModel);
    } else if (rootModel instanceof StatechartSpecification) {
        suppressKeywords(suppressKeywords, (StatechartSpecification) rootModel);
    }
    EObject currentModel = contentAssistContext.getCurrentModel();
    if (currentModel instanceof InterfaceScope) {
        suppressKeywords(suppressKeywords, (InterfaceScope) currentModel);
    }
    if (currentModel instanceof FeatureCall) {
        suppressKeywords(suppressKeywords, (FeatureCall) currentModel);
    }
    if (currentModel instanceof ElementReferenceExpression) {
        suppressKeywords(suppressKeywords, (ElementReferenceExpression) currentModel);
    }
    if (currentModel instanceof InternalScope) {
        suppressKeywords(suppressKeywords, (InternalScope) currentModel);
    }
    if (!suppressKeywords.contains(keyword)) {
        super.completeKeyword(keyword, contentAssistContext, new AcceptorDelegate(acceptor));
    }
}
Also used : Keyword(org.eclipse.xtext.Keyword) SimpleScope(org.yakindu.sct.model.stext.stext.SimpleScope) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) TransitionSpecification(org.yakindu.sct.model.stext.stext.TransitionSpecification) StatechartSpecification(org.yakindu.sct.model.stext.stext.StatechartSpecification) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression)

Example 2 with ElementReferenceExpression

use of org.yakindu.base.expressions.expressions.ElementReferenceExpression in project statecharts by Yakindu.

the class ExpressionsJavaValidator method checkAssignmentToFinalVariable.

@Check(CheckType.FAST)
public void checkAssignmentToFinalVariable(AssignmentExpression exp) {
    Expression varRef = exp.getVarRef();
    EObject referencedObject = null;
    if (varRef instanceof FeatureCall)
        referencedObject = ((FeatureCall) varRef).getFeature();
    else if (varRef instanceof ElementReferenceExpression)
        referencedObject = ((ElementReferenceExpression) varRef).getReference();
    if (referencedObject instanceof Property) {
        if (((Property) referencedObject).isConst()) {
            error(ERROR_ASSIGNMENT_TO_CONST_MSG, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF, ERROR_ASSIGNMENT_TO_CONST_CODE);
        }
    }
}
Also used : PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Property(org.yakindu.base.types.Property) Check(org.eclipse.xtext.validation.Check)

Example 3 with ElementReferenceExpression

use of org.yakindu.base.expressions.expressions.ElementReferenceExpression in project statecharts by Yakindu.

the class STextScopeProvider method scope_FeatureCall_feature.

public IScope scope_FeatureCall_feature(final FeatureCall context, EReference reference) {
    Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
    Expression owner = context.getOwner();
    EObject element = null;
    if (owner instanceof ElementReferenceExpression) {
        element = ((ElementReferenceExpression) owner).getReference();
    } else if (owner instanceof FeatureCall) {
        element = ((FeatureCall) owner).getFeature();
    } else {
        return getDelegate().getScope(context, reference);
    }
    IScope scope = IScope.NULLSCOPE;
    InferenceResult result = typeInferrer.infer(owner);
    Type ownerType = result != null ? result.getType() : null;
    if (element instanceof Scope) {
        scope = Scopes.scopeFor(((Scope) element).getDeclarations());
        return new FilteringScope(scope, predicate);
    } else if (ownerType != null) {
        scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
        scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType), scope);
    }
    if (ownerType instanceof ComplexType) {
        return addScopeForComplexType((ComplexType) ownerType, scope, predicate);
    }
    if (ownerType instanceof EnumerationType) {
        return addScopeForEnumType((EnumerationType) ownerType, scope, predicate);
    }
    return scope;
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) EnumerationType(org.yakindu.base.types.EnumerationType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ComplexType(org.yakindu.base.types.ComplexType) EnumerationType(org.yakindu.base.types.EnumerationType) Type(org.yakindu.base.types.Type) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) IScope(org.eclipse.xtext.scoping.IScope) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ImportScope(org.eclipse.xtext.scoping.impl.ImportScope) Expression(org.yakindu.base.expressions.expressions.Expression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ComplexType(org.yakindu.base.types.ComplexType) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope)

Example 4 with ElementReferenceExpression

use of org.yakindu.base.expressions.expressions.ElementReferenceExpression in project statecharts by Yakindu.

the class RenameRefactoring method internalExecute.

@Override
protected void internalExecute() {
    NamedElement element = getContextObject();
    Collection<EObject> elementReferers = findReferers(element);
    element.setName(newName);
    for (EObject referer : elementReferers) {
        if (referer instanceof FeatureCall) {
            FeatureCall featureCall = (FeatureCall) referer;
            featureCall.setFeature(element);
        } else if (referer instanceof ElementReferenceExpression) {
            ElementReferenceExpression expr = (ElementReferenceExpression) referer;
            expr.setReference(element);
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) NamedElement(org.yakindu.base.base.NamedElement) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression)

Example 5 with ElementReferenceExpression

use of org.yakindu.base.expressions.expressions.ElementReferenceExpression in project statecharts by Yakindu.

the class RenameElementHandler method unwrap.

/**
 * Unwraps the given selection into a state sgraph element
 *
 * @param selection the current selection
 * @return the state sgraph element for the given selection
 */
public NamedElement unwrap(ISelection selection) {
    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    EObject selectedElement = (EObject) structuredSelection.getFirstElement();
    // We need to find the actual element in our statechart for this fake element
    if (selectedElement instanceof FeatureCall) {
        return findElementForFakeInStatechart((NamedElement) ((FeatureCall) selectedElement).getFeature());
    } else if (selectedElement instanceof ElementReferenceExpression) {
        return findElementForFakeInStatechart((NamedElement) ((ElementReferenceExpression) selectedElement).getReference());
    }
    if (selectedElement instanceof NamedElement)
        return findElementForFakeInStatechart((NamedElement) selectedElement);
    return null;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) NamedElement(org.yakindu.base.base.NamedElement)

Aggregations

ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)23 EObject (org.eclipse.emf.ecore.EObject)10 Test (org.junit.Test)10 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)9 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)9 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)9 Expression (org.yakindu.base.expressions.expressions.Expression)7 Statechart (org.yakindu.sct.model.sgraph.Statechart)7 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)7 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)7 Transition (org.yakindu.sct.model.sgraph.Transition)6 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)6 Check (org.eclipse.xtext.validation.Check)5 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)5 NamedElement (org.yakindu.base.base.NamedElement)4 PostFixUnaryExpression (org.yakindu.base.expressions.expressions.PostFixUnaryExpression)4 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)4 If (org.yakindu.sct.model.sexec.If)4 Region (org.yakindu.sct.model.sgraph.Region)4 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)4