| /******************************************************************************* |
| * 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 org.eclipse.viatra2.gtasm.interpreter.exception.GTASMException; |
| import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException; |
| import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment; |
| import org.eclipse.viatra2.gtasm.interpreter.term.rules.TermEvaluator; |
| 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.term.AbstractTermCheckOperation; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermCheckExecutionEnvironment; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
|
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
|
| |
|
|
| public class TermCheckOperation extends AbstractTermCheckOperation {
|
| private IExecutionEnvironment parentEnv;
|
| private GTPattern pattern;
|
| private int uid;
|
| private Term term;
|
|
|
| public TermCheckOperation(IExecutionEnvironment parentEnv,
|
| GTPattern pattern, int uid, Term term) {
|
| this.parentEnv = parentEnv;
|
| this.pattern = pattern;
|
| this.uid = uid;
|
| this.term = term;
|
| }
|
|
|
| public boolean check(MatchingFrame frame) throws PatternMatcherRuntimeException{
|
| TermCheckExecutionEnvironment env = new TermCheckExecutionEnvironment(parentEnv, pattern, uid, frame);
|
| Boolean result = false;
|
| try {
|
| result = (Boolean) TermEvaluator.getInstance().evaluate(env, term);
|
| } catch (ViatraTransformationException e) {
|
| throw new PatternMatcherRuntimeException(e,term);
|
| } catch (ClassCastException e) {
|
| String[] context = {pattern.getName()}; |
| throw new PatternMatcherRuntimeException( |
| PatternMatcherErrorStrings.CHECK_EXPRESSION_NOT_EVALUATED_TO_A_BOOLEAN |
| ,context |
| ,term);
|
| }
|
| return result;
|
| } |
| |
| public AnnotatedElement getErrorfulElement(MatchingFrame frame) { |
| return term; |
| }
|
| }
|