| /******************************************************************************* |
| * 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.patternmatcher.internal.operation;
|
|
|
| import org.eclipse.viatra2.core.IModelElement;
|
| import org.eclipse.viatra2.core.IRelation;
|
| import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.EdgeType; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement; |
|
|
|
|
| public class ConstantToConstantCheckOperation extends EdgeConstraintCheckOperation {
|
| private IModelElement source;
|
| private IModelElement target;
|
| private SearchGraphEdge edge;
|
|
|
|
|
| public ConstantToConstantCheckOperation(IModelElement source,
|
| IModelElement target,
|
| SearchGraphEdge edge) {
|
| this.source = source;
|
| this.target = target;
|
| this.edge = edge;
|
| }
|
|
|
| protected boolean check(MatchingFrame frame)
|
| throws PatternMatcherRuntimeException {
|
| if (source == null) {
|
| String[] context = {edge.getTargetNode().getName(),getClass().getSimpleName()}; |
| throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE |
| ,context |
| ,edge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement()); |
|
|
| }
|
| if (target == null) {
|
| String[] context = {edge.getTargetNode().getName(),getClass().getSimpleName()}; |
| throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE |
| ,context |
| ,edge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement()); |
|
|
| }
|
|
|
| if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && !edge.isSource()) {
|
| //return source.getAllTypes().contains(target); |
| return source.isInstanceOf(target);
|
| } else if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && edge.isSource()) {
|
| //return source.getAllInstances().contains(target); |
| return target.isInstanceOf(source);
|
| } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && !edge.isSource()) {
|
| //return source.getAllSubtypes().contains(target); |
| return target.isSubtypeOf(source);
|
| } else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && edge.isSource()) {
|
| //return source.getAllSupertypes().contains(target); |
| return source.isSubtypeOf(target);
|
| } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && !edge.isSource()) {
|
| return (target instanceof IRelation ?
|
| ((IRelation) target).getFrom().equals(source) :
|
| false);
|
| } else if (edge.getVPMEdgeType() == EdgeType.SOURCE && edge.isSource()) {
|
| return (source instanceof IRelation ?
|
| ((IRelation) source).getFrom().equals(target) :
|
| false);
|
| } else if (edge.getVPMEdgeType() == EdgeType.TARGET && !edge.isSource()) {
|
| return (target instanceof IRelation ?
|
| ((IRelation) target).getTo().equals(source) :
|
| false);
|
| } else if (edge.getVPMEdgeType() == EdgeType.TARGET && edge.isSource()) {
|
| return (source instanceof IRelation ?
|
| ((IRelation) source).getTo().equals(target) :
|
| false);
|
| } else if (edge.getVPMEdgeType() == EdgeType.IN && !edge.isSource()) {
|
| return source.getNamespace().compareTo(target) == 0;
|
| } else if (edge.getVPMEdgeType() == EdgeType.IN && edge.isSource()) {
|
| return target.getNamespace().compareTo(source) == 0;
|
| } else if (edge.getVPMEdgeType() == EdgeType.BELOW && !edge.isSource()) {
|
| return source.isBelowNamespace(target);
|
| } else if (edge.getVPMEdgeType() == EdgeType.BELOW && edge.isSource()) {
|
| return target.isBelowNamespace(source);
|
| }
|
| String [] context = {edge.getVPMEdgeType().toString(),getClass().getSimpleName()}; |
| throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_SUPPORTED |
| ,context |
| ,edge.getTraceabilityElement().getRepresentativeEMFElement()); |
| }
|
|
|
| public String toString() {
|
| return getClass().getSimpleName() + " : " +
|
| source.getName() + " -- " + edge.getVPMEdgeType().name()+ " -> " + target.getName();
|
| } |
| |
| public AnnotatedElement getErrorfulElement(MatchingFrame frame) { |
| return edge.getTraceabilityElement().getRepresentativeEMFElement(); |
| }
|
| }
|