當前位置: 首頁>>代碼示例>>Java>>正文


Java OCLFeatureCall.inferDatatype方法代碼示例

本文整理匯總了Java中net.ssehub.easy.varModel.cst.OCLFeatureCall.inferDatatype方法的典型用法代碼示例。如果您正苦於以下問題:Java OCLFeatureCall.inferDatatype方法的具體用法?Java OCLFeatureCall.inferDatatype怎麽用?Java OCLFeatureCall.inferDatatype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.ssehub.easy.varModel.cst.OCLFeatureCall的用法示例。


在下文中一共展示了OCLFeatureCall.inferDatatype方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createFreezeBlock

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的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;
}
 
開發者ID:QualiMaster,項目名稱:QM-EASyProducer,代碼行數:40,代碼來源:Utils.java

示例2: testBasisOperation

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的package包/類
/**
 * Copies an operation and compares this with the origin.
 * @param operation the current operation which should be copied
 * @throws CSTSemanticException should not occur
 */
private void testBasisOperation(Operation operation) throws CSTSemanticException {

    Variable operand = map.get(operation.getOperand());
    
    //create a new OCLFeatureCall with the same operand, operation and parameters
    if (null != operand && operation != AnyType.AS_TYPE) { // asType cannot be tested in that way 
        Variable[] parameters = new Variable[operation.getParameterCount()];
        for (int j = 0; j < operation.getParameterCount(); j++) {                
            parameters[j] = map.get(operation.getParameterType(j));  
        }
     
        if (MetaType.ALL_INSTANCES != operation) {
            OCLFeatureCall call = new OCLFeatureCall(operand, operation.getName(), parameters);
            IDatatype opType = operation.getReturns();
            IDatatype callType = call.inferDatatype();
            Assert.assertTrue("expected type " + opType + " is not the same as " + callType, 
                TypeQueries.sameTypes(operation.getReturns(), call.inferDatatype()));
        }
    }
    
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:27,代碼來源:OperationTest.java

示例3: setUp

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的package包/類
/**
 * Creates common parts, which are used in all tests.
 * 
 * @throws CSTSemanticException in case of CST problems (shall not occur)
 * @throws ConfigurationException in case of configuration problems (shall not occur)
 * @throws ValueDoesNotMatchTypeException in case of value assignment problems (shall not occur)
 */
@Before
public void setUp() throws CSTSemanticException, ConfigurationException, ValueDoesNotMatchTypeException {
    Project prj = new Project("KeyPartTest");
    Compound fieldType = createFieldType(prj);
    Compound field = createFieldDef(prj, fieldType);
    DerivedDatatype fields = new DerivedDatatype("Fields", new Sequence("seqField", field, prj), prj);
    prj.add(fields);
    Compound tuple = createTuple(prj, fields);
    DerivedDatatype tuples = new DerivedDatatype("Tuples", new Sequence("seqTuple", tuple, prj), prj);
    prj.add(tuples);
    
    createCollectFieldTypesOperation(prj, tuples, tuple, field, fieldType);
    createFieldCheckOperation(prj, tuples);
    
    intType = new DecisionVariableDeclaration("intType", fieldType, prj);
    prj.add(intType);
    stringType = new DecisionVariableDeclaration("stringType", fieldType, prj);
    prj.add(stringType);
    tuples1 = new DecisionVariableDeclaration("output", tuples, prj);
    prj.add(tuples1);
    tuples2 = new DecisionVariableDeclaration("aOutput", tuples, prj);
    prj.add(tuples2);
    if (DEBUG) {
        System.out.println(StringProvider.toIvmlString(prj));
    }
    
    expr = new OCLFeatureCall(new Variable(tuples1), "fieldCheck", prj, new Variable(tuples2));
    expr.inferDatatype();
    if (DEBUG) {
        System.out.println(StringProvider.toIvmlString(expr));
    }
    
    cfg = new Configuration(prj);
    setValue(cfg, intType, new Object[]{"name", "INTEGER"});
    setValue(cfg, stringType, new Object[]{"name", "STRING"});
    visitor = new EvaluationVisitor();
    visitor.init(cfg, AssignmentState.DEFAULT, false, null);
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:46,代碼來源:CustomOpOnCustomDataTypesTest.java

示例4: testMultiAnd

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的package包/類
/**
 * Tests the multi-and expression.
 * 
 * @throws CSTSemanticException in case of constraint failures (shall not occur)
 * @throws ValueDoesNotMatchTypeException if a value does not match the expected type (shall not occur)
 * @throws ConfigurationException if a value cannot be configured (shall not occur)
 */
@Test
public void testMultiAnd() throws ValueDoesNotMatchTypeException, CSTSemanticException, ConfigurationException {
    Project prj = new Project("test");
    DecisionVariableDeclaration var1 = new DecisionVariableDeclaration("var1", IntegerType.TYPE, prj);
    var1.setValue(ValueFactory.createValue(IntegerType.TYPE, 1));
    prj.add(var1);
    DecisionVariableDeclaration var2 = new DecisionVariableDeclaration("var2", IntegerType.TYPE, prj);
    var2.setValue(ValueFactory.createValue(IntegerType.TYPE, 2));
    prj.add(var2);
    DecisionVariableDeclaration var3 = new DecisionVariableDeclaration("var3", IntegerType.TYPE, prj);
    var3.setValue(ValueFactory.createValue(IntegerType.TYPE, 3));
    prj.add(var3);

    OCLFeatureCall call1 = new OCLFeatureCall(new Variable(var1), OclKeyWords.LESS, new Variable(var2));
    call1.inferDatatype();
    OCLFeatureCall call2 = new OCLFeatureCall(new Variable(var2), OclKeyWords.LESS, new Variable(var3));
    call1.inferDatatype();
    MultiAndExpression maEx = new MultiAndExpression(call1, call2);
    maEx.inferDatatype();

    Configuration config = new Configuration(prj);
    EvaluationVisitor visitor = new EvaluationVisitor();
    visitor.init(config, AssignmentState.DEFAULT, false, null);
    visitor.visit(maEx);

    Assert.assertTrue(visitor.getResult() instanceof BooleanValue);
    Assert.assertEquals(true, ((BooleanValue) visitor.getResult()).getValue().booleanValue());
    
    config.getDecision(var2).setValue(ValueFactory.createValue(IntegerType.TYPE, 5), AssignmentState.ASSIGNED);
    visitor.visit(maEx);

    Assert.assertTrue(visitor.getResult() instanceof BooleanValue);
    Assert.assertEquals(false, ((BooleanValue) visitor.getResult()).getValue().booleanValue());

    visitor.clearResult();
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:44,代碼來源:EvaluationVisitorTest.java

示例5: testTooManyParametersInOperation

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的package包/類
/**
 * Copies an Operation which a too long parameter list.
 * @param operation the current operation which should be changed
 */
private void testTooManyParametersInOperation(Operation operation) {        
    Variable operand = map.get(operation.getOperand());
    
    if (null != operand) {
        //creates a "too long" array
        Variable[] parameters = new Variable[operation.getParameterCount() + 1];
        for (int i = 0; i < operation.getParameterCount(); i++) {
            parameters[i] = map.get(operation.getParameterType(i));
        }
        
        //try to add a parameter a second time to the parameter array
        int pos = operation.getParameterCount();
        if (0 != pos) {
            parameters[pos] = map.get(operation.getParameterType(pos - 1));
        } else {
            parameters[pos] = map.get(BooleanType.TYPE);
        }
        OCLFeatureCall call = new OCLFeatureCall(operand, operation.getName(), parameters);
        
        try {
            call.inferDatatype();
            Assert.fail();
        } catch (CSTSemanticException cstExc) {
            //Should occur --> everything is ok
        }
    }        
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:32,代碼來源:OperationTest.java

示例6: testSimpleImplication

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的package包/類
/**
 * Tests a simple failing implication, left => right.
 * 
 * @param left the left clause data
 * @param right the right clause data
 * @param deviation the expected deviation of the actual variable due to <code>right.operation</code> and 
 *    <code>right.limit</code>, may be <b>null</b> if no deviation is expected 
 * 
 * @throws ValueDoesNotMatchTypeException shall not occur
 * @throws CSTSemanticException shall not occur
 * @throws ConfigurationException shall not occur
 */
private void testSimpleImplication(ClauseData left, ClauseData right, Double deviation) 
    throws ValueDoesNotMatchTypeException, CSTSemanticException, ConfigurationException {
    ReasonerConfiguration rCfg = new ReasonerConfiguration();
    rCfg.setRuntimeMode(true);

    Project prj = new Project("test");

    // relevantVariables
    DecisionVariableDeclaration declLeft = new DecisionVariableDeclaration("monVarLeft", RealType.TYPE, prj);
    prj.add(declLeft);
    DecisionVariableDeclaration declRight = new DecisionVariableDeclaration("monVarRight", RealType.TYPE, prj);
    prj.add(declRight);
    
    OCLFeatureCall cstLeft = new OCLFeatureCall(new Variable(declLeft), left.operation, new ConstantValue(
         ValueFactory.createValue(RealType.TYPE, left.limit)));
    cstLeft.inferDatatype();
    OCLFeatureCall cstRight = new OCLFeatureCall(new Variable(declRight), right.operation, new ConstantValue(
        ValueFactory.createValue(RealType.TYPE, right.limit)));
    cstRight.inferDatatype();
    ConstraintSyntaxTree cst = new OCLFeatureCall(cstLeft, "implies", cstRight);
    cst.inferDatatype();
    
    prj.add(new Constraint(cst, prj));

    Configuration cfg = new Configuration(prj);
    cfg.getDecision(declLeft).setValue(ValueFactory.createValue(RealType.TYPE, left.value), 
        AssignmentState.ASSIGNED);
    cfg.getDecision(declRight).setValue(ValueFactory.createValue(RealType.TYPE, right.value), 
        AssignmentState.ASSIGNED);

    ReasoningResult rResult = ReasonerFrontend.getInstance().check(prj, cfg, rCfg, ProgressObserver.NO_OBSERVER);
    Assert.assertNotNull(rResult);
    Assert.assertEquals(deviation != null, rResult.hasConflict());
    
    AnalyzerVisitor analyzer = new AnalyzerVisitor();
    List<Violation> violations = analyzer.analyze(cfg, rResult);
    analyzer.clear();
    
    if (null != deviation) { // we expect one violation, for the relevant variable
        Assert.assertNotNull(violations);
        Assert.assertEquals(1, violations.size()); 
        Violation violation = violations.get(0);
        
        Assert.assertEquals(cfg.getDecision(declRight), violation.getVariable());
        Assert.assertEquals(right.operation, violation.getOperation());
        Assert.assertEquals(deviation, violation.getDeviation(), 0.05);
        Assert.assertNotNull(violation.getDeviationPercentage());
        Assert.assertNotNull(Math.abs(violation.getDeviationPercentage()) >= 0.00005);            
    } else { // no violation expected
        Assert.assertTrue(null == violations || 1 == violations.size());    
    }
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:65,代碼來源:AnalyzerTest.java

示例7: testReusedOperationsInConstraintVar

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的package包/類
/**
 * Simple test whether Operation definitions are kept correctly or whether name space spearators are introduced.
 * The later one occurs if the constraint is not resolved correctly.
 * @throws ValueDoesNotMatchTypeException Must not occur, otherwise the {@link ValueFactory} or
 * {@link net.ssehub.easy.varModel.model.AbstractVariable#setValue(String)} are broken.
 * @throws CSTSemanticException Must not occur, otherwise
 * @throws IOException Must not occur, otherwise {@link IVMLWriter#flush()} is not working.
 */
@Test
public void testReusedOperationsInConstraintVar() throws ValueDoesNotMatchTypeException, CSTSemanticException,
    IOException {
    
    Project p = new Project("testReusedOperationsInConstraintVar");
    DecisionVariableDeclaration declA = new DecisionVariableDeclaration("varA", IntegerType.TYPE, p);
    declA.setValue(10);
    p.add(declA);
    DecisionVariableDeclaration constDecl = new DecisionVariableDeclaration("constVar", ConstraintType.TYPE, p);
    p.add(constDecl);
    // A user defined operation, re-using the constraint variable
    OperationDefinition customOp = new OperationDefinition(p);
    DecisionVariableDeclaration paramDecl = new DecisionVariableDeclaration("dv", IntegerType.TYPE, customOp);
    OCLFeatureCall funcCst = new OCLFeatureCall(new Variable(paramDecl), OclKeyWords.LESS, THOUSAND);
    funcCst.inferDatatype();
    CustomOperation functionDef = new CustomOperation(BooleanType.TYPE, "operationCheck", p.getType(), funcCst,
        new DecisionVariableDeclaration[] {paramDecl});
    customOp.setOperation(functionDef);
    p.add(customOp);
    // Second operation, re-using the first one
    OperationDefinition customOp2 = new OperationDefinition(p);
    DecisionVariableDeclaration paramDecl2 = new DecisionVariableDeclaration("dv", IntegerType.TYPE, customOp2);
    OCLFeatureCall compare = new OCLFeatureCall(new Variable(paramDecl2), OclKeyWords.GREATER, ZERO);
    OCLFeatureCall callOp1 = new OCLFeatureCall(new Variable(paramDecl2), customOp.getName(), p);
    OCLFeatureCall funcCst2 = new OCLFeatureCall(compare, OclKeyWords.AND, callOp1);
    CustomOperation functionDef2 = new CustomOperation(BooleanType.TYPE, "operationCheck2", p.getType(), funcCst2,
        new DecisionVariableDeclaration[] {paramDecl2});
    funcCst2.inferDatatype();
    customOp2.setOperation(functionDef2);
    p.add(customOp2);
    
    // Default value for constraint var + freeze
    OCLFeatureCall comparison = new OCLFeatureCall(new Variable(declA), customOp.getName(), p);
    comparison.inferDatatype();
    constDecl.setValue(comparison);
    p.add(new FreezeBlock(new IFreezable[] {declA, constDecl}, null, null, p));
    
    ProjectTestUtilities.validateProject(p);
    Configuration config = new Configuration(p);
    
    ProjectRewriteVisitor rewriter = new ProjectRewriteVisitor(p, FilterType.ALL);
    rewriter.addModelCopyModifier(new FrozenConstraintVarFilter(config));
    p.accept(rewriter);
    ProjectTestUtilities.validateProject(p);
    StringWriter sWriter = new StringWriter();
    IVMLWriter iWriter = new IVMLWriter(sWriter);
    p.accept(iWriter);
    iWriter.flush();
    Assert.assertFalse(sWriter.toString().contains(IvmlKeyWords.NAMESPACE_SEPARATOR));
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:59,代碼來源:ProjectRewriteVisitorTest.java

示例8: testWrongParametersInOperation

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的package包/類
/**
 * Copies an Operation with a wrong parameter list.
 * @param operation the current operation which should be changed
 */
private void testWrongParametersInOperation(Operation operation) {
    
    Variable operand = map.get(operation.getOperand());
    
    Boolean found = false;
    Operation op = Operation.getOperation(0);
    if (0 != operation.getParameterCount()) {
        //search for a operation with operationsCount == 0
        for (int i = 0; i < Operation.getOperationsCount() && !found; i++) {
            if (0 == Operation.getOperation(i).getParameterCount()) {
                op = Operation.getOperation(i);
                found = true;
            }
        }            
    } else {
        //search for a operation with operationsCount != 0
        for (int i = 0; i < Operation.getOperationsCount() && !found; i++) {
            if (0 != Operation.getOperation(i).getParameterCount()) {
                op = Operation.getOperation(i);
                found = true;
            }
        }
    }
    
    //create a new OCLFeatureCall with the same variables of the operation except the parameters
    if (null != operand && op.getParameterCount() > 0) {
        Variable[] parameters = new Variable[op.getParameterCount()];
        for (int i = 0; i < op.getParameterCount(); i++) {
            parameters[i] = map.get(op.getParameterType(i));           
        }

        //copy the operation with a wrong parameter-list
        OCLFeatureCall call = new OCLFeatureCall(operand, operation.getName(), parameters);
        try {
            call.inferDatatype();                
            System.out.println(operation.getName());
            System.out.println(operation.getOperand().getName());
            System.out.println(operation.getParameterCount());
            System.out.println(call.getParameterCount());                
            Assert.fail();
        } catch (CSTSemanticException cstExc) {
            //Should occur --> everything is ok
        }
    }        
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:50,代碼來源:OperationTest.java

示例9: getTranslator

import net.ssehub.easy.varModel.cst.OCLFeatureCall; //導入方法依賴的package包/類
/**
 * Returns for the given {@link OCLFeatureCall} a {@link TranslationFragment}, which is able to translate
 * the given {@link OCLFeatureCall} automatically into Drools specific code.
 * @param constraint An {@link OCLFeatureCall}, which should be translated 
 * @return A {@link TranslationFragment} instance, which is able to translate the given {@link OCLFeatureCall}
 *     into Drools specific code.
 * @throws CSTSemanticException Will be thrown in case that {@link OCLFeatureCall#inferDatatype()} leads
 *     to this exception.
 */
public static TranslationFragment getTranslator(OCLFeatureCall constraint) throws CSTSemanticException {
    // Ensure that constraint.getResolvedOperation() is possible
    constraint.inferDatatype();
    Operation operation = constraint.getResolvedOperation();
    TranslationFragment translator = TRANSLATION_MAP.get(operation);
    
    return translator;
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:18,代碼來源:OCLFeatureTranslationFactory.java


注:本文中的net.ssehub.easy.varModel.cst.OCLFeatureCall.inferDatatype方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。