blob: 98d83faffc70d8a282c02372a04353e830469068 [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.Iterator;
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;
/**
* The ExtendOperation is a SearchPlanOperation, where
* an already bound node is extended towards
* an unbound node.
*/
public abstract class ExtendOperation extends SearchPlanOperation {
protected Integer unbound;
protected SearchGraphEdge edge;
protected Iterator iterator;
public ExtendOperation(Integer unbound, SearchGraphEdge edge) {
this.unbound = unbound;
this.edge = edge;
this.iterator = null;
}
public void postprocess(MatchingFrame frame) {
frame.setValue(unbound, null);
iterator = null;
}
public boolean execute(MatchingFrame frame)
throws PatternMatcherRuntimeException {
Object next = "";
try {
if (iterator.hasNext()) {
next = iterator.next();
IModelElement modelElement = (IModelElement) next;
frame.setValue(unbound, modelElement);
return true;
} else {
return false;
}
} catch (ClassCastException e) {
String[] context = {edge.getVPMEdgeType().toString(), frame.getPattern().getSearchGraph().getSearchNode(unbound).getName(), next.getClass().getName()};
throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.NOT_A_MODELELEMENT_EXTEND
,context
,frame.getPattern().getSearchGraph().getSearchNode(unbound).getTraceabilityElement().getRepresentativeEMFElement());
}
}
public void calculateSidewaysPassedVariables(Set<Integer> variableSet) {
variableSet.remove(unbound);
}
public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
return frame.getPattern().getSearchGraph().getSearchNode(unbound).getTraceabilityElement().getRepresentativeEMFElement();
}
}