blob: 02761617622a0b26f444eb493031c52987a4630f [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.Collection;
import java.util.HashSet;
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;
/**
* ExtendConstantNodeOperation is an ExtendOperation where
* the bound node is a constant node.
*/
public class ExtendConstantNodeOperation extends ExtendOperation {
private IModelElement bound;
/**
* @param bound The constant node to be extended.
* @param unbound The unbound pattern variable.
* @param edgeType The type of the edge.
* @param isSrc true, if the constant node is the source of the
* edge.
*/
public ExtendConstantNodeOperation(IModelElement bound, Integer unbound,
SearchGraphEdge edge) {
super(unbound,edge);
this.bound = bound;
}
public void preprocess(MatchingFrame frame)
throws PatternMatcherRuntimeException {
if (bound == null) {
String[] context = {edge.getSourceNode().getName(),getClass().getSimpleName()};
throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE
,context
,edge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
}
if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && !edge.isSource()) {
iterator = bound.getAllTypes().iterator();
} else if (edge.getVPMEdgeType() == EdgeType.INSTANCEOF && edge.isSource()) {
iterator = bound.getAllInstances().iterator();
} else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && !edge.isSource()) {
iterator = bound.getAllSubtypes().iterator();
} else if (edge.getVPMEdgeType() == EdgeType.SUPERTYPEOF && edge.isSource()) {
iterator = bound.getAllSupertypes().iterator();
} else if (edge.getVPMEdgeType() == EdgeType.SOURCE && !edge.isSource()) {
iterator = bound.getRelationsFrom().iterator();
} else if (edge.getVPMEdgeType() == EdgeType.SOURCE && edge.isSource()) {
Collection<IModelElement> coll = new HashSet<IModelElement>();
if (bound instanceof IRelation) {
coll.add(((IRelation) bound).getFrom());
}
iterator = coll.iterator();
} else if (edge.getVPMEdgeType() == EdgeType.TARGET && !edge.isSource()) {
iterator = bound.getRelationsTo().iterator();
} else if (edge.getVPMEdgeType() == EdgeType.TARGET && edge.isSource()) {
Collection<IModelElement> coll = new HashSet<IModelElement>();
if (bound instanceof IRelation) {
coll.add(((IRelation) bound).getTo());
}
iterator = coll.iterator();
} else if (edge.getVPMEdgeType() == EdgeType.IN && edge.isSource()) {
iterator = bound.getElementsInNamespace().iterator();
} else if (edge.getVPMEdgeType() == EdgeType.BELOW && edge.isSource()) {
iterator = bound.getAllElementsInNamespace().iterator();
} else if (edge.getVPMEdgeType() == EdgeType.IN && !edge.isSource()) {
Collection<IModelElement> coll = new HashSet<IModelElement>();
if(bound.getNamespace() != null)
coll.add(bound.getNamespace());
iterator = coll.iterator();
} else if (edge.getVPMEdgeType() == EdgeType.BELOW && !edge.isSource()) {
String[] context = {frame.getPattern().getSearchGraph().getSearchNode(unbound).getName(),edge.getVPMEdgeType().toString()};
throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_POSSIBLE
,context
,edge.getTraceabilityElement().getRepresentativeEMFElement());
} else if (edge.getVPMEdgeType() == EdgeType.NACCHECK) {
String[] context = {frame.getPattern().getSearchGraph().getSearchNode(unbound).getName(),edge.getVPMEdgeType().toString()};
throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_OPERATION_NOT_POSSIBLE
,context
,edge.getTraceabilityElement().getRepresentativeEMFElement());
}
}
public String toString() {
return getClass().getSimpleName() + " : " +
bound.getName() + " -- " + edge.getVPMEdgeType().name() + " -> " + unbound;
}
}