Search in sources :

Example 1 with NamedElement

use of org.yakindu.base.base.NamedElement in project statecharts by Yakindu.

the class STextJavaValidator method checkReactionTriggerRegularEvent.

@Check(CheckType.FAST)
public void checkReactionTriggerRegularEvent(ReactionTrigger reactionTrigger) {
    for (int i = 0; i < reactionTrigger.getTriggers().size(); i++) {
        EventSpec eventSpec = reactionTrigger.getTriggers().get(i);
        if (eventSpec instanceof RegularEventSpec) {
            EObject element = unwrap(((RegularEventSpec) eventSpec).getEvent());
            if (element != null && (!(element instanceof Event))) {
                String elementName = "";
                if (element instanceof NamedElement) {
                    elementName = "'" + ((NamedElement) element).getName() + "' ";
                }
                error("Trigger " + elementName + "is no event.", StextPackage.Literals.REACTION_TRIGGER__TRIGGERS, i, TRIGGER_IS_NO_EVENT);
            }
        }
    }
}
Also used : TimeEventSpec(org.yakindu.sct.model.stext.stext.TimeEventSpec) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) EventSpec(org.yakindu.sct.model.stext.stext.EventSpec) EObject(org.eclipse.emf.ecore.EObject) ExitEvent(org.yakindu.sct.model.stext.stext.ExitEvent) EntryEvent(org.yakindu.sct.model.stext.stext.EntryEvent) Event(org.yakindu.base.types.Event) NamedElement(org.yakindu.base.base.NamedElement) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) Check(org.eclipse.xtext.validation.Check)

Example 2 with NamedElement

use of org.yakindu.base.base.NamedElement 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 3 with NamedElement

use of org.yakindu.base.base.NamedElement in project statecharts by Yakindu.

the class RenameElementHandler method findElementForFakeInStatechart.

private NamedElement findElementForFakeInStatechart(NamedElement fakeElement) {
    Resource resource = fakeElement.eResource();
    // only do something if element is really from fake resource
    if (resource instanceof LazyLinkingResource) {
        Statechart sct = getStatechartFromFakeResource((LazyLinkingResource) resource);
        EList<Scope> scopes = sct.getScopes();
        for (Scope scope : scopes) {
            // check all declarations
            EList<Declaration> declarations = scope.getDeclarations();
            for (Declaration decl : declarations) {
                if (decl.eClass().getName().equals(fakeElement.eClass().getName()) && decl.getName().equals(fakeElement.getName())) {
                    return decl;
                }
            }
            // check scope itself it is a named one
            if (scope instanceof NamedElement) {
                NamedElement namedScope = (NamedElement) scope;
                if (namedScope.eClass().getName().equals(fakeElement.eClass().getName()) && namedScope.getName().equals(fakeElement.getName())) {
                    return namedScope;
                }
            }
        }
    }
    return fakeElement;
}
Also used : Scope(org.yakindu.sct.model.sgraph.Scope) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) Resource(org.eclipse.emf.ecore.resource.Resource) Statechart(org.yakindu.sct.model.sgraph.Statechart) Declaration(org.yakindu.base.types.Declaration) NamedElement(org.yakindu.base.base.NamedElement)

Example 4 with NamedElement

use of org.yakindu.base.base.NamedElement 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)

Example 5 with NamedElement

use of org.yakindu.base.base.NamedElement in project statecharts by Yakindu.

the class RenameElementHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    NamedElement element = refactoring.getContextObject();
    if (element != null) {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        InputDialog dialog = new InputDialog(window.getShell(), "Rename..", "Please enter new name:", element.getName(), new NameUniquenessValidator(element));
        if (dialog.open() == Window.OK) {
            String newName = dialog.getValue();
            if (newName != null) {
                ((RenameRefactoring) refactoring).setNewName(newName);
                refactoring.execute();
            }
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) InputDialog(org.eclipse.jface.dialogs.InputDialog) RenameRefactoring(org.yakindu.sct.refactoring.refactor.impl.RenameRefactoring) NamedElement(org.yakindu.base.base.NamedElement)

Aggregations

NamedElement (org.yakindu.base.base.NamedElement)12 EObject (org.eclipse.emf.ecore.EObject)8 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)4 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)4 Check (org.eclipse.xtext.validation.Check)3 Event (org.yakindu.base.types.Event)3 EntryEvent (org.yakindu.sct.model.stext.stext.EntryEvent)3 ExitEvent (org.yakindu.sct.model.stext.stext.ExitEvent)3 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)2 Expression (org.yakindu.base.expressions.expressions.Expression)2 ArrayList (java.util.ArrayList)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 IElementType (org.eclipse.gmf.runtime.emf.type.core.IElementType)1 View (org.eclipse.gmf.runtime.notation.View)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)1 PostFixUnaryExpression (org.yakindu.base.expressions.expressions.PostFixUnaryExpression)1