Package org.eclipse.dltk.ast.expressions

Examples of org.eclipse.dltk.ast.expressions.Expression


      }
    }

    protected void postProcess(Expression node) {
      if (node instanceof Assignment) {
        Expression variable = ((Assignment) node).getVariable();
        if (variable instanceof VariableReference) {
          VariableReference variableReference = (VariableReference) variable;
          if (variableName.equals(variableReference.getName())) {
            setNextRange();
          }
View Full Code Here


  private IGoal[] produceNextSubgoal(IGoal previousGoal,
      IEvaluatedType previousResult, GoalState goalState) {

    ExpressionTypeGoal typedGoal = (ExpressionTypeGoal) goal;
    Expression expression = (Expression) typedGoal.getExpression();

    Expression receiver;
    Expression field;
    if (expression instanceof FieldAccess) {
      FieldAccess fieldAccess = (FieldAccess) expression;
      receiver = fieldAccess.getDispatcher();
      field = fieldAccess.getField();
    } else if (expression instanceof StaticFieldAccess) {
View Full Code Here

        ASTVisitor visitor = new ASTVisitor() {
          public boolean visitGeneral(ASTNode node) throws Exception {
            if (node instanceof ReturnStatement) {
              ReturnStatement statement = (ReturnStatement) node;
              Expression expr = statement.getExpr();
              if (expr == null) {
                evaluated.add(PHPSimpleTypes.VOID);
              } else {
                subGoals.add(new ExpressionTypeGoal(
                    innerContext, expr));
              }
            } else if (node instanceof YieldExpression) {
              YieldExpression statement = (YieldExpression) node;
              Expression expr = statement.getExpr();
              if (expr == null) {
                yieldEvaluated.add(PHPSimpleTypes.NULL);
              } else {
                final ExpressionTypeGoal yg = new ExpressionTypeGoal(
                    innerContext, expr);
View Full Code Here

    private void parseVariablesFromArray(ArrayCreation array, String viewPath) {


        for (ArrayElement element : array.getElements()) {

            Expression key = element.getKey();
            Expression value = element.getValue();

            if (key.getClass() == Scalar.class) {

                Scalar varName = (Scalar) key;

                // something in the form:  return array ('foo' => $bar);
                // check the type of $bar:
                if (value.getClass() == VariableReference.class) {

                    VariableReference ref = (VariableReference) value;

                    for (TemplateVariable variable : deferredVariables) {

                        // we got the variable, add it the the templateVariables
                        if (ref.getName().equals(variable.getName())) {
                            // alter the variable name

                            variable.setName(varName.getValue());

                            templateVariables.put(variable, viewPath);
                            break;
                        }
                    }

                    // this is more complicated, something like:
                    // return array('form' => $form->createView());
                    // we need to infer $form and then check the returntype of createView()
                } else if(value.getClass() == PHPCallExpression.class) {

                    PHPCallExpression callExp = (PHPCallExpression) value;

                    VariableReference varRef = null;
                    try {
                        varRef = (VariableReference) callExp.getReceiver();
                    } catch (ClassCastException e) {
                        Logger.log(Logger.WARNING, callExp.getReceiver().getClass().toString()
                                + " could not be cast to VariableReference in " + currentMethod.getName() );

                    }


                    if (varRef == null) {
                        continue;
                    }

                    SimpleReference callName = callExp.getCallName();

                    // we got the variable name (in this case $form)
                    // now search for the defferedVariable:
                    for (TemplateVariable deferred : deferredVariables) {

                        // we got it, find the returntype of the
                        // callExpression
                        if (deferred.getName().equals(varRef.getName())) {

                            TemplateVariable tempVar = SymfonyModelAccess.getDefault()
                                    .createTemplateVariableByReturnType(source, currentMethod,
                                            callName, deferred.getClassName(), deferred.getNamespace(),
                                            varRef.getName(), cache);

                            templateVariables.put(tempVar, viewPath);
                            break;
                        }
                    }

                    // this is a direct ClassInstanceCreation, ie:
                    // return array('user' => new User());
                } else if (value.getClass() == ClassInstanceCreation.class) {

                    ClassInstanceCreation instance = (ClassInstanceCreation) value;

                    if (instance.getClassName().getClass() == FullyQualifiedReference.class) {

                        FullyQualifiedReference fqcn = (FullyQualifiedReference) instance.getClassName();
                        NamespaceReference nsRef = createFromFQCN(fqcn);

                        if (nsRef != null) {
                            TemplateVariable variable = new TemplateVariable(currentMethod, varName.getValue(),
                                    varName.sourceStart(), varName.sourceEnd(), nsRef.getNamespace(), nsRef.getClassName());
                            templateVariables.put(variable, viewPath);
                        }
                    }
                } else {

                    Logger.debugMSG("array value: " + value.getClass());
                }
            }
        }
    }
View Full Code Here

                    @Override
                    public boolean visit(ArrayElement s) throws Exception
                    {

                        Expression key = s.getKey();
                        Expression value = s.getValue();

                        if (key == null | value == null) {
                            return false;
                        }

                        if (key.getClass() == Scalar.class && value.getClass() == ClassInstanceCreation.class) {

                            Scalar name = (Scalar) key;
                            ClassInstanceCreation filterClass = (ClassInstanceCreation) value;

                            CallArgumentsList ctorParams = filterClass.getCtorParams();
                            Object child = ctorParams.getChilds().get(0);

                            if (child instanceof VariableReference && ((VariableReference)child).getName().equals("$this") &&
                                    filterClass.getClassName().toString().equals((TwigCoreConstants.TWIG_FILTER_METHOD))) {
                               
                                    if (ctorParams.getChilds().size() > 2 && ctorParams.getChilds().get(1) instanceof Scalar) {
                                        Scalar internal = (Scalar) ctorParams.getChilds().get(1);
                                        String elemName = name.getValue().replaceAll("['\"]", "");
                                        Filter filter = new Filter(elemName);
                                        filter.setInternalFunction(internal.getValue().replaceAll("['\"]", ""));
                                        filter.setPhpClass(currentClass.getName());
                                        filters.add(filter);
                                    }
                            }
                           
                            if (!(child instanceof Scalar)) {
                                return true;
                            }

                            Scalar internal = (Scalar) child;

                            if (filterClass.getClassName().toString().equals(TwigCoreConstants.TWIG_FILTER_FUNCTION)) {

                                String elemName = name.getValue().replaceAll("['\"]", "");

                                Filter filter = new Filter(elemName);
                                filter.setInternalFunction(internal.getValue()
                                        .replaceAll("['\"]", ""));
                                filter.setPhpClass(currentClass.getName());

                                filters.add(filter);

                            }
                        }
                        return true;
                    }
                });

            } else if (inTwigExtension && TwigCoreConstants.GET_TESTS.equals(s.getName())) {

                phpMethod.traverse(new PHPASTVisitor()
                {

                    @Override
                    public boolean visit(ArrayElement s) throws Exception
                    {

                        Expression key = s.getKey();
                        Expression value = s.getValue();

                        if (key == null || value == null)
                            return false;

                        if (key.getClass() == Scalar.class && value.getClass() == ClassInstanceCreation.class) {

                            Scalar name = (Scalar) key;
                            ClassInstanceCreation functionClass = (ClassInstanceCreation) value;

                            CallArgumentsList args = functionClass.getCtorParams();
                            Scalar internalFunction = (Scalar) args.getChilds().get(0);

                            if (internalFunction == null)
                                return true;

                            if (functionClass.getClassName().toString().equals(TwigCoreConstants.TWIG_TEST_FUNCTION)) {

                                String elemName = name.getValue().replaceAll("['\"]", "");

                                JSONObject metadata = new JSONObject();
                                metadata.put(TwigType.PHPCLASS,currentClass.getName());

                                Test test = new Test(elemName);
                                test.setPhpClass(currentClass.getName());
                                test.setInternalFunction(internalFunction.getValue().replaceAll("['\"]", ""));
                                tests.add(test);

                            }
                        }
                        return true;
                    }
                });

            } else if (inTwigExtension&& TwigCoreConstants.GET_FUNCTIONS.equals(s.getName())) {

                phpMethod.traverse(new PHPASTVisitor()
                {
                    @Override
                    public boolean visit(ArrayElement s) throws Exception
                    {

                        Expression key = s.getKey();
                        Expression value = s.getValue();

                        if (key == null || value == null) {
                            return false;
                        }

                        if (key.getClass() == Scalar.class && value.getClass() == ClassInstanceCreation.class) {

                            Scalar name = (Scalar) key;
                            ClassInstanceCreation functionClass = (ClassInstanceCreation) value;
                            CallArgumentsList args = functionClass.getCtorParams();
                            String functionClassName = functionClass.getClassName().toString();
View Full Code Here

                        public boolean visit(ArrayCreation array)
                                throws Exception
                        {
                            for (ArrayElement elem : array.getElements()) {

                                Expression value = elem.getValue();

                                if (value == null)
                                    continue;

                                if (value.getClass() == Scalar.class) {

                                    Scalar scalar = (Scalar) value;
                                    String subParseMethod = scalar.getValue().replaceAll("['\"]", "");

                                    for (MethodDeclaration method : currentClass.getMethods()) {
View Full Code Here

                                ArrayCreation array = (ArrayCreation) arg;

                                for (ArrayElement key : array.getElements()) {

                                    Expression value = key.getValue();

                                    if (value != null
                                            && value instanceof Scalar) {

                                        Scalar scalar = (Scalar) value;
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.ast.expressions.Expression

Copyright © 2018 www.massapicom. 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.