blob: 635a9ac7a453731701497fe08b697839df8a613c [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.core;
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.extension.IGTRuleMatcherFactory;
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.internal.ExtendedGTRuleMatcherwithAlternativePatternMatcher;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.BasicTermHandler;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermHandler;
import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;
/**
*
* Implements the IGTRuleMatcherFactory extension point for the viatra GTASM interpreter with Incremental pattern matching
* @author Akos Horvath
*/
public class ExtendedGTRuleMatcherwithAlternativePatternMatcherFactory implements IGTRuleMatcherFactory {
private IGTRuleMatcher construct(GTRule gtRule, IExecutionEnvironment enviroment, PatternMatcherParameters pmParams)
throws ViatraTransformationException {
if (gtRule.getPrecondition() != null) {
// traditional type gtRule with alternative pattern matching
TermHandler handler = new BasicTermHandler(enviroment);
return new ExtendedGTRuleMatcherwithAlternativePatternMatcher(gtRule,enviroment, handler, pmParams);
} else {
enviroment.getFramework().getLogger().warning("ActionPattern type GTRule not yet supported");
}
return null;
}
public IGTRuleMatcher getGTMatcher(IExecutionEnvironment gtEnviroment,
GTRule gtRule, PatternMatcherParameters mp)
throws ViatraTransformationException {
IGTRuleMatcher gtMatcher=null;
if (GTRuleMatchers.getInstance().containsKey(gtRule)) {
// We already had it precompiled
gtMatcher=GTRuleMatchers.getInstance().get(gtRule);
gtMatcher.initGTRule(gtEnviroment);
} else {
// We need to createa new gtmatcher
gtMatcher = construct(gtRule, gtEnviroment,mp);
if (gtMatcher != null) {
GTRuleMatchers.getInstance().put(gtRule, gtMatcher);
} else {
String[] context = {gtRule.getName()};
throw new GraphTransformationException(GTErrorStrings.GTRULETYPE_NOTSUPPORTED
,context
,gtRule);
}
}
return gtMatcher;
}
}