| /******************************************************************************* |
| * 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.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.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement; |
|
|
|
|
| /**
|
| * @author Akos Horvath
|
| *
|
| */
|
| public class CreateInstanceofConstant2Constant extends CreateConstant2Constant {
|
|
|
| private SearchGraphEdge relatedSearchGraphEdge; |
|
|
| public CreateInstanceofConstant2Constant(IModelElement s, |
| IModelElement t,IModelManager manager, SearchGraphEdge edge){
|
| super(manager);
|
| source = s;
|
| target= t; |
| relatedSearchGraphEdge = edge;
|
| }
|
|
|
| @Override
|
| protected boolean create(MatchingFrame frame)throws GTOperationException {
|
|
|
| if (source == null) {
|
| String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()}; |
| throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE |
| ,context |
| ,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement()); |
|
|
| }
|
| if (target == null) {
|
| String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()}; |
| throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE |
| ,context |
| ,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement()); |
| }
|
|
|
| try {
|
| manager.newInstanceOf(source,target);
|
| } catch (VPMCoreException e) {
|
| String[] context = {source.getFullyQualifiedName(),target.getFullyQualifiedName(), e.getMessage()}; |
| throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_INSTANCEOF |
| ,context |
| ,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement()); |
| }
|
|
|
| return true;
|
| }
|
|
|
| public String toString() {
|
| return getClass().getSimpleName() + " : " +
|
| source.getName() + "(type) -- instanceof -> " + target.getName();
|
| } |
| |
| @Override |
| public AnnotatedElement getErrorfulElement(MatchingFrame frame){ |
| return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement(); |
| }
|
| }
|