blob: 0bdf8bfb2da62197b86125487461619512c2b4be [file] [log] [blame]
/**
* Copyright (c) 2008 - 2010 OptXware Research and Development LLC.
* 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:
* Daniel Varro - Initial API and implementation
*/
package org.eclipse.viatra2.lpgparser.typechecker;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.core.IModelManager;
import org.eclipse.viatra2.core.IRelation;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Constant;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
public class CustomTypeJudgementCheck {
public static final String typeElementReference(IModelManager modelManager, Term operand) {
// TODO: Maybe, a sophisticated static analysis could be carried out here
if (operand instanceof Constant) {
Constant constant = (Constant) operand;
return constant.getValue();
} else {
return VTCLTypeNameConstants.TOP;
}
}
/**
* Custom type checking: if operand can be resolved to a metamodel relation
* then returns its source model element as type
*
* @param modelManager
* @param operand
* @return type of the source model element
*/
public static final String typeSource(IModelManager modelManager, String operand) {
IModelElement element = modelManager.getElementByName(operand);
if (element != null && element instanceof IRelation) {
IRelation relation = (IRelation) element;
return relation.getFrom().getFullyQualifiedName();
}
else return VTCLTypeNameConstants.TOP;
}
/**
* Custom type checking: if operand can be resolved to a metamodel relation
* then returns its target model element as type
*
* @param modelManager
* @param operand FQN of a relation
* @return type of the target model element
*/
public static final String typeTarget(IModelManager modelManager, String operand) {
IModelElement element = modelManager.getElementByName(operand);
if (element != null && element instanceof IRelation) {
IRelation relation = (IRelation) element;
return relation.getFrom().getFullyQualifiedName();
}
else return VTCLTypeNameConstants.TOP;
}
/**
* Custom type checking: if operand can be resolved to a metamodel relation
* then returns its inverse relation as type
*
* @param modelManager
* @param operand FQN of a relation
* @return type of the inverse
*/
public static final String typeInverse(IModelManager modelManager, String operand) {
IModelElement element = modelManager.getElementByName(operand);
if (element != null && element instanceof IRelation) {
IRelation relation = (IRelation) element;
IRelation inverse = relation.getInverse();
if (inverse!= null) {
return inverse.getFullyQualifiedName();
}
}
return VTCLTypeNameConstants.TOP;
}
}