本文整理汇总了Java中net.ssehub.easy.varModel.cst.Variable类的典型用法代码示例。如果您正苦于以下问题:Java Variable类的具体用法?Java Variable怎么用?Java Variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Variable类属于net.ssehub.easy.varModel.cst包,在下文中一共展示了Variable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTopLevelValues
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Adds top level values configured for <code>source</code> to <code>target</code>.
*
* @param cfg the actual configuration holding the values
* @param source the source project
* @param target the target project
* @param exclude the variable names to exclude
* @return the changed top-level variables ready for freezing
* @throws CSTSemanticException in case of CST errors
*/
private static List<IFreezable> addTopLevelValues(Configuration cfg, Project source, Project target,
String... exclude) throws CSTSemanticException {
List<IFreezable> result = new ArrayList<IFreezable>();
for (int e = 0; e < source.getElementCount(); e++) {
ContainableModelElement elt = source.getElement(e);
if (elt instanceof DecisionVariableDeclaration) {
DecisionVariableDeclaration decl = (DecisionVariableDeclaration) elt;
if (!Arrays.contains(exclude, decl.getName())) {
IDecisionVariable decVar = cfg.getDecision(decl);
Value value = decVar.getValue();
if (null != value && !ConstraintType.isConstraint(decVar.getDeclaration().getType())) {
ConstraintSyntaxTree cst = new OCLFeatureCall(new Variable(decl), IvmlKeyWords.ASSIGNMENT,
new ConstantValue(decVar.getValue().clone()));
cst.inferDatatype();
Constraint constraint = new Constraint(cst, target);
target.addConstraint(constraint);
result.add(decl);
}
}
}
}
return result;
}
示例2: setPipelines
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Sets the given <code>pipeline</code> as value in the <code>varName</code> of <code>prj</code>.
*
* @param prj the project to modify
* @param varName the variable to modify
* @param pipeline the pipeline to set as (reference) value
* @return the affected variable
* @throws ModelQueryException if access to the variable failed
* @throws CSTSemanticException in case of CST errors
* @throws ValueDoesNotMatchTypeException if <code>pipeline</code> does not match as a value
*/
private static DecisionVariableDeclaration setPipelines(Project prj, String varName,
DecisionVariableDeclaration pipeline) throws ModelQueryException, CSTSemanticException,
ValueDoesNotMatchTypeException {
DecisionVariableDeclaration pipelinesVar = (DecisionVariableDeclaration) ModelQuery.findVariable(prj,
varName, DecisionVariableDeclaration.class);
if (null != pipelinesVar && pipelinesVar.getType() instanceof Container) {
Container cType = (Container) pipelinesVar.getType();
ConstraintSyntaxTree cst = new OCLFeatureCall(new Variable(pipelinesVar), IvmlKeyWords.ASSIGNMENT,
new ConstantValue(ValueFactory.createValue(cType, pipeline)));
cst.inferDatatype();
Constraint constraint = new Constraint(cst, prj);
prj.addConstraint(constraint);
} else {
throw new ModelQueryException("pipelines variable '" + varName + "' not found",
ModelQueryException.ACCESS_ERROR);
}
return pipelinesVar;
}
示例3: createFreezeBlock
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Creates a freeze block for project. [legacy style, does not add to project]
*
* @param freezables
* the freezables
* @param project
* the IVML project to add to (may be <b>null</b> if failed)
* @param fallbackForType
* in case that <code>project</code> is being written the first time, may be <b>null</b>
* @return the created freeze block
* @throws CSTSemanticException
* in case of CST errors
* @throws ValueDoesNotMatchTypeException
* in case of unmatching values
* @throws ModelQueryException
* in case of model access problems
*/
public static FreezeBlock createFreezeBlock(IFreezable[] freezables, Project project, Project fallbackForType)
throws CSTSemanticException, ValueDoesNotMatchTypeException, ModelQueryException {
FreezeBlock result = null;
FreezeVariableType iterType = new FreezeVariableType(freezables, project);
DecisionVariableDeclaration iter = new DecisionVariableDeclaration("f", iterType, project);
net.ssehub.easy.varModel.model.datatypes.Enum type = ModelQuery.findEnum(project, TYPE_BINDING_TIME);
if (null == type && null != fallbackForType) {
type = ModelQuery.findEnum(fallbackForType, TYPE_BINDING_TIME);
}
String butOperation = "==";
EnumLiteral literal = type.get(CONST_BINDING_TIME_RUNTIME);
if (null == literal) { // newer version of the model
literal = type.get(CONST_BINDING_TIME_RUNTIME_MON);
butOperation = ">=";
}
ConstraintSyntaxTree runtime = new ConstantValue(ValueFactory.createValue(type, literal));
Variable iterEx = new AttributeVariable(new Variable(iter), iterType.getAttribute(ANNOTATION_BINDING_TIME));
OCLFeatureCall op = new OCLFeatureCall(iterEx, butOperation, runtime);
op.inferDatatype();
result = new FreezeBlock(freezables, iter, op, project);
return result;
}
示例4: writeConstraintLogicForNestedElement
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Method to write the constraint logic in drools for a nested element.
* @param variable variable.
* @param name Name of the variable.
* @param isDerivedType <b>True</b> if the variable is a derived type.
*/
private void writeConstraintLogicForNestedElement(Variable variable, String name, boolean isDerivedType) {
String patternToAdd;
patternToAdd = "isDefined( $" + variable.getVariable().getParent().getName() + "." + name + ")";
pattern.add(patternToAdd);
String parent = variable.getVariable().getParent().getName();
if (!compoundPlaceHolders.contains(parent)) {
compoundPlaceHolders.add(parent);
compoundHeads += "\n" + "$" + parent + ": " + parent + "()";
}
constraint += "$" + parent + "." + name;
List<String> li = DroolsVisitor.getCompoundMap().get(parent);
if (isDerivedType && (null != li)) {
String cAc1 = variableStatusChecker + "(" + "\"" + parent + "\"" + ")";
String cAc2 = variableStatusChecker + "(" + "\"" + parent + "." + name + "\"" + ")";
String pattern1 = cAc1 + " || " + cAc2;
String pattern22 = "";
for (int i = 0; i < li.size(); i++) {
String access1 = variableStatusChecker + "(" + "\"" + li.get(i) + "\"" + ")";
String access2 = variableStatusChecker + "(" + "\"" + li.get(i) + "." + name + "\"" + ")";
pattern22 += " || " + access1 + " || " + access2;
}
pattern.add("(" + pattern1 + pattern22 + ")");
}
}
示例5: writeConstraintLogicForNonNestedElement
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Method to write constraint logic for non nested element. This can be written in
* Drools Java dialect or Mvel dialect. Previous measures show Java dialect for non-nested elements
* is much faster than using mvel.
* @param variable variable.
* @param name name of the variable.
*/
private void writeConstraintLogicForNonNestedElement(Variable variable, String name) {
writeDroolsClassPattern(name);
int thr = getDroolsClassNr(name);
char ch = name.charAt(0);
ch = Character.toUpperCase(ch);
StringBuilder nameTemp = new StringBuilder(name);
nameTemp.setCharAt(0, ch);
String javaDialectNotation = "P" + thr + ".get" + nameTemp + letSuffix + "()";
if (isNotPrimitiveType(variable)) {
if (USEJAVADIALECT) {
pattern.add("isDefined(" + javaDialectNotation + ")");
} else {
pattern.add("isDefined(" + "P" + thr + "." + name + ")");
}
}
if (USEJAVADIALECT) {
constraint += "P" + thr + ".get" + nameTemp + letSuffix + "()";
} else {
constraint += "P" + thr + "." + name + letSuffix;
}
}
示例6: processModificationForVariable
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Process modification rules, where operand is a variable.
* @param call OCL Call.
* @param constraintRule A string representation of Drools "not" of this this call.
*/
private void processModificationForVariable(OCLFeatureCall call,
String constraintRule) {
Variable var = (Variable) call.getOperand();
String name = ((Variable) call.getOperand()).getVariable().getName();
assgnConstraintsCalls(call);
addAssinmentConstraintsToMap(constraintRule, name);
configuredByDefaultList.add(name);
boolean varIsContainer = var.getVariable().getType().getTypeClass().equals(Sequence.class)
|| var.getVariable().getType().getTypeClass().equals(Set.class);
// boolean varIsCompound = var.getVariable().getType().getTypeClass().equals(Compound.class);
if (!varIsContainer ) {
logger.info("");
}
}
示例7: testSortedByCompoundSequenceOperation
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Tests the sortedBy operation on integer sequences.
*
* @throws ValueDoesNotMatchTypeException in case that value assignments fail (shall not occur)
* @throws ConfigurationException in case that initial assignment of values fail (shall not occur)
* @throws CSTSemanticException in case that the expressions created during this test are not
* valid (shall not occur)
*/
@Test
public void testSortedByCompoundSequenceOperation() throws ValueDoesNotMatchTypeException, ConfigurationException,
CSTSemanticException {
Project project = new Project("Test");
Compound cmp = new Compound("Cmp", project);
DecisionVariableDeclaration cmpA = new DecisionVariableDeclaration("a", StringType.TYPE, project);
cmp.add(cmpA);
project.add(cmp);
// some expression, also just a would do the job
DecisionVariableDeclaration localDecl = new DecisionVariableDeclaration("c", cmp, null);
ConstraintSyntaxTree itExpression = new CompoundAccess(new Variable(localDecl), "a");
Object[] actual = new Object[3];
actual[0] = ValueFactory.createValue(cmp, new Object[]{"a", "zz"});
actual[1] = ValueFactory.createValue(cmp, new Object[]{"a", "aa"});
actual[2] = ValueFactory.createValue(cmp, new Object[]{"a", "bb"});
Object[] expected = new Object[3];
expected[0] = actual[1];
expected[1] = actual[2];
expected[2] = actual[0];
testSortedBySequenceOperation(cmp, actual, expected, localDecl, itExpression, project);
}
示例8: visitOclFeatureCall
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
@Override
public void visitOclFeatureCall(OCLFeatureCall call) {
boolean operationIsEquals = (call.getOperation().equals(OclKeyWords.EQUALS));
boolean operationIsImplies = call.getOperation().equals(OclKeyWords.IMPLIES);
if (operationIsEquals) {
if ((call.getOperand() instanceof Variable) || (call.getOperand() instanceof CompoundAccess)) {
// logger.info("This constraint needs to be there.");
acceptConstraint = true;
}
} else if (operationIsImplies) {
if (call.getParameter(0).getClass().equals(call.getClass())) {
OCLFeatureCall temp = (OCLFeatureCall) call.getParameter(0);
if (temp.getOperation().equals(OclKeyWords.EQUALS)) {
// logger.info("this should also be included.");
acceptConstraint = true;
}
} else if (call.getParameter(0) instanceof Parenthesis) {
OCLFeatureCall temp2 = new OCLFeatureCall(call.getOperand(), OclKeyWords.IMPLIES,
((Parenthesis) call.getParameter(0)).getExpr());
temp2.accept(this);
}
}
}
示例9: createFieldCheckOperation
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Creates the field check operation.
*
* @param prj the parent project
* @param tuples the tuples type
* @throws CSTSemanticException in case of constraint syntax errors
*/
private void createFieldCheckOperation(Project prj, IDatatype tuples) throws CSTSemanticException {
OperationDefinition collectFieldTypes = new OperationDefinition(prj);
DecisionVariableDeclaration[] params = new DecisionVariableDeclaration[2];
params[0] = new DecisionVariableDeclaration("fTuples", tuples, collectFieldTypes);
params[1] = new DecisionVariableDeclaration("aTuples", tuples, collectFieldTypes);
ConstraintSyntaxTree cf0 = new OCLFeatureCall(new Variable(params[0]), "collectFieldTypes", prj);
cf0.inferDatatype();
ConstraintSyntaxTree cf1 = new OCLFeatureCall(new Variable(params[1]), "collectFieldTypes", prj);
cf1.inferDatatype();
ConstraintSyntaxTree expr = new OCLFeatureCall(cf0, "==", cf1);
IDatatype exprType = expr.inferDatatype();
IDatatype resultType = BooleanType.TYPE;
Assert.assertTrue(resultType.isAssignableFrom(exprType));
collectFieldTypes.setOperation(new CustomOperation(resultType, "fieldCheck", prj.getType(), expr, params));
prj.add(collectFieldTypes);
}
示例10: getDisplayName
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Returns the display name of a constraint, e.g., for a value of a reference.
*
* @param constraint the constraint to return the name for
* @param configuration the containing configuration in order to avoid unnecessary qualifications or to resolve
* expressions for better readability
* @return the display name (must not be <b>null</b>)
*/
public String getDisplayName(ConstraintSyntaxTree constraint, Configuration configuration) {
// TODO make it clean / use visitor
String name;
if (constraint instanceof Variable) {
name = getDisplayName(((Variable) constraint).getVariable());
} else if (constraint instanceof CompoundAccess) {
CompoundAccess access = (CompoundAccess) constraint;
String varName = (null != access.getResolvedSlot()) ? getDisplayName(access.getResolvedSlot())
: access.getSlotName();
name = getDisplayName(access.getCompoundExpression(), configuration)
+ IvmlKeyWords.COMPOUND_ACCESS + varName;
} else if (constraint instanceof OCLFeatureCall
&& OclKeyWords.INDEX_ACCESS.equals(((OCLFeatureCall) constraint).getOperation())) {
OCLFeatureCall call = (OCLFeatureCall) constraint;
name = getDisplayNameForIndexAccess(call, configuration);
} else {
name = StringProvider.toIvmlString(constraint, configuration.getProject());
}
return name;
}
示例11: visitOclFeatureCall
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
@Override
public void visitOclFeatureCall(OCLFeatureCall call) {
if (null != call.getOperand()) {
if ((call.getOperand() instanceof Variable
|| call.getOperand() instanceof CompoundAccess)
&& call.getParameterCount() == 1
&& call.getOperation().equals(OclKeyWords.ASSIGNMENT)) {
if (call.getParameter(0) instanceof ContainerInitializer) {
isConstraintContainer = true;
cst = call.getParameter(0);
}
if (call.getParameter(0) instanceof CompoundInitializer) {
isCompoundInitializer = true;
cst = call.getParameter(0);
}
}
call.getOperand().accept(this);
for (int i = 0; i < call.getParameterCount(); i++) {
call.getParameter(i).accept(this);
}
}
}
示例12: testSimpleConstraintCopy
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Copies a constraint, which has no outstanding dependencies.
* @throws ValueDoesNotMatchTypeException If String values cannot be created.
* @throws CSTSemanticException If a string constraint cannot be created
*/
@Test
public void testSimpleConstraintCopy() throws ValueDoesNotMatchTypeException, CSTSemanticException {
Project original = new Project("testSimpleConstraintCopy");
IDatatype basisType = StringType.TYPE;
DecisionVariableDeclaration decl = new DecisionVariableDeclaration("decl", basisType, original);
original.add(decl);
Constraint constraint = new Constraint(original);
ConstantValue helloWorldVal = new ConstantValue(ValueFactory.createValue(basisType, "Hello World"));
OCLFeatureCall equality = new OCLFeatureCall(new Variable(decl), OclKeyWords.EQUALS, helloWorldVal);
constraint.setConsSyntax(equality);
original.add(constraint);
java.util.Set<Project> copiedProjects = new HashSet<Project>();
Project copy = copyProject(original, copiedProjects);
Constraint copiedConstraint = (Constraint) copy.getElement(1);
assertConstraint(constraint, copiedConstraint, copy, copiedProjects);
}
示例13: testDependingConstraintCopy
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Copies a constraint, which is depending on elements, defined at a later point.
* @throws ValueDoesNotMatchTypeException If String values cannot be created.
* @throws CSTSemanticException If a string constraint cannot be created
*/
@Test
public void testDependingConstraintCopy() throws ValueDoesNotMatchTypeException, CSTSemanticException {
Project original = new Project("testDependingConstraintCopy");
IDatatype basisType = StringType.TYPE;
DecisionVariableDeclaration decl = new DecisionVariableDeclaration("decl", basisType, original);
Constraint constraint = new Constraint(original);
ConstantValue helloWorldVal = new ConstantValue(ValueFactory.createValue(basisType, "Hello World"));
OCLFeatureCall equality = new OCLFeatureCall(new Variable(decl), OclKeyWords.EQUALS, helloWorldVal);
constraint.setConsSyntax(equality);
original.add(constraint);
original.add(decl);
java.util.Set<Project> copiedProjects = new HashSet<Project>();
Project copy = copyProject(original, copiedProjects);
Constraint copiedConstraint = (Constraint) copy.getElement(0);
assertConstraint(constraint, copiedConstraint, copy, copiedProjects);
}
示例14: testSimpleDeclarationWithDependingDefaultCopy
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Tests whether declarations can be copied. This method tests a declaration:
* <ul>
* <li>No {@link Attribute}s</li>
* <li>Simple data type (is already known)</li>
* <li>Has a default value referencing another variable, which is defined at a later point</li>
* </ul>
* @throws ValueDoesNotMatchTypeException Identifies errors in {@link DecisionVariableDeclaration
* #setValue(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree )}
* @throws CSTSemanticException Identifies errors in {@link DecisionVariableDeclaration
* #setValue(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree )}
*/
@Test
public void testSimpleDeclarationWithDependingDefaultCopy() throws ValueDoesNotMatchTypeException,
CSTSemanticException {
Project original = new Project("testSimpleDeclarationWithDefaultCopy");
IDatatype basisType = RealType.TYPE;
DecisionVariableDeclaration declA = new DecisionVariableDeclaration("declA", basisType, original);
DecisionVariableDeclaration declB = new DecisionVariableDeclaration("declB", basisType, original);
declA.setValue(new Variable(declB));
original.add(declA);
original.add(declB);
Project copy = copyProject(original);
AbstractVariable copiedDeclA = (AbstractVariable) copy.getElement(0);
AbstractVariable copiedDeclB = (AbstractVariable) copy.getElement(1);
Map<AbstractVariable, IModelElement> copyMapping = new HashMap<AbstractVariable, IModelElement>();
copyMapping.put(declA, copy);
copyMapping.put(declB, copy);
assertDeclaration(declA, copiedDeclA, copyMapping);
assertDeclaration(declB, copiedDeclB, copyMapping);
Variable defaultA = (Variable) copiedDeclA.getDefaultValue();
Assert.assertSame("Default value of first declaration is pointing to wrong instance of second declaration",
copiedDeclB, defaultA.getVariable());
}
示例15: testCopyDerivedType
import net.ssehub.easy.varModel.cst.Variable; //导入依赖的package包/类
/**
* Tests whether a simple {@link DerivedDatatype} without any dependencies can be copied.
* @throws CSTSemanticException If <tt>true</tt> cannot be created as constraint for a boolean type
*/
@Test
public void testCopyDerivedType() throws CSTSemanticException {
Project original = new Project("testCopyDerivedType");
IDatatype basisType = BooleanType.TYPE;
DerivedDatatype dType = new DerivedDatatype("posType", basisType, original);
Constraint constraint = new Constraint(dType);
OCLFeatureCall equality = new OCLFeatureCall(new Variable(dType.getTypeDeclaration()), OclKeyWords.EQUALS,
new ConstantValue(BooleanValue.TRUE));
constraint.setConsSyntax(equality);
dType.setConstraints(new Constraint[] {constraint});
original.add(dType);
java.util.Set<Project> copiedProjects = new HashSet<Project>();
Project copy = copyProject(original, copiedProjects);
DerivedDatatype copiedType = (DerivedDatatype) copy.getElement(0);
assertDerivedType(dType, copiedType, copy, copiedProjects);
}