本文整理汇总了Java中net.ssehub.easy.varModel.model.Project.attribute方法的典型用法代码示例。如果您正苦于以下问题:Java Project.attribute方法的具体用法?Java Project.attribute怎么用?Java Project.attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.ssehub.easy.varModel.model.Project
的用法示例。
在下文中一共展示了Project.attribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDeclarationWithAnnotationCopy
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests whether declarations can be copied. This method tests a declaration:
* <ul>
* <li>Has an {@link Attribute}</li>
* <li>Simple data type (is already known)</li>
* <li>No default value</li>
* </ul>
*/
@Test
public void testDeclarationWithAnnotationCopy() {
Project original = new Project("testDeclarationWithAnnotationCopy");
Attribute annotation = new Attribute("anno", StringType.TYPE, original, original);
original.add(annotation);
original.attribute(annotation);
DecisionVariableDeclaration decl = new DecisionVariableDeclaration("decl", RealType.TYPE, original);
original.add(decl);
// decl.attribute(annotation);
Project copiedProject = copyProject(original);
AbstractVariable copiedAnnotation = (AbstractVariable) copiedProject.getElement(0);
DecisionVariableDeclaration copieddecl = (DecisionVariableDeclaration) copiedProject.getElement(1);
Map<AbstractVariable, IModelElement> mapping = new HashMap<AbstractVariable, IModelElement>();
mapping.put(copiedAnnotation, copiedProject);
mapping.put(copieddecl, copiedProject);
assertDeclaration(decl, copieddecl, mapping);
}
示例2: testDeclarationWithDependingAnnotationCopy
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests whether declarations can be copied. This method tests a declaration:
* <ul>
* <li>Has an {@link Attribute}, which is defined after the declaration</li>
* <li>Simple data type (is already known)</li>
* <li>No default value</li>
* </ul>
*/
@Test
public void testDeclarationWithDependingAnnotationCopy() {
Project original = new Project("testDeclarationWithDependingAnnotationCopy");
Attribute annotation = new Attribute("anno", StringType.TYPE, original, original);
DecisionVariableDeclaration decl = new DecisionVariableDeclaration("decl", RealType.TYPE, original);
original.add(decl);
original.add(annotation);
original.attribute(annotation);
Project copiedProject = copyProject(original);
AbstractVariable copiedAnnotation = (AbstractVariable) copiedProject.getElement(1);
DecisionVariableDeclaration copieddecl = (DecisionVariableDeclaration) copiedProject.getElement(0);
Map<AbstractVariable, IModelElement> mapping = new HashMap<AbstractVariable, IModelElement>();
mapping.put(copiedAnnotation, copiedProject);
mapping.put(copieddecl, copiedProject);
assertDeclaration(decl, copieddecl, mapping);
}
示例3: testFreezeBlockKnownDeclarationAnnotationBut
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests copying a {@link FreezeBlock}. It tests:
* <ul>
* <li>A known declaration</li>
* <li>But expression on annotation</li>
* </ul>
*/
@Test
public void testFreezeBlockKnownDeclarationAnnotationBut() {
Project orgProject = new Project("testFreezeBlockKnownDeclarationAnnotationBut");
Attribute annoDecl = new Attribute("anno", BooleanType.TYPE, orgProject, orgProject);
orgProject.add(annoDecl);
orgProject.attribute(annoDecl);
Compound cType = new Compound("CP", orgProject);
DecisionVariableDeclaration slotDecl = new DecisionVariableDeclaration("slot", StringType.TYPE, cType);
cType.add(slotDecl);
orgProject.add(cType);
DecisionVariableDeclaration decl = new DecisionVariableDeclaration("decl", cType, orgProject);
orgProject.add(decl);
DecisionVariableDeclaration itrDecl = new DecisionVariableDeclaration("i", BooleanType.TYPE, orgProject);
AttributeVariable annotationAccess = new AttributeVariable(new Variable(itrDecl), annoDecl);
ConstantValue trueExpr = new ConstantValue(BooleanValue.TRUE);
OCLFeatureCall equality = new OCLFeatureCall(annotationAccess, OclKeyWords.EQUALS, trueExpr);
FreezeBlock freeze = new FreezeBlock(new IFreezable[] {decl}, itrDecl, equality, orgProject);
orgProject.add(freeze);
java.util.Set<Project> allCopiedProjects = new HashSet<Project>();
Project copiedProject = copyProject(orgProject, allCopiedProjects);
FreezeBlock copiedBlock = (FreezeBlock) copiedProject.getElement(3);
assertFreezeBlock(freeze, copiedBlock, copiedProject, allCopiedProjects);
}
示例4: testAssignBlockCopySimple
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests that simple {@link AttributeAssignment}s can be copied without outstanding dependencies.
*/
@Test
public void testAssignBlockCopySimple() {
Project orgProject = new Project("testAssignBlockCopySimple");
Attribute annoDecl = new Attribute("anno", BooleanType.TYPE, orgProject, orgProject);
orgProject.add(annoDecl);
orgProject.attribute(annoDecl);
AttributeAssignment assignBlock = new AttributeAssignment(orgProject);
ConstantValue constTrue = new ConstantValue(BooleanValue.TRUE);
Assignment assignment = new Assignment(annoDecl.getName(), OclKeyWords.EQUALS, constTrue);
assignBlock.add(assignment);
DecisionVariableDeclaration decl = new DecisionVariableDeclaration("decl", StringType.TYPE, assignBlock);
assignBlock.add(decl);
orgProject.add(assignBlock);
java.util.Set<Project> allCopiedProject = new HashSet<Project>();
Project copy = copyProject(orgProject, allCopiedProject);
AttributeAssignment copiedBlock = (AttributeAssignment) copy.getElement(1);
assertAssignBlock(assignBlock, copiedBlock, copy, allCopiedProject);
}
示例5: testAssignBlockCopyDependingOnNestedelement
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests that {@link AttributeAssignment}s can be copied, which are dependent on elements defined in itself.
*/
@Test
public void testAssignBlockCopyDependingOnNestedelement() {
Project orgProject = new Project("testAssignBlockCopySimple");
Attribute annoDecl = new Attribute("anno", BooleanType.TYPE, orgProject, orgProject);
orgProject.add(annoDecl);
orgProject.attribute(annoDecl);
AttributeAssignment assignBlock = new AttributeAssignment(orgProject);
DecisionVariableDeclaration decl = new DecisionVariableDeclaration("decl", BooleanType.TYPE, assignBlock);
Variable var = new Variable(decl);
Assignment assignment = new Assignment(annoDecl.getName(), OclKeyWords.EQUALS, var);
assignBlock.add(assignment);
assignBlock.add(decl);
orgProject.add(assignBlock);
java.util.Set<Project> allCopiedProject = new HashSet<Project>();
Project copy = copyProject(orgProject, allCopiedProject);
AttributeAssignment copiedBlock = (AttributeAssignment) copy.getElement(1);
assertAssignBlock(assignBlock, copiedBlock, copy, allCopiedProject);
}
示例6: testSimpleAnnotationCopy
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests whether Attribute can be copied. This method tests a declaration:
* <ul>
* <li>Annotated to whole project</li>
* <li>Simple data type (is already known)</li>
* <li>No default value</li>
* </ul>
*/
@Test
public void testSimpleAnnotationCopy() {
Project original = new Project("testSimpleAnnotationCopy");
IDatatype basisType = StringType.TYPE;
Attribute decl = new Attribute("anno", basisType, original, original);
original.add(decl);
original.attribute(decl);
Project copy = copyProject(original);
AbstractVariable copieddecl = (AbstractVariable) copy.getElement(0);
Map<AbstractVariable, IModelElement> copyMapping = new HashMap<AbstractVariable, IModelElement>();
copyMapping.put(decl, copy);
assertDeclaration(decl, copieddecl, copyMapping);
}
示例7: testAssignProjectAnnotation
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests the correct assignment of annotations.
* @throws ValueDoesNotMatchTypeException Must not occur otherwise there is a failure inside the
* {@link ValueFactory}.
* @throws CSTSemanticException Must not occur otherwise there is a failure inside the constraint syntax trees.
*/
@Test
public void testAssignProjectAnnotation() throws ValueDoesNotMatchTypeException, CSTSemanticException {
// Creates a project with an annotation of the complete project
Project project = new Project("testAssignProjectAnnotation");
// Annotation for project
Enum btType = new Enum("Bindingtime", project, "compile_time", "run_time");
project.add(btType);
Attribute btDecl = new Attribute("bindingtime", btType, project, project);
Value compileValue = ValueFactory.createValue(btType, btType.getLiteral(0));
ConstantValue constValCompiletime = new ConstantValue(compileValue);
btDecl.setValue(constValCompiletime);
project.add(btDecl);
project.attribute(btDecl);
// Two declarations, one nested, one not
DecisionVariableDeclaration declA = new DecisionVariableDeclaration("intA", IntegerType.TYPE, project);
project.add(declA);
// Overwrite default annotation of second declaration
AttributeAssignment assignBlock = new AttributeAssignment(project);
Value runValue = ValueFactory.createValue(btType, btType.getLiteral(1));
ConstantValue constValRuntime = new ConstantValue(runValue);
Assignment assign = new Assignment(btDecl.getName(), OclKeyWords.ASSIGNMENT, constValRuntime);
assignBlock.add(assign);
DecisionVariableDeclaration declB = new DecisionVariableDeclaration("intB", IntegerType.TYPE, assignBlock);
assignBlock.add(declB);
project.add(assignBlock);
ProjectTestUtilities.validateProject(project);
Configuration config = new Configuration(project, true);
// Test correct behavior:
// intA.bindingtime = compile_time
// intB.bindingtime = run_time
assertAnnotationValue(compileValue, config.getDecision(declA));
assertAnnotationValue(runValue, config.getDecision(declB));
}
示例8: createProject
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Creates the main project.
*
* @throws ModelManagementException in case of "resolving" the imported project fails
*/
private void createProject() throws ModelManagementException {
project = new Project("test");
project.setVersion(new Version(1, 0));
ProjectImport imp = new ProjectImport("imported", null);
imp.setResolved(impProject);
project.addImport(imp);
project.attribute(new net.ssehub.easy.varModel.model.Attribute("bindingTime",
IntegerType.TYPE, project, project)); // just to simplify the process
pInt = new DecisionVariableDeclaration("pInt", IntegerType.TYPE, project);
project.add(pInt);
pString = new DecisionVariableDeclaration("pString", StringType.TYPE, project);
project.add(pString);
pReal = new DecisionVariableDeclaration("pReal", RealType.TYPE, project);
project.add(pReal);
pBoolean = new DecisionVariableDeclaration("pBoolean", BooleanType.TYPE, project);
project.add(pBoolean);
pBooleanUF = new DecisionVariableDeclaration("pBooleanUnfrozen", BooleanType.TYPE, project);
project.add(pBooleanUF);
enm = new net.ssehub.easy.varModel.model.datatypes.Enum("pEnumeration", impProject,
"val1", "val2", "val3");
impProject.add(enm);
pEnum = new DecisionVariableDeclaration("pEnum", enm, project);
project.add(pEnum);
comp = new Compound("pCompound", project);
pcInt = new DecisionVariableDeclaration("pcInt", IntegerType.TYPE, comp);
comp.add(pcInt);
pcString = new DecisionVariableDeclaration("pcString", StringType.TYPE, comp);
comp.add(pcString);
project.add(comp);
pComp = new DecisionVariableDeclaration("pComp", comp, project);
project.add(pComp);
seq = new Sequence("pCompoundSequence", comp, project);
pCompSeq = new DecisionVariableDeclaration("pCompSeq", seq, project);
project.add(pCompSeq);
}
示例9: testRewritingOfFreezeBlockSelector
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests that the but condition of a FreezeBlock is created correctly after filtering declarations.
* @throws ValueDoesNotMatchTypeException Must not occur, otherwise the {@link ValueFactory} or
* {@link net.ssehub.easy.varModel.model.AbstractVariable#setValue(String)} are broken.
*/
@Test
public void testRewritingOfFreezeBlockSelector() throws ValueDoesNotMatchTypeException {
// Create original project with two declaration, an annotation and a FreezeBlock
Project p = new Project("testProjectFreezeBlockSelector");
OrderedEnum btType = new OrderedEnum("BindingTime", p);
btType.add(new EnumLiteral("Compiletime", 1, btType));
btType.add(new EnumLiteral("runtime", 2, btType));
p.add(btType);
Attribute attr = new Attribute("bindingTime", btType, p, p);
p.attribute(attr);
p.add(attr);
DecisionVariableDeclaration declA = new DecisionVariableDeclaration("declarationA", IntegerType.TYPE, p);
declA.setValue(42);
p.add(declA);
DecisionVariableDeclaration declB = new DecisionVariableDeclaration("declarationB", IntegerType.TYPE, p);
p.add(declB);
declB.setValue(21);
// Freeze one declaration
DecisionVariableDeclaration itr = new DecisionVariableDeclaration("itr", AnyType.TYPE, null);
AttributeVariable itrVar = new AttributeVariable(new Variable(itr), attr);
ConstantValue btValue = new ConstantValue(ValueFactory.createValue(btType, btType.getLiteral(1)));
ConstraintSyntaxTree selectorCST = new OCLFeatureCall(itrVar, OclKeyWords.GREATER_EQUALS, btValue);
FreezeBlock block = new FreezeBlock(new IFreezable[] {declA, declB}, itr , selectorCST, p);
p.add(block);
// Project should be valid
ProjectTestUtilities.validateProject(p);
// Filter one declaration
ProjectRewriteVisitor rewriter = new ProjectRewriteVisitor(p, FilterType.ALL);
rewriter.addModelCopyModifier(new DeclarationNameFilter(new String[] {declA.getName()}));
p.accept(rewriter);
ProjectTestUtilities.validateProject(p);
assertProjectContainment(p, declA, true, 4);
assertProjectContainment(p, declB, false, 4);
StringWriter sWriter = new StringWriter();
IVMLWriter iWriter = new IVMLWriter(sWriter);
p.getElement(3).accept(iWriter);
try {
iWriter.flush();
} catch (IOException e) {
e.printStackTrace();
}
String freezeAsString = sWriter.toString();
Assert.assertTrue("Annotation access in freeze block selector not handled correctly.",
freezeAsString.contains(itr.getName() + IvmlKeyWords.ATTRIBUTE_ACCESS + attr.getName()));
Assert.assertFalse("Invalid qualified name introduced to annotation access in freeze block selector.",
freezeAsString.contains(p.getName() + IvmlKeyWords.NAMESPACE_SEPARATOR + itr.getName()));
}
示例10: setUp
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Creates the project which is needed during the tests.
*/
@Before
public void setUp() {
project = new Project("Project");
// Create Attribute
attributeType = new Enum("attributeType", project, "STATE_1", "STATE_2");
project.add(attributeType);
Attribute attribute = new Attribute("attr", attributeType, project, project);
project.add(attribute);
project.attribute(attribute);
// Create custom datatypes
oEnumType = new OrderedEnum("orderedEnumType", project);
EnumLiteral oLiteral1 = new EnumLiteral("Lit1", 10, oEnumType);
EnumLiteral oLiteral2 = new EnumLiteral("Lit2", 30, oEnumType);
oEnumType.add(oLiteral1);
oEnumType.add(oLiteral2);
project.add(oEnumType);
cType1 = new Compound("C1", project);
project.add(cType1);
cType2 = new Compound("C2", project, cType1);
project.add(cType2);
cType3 = new Compound("C3", project);
project.add(cType3);
refType = new Reference("refType", cType1, project);
project.add(refType);
dType = new DerivedDatatype("MyInt", IntegerType.TYPE, project);
project.add(dType);
DecisionVariableDeclaration refDecl = new DecisionVariableDeclaration("cmpReference", refType, project);
project.add(refDecl);
setType = new Set("Integer_Set", IntegerType.TYPE, project);
project.add(setType);
DecisionVariableDeclaration setDecl = new DecisionVariableDeclaration("integerSet", setType, project);
project.add(setDecl);
seqType = new Sequence("Compound_Set", cType1, project);
project.add(seqType);
DecisionVariableDeclaration seqDecl = new DecisionVariableDeclaration("cmpSeq", setType, project);
project.add(seqDecl);
// StringWriter sWriter = new StringWriter();
// IVMLWriter iWriter = new IVMLWriter(sWriter);
// project.accept(iWriter);
// sWriter.flush();
// System.out.println(sWriter.toString());
// Check whether the project could be used for testing
IvmlValidationVisitor validator = new IvmlValidationVisitor();
project.accept(validator);
Assert.assertEquals(0, validator.getErrorCount());
}
示例11: setUp
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Executed before a single test.
*
* @throws CSTSemanticException shall not occur
* @throws ValueDoesNotMatchTypeException shall not occur
*/
@Before
public void setUp() throws CSTSemanticException, ValueDoesNotMatchTypeException {
prj = new Project("FreezeTest");
// Annotation
Enum bindingTime = new OrderedEnum("BindingTime", prj);
bindingTime.add(new EnumLiteral("compile", 1, bindingTime));
bindingTime.add(new EnumLiteral("link", 2, bindingTime));
bindingTime.add(new EnumLiteral("monitor", 3, bindingTime));
bindingTime.add(new EnumLiteral("enact", 4, bindingTime));
prj.add(bindingTime);
Attribute attr = new Attribute("binding", bindingTime, prj, prj);
prj.attribute(attr);
prj.add(attr);
// Basis compound
param = new Compound("IntParameter", prj);
param.add(new DecisionVariableDeclaration("defaultValue", IntegerType.TYPE, param));
AttributeAssignment assng = new AttributeAssignment(param);
assng.add(new Assignment(attr.getName(), OclKeyWords.ASSIGNMENT,
new ConstantValue(ValueFactory.createValue(bindingTime, bindingTime.getLiteral(3)))));
assng.add(new DecisionVariableDeclaration("value", IntegerType.TYPE, assng));
param.add(assng);
prj.add(param);
myParam = new DecisionVariableDeclaration("myParam", param, prj);
prj.add(myParam);
// Sequence of basis compound
Sequence paramSeq = new Sequence("", param, prj);
myParamSeq = new DecisionVariableDeclaration("myParamSeq", paramSeq, prj);
prj.add(myParamSeq);
// Refined Compound
refinedCType = new Compound("refinedCP", prj, param);
AttributeAssignment assng2 = new AttributeAssignment(refinedCType);
assng2.add(new Assignment(attr.getName(), OclKeyWords.ASSIGNMENT,
new ConstantValue(ValueFactory.createValue(bindingTime, bindingTime.getLiteral(2)))));
DecisionVariableDeclaration refinedValue1 = new DecisionVariableDeclaration("rVal1", IntegerType.TYPE, assng2);
assng2.add(refinedValue1);
AttributeAssignment assng3 = new AttributeAssignment(assng2);
assng3.add(new Assignment(attr.getName(), OclKeyWords.ASSIGNMENT,
new ConstantValue(ValueFactory.createValue(bindingTime, bindingTime.getLiteral(1)))));
DecisionVariableDeclaration refinedValue2 = new DecisionVariableDeclaration("rVal2", IntegerType.TYPE, assng3);
assng3.add(refinedValue2);
assng2.add(assng3);
refinedCType.add(assng2);
prj.add(refinedCType);
refCmpDecl = new DecisionVariableDeclaration("refinedCmp", refinedCType, prj);
prj.add(refCmpDecl);
// Freeze
IFreezable[] freezables = new IFreezable[3];
freezables[0] = myParam;
freezables[1] = myParamSeq;
freezables[2] = refCmpDecl;
FreezeVariableType iterType = new FreezeVariableType(freezables, prj);
DecisionVariableDeclaration freezeIter = new DecisionVariableDeclaration("b", iterType, prj);
Variable iterEx = new AttributeVariable(new Variable(freezeIter), iterType.getAttribute(attr.getName()));
ConstraintSyntaxTree selector = new OCLFeatureCall(iterEx, OclKeyWords.GREATER_EQUALS,
new ConstantValue(ValueFactory.createValue(bindingTime, bindingTime.getLiteral(2))));
selector.inferDatatype();
FreezeBlock freeze = new FreezeBlock(freezables, freezeIter, selector, prj);
prj.add(freeze);
}
示例12: testAssignmentBlockInCompounds
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests whether assignment blocks nested in compounds will be resolved correctly.
* @throws ValueDoesNotMatchTypeException Must not occur otherwise there is a failure inside the
* {@link ValueFactory}.
* @throws CSTSemanticException Must not occur otherwise there is a failure inside the constraint syntax trees.
*/
@Test
public void testAssignmentBlockInCompounds() throws ValueDoesNotMatchTypeException, CSTSemanticException {
Project project = new Project("testAssignmentBlockInCompounds");
// Annotation for project
Enum btType = new Enum("Bindingtime", project, "compile_time", "run_time");
project.add(btType);
Attribute btDecl = new Attribute("bindingtime", btType, project, project);
Value compileValue = ValueFactory.createValue(btType, btType.getLiteral(0));
ConstantValue constValCompiletime = new ConstantValue(compileValue);
btDecl.setValue(constValCompiletime);
project.attribute(btDecl);
project.add(btDecl);
Compound cType = new Compound("Dimension", project);
DecisionVariableDeclaration widthDecl = new DecisionVariableDeclaration("width", IntegerType.TYPE, cType);
cType.add(widthDecl);
// Overwrite default annotation of second declaration
AttributeAssignment assignBlock = new AttributeAssignment(cType);
Value runValue = ValueFactory.createValue(btType, btType.getLiteral(1));
ConstantValue constValRuntime = new ConstantValue(runValue);
Assignment assign = new Assignment(btDecl.getName(), OclKeyWords.ASSIGNMENT, constValRuntime);
assignBlock.add(assign);
DecisionVariableDeclaration heightDecl = new DecisionVariableDeclaration("height", IntegerType.TYPE,
assignBlock);
assignBlock.add(heightDecl);
cType.add(assignBlock);
project.add(cType);
DecisionVariableDeclaration dimDecl = new DecisionVariableDeclaration("dimension", cType, project);
project.add(dimDecl);
ProjectTestUtilities.validateProject(project);
Configuration config = new Configuration(project, true);
// Test correct behavior:
// dimension = compile_time
// dimension.width = compile_time
// dimension.height = run_time
IDecisionVariable dimVar = config.getDecision(dimDecl);
IDecisionVariable widthVar = null;
IDecisionVariable heightVar = null;
for (int i = 0; i < dimVar.getNestedElementsCount(); i++) {
IDecisionVariable nestedVar = dimVar.getNestedElement(i);
if (widthDecl == nestedVar.getDeclaration()) {
widthVar = nestedVar;
} else if (heightDecl == nestedVar.getDeclaration()) {
heightVar = nestedVar;
}
}
assertAnnotationValue(compileValue, dimVar);
assertAnnotationValue(compileValue, widthVar);
assertAnnotationValue(runValue, heightVar);
}
示例13: testAssignmentBlockAndAssignmentStatements
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests whether assignment blocks and assignment statements are considered correctly.
* A (re-)assigned value should overwrite the value from the assignment block.
* @throws ValueDoesNotMatchTypeException Must not occur otherwise there is a failure inside the
* {@link ValueFactory}.
* @throws CSTSemanticException Must not occur otherwise there is a failure inside the constraint syntax trees.
*/
@Test
public void testAssignmentBlockAndAssignmentStatements() throws ValueDoesNotMatchTypeException,
CSTSemanticException {
Project project = new Project("testAssignmentBlockAndAssignmentStatements");
// Annotation for project
Enum btType = new Enum("Bindingtime", project, "compile_time", "run_time");
project.add(btType);
Attribute btDecl = new Attribute("bindingtime", btType, project, project);
Value compileValue = ValueFactory.createValue(btType, btType.getLiteral(0));
ConstantValue constValCompiletime = new ConstantValue(compileValue);
btDecl.setValue(constValCompiletime);
project.attribute(btDecl);
project.add(btDecl);
Compound cType = new Compound("Dimension", project);
DecisionVariableDeclaration widthDecl = new DecisionVariableDeclaration("width", IntegerType.TYPE, cType);
cType.add(widthDecl);
// Overwrite default annotation of second declaration
AttributeAssignment assignBlock = new AttributeAssignment(cType);
Value runValue = ValueFactory.createValue(btType, btType.getLiteral(1));
ConstantValue constValRuntime = new ConstantValue(runValue);
Assignment assign = new Assignment(btDecl.getName(), OclKeyWords.ASSIGNMENT, constValRuntime);
assignBlock.add(assign);
DecisionVariableDeclaration heightDecl = new DecisionVariableDeclaration("height", IntegerType.TYPE,
assignBlock);
assignBlock.add(heightDecl);
cType.add(assignBlock);
project.add(cType);
DecisionVariableDeclaration dimDecl1 = new DecisionVariableDeclaration("dimension1", cType, project);
project.add(dimDecl1);
DecisionVariableDeclaration dimDecl2 = new DecisionVariableDeclaration("dimension2", cType, project);
project.add(dimDecl2);
// Re assign value for second instance
Constraint reassignment = new Constraint(project);
AttributeVariable annotationVar = new AttributeVariable(new CompoundAccess(new Variable(dimDecl2),
heightDecl.getName()), btDecl);
OCLFeatureCall call = new OCLFeatureCall(annotationVar, OclKeyWords.ASSIGNMENT, constValCompiletime);
reassignment.setConsSyntax(call);
project.add(reassignment);
ProjectTestUtilities.validateProject(project);
Configuration config = new Configuration(project, true);
// Test correct behavior:
// dimension1 = compile_time
// dimension1.width = compile_time
// dimension1.height = run_time
// dimension2 = compile_time
// dimension2.width = compile_time
// --> dimension2.height = compile_time <--
IDecisionVariable dimVar1 = config.getDecision(dimDecl1);
IDecisionVariable[] slots = getSlotsOfDimensionVariable(dimVar1, widthDecl, heightDecl);
IDecisionVariable widthVar = slots[0];
IDecisionVariable heightVar = slots[1];
assertAnnotationValue(compileValue, dimVar1);
assertAnnotationValue(compileValue, widthVar);
assertAnnotationValue(runValue, heightVar);
IDecisionVariable dimVar2 = config.getDecision(dimDecl2);
slots = getSlotsOfDimensionVariable(dimVar2, widthDecl, heightDecl);
widthVar = slots[0];
heightVar = slots[1];
assertAnnotationValue(compileValue, dimVar2);
assertAnnotationValue(compileValue, widthVar);
assertAnnotationValue(compileValue, heightVar);
}
示例14: assertSavingAttributeValues
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Part of {@link #testSaveConfiguredAttributes()}. Creates two attributes on different ways for the same
* {@link IDecisionVariable}, configures them and test whether they are saved correctly.
* @param changeStates One variable is created with a default value, the other with an assigned value. <tt>true</tt>
* will change the sates to check whether both kinds of attributes can be saved.
* @throws ValueDoesNotMatchTypeException Must not occur, otherwise string values cannot be assigned to string
* variables
* @throws CSTSemanticException Must not occur, otherwise assignment constraints cannot be created.
* @throws ConfigurationException Must not occcur, otherwise {@link Configuration#toProject(boolean)} is broken.
*/
private void assertSavingAttributeValues(boolean changeStates) throws ValueDoesNotMatchTypeException,
CSTSemanticException, ConfigurationException {
Project pro = new Project("test_Project_for_saving_attribute_values");
DecisionVariableDeclaration intA = new DecisionVariableDeclaration("intA", IntegerType.TYPE, pro);
pro.add(intA);
Attribute attributeDef1 = new Attribute("attribute1", StringType.TYPE, pro, pro);
String firstAttrValue = "a Default Value";
attributeDef1.setValue(firstAttrValue);
pro.add(attributeDef1);
pro.attribute(attributeDef1);
Attribute attributeDef2 = new Attribute("attribute2", StringType.TYPE, pro, pro);
pro.add(attributeDef2);
pro.attribute(attributeDef2);
// Assignment of 2nd attribute via constraint
Constraint constraint = new Constraint(pro);
AttributeVariable attrVar = new AttributeVariable(new Variable(intA), attributeDef2);
Value assignedValue = ValueFactory.createValue(attributeDef2.getType(), "Hello World");
ConstantValue cstValue = new ConstantValue(assignedValue);
OCLFeatureCall assignment = new OCLFeatureCall(attrVar, OclKeyWords.ASSIGNMENT, cstValue);
constraint.setConsSyntax(assignment);
pro.add(constraint);
// Test whether project is valid and can be used for testing
ProjectTestUtilities.validateProject(pro);
// Create configuration and check whether the attributes are configured correctly
// Configuration must be started with AssignmentResolver, since Reasoner is not available in this project.
Configuration config = new Configuration(pro, true);
IDecisionVariable var = config.getDecision(intA);
Assert.assertEquals(2, var.getAttributesCount());
IDecisionVariable firstAttribute = var.getAttribute(0);
IDecisionVariable secondAttribute = var.getAttribute(1);
Assert.assertNotNull(firstAttribute);
Assert.assertEquals(firstAttrValue, firstAttribute.getValue().getValue().toString());
Assert.assertSame(AssignmentState.DEFAULT, firstAttribute.getState());
Assert.assertNotNull(secondAttribute);
Assert.assertEquals(assignedValue, secondAttribute.getValue());
Assert.assertSame(config.getResolutionState(), secondAttribute.getState());
if (changeStates) {
firstAttribute.setValue(firstAttribute.getValue(), AssignmentState.ASSIGNED);
secondAttribute.setValue(secondAttribute.getValue(), AssignmentState.DEFAULT);
}
// Save configuration and test whether the attribute values appear inside the saved configuration
Project confProject = config.toProject(true, false);
StringWriter sWriter = new StringWriter();
IVMLWriter iWriter = new IVMLWriter(sWriter);
confProject.accept(iWriter);
String savedResult = sWriter.toString();
// Test: Attribute1 shall NOT be saved, Attribute 2 should be saved.
String assignmentStr1 = intA.getName() + "." + attributeDef1.getName() + " " + OclKeyWords.ASSIGNMENT + " \""
+ firstAttrValue + "\";";
String assignmentStr2 = intA.getName() + "." + attributeDef2.getName() + " " + OclKeyWords.ASSIGNMENT
+ " \"" + assignedValue.getValue().toString() + "\";";
Assert.assertEquals("Error: value of attribute \"" + firstAttribute.getDeclaration().getName() + "\" was saved"
+ " but its state is \"" + firstAttribute.getState() + "\"", changeStates,
savedResult.contains(assignmentStr1));
Assert.assertEquals("Error: value of attribute \"" + secondAttribute.getDeclaration().getName() + "\" was saved"
+ " but its state is \"" + secondAttribute.getState() + "\"", !changeStates,
savedResult.contains(assignmentStr2));
}
示例15: testFreezing
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Creates a project for freezing and checks the frozen states.
*
* @param runtimeMode whether the test shall happen in runtime reasoning mode
* @throws ValueDoesNotMatchTypeException shall not occur
* @throws CSTSemanticException shall not occur
*/
private void testFreezing(boolean runtimeMode) throws ValueDoesNotMatchTypeException, CSTSemanticException {
Project prj = new Project("test");
Enum bindingTime = new OrderedEnum("BindingTime", prj);
bindingTime.add(new EnumLiteral("compile", 1, bindingTime));
bindingTime.add(new EnumLiteral("monitor", 2, bindingTime));
bindingTime.add(new EnumLiteral("enact", 3, bindingTime));
prj.add(bindingTime);
Attribute attr = new Attribute("binding", bindingTime, prj, prj);
attr.setValue(ValueFactory.createValue(bindingTime, "compile"));
prj.attribute(attr);
prj.add(attr);
Compound param = new Compound("IntParameter", prj);
param.add(new DecisionVariableDeclaration("defaultValue", IntegerType.TYPE, param));
AttributeAssignment assng = new AttributeAssignment(param);
assng.add(new Assignment("binding", "=", new ConstantValue(ValueFactory.createValue(bindingTime, "enact"))));
assng.add(new DecisionVariableDeclaration("value", IntegerType.TYPE, param));
param.add(assng);
prj.add(param);
DecisionVariableDeclaration myParam = new DecisionVariableDeclaration("myParam", param, prj);
prj.add(myParam);
IFreezable[] freezables = new IFreezable[1];
freezables[0] = myParam;
FreezeVariableType iterType = new FreezeVariableType(freezables, prj);
DecisionVariableDeclaration freezeIter = new DecisionVariableDeclaration("b", iterType, prj);
Variable iterEx = new AttributeVariable(new Variable(freezeIter), iterType.getAttribute("binding"));
ConstraintSyntaxTree selector = new OCLFeatureCall(iterEx, ">=",
new ConstantValue(ValueFactory.createValue(bindingTime, "monitor")));
selector.inferDatatype();
FreezeBlock freeze = new FreezeBlock(freezables, freezeIter, selector, prj);
prj.add(freeze);
// debugging
System.out.println(StringProvider.toIvmlString(prj));
Configuration cfg = new Configuration(prj);
IDecisionVariable myParamVar = cfg.getDecision(myParam);
Assert.assertNotNull(myParamVar);
IDecisionVariable myParamVarDeflt = findNested(myParamVar, "defaultValue");
Assert.assertNotNull(myParamVarDeflt);
Assert.assertEquals(1, myParamVarDeflt.getAttributesCount());
IDecisionVariable myParamVarValue = findNested(myParamVar, "value");
Assert.assertNotNull(myParamVarValue);
Assert.assertEquals(1, myParamVarValue.getAttributesCount());
ReasonerConfiguration rConfig = new ReasonerConfiguration();
rConfig.setRuntimeMode(runtimeMode);
// Perform reasoning
Engine engine = new Engine(prj, cfg, rConfig, ProgressObserver.NO_OBSERVER);
engine.reason();
Assert.assertEquals(AssignmentState.FROZEN, myParamVarDeflt.getState());
Assert.assertNotEquals(AssignmentState.FROZEN, myParamVarValue.getState());
//Assert.assertNotEquals(AssignmentState.FROZEN, myParamVar.getState());
}