Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.MethodInvocation


        if (isStatic && !HANDLE_STATIC_FIELDS) {
            return;
        }

        // The new method invocation to replace the assignment.
        MethodInvocation invocation = ast.newMethodInvocation();

        // Set the expression and name of the method invocation.
        if (newObject != null) {
            invocation.setExpression(newObject);
        }

        SimpleName newName = ast.newSimpleName(_getAssignMethodName(name
                .getIdentifier(), isSpecial));
        invocation.setName(newName);

        // If the field is static, add the checkpoint object as the first
        // argument.
        if (isStatic) {
            invocation.arguments().add(ast.newSimpleName(CHECKPOINT_NAME));
        }

        // Add an operator, if necessary.
        Type type = Type.getType(node);

        if (isSpecial && _assignOperators.containsKey(type.getName())) {
            int i = 0;
            String[] operators = _assignOperators.get(type.getName());

            String operator;

            if (node instanceof Assignment) {
                operator = ((Assignment) node).getOperator().toString();
            } else if (node instanceof PrefixExpression) {
                operator = ((PrefixExpression) node).getOperator().toString();
            } else {
                operator = ((PostfixExpression) node).getOperator().toString();
            }

            for (; i < operators.length; i++) {
                if (operators[i].equals(operator)) {
                    break;
                }
            }

            if (node instanceof PrefixExpression) {
                i += 2;
            }

            invocation.arguments().add(
                    ast.newNumberLiteral(Integer.toString(i)));
        }

        // Add all the indices into the argument list.
        invocation.arguments().addAll(indices);

        // Add the right-hand side expression to the argument list.
        Type rightHandType = Type.getType(rightHand);

        if (!isSpecial && type.isPrimitive() && !type.equals(rightHandType)) {
            // Require an explicit conversion.
            CastExpression castExpression = ast.newCastExpression();
            castExpression.setType(createType(ast, type.getName()));
            castExpression.setExpression((Expression) ASTNode.copySubtree(ast,
                    rightHand));
            rightHand = castExpression;
        } else {
            rightHand = (Expression) ASTNode.copySubtree(ast, rightHand);

            if (isSpecial && type.getName().equals(String.class.getName())
                    && !type.equals(rightHandType)) {
                InfixExpression extraPlus = ast.newInfixExpression();
                extraPlus.setLeftOperand(ast.newStringLiteral());
                extraPlus.setOperator(InfixExpression.Operator.PLUS);
                extraPlus.setRightOperand(rightHand);
                rightHand = extraPlus;
            }
        }

        invocation.arguments().add(rightHand);

        // Set the type of this invocation.
        Type.propagateType(invocation, node);

        // Replace the assignment node with this method invocation.
View Full Code Here


            // Create a simple initializer.
            Initializer initializer = ast.newInitializer();
            Block body = ast.newBlock();
            initializer.setBody(body);

            MethodInvocation addInvocation = ast.newMethodInvocation();
            addInvocation.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
            addInvocation.setName(ast.newSimpleName("addObject"));

            ClassInstanceCreation proxy = ast.newClassInstanceCreation();
            proxy
                    .setType(ast.newSimpleType(ast
                            .newSimpleName(_getProxyName())));
            addInvocation.arguments().add(proxy);
            body.statements().add(ast.newExpressionStatement(addInvocation));
            bodyDeclarations.add(initializer);

            if (declarationRecord != null) {
                declarationRecord._addExtendedDeclaration(initializer);
View Full Code Here

    if(loc.isConstant()) {
      return display.getSystemColor(SWT.COLOR_DARK_BLUE);
    } else {
        String fullCalleeName = null;
      if(loc.getASTNode() instanceof MethodInvocation) {
        MethodInvocation mi = (MethodInvocation) loc.getASTNode();
        Expression s=mi.getExpression();
        fullCalleeName = mi.getName().getFullyQualifiedName();
      }else
        if(loc.getASTNode() instanceof ClassInstanceCreation) {
            ClassInstanceCreation mi = (ClassInstanceCreation) loc.getASTNode();
        fullCalleeName = mi.getType().toString();
      }
       
        if(fullCalleeName != null) {
        if(SourceView.isSourceName(fullCalleeName)) {
          return display.getSystemColor(SWT.COLOR_DARK_RED);
View Full Code Here

           
            if(!(expr instanceof MethodInvocation)) {
              logError("Can't match " + expr + " of type " + expr.getClass());
              continue;
            }
            MethodInvocation mi = (MethodInvocation) expr;
 
            ViewMatch match = new ViewMatch(
                expr.toString(),
                expr,
                element.getCompilationUnit(),
View Full Code Here

                if (decl.getInitializer() != null) {
                    return isStringContant(decl.getInitializer(), unit, resource);
                }
            }
        } else if (arg instanceof MethodInvocation) {
            MethodInvocation inv = (MethodInvocation) arg;
            if (inv.getName().getIdentifier().equals("toString")) {
                // TODO: StringBuffer.toString() return result
                Expression target = inv.getExpression();
                // System.err.println("TODO -> methodInv: " + inv);
            }
        }
        // TODO: add final/const
        return false;       // this is a conservative return value
View Full Code Here

    } else
    if(e instanceof MethodInvocation) {
      /**
       * Go back through a method invocation.
       * */
      MethodInvocation mi = (MethodInvocation) e;
      SimpleName methodName = mi.getName();
      log("Going back through callee " + methodName.toString());
      HistoryDefinitionLocation callDL;
      if(!first){
      callDL= new HistoryDefinitionLocation(
          mi.toString(),
          resource,
          cu.getLineNumber(mi.getStartPosition()),
          mi,
          parent, HistoryDefinitionLocation.CALL);
      }
      else{
        callDL=parent;
      }
     
      if(registerExpansion(callDL)) {
        Collection/*<MethodDeclarationUnitPair>*/ callees = CallerFinder.findCallees(monitor, methodName.toString(), null, false);
        if(callees.isEmpty()) {
          if(SinkView.isDerivationName(methodName.getFullyQualifiedName()))
          {
              HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
                  mi.getExpression().toString(),
                  resource,
                  cu.getLineNumber(mi.getStartPosition()),
                  mi.getExpression(), callDL, HistoryDefinitionLocation.DERIVATION);
              if(registerExpansion(dl)) {
                Expression expr = mi.getExpression();
                if(expr != null) {
                  // Recurse on the returned expression
                  processExpression(dl, expr, cu, resource, stack, monitor, HistoryDefinitionLocation.DERIVATION,false);
                 
                }
              }
          }
          else{
          logError("No suitable callees for " + methodName + " in " + resource + " found");
          System.out.println("No suitable callees for " + methodName + " in " + resource + " found");
          }
        } else
        for (Iterator iter = callees.iterator(); iter.hasNext();) {
          Utils.MethodDeclarationUnitPair element
                            = (Utils.MethodDeclarationUnitPair) iter.next();
          MethodDeclaration methodDeclaration = element.getMethod();
          CompilationUnit nextCU         = element.getCompilationUnit();
          IResource nextResource         = element.getResource();       
       
          if(methodDeclaration  != null){
            if(!LapsePlugin.FOLLOW_INTO_FUNCTIONS) {
              /*HistoryDefinitionLocation dl = */new HistoryDefinitionLocation(
                  "Method " + methodDeclaration.getName().getFullyQualifiedName(),
                  nextResource,
                  nextCU.getLineNumber(e.getStartPosition()),
                  methodDeclaration, callDL, HistoryDefinitionLocation.RETURN);
            } else {
              Collection/*<ReturnStatement>*/ returns = CallerFinder.findReturns(monitor, methodDeclaration, null);
              for (Iterator iter2 = returns.iterator(); iter2.hasNext();) {
                ReturnStatement returnStmt = (ReturnStatement) iter2.next();
             
                HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
                    returnStmt.toString(),
                    nextResource,
                    nextCU.getLineNumber(returnStmt.getStartPosition()),
                    returnStmt, callDL, HistoryDefinitionLocation.RETURN);
                if(registerExpansion(dl)) {
                  Expression expr = returnStmt.getExpression();
                  if(expr != null) {
                    // Recurse on the returned expression
                    stack.addLast(mi);
                    processExpression(dl, expr, nextCU, nextResource, stack, monitor, HistoryDefinitionLocation.COPY,false);
                    stack.removeLast();
                  }
                }
              }
            }
          }
          else{
            //check if it is a derivtion expression
            if(SinkView.isDerivationName(methodName.getFullyQualifiedName()))
            {
       
                    processExpression(callDL, mi.getExpression(), cu, resource, stack, monitor, HistoryDefinitionLocation.DERIVATION,false);
               
                break;
            }
          } 
        }
View Full Code Here

          addHistoryEntry(dl);
          fContentProvider.addElement(dl);
          refresh();
        }
       else if(covering instanceof MethodInvocation) {
        MethodInvocation mi=(MethodInvocation)covering;
        HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
              mi.toString(),
              (IFile)resource,
              unit.getLineNumber(0),
              covering,null, HistoryDefinitionLocation.CALL);
          processExpression(dl, mi, unit, resource, new LinkedList<MethodInvocation>(), monitor, HistoryDefinitionLocation.CALL,true);
          setCurrentInput(dl);
View Full Code Here

                              
                                int argCount = 0;
                                Expression arg = null;
                                int argumentNumber = desc.getVulnerableParameter();
                                if (expr instanceof MethodInvocation) {
                                    MethodInvocation mi = (MethodInvocation) expr;
                                    argCount = mi.arguments().size();
                                    if (argCount > 0) {
                                        arg = (Expression) mi.arguments().get(argumentNumber);
                                    }
                                   
                                } else if (expr instanceof ClassInstanceCreation) {
                                    ClassInstanceCreation ci = (ClassInstanceCreation) expr;
                                    argCount = ci.arguments().size();
View Full Code Here

                if (decl.getInitializer() != null) {
                    return isStringContant(decl.getInitializer(), unit, resource);
                }
            }
        } else if (arg instanceof MethodInvocation) {
            MethodInvocation inv = (MethodInvocation) arg;
            if (inv.getName().getIdentifier().equals("toString")) {
                // TODO: StringBuffer.toString() return result
                Expression target = inv.getExpression();
                // System.err.println("TODO -> methodInv: " + inv);
            }
        }
        // TODO: add final/const
        return false;       // this is a conservative return value
View Full Code Here

                Type newType = JDTUtils.createQualifiedType(vdf.getAST(), toClass);
                newClassInstanceCreation.setType(newType);
                List arguments = newClassInstanceCreation.arguments();
                arguments.clear();
               
                MethodInvocation initializer = (MethodInvocation) vdf.getInitializer();
                List newArguments = ASTNode.copySubtrees(newClassInstanceCreation.getAST(), initializer.arguments());
                arguments.addAll(newArguments);
                 
                vdf.setInitializer(newClassInstanceCreation);
              }
            }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.MethodInvocation

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.