| /******************************************************************************* |
| * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Akos Horvath, Gergely Varro - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;
|
|
|
| import org.eclipse.viatra2.core.EDeleteSemantics; |
| import org.eclipse.viatra2.core.IModelElement; |
| import org.eclipse.viatra2.core.IModelManager; |
| import org.eclipse.viatra2.errors.VPMCoreException; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ValueKind; |
|
|
| /**
|
| * @author Akos Horvath
|
| *
|
| */
|
| public class DeleteModelElement extends DeleteElement {
|
|
|
| public DeleteModelElement(IModelManager manager, int variableI) {
|
| super(manager, variableI);
|
| }
|
|
|
| @Override
|
| protected boolean delete(MatchingFrame frame) throws GTOperationException {
|
|
|
| IModelElement elementToDelete = null;
|
|
|
| try {
|
| elementToDelete = (IModelElement) frame.getValue(this.variableIndex);
|
| } catch (ClassCastException e) {
|
| String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(), getClass().getSimpleName()}; |
| throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT |
| ,context |
| ,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement()); |
| }
|
| if (elementToDelete == null) {
|
| String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),getClass().getSimpleName()}; |
| throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE |
| ,context |
| ,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement()); |
|
|
| }
|
|
|
| try {
|
| manager.deleteElement(elementToDelete, EDeleteSemantics.DELETE_SEMANTICS_BRANCH_FORCE);
|
| frame.setValue(variableIndex, ValueKind.UNDEF_LITERAL);
|
|
|
| }catch (VPMCoreException e) {
|
| String context[] = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()}; |
| throw new GTOperationException(GTErrorStrings.INTERNAL_DELETE_MODELELEMENT |
| ,context |
| ,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement()); |
| }
|
| return true;
|
| }
|
|
|
|
|
| public String toString(){
|
| return "Del: "+variableIndex;
|
| } |
| |
| @Override |
| public AnnotatedElement getErrorfulElement(MatchingFrame frame){ |
| return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement(); |
| } |
| }
|