blob: f3a4ebe255be437ec2729329ce82bf10e9b7991c [file] [log] [blame]
/*******************************************************************************
* 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 java.util.Set;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
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 CopyValueOperation extends CheckOperation {
private Integer bound;
private Integer unbound;
private SearchGraphEdge relatedSearchGraphEdge;
public CopyValueOperation(Integer bound, Integer unbound, SearchGraphEdge edge) {
this.bound = bound;
this.unbound = unbound;
relatedSearchGraphEdge = edge;
}
@Override
protected boolean check(MatchingFrame frame) throws PatternMatcherRuntimeException {
IModelElement boundElement = null;
try {
boundElement = (IModelElement) frame.getValue(bound);
} catch (ClassCastException e) {
String[] context = {frame.getPattern().getSearchGraph().getSearchNode(bound).getName(), getClass().getSimpleName()};
throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT
,context
,frame.getPattern().getSearchGraph().getSearchNode(bound).getTraceabilityElement().getRepresentativeEMFElement());
}
if (boundElement == null) {
String[] context = {frame.getPattern().getSearchGraph().getSearchNode(bound).getName(),getClass().getSimpleName()};
throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
,context
,frame.getPattern().getSearchGraph().getSearchNode(bound).getTraceabilityElement().getRepresentativeEMFElement());
}
frame.setValue(unbound, boundElement);
return true;
}
public String toString() {
return getClass().getSimpleName() + " : " + bound + " -> " + unbound;
}
public void calculateSidewaysPassedVariables(Set<Integer> variableSet) {
variableSet.add(bound);
variableSet.remove(unbound);
}
public void calculateLocalVariables(Set<Integer> variableSet) {
variableSet.add(bound);
}
public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
return frame.getPattern().getGTASMRepresentation(relatedSearchGraphEdge);
}
}