本文整理汇总了Java中net.ssehub.easy.varModel.model.datatypes.IDatatype.isAssignableFrom方法的典型用法代码示例。如果您正苦于以下问题:Java IDatatype.isAssignableFrom方法的具体用法?Java IDatatype.isAssignableFrom怎么用?Java IDatatype.isAssignableFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.ssehub.easy.varModel.model.datatypes.IDatatype
的用法示例。
在下文中一共展示了IDatatype.isAssignableFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: obtainPipeline
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Returns the pipeline decision for the given pipeline <code>element</code>.
*
* @param configuration the configuration for the lookup
* @param element the pipeline element (may be <b>null</b>, leads to <b>null</b>)
* @return the pipeline, may be <b>null</b> if the pipeline was not found
* @throws ModelQueryException if accessing type information fails
*/
@Invisible
public static IDecisionVariable obtainPipeline(net.ssehub.easy.varModel.confModel.Configuration configuration,
IDecisionVariable element) throws ModelQueryException {
IDecisionVariable result = null;
if (null != element) {
AbstractVariable elementDecl = element.getDeclaration();
IDatatype elementType = elementDecl.getType();
IModelElement par = elementDecl.getTopLevelParent();
if (par instanceof Project) {
Project prj = (Project) par;
IDatatype pipelineElementType = ModelQuery.findType(prj, QmConstants.TYPE_PIPELINE_ELEMENT, null);
if (null != pipelineElementType && pipelineElementType.isAssignableFrom(elementType)) {
IDatatype pipelineType = ModelQuery.findType(prj, QmConstants.TYPE_PIPELINE, null);
if (null != pipelineType) {
result = searchScope(configuration, prj, pipelineType);
}
}
}
}
return result;
}
示例2: isHardwareAlgorithm
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Returns whether <code>var</code> is a hardware algorithm.
*
* @param var the variable to check
* @return <code>true</code> for hardware algorithm, <code>false</code> else
*/
@QMInternal
public static boolean isHardwareAlgorithm(IDecisionVariable var) {
boolean result = false;
if (null != var) {
try {
IDatatype hwAlgType = ModelQuery.findType(var.getConfiguration().getProject(),
QmConstants.TYPE_HARDWARE_ALGORITHM, null);
if (null != hwAlgType) {
result = hwAlgType.isAssignableFrom(var.getDeclaration().getType());
}
} catch (ModelQueryException e) {
// -> result = null
}
}
return result;
}
示例3: diff
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Returns the difference indicator between two types.
*
* @param opType the operation type
* @param paramType the parameter type
* @return <code>0</code> in case of type equality, <code>-1</code> if the signature
* does not match the required types, <code>1</code> in case of assignable (not equal) types else
*/
private static int diff(IDatatype opType, IDatatype paramType) {
int result = -1;
if (opType.isAssignableFrom(paramType)) {
if (paramType.isAssignableFrom(opType)) {
result = 0; // both are equal
} else {
result = 1; // actually, there is a distance
if (Compound.TYPE.isAssignableFrom(paramType)) {
// in case of compounds, also consider the distance to the refined types so that not only
// direct matches but also intermediary refined types can be specified
result += diff((Compound) paramType, opType);
}
if (Container.TYPE.isAssignableFrom(opType) && Container.TYPE.isAssignableFrom(paramType)) {
// in case of container, also take the generic types into account
result = diffContainer((Container) opType, (Container) paramType);
}
}
}
if (result != 0 && paramType instanceof Reference) {
result = diff(opType, Reference.dereference(paramType));
}
return result;
}
示例4: ContainerInitializer
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Creates a new container initializer.
*
* @param type the type of the compound
* @param expressions the initializing expressions (in sequence for containers which support sequences)
* @throws CSTSemanticException in case that the initialization fails, element type mismatch
*/
public ContainerInitializer(Container type, ConstraintSyntaxTree[] expressions) throws CSTSemanticException {
this.type = type;
this.expressions = expressions;
if (null == expressions) {
throw new CSTSemanticException("expressions is null", CSTSemanticException.INTERNAL);
}
IDatatype containedType = type.getContainedType();
for (int e = 0; e < expressions.length; e++) {
IDatatype eType = expressions[e].inferDatatype();
if (!containedType.isAssignableFrom(eType)) {
throw new CSTSemanticException("value " + e + " in initializer is of type '"
+ IvmlDatatypeVisitor.getQualifiedType(eType) + "' but not of expected type '"
+ IvmlDatatypeVisitor.getQualifiedType(containedType) + "'", CSTSemanticException.TYPE_MISMATCH);
}
}
}
示例5: inferDatatype
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
@Override
public IDatatype inferDatatype() throws CSTSemanticException {
if (null == result) {
IDatatype ifType = ifExpr.inferDatatype();
if (!BooleanType.TYPE.isAssignableFrom(ifType)) {
throw new CSTSemanticException("if expression type ('"
+ ifType.getName() + "') is not Boolean", CSTSemanticException.TYPE_MISMATCH);
}
IDatatype thenType = thenExpr.inferDatatype();
IDatatype elseType = elseExpr.inferDatatype();
if (!thenType.isAssignableFrom(elseType)) {
throw new CSTSemanticException("types of then ('"
+ thenType.getName() + "') and else ('"
+ elseType.getName() + "') part do not match", CSTSemanticException.TYPE_MISMATCH);
}
result = thenType;
}
return result;
}
示例6: checkRequiredAssignableParameter
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Checks the operation for required assignable parameter if required. Mismatch leads
* to exception.
*
* @param op the resolved operation
* @param operandType the resolved operand type
* @param paramTypes the resolved parameter types
* @throws CSTSemanticException in case of any type conflict or mismatching parameter
*/
private void checkRequiredAssignableParameter(Operation op, IDatatype operandType,
IDatatype[] paramTypes) throws CSTSemanticException {
if (op.requiresAssignableParameter()) {
boolean ok = true;
// one parameter, i.e. only operand is no problem
for (int p = 0; p < paramTypes.length; p++) {
ok &= operandType.isAssignableFrom(paramTypes[p])
|| paramTypes[p].isAssignableFrom(operandType);
}
if (!ok) {
throw new CSTSemanticException("the types of all parameters of operation '"
+ op.getName() + "' need to be compliant", CSTSemanticException.TYPE_MISMATCH);
}
}
}
示例7: getSpecificType
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Returns the specific type of a collection initializer.
*
* @param lhsType the left hand side which defines the type (part)
* @param initializer the initializer
* @param context the type context for resolving variables etc.
* @return the specific type (may be <b>null</b> if there is none)
* @throws TranslatorException in case that the processing of the <code>initializer</code>
* must be terminated abnormally
*/
private IDatatype getSpecificType(IDatatype lhsType, ContainerInitializer initializer, TypeContext context)
throws TranslatorException {
IDatatype specificType = null;
// this may now initialize either a container or a compound
// the grammar prescribes only values but not expressions!
if (null != initializer.getType()) {
try {
String sTypeName = Utils.getQualifiedNameString(initializer.getType());
specificType = context.findType(sTypeName, null);
if (null == specificType) {
throw new TranslatorException("type '" + sTypeName + "' is not defined", initializer,
IvmlPackage.Literals.CONTAINER_INITIALIZER__TYPE, ErrorCodes.TYPE_CONSISTENCY);
}
if (null != lhsType && !lhsType.isAssignableFrom(specificType)) {
throw new TranslatorException("collection type '" + IvmlDatatypeVisitor.getQualifiedType(lhsType)
+ "' does not match specified entry type'" + sTypeName + "'", initializer,
IvmlPackage.Literals.CONTAINER_INITIALIZER__TYPE, ErrorCodes.TYPE_CONSISTENCY);
}
//lhsType = specificType;
} catch (ModelQueryException e) {
throw new TranslatorException(e, initializer, IvmlPackage.Literals.CONTAINER_INITIALIZER__TYPE);
}
}
return specificType;
}
示例8: isAssignable
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Returns whether <code>var</code> is assignable from <code>type</code>.
*
* @param type the type to check for (may be <b>null</b>)
* @param var the variable to check (may be <b>null</b>)
* @return <code>true</code> if assignable, <code>false</code> if not or one of the parameters is <b>null</b>
*/
private static boolean isAssignable(IDatatype type, IDecisionVariable var) {
boolean result = false;
if (null != var && null != type) {
result = type.isAssignableFrom(var.getDeclaration().getType());
}
return result;
}
示例9: findNamedVariable
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Finds a named variable of given <code>type</code> in <code>config</code>.
*
* @param config the configuration
* @param type the type to search for (ignored if <b>null</b>)
* @param name the (logical) name
* @return the decision variable
*/
public static final IDecisionVariable findNamedVariable(Configuration config, IDatatype type, String name) {
IDecisionVariable result = null;
Iterator<IDecisionVariable> iter = config.iterator();
while (null == result && iter.hasNext()) {
IDecisionVariable var = Configuration.dereference(iter.next());
if ((null == type || type.isAssignableFrom(var.getDeclaration().getType())) && hasName(var, name)) {
result = var;
}
}
return result;
}
示例10: obtainPipelineElementByName
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Obtains a pipeline element.
*
* @param pipeline the pipeline
* @param type the type of the element (may be <b>null</b>)
* @param name the name of the element
* @return the element or <b>null</b> if it does not exist for some reason
*/
@QMInternal
public static IDecisionVariable obtainPipelineElementByName(IDecisionVariable pipeline, IDatatype type,
String name) {
IDecisionVariable result = null;
net.ssehub.easy.varModel.confModel.Configuration config = null;
Project project = null;
if (null != pipeline) {
config = pipeline.getConfiguration();
AbstractVariable var = pipeline.getDeclaration();
project = var.getProject();
}
if (null != project) { // implies config != null
for (int e = 0, n = project.getElementCount(); null == result && e < n; e++) {
ContainableModelElement elt = project.getElement(e);
if (elt instanceof DecisionVariableDeclaration) {
DecisionVariableDeclaration decl = (DecisionVariableDeclaration) elt;
if (null == type || type.isAssignableFrom(decl.getType())) {
IDecisionVariable decVar = config.getDecision(decl);
if (VariableHelper.hasName(decVar, name) || decVar.getDeclaration().getName().equals(name)) {
result = decVar;
}
}
}
}
}
return result;
}
示例11: evaluate
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
public EvaluationAccessor evaluate(EvaluationAccessor operand, EvaluationAccessor[] arguments) {
EvaluationAccessor result = null;
if (1 == arguments.length) {
Value oValue = operand.getValue();
IDatatype oType = toType(oValue);
IDatatype aType = toType(arguments[0].getValue());
if (aType.isAssignableFrom(oType)) {
result = ConstantAccessor.POOL.getInstance().bind(oValue, operand.getContext());
}
}
return result;
}
示例12: evaluate
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
@Override
public EvaluationAccessor evaluate(EvaluationAccessor operand, EvaluationAccessor[] arguments) {
EvaluationAccessor result = null;
if (1 == arguments.length) {
Value opValue = operand.getValue();
Value argValue = arguments[0].getValue();
if (opValue instanceof ContainerValue && argValue instanceof MetaTypeValue) {
ContainerValue cont = (ContainerValue) opValue;
IDatatype type = ((MetaTypeValue) argValue).getValue();
List<Value> tmp = new ArrayList<Value>();
int size = cont.getElementSize();
for (int i = 0; i < size; i++) {
Value elt = cont.getElement(i);
boolean condition;
if (kindOf) {
condition = type.isAssignableFrom(elt.getType());
} else {
condition = TypeQueries.sameTypes(type, elt.getType());
}
if (reject) {
condition = !condition;
}
if (condition) {
tmp.add(elt);
}
}
try {
Value rValue = ValueFactory.createValue(operand.getValue().getType(), tmp.toArray());
result = ConstantAccessor.POOL.getInstance().bind(rValue, operand.getContext());
} catch (ValueDoesNotMatchTypeException e) {
operand.getContext().addErrorMessage(e);
}
}
}
return result;
}
示例13: addVariableByType
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Recursive part of {@link #collectVariablesByType(Configuration, IDatatype, boolean)}, which searches for (nested)
* variables.
* @param variable The currently tested variable, which should maybe added.
* @param type The type of which the variables shall be returned, or <tt>null</tt> if all variables should
* be returned.
* @param onlyToplevel <tt>true</tt> only top level variables will be returned, <tt>false</tt> also nested
* variables will be returned, e.g. nested inside a compound.
* @param variables The set of variables to be returned (will be changed as a side-effect).
*/
private static void addVariableByType(IDecisionVariable variable, IDatatype type, boolean onlyToplevel,
List<IDecisionVariable> variables) {
if (null == type || type.isAssignableFrom(variable.getDeclaration().getType())) {
variables.add(variable);
}
if (!onlyToplevel) {
for (int i = 0, end = variable.getNestedElementsCount(); i < end; i++) {
addVariableByType(variable.getNestedElement(i), type, onlyToplevel, variables);
}
}
}
示例14: getStaticType
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
/**
* Returns the static type in case that this compound access is a static access.
*
* @return the static type or <b>null</b>
* @throws CSTSemanticException in case of semantic errors
*/
public IDatatype getStaticType() throws CSTSemanticException {
IDatatype result = null;
IDatatype cExpression = compoundExpression.inferDatatype();
if (cExpression.isAssignableFrom(MetaType.TYPE)) {
if (compoundExpression instanceof ConstantValue) {
// ugly!
Value value = ((ConstantValue) compoundExpression).getConstantValue();
if (value instanceof MetaTypeValue) {
result = ((MetaTypeValue) value).getValue();
}
}
}
return result;
}
示例15: inferDatatype
import net.ssehub.easy.varModel.model.datatypes.IDatatype; //导入方法依赖的package包/类
@Override
public IDatatype inferDatatype() throws CSTSemanticException {
IDatatype result = null;
if (null == slot) {
IDatatype cExpression;
IDatatype staticType = getStaticType();
if (null != staticType) {
cExpression = staticType;
} else {
cExpression = compoundExpression.inferDatatype();
}
cExpression = Reference.dereference(cExpression);
if (cExpression.isAssignableFrom(MetaType.TYPE)) {
if (cExpression instanceof ConstantValue) {
// ugly!
Value value = ((ConstantValue) cExpression).getConstantValue();
if (value instanceof MetaTypeValue) {
cExpression = ((MetaTypeValue) value).getValue();
}
}
}
if (cExpression.isAssignableFrom(Compound.TYPE) && cExpression instanceof Compound) {
Compound comp = (Compound) cExpression;
slot = searchSlot(comp, slotName);
if (null == slot) {
throw new CSTSemanticException("type '" + comp.getName()
+ "' does not have a slot named '" + slotName + "'",
CSTSemanticException.UNKNOWN_ELEMENT);
}
} else {
throw new CSTSemanticException("expression does not evaluate to a compound",
CSTSemanticException.TYPE_MISMATCH);
}
}
if (null != slot) {
result = slot.getType();
}
return result;
}