Package org.eclipse.php.internal.core.compiler.ast.nodes

Examples of org.eclipse.php.internal.core.compiler.ast.nodes.PHPCallExpression


          @Override
          public void acceptSearchMatch(final SearchMatch match) throws CoreException {
            if (match instanceof MethodReferenceMatch && ((MethodReferenceMatch) match).getNode() instanceof PHPCallExpression && match.getElement() instanceof IModelElement) {
              final ISourceModule module = (ISourceModule) ((IModelElement) match.getElement()).getAncestor(IModelElement.SOURCE_MODULE);
              if (module != null && RefactoringAvailabilityTester.isRenameAvailable(module)) {
                PHPCallExpression expression = (PHPCallExpression) ((MethodReferenceMatch) match).getNode();
                if (expression.getReceiver() == null) {
                  if (expression.getCallName() instanceof FullyQualifiedReference) {
                    int offset;
                    if (((FullyQualifiedReference) expression.getCallName()).getNamespace() == null) {
                      offset = expression.getCallName().sourceStart();
                    } else {
                      if ("\\".equals(((FullyQualifiedReference) expression.getCallName()).getNamespace().getName())) {
                        offset = ((FullyQualifiedReference) expression.getCallName()).getNamespace().sourceEnd();
                      } else {
                        offset = ((FullyQualifiedReference) expression.getCallName()).getNamespace().sourceEnd() + 1;
                      }
                    }

                    try {
                      addTextEdit(
                        changeManager.get(module),
                        getProcessorName(),
                        new ReplaceEdit(offset, method.getElementName().length(), getNewElementName())
                      );
                    } catch (MalformedTreeException e) {
                      // conflicting update -> omit text match
                    }
                  }
                } else {
                  IModelElement sourceElement = PDTModelUtils.getSourceElement(module, expression.getCallName().sourceStart(), expression.getCallName().matchLength());
                  if (sourceElement != null && sourceElement.getElementType() == IModelElement.METHOD) {
                    IType declaringType = ((IMethod) sourceElement).getDeclaringType();
                    if (declaringType != null && new PHPType(declaringType).isInstanceOf(method.getDeclaringType())) {
                      try {
                        addTextEdit(
                          changeManager.get(module),
                          getProcessorName(),
                          new ReplaceEdit(expression.getCallName().sourceStart(), method.getElementName().length(), getNewElementName())
                        );
                      } catch (MalformedTreeException e) {
                        // conflicting update -> omit text match
                      }
                    }
View Full Code Here


    ModuleDeclaration module = SourceParserUtil
        .getModuleDeclaration(sourceModule);
    ASTNode node = PHPModelUtils.getNodeByField(module, field);

    if (node == null) {// define constant
      PHPCallExpression callExpression = DefineMethodUtils
          .getDefineNodeByField(module, field);
      if (callExpression != null) {
        CallArgumentsList args = callExpression.getArgs();
        if (args != null && args.getChilds() != null
            && args.getChilds().size() >= 2) {
          ASTNode argument = (ASTNode) args.getChilds().get(1);
          if (argument instanceof Scalar) {
            String value = ASTUtils.stripQuotes(((Scalar) argument)
View Full Code Here

  public SearchMatch newMethodReferenceMatch(IModelElement enclosingElement,
      int accuracy, int offset, int length, boolean isConstructor,
      boolean isSynthetic, ASTNode reference, SearchPattern pattern) {
    if (pattern instanceof MethodPattern
        && (reference instanceof PHPCallExpression)) {
      PHPCallExpression pce = (PHPCallExpression) reference;
      ISourceModule module = (ISourceModule) enclosingElement
          .getAncestor(IModelElement.SOURCE_MODULE);
      if (module != null) {
        try {
          MethodPattern methodPattern = (MethodPattern) pattern;
          IModelElement[] elements = module.codeSelect(pce
              .getCallName().sourceStart(), 0);
          if (elements == null || elements.length == 0) {
            return super.newMethodReferenceMatch(enclosingElement,
                accuracy, offset, length, isConstructor,
                isSynthetic, reference);
View Full Code Here

            // a render call:
            // return return $this->render("DemoBundle:Test:index.html.twig", array('foo' => $bar));
            } else if (statement.getExpr().getClass() == PHPCallExpression.class) {

                PHPCallExpression expression = (PHPCallExpression) statement.getExpr();
                String callName = expression.getCallName().getName();

                if (callName.startsWith(SymfonyCoreConstants.RENDER_PREFIX)) {

                    CallArgumentsList args = expression.getArgs();
                    List<ASTNode> children = args.getChilds();

                    Scalar view = (Scalar) children.get(0);

                    if (children.size() >= 2 && children.get(1).getClass() == ArrayCreation.class) {
View Full Code Here

                    // 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) {
View Full Code Here

                // 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())) {
View Full Code Here

    public boolean visit(Statement s) throws Exception {

        if (s instanceof ExpressionStatement) {
            ExpressionStatement stmt = (ExpressionStatement) s;
            if (stmt.getExpr() instanceof PHPCallExpression) {
                PHPCallExpression call = (PHPCallExpression) stmt.getExpr();

                if (("registerNamespaces".equals(call.getName()) || "registerNamespaceFallbacks".equals(call.getName()))
                        && call.getReceiver() instanceof VariableReference) {

                    if (sourceModule.getElementName().equals("bootstrap.php"))
                        return false;

                    RegisterNamespaceVisitor registrar = new RegisterNamespaceVisitor(sourceModule);
                    registrar.visit(call);

                    for (IPath namespace : registrar.getNamespaces()) {
                        ReferenceInfo info = new ReferenceInfo(ISymfonyModelElement.NAMESPACE, 0, 0, namespace.toString(), null, null);
                        requestor.addReference(info);
                    }
                }
                // TODO: check if the variable implements Symfony\Component\DependencyInjection\ContainerInterface
                else if("setAlias".equals(call.getName())) {

                    if (call.getReceiver() instanceof VariableReference) {
                        CallArgumentsList args = call.getArgs();
                        if (args.getChilds().size() == 2) {

                            List<ASTNode> nodes = args.getChilds();

                            try {
View Full Code Here

                public boolean visit(ReturnStatement s) throws Exception
                {

                    if (s.getExpr() instanceof PHPCallExpression) {

                        PHPCallExpression call = (PHPCallExpression) s
                                .getExpr();
                        CallArgumentsList args = call.getArgs();

                        if ("test".equals(call.getName())
                                && args.getChilds().size() == 1) {

                            Object arg = args.getChilds().get(0);

                            if (arg instanceof Scalar) {
View Full Code Here

TOP

Related Classes of org.eclipse.php.internal.core.compiler.ast.nodes.PHPCallExpression

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.