Examples of Declaration


Examples of org.candle.decompiler.intermediate.expression.Declaration

            }
           
           
            //otherwise, let's see if the declaration is an iterator.
            if(declaration.getExpression() instanceof Declaration) {
              Declaration declarationExpression = (Declaration)declaration.getExpression();
              Variable v = (Variable)declarationExpression.getAssignment().getLeftHandSide();
             
              //check to see if the declaration is the same as the iterator's name.
              if(StringUtils.equals(iteratorName, v.getName())) {
                LOG.debug("Identified Likely Iterator: "+v.getName());
               
                //get the ".next()" statement, which should be the first child.
                AbstractIntermediate firstChild = igc.getTrueTarget(line);
               
                //see if this is a statement, if the statement is an assignment...
                //then check the right side to see if it is an invocation.. and the invocation has the method name "next"...
                if(firstChild instanceof StatementIntermediate) {
                  StatementIntermediate nextStatement = (StatementIntermediate)firstChild;
                  if(nextStatement.getExpression() instanceof Declaration) {
                    //the statement is indeed a declaration.
                    Declaration nextDeclaration = (Declaration)nextStatement.getExpression();
                   
                    if(nextDeclaration.getAssignment().getRightHandSide() instanceof MethodInvocation) {
                      MethodInvocation nextMethodInvocation = (MethodInvocation)nextDeclaration.getAssignment().getRightHandSide();
                     
                      if(StringUtils.equals("next", nextMethodInvocation.getMethodName())) {
                        //YES.
                       
                        //check to see if the next method is on the candidate iterator.
                        if(nextMethodInvocation.getTarget() instanceof Variable) {
                          Variable nextMethodTarget = (Variable)nextMethodInvocation.getTarget();
                         
                         
                          if(StringUtils.equals(iteratorName, nextMethodTarget.getName())) {
                            LOG.info("Definitely an enhanced for loop.");
                           
                            if(declarationExpression.getAssignment().getRightHandSide() instanceof MethodInvocation) {
                              MethodInvocation iteratorInvocation = (MethodInvocation)declarationExpression.getAssignment().getRightHandSide();
                             
                              if(StringUtils.equals("iterator", iteratorInvocation.getMethodName())) {
                                //now, we are pretty certain this is an enhanced for loop...  we can chop up the graph.
                               
                                EnhancedForIntermediate enhancedFor = new EnhancedForIntermediate(line, nextDeclaration.getVariable(), iteratorInvocation.getTarget());
                                igc.getGraph().addVertex(enhancedFor);
                               
                                igc.redirectSuccessors(line, enhancedFor);
                                igc.redirectPredecessors(line, enhancedFor);
                                igc.getGraph().removeVertex(line);
View Full Code Here

Examples of org.drools.core.rule.Declaration

                reader = null;
            } finally {
                context.setDialect( dialect );
            }
        } else {
            Declaration decl = context.getDeclarationResolver().getDeclarations( context.getRule() ).get(fieldName);
            if (decl != null && decl.getExtractor() instanceof ClassFieldReader && "this".equals(((ClassFieldReader)decl.getExtractor()).getFieldName())) {
                return decl.getExtractor();
            }

            boolean alternatives = false;
            try {
                Map<String, Class< ? >> declarations = getDeclarationsMap( descr, context, false );
View Full Code Here

Examples of org.drools.rule.Declaration

    }
   
    private boolean checkProcessInstance(Activation activation) {
      final Map<?, ?> declarations = activation.getSubRule().getOuterDeclarations();
        for ( Iterator<?> it = declarations.values().iterator(); it.hasNext(); ) {
            Declaration declaration = (Declaration) it.next();
            if ("processInstance".equals(declaration.getIdentifier())) {
              Object value = declaration.getValue(
              ((StatefulKnowledgeSessionImpl) getProcessInstance().getKnowledgeRuntime()).session,
              ((InternalFactHandle) activation.getTuple().get(declaration)).getObject());
              if (value instanceof ProcessInstance) {
                return ((ProcessInstance) value).getId() == getProcessInstance().getId();
              }
View Full Code Here

Examples of org.drools.rule.Declaration

    }
   
    private boolean checkProcessInstance(Activation activation) {
      final Map<?, ?> declarations = activation.getSubRule().getOuterDeclarations();
        for ( Iterator<?> it = declarations.values().iterator(); it.hasNext(); ) {
            Declaration declaration = (Declaration) it.next();
            if ("processInstance".equals(declaration.getIdentifier())) {
              Object value = declaration.getValue(
              ((StatefulKnowledgeSessionImpl) getProcessInstance().getKnowledgeRuntime()).session,
              ((InternalFactHandle) activation.getTuple().get(declaration)).getObject());
              if (value instanceof ProcessInstance) {
                return ((ProcessInstance) value).getId() == getProcessInstance().getId();
              }
View Full Code Here

Examples of org.drools.rule.Declaration

        this.rules = ruleSet.getRules( );
    }

    public RuleBase buildRuleBase()
    {
        Declaration declaration;
        Rule rule;
        ParameterNode parameterNode;
        for ( int i = 0; i < rules.length; i++ )
        {
            rule = rules[i];
            for ( Iterator j = rule.getParameterDeclarations( ).iterator( ); j.hasNext( ); )
            {
                declaration = ( Declaration ) j.next();

                parameterNode = new ParameterNode( rete.getOrCreateObjectTypeNode( declaration.getObjectType( ) ),
                                                   declaration );

                parameterNode.attach( );

                List conditions = rule.getConditions( );
View Full Code Here

Examples of org.drools.rule.Declaration

        Set refs = visitor.getVariables( );

        List decls = new LinkedList( );
        for ( Iterator declIter = availDecls.iterator( ); declIter.hasNext( ); )
        {
            Declaration eachDecl = ( Declaration ) declIter.next( );

            if ( refs.contains( eachDecl.getIdentifier( ) ) )
            {
                decls.add( eachDecl );
                refs.remove( eachDecl.getIdentifier( ) );
            }
        }

        return ( Declaration[] ) decls.toArray( new Declaration[ decls.size( ) ] );
    }
View Full Code Here

Examples of org.drools.rule.Declaration

     * @return The dictionary
     */
    protected PyDictionary setUpDictionary(Tuple tuple,
                                           Iterator declIter) throws Exception
    {
        Declaration eachDecl;

        ObjectType objectType;
        String type;
        Class clazz;
        int nestedClassPosition;
        int dotPosition;

        PyDictionary dict = new PyDictionary( );

        // dict.setdefault( new PyString( "q" ), qFunc ); //add tenerary
        // function

        RuleBaseContext ruleBaseContext = rule.getRuleSet( ).getRuleBaseContext( );
        ClassLoader cl = (ClassLoader) ruleBaseContext.get( "smf-classLoader" );
        if ( cl == null )
        {
            cl = Thread.currentThread( ).getContextClassLoader( );
            ruleBaseContext.put( "smf-classLoader",
                                 cl );
        }

        if ( cl == null )
        {
            cl = getClass( ).getClassLoader( );
            ruleBaseContext.put( "smf-classLoader",
                                 cl );
        }
       

        while ( declIter.hasNext( ) )
        {
            eachDecl = (Declaration) declIter.next( );

            dict.setdefault( new PyString( eachDecl.getIdentifier( ).intern( ) ),
                             Py.java2py( tuple.get( eachDecl ) ) );

            objectType = eachDecl.getObjectType( );

            if ( objectType instanceof ClassObjectType )
            {
                clazz = ((ClassObjectType) objectType).getType( );
                type = clazz.getName( );
View Full Code Here

Examples of org.drools.rule.Declaration

        List decls = new ArrayList( );

        Set refs = ( Set ) visitor.eval_input( expr );

        Iterator declIter = availDecls.iterator( );
        Declaration eachDecl;

        while ( declIter.hasNext( ) )
        {
            eachDecl = ( Declaration ) declIter.next( );

            if ( refs.contains( eachDecl.getIdentifier( ) ) )
            {
                decls.add( eachDecl );
                refs.remove( eachDecl.getIdentifier( ) );
            }
        }

        return ( Declaration[] ) decls.toArray( new Declaration[ decls.size( ) ] );
    }
View Full Code Here

Examples of org.drools.rule.Declaration

    public void testGetRequiredTupleMembers() throws Exception {
        Rule rule = new Rule("for-test.declaration-factory");
        Argument[] parameterValues = new Argument[3];
        MockControl controlObjectType_1 = mocks.createControl(ObjectType.class);
        MockControl controlObjectType_2 = mocks.createControl(ObjectType.class);
        Declaration expectedDeclaration_1 = rule.addParameterDeclaration(
                "id-1", (ObjectType) controlObjectType_1.getMock());
        Declaration expectedDeclaration_2 = rule.addParameterDeclaration(
                "id-2", (ObjectType) controlObjectType_2.getMock());

        parameterValues[0] = new ApplicationDataArgument("name", Object.class);
        parameterValues[1] = new FactArgument(expectedDeclaration_1);
        parameterValues[2] = new FactArgument(expectedDeclaration_2);
View Full Code Here

Examples of org.drools.rule.Declaration

        // identifiers based on the parameter class (ie, all identifiers for a given type
        // will be identical).
        List parameterDeclarations = rule.getParameterDeclarations();
        assertEquals(expectedDeclarationObjectTypes.size(), parameterDeclarations.size());
        for (Iterator iter = parameterDeclarations.iterator(); iter.hasNext();) {
            Declaration declaration = (Declaration) iter.next();
            if (!expectedDeclarationObjectTypes.contains(declaration.getObjectType())) {
                fail("Unexpected rule declaration object-type: " + declaration.getObjectType());
            }
        }

        List conditions = rule.getConditions();
        assertEquals(2, conditions.size());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.