Package org.eclipse.dltk.ast.references

Examples of org.eclipse.dltk.ast.references.VariableReference


  public IGoal[] init() {
    ExpressionTypeGoal typedGoal = (ExpressionTypeGoal) goal;
    ArrayVariableReference reference = (ArrayVariableReference) typedGoal
        .getExpression();
    return new IGoal[] { new ExpressionTypeGoal(goal.getContext(),
        new VariableReference(reference.sourceStart(),
            reference.sourceEnd(), reference.getName())) };
  }
View Full Code Here


                // 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;
                        }
                    }
View Full Code Here

        if (inAction) {

            Service service = null;
            if (s.getVariable().getClass() == VariableReference.class) {

                VariableReference var = (VariableReference) s.getVariable();

                // A call expression like $foo = $this->get('bar');
                //
                if (s.getValue().getClass() == PHPCallExpression.class) {

                    PHPCallExpression exp = (PHPCallExpression) s.getValue();

                    // are we requesting a Service?
                    if (exp.getName().equals("get")) {

                        service = ModelUtils.extractServiceFromCall(exp, source.getScriptProject().getPath());



                        if (service != null) {

                            String fqsn =  service.getNamespace() != null ? service.getNamespace().getQualifiedName() : null;

                            TemplateVariable tempVar= new TemplateVariable(currentMethod, var.getName(), exp.sourceStart(), exp.sourceEnd(), fqsn, service.getClassName());
                            deferredVariables.push(tempVar);
                        }

                        // a more complex expression like
                        // $form = $this->get('form.factory')->create(new ContactType());
                    } else if (exp.getReceiver().getClass() == PHPCallExpression.class) {

                        // try to extract a service if it's a Servicecontainer call
                        service = ModelUtils.extractServiceFromCall((PHPCallExpression) exp.getReceiver(), source.getScriptProject().getPath());

                        // nothing found, return
                        if (service == null || exp.getCallName() == null) {
                            return true;
                        }

                        SimpleReference callName = exp.getCallName();

                        //TODO: this is a problematic case, as during a clean build
                        // it's possible that the SourceModule in which the
                        // called method was declared is not yet in the index, so
                        // the return type cannot be evaluated and therefore
                        // the templatevariable won't be created...
                        //
                        // Possible solution: check if there's an event fired when the
                        // build is completed and store those return types in a global
                        // singleton, evaluate them when the whole build process is finished.


                        String fqsn = service.getNamespace() != null ? service.getNamespace().getQualifiedName() : null;
                        TemplateVariable tempVar = null;

                            tempVar = SymfonyModelAccess.getDefault()
                                    .createTemplateVariableByReturnType(source, currentMethod, callName,
                                            service.getClassName(), fqsn, var.getName(), cache);

                        if (tempVar != null) {

                            deferredVariables.push(tempVar);
                        }

                        // something like $formView = $form->createView();
                    } else if (exp.getReceiver().getClass() == VariableReference.class) {

                        VariableReference varRef = (VariableReference) exp.getReceiver();
                        SimpleReference ref = exp.getCallName();

                        // check for a previosly declared variable
                        for (TemplateVariable tempVar : deferredVariables) {
                            if (tempVar.getName().equals(varRef.getName())) {

                                TemplateVariable tVar = SymfonyModelAccess.getDefault()
                                        .createTemplateVariableByReturnType(source, currentMethod, ref, tempVar.getClassName(), tempVar.getNamespace(), var.getName(), cache);

                                if (tVar != null) {
View Full Code Here

   
   
    if (receiver instanceof VariableReference) {

      VariableReference ref = (VariableReference) receiver;

      // is the receiver an object instance ?
      if (ref.getName().equals("$this")) {

        List args = call.getArgs().getChilds();

        // does the get() method have exact one argument?
View Full Code Here

       
        ASTNode node = expressionGoal.getExpression();
       
        if (node instanceof VariableReference) {
         
          VariableReference variable = (VariableReference) node;
          TemplateField element = SymfonyModelAccess.getDefault().findTemplateVariableType(variable.toString(), context.getSourceModule());
          
           if (element != null) {
                        
             String viewName = PathUtils.createViewPathFromTemplate(context.getSourceModule(), false);
            
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.ast.references.VariableReference

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.