blob: d7c9e523cb6aa3de090b983bf81af0d2cff7f1c6 [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.gtmatcher.internal;
import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
import org.eclipse.viatra2.gtasm.patternmatcher.PatternMatcherParameters;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GraphTransformationException;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.extension.AlternativePatternMactherProvider;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.ITermHandler;
import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.RuntimeAnnotation;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;
/**
* Provides a complete GT rule matcher functionality with the possibility to use alternative pattern matchers for the LHS of the GT rule
* @author Akos Horvath
*
*/
public class ExtendedGTRuleMatcherwithAlternativePatternMatcher extends TraditionalGTRuleMatcher {
public ExtendedGTRuleMatcherwithAlternativePatternMatcher(GTRule gt,
IExecutionEnvironment enviroment, ITermHandler handler,
PatternMatcherParameters mp) throws ViatraTransformationException {
super(gt, enviroment, handler, mp);
}
/* The only method that has to be overridden in order to enable the Alternative Pattern Matchers in case when we want to use
* the already implemented Traditional GT Rule matcher
* (non-Javadoc)
* @see org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.TraditionalGTRuleMatcher#getPatternMatcherforPreCondition()
*/
@Override
protected IPatternMatcher getPatternMatcherforPreCondition() throws ViatraTransformationException{
// is true pseudorandom required?
isRandom = false;
for (Object annot : gtRule.getPrecondition().getCalledPattern().getRuntimeAnnotations()) {
if ("@random".equals(((RuntimeAnnotation) annot).getAnnotationName().toLowerCase())) {
isRandom = true; break;
}
}
if(AlternativePatternMactherProvider.getInstance().hasAlternatePatternMatcher()) {
return AlternativePatternMactherProvider.getInstance().getPatternMatcher(gtEnvironment, gtRule);
} else {
String[] context = {gtRule.getName()};
throw new GraphTransformationException(GTErrorStrings.NO_ALTERNATIVE_PATTERN_MATCHER
,context
,gtRule);
}
}
}