Ejemplo n.º 1
0
  public Collection<AssignableNode> findFieldAsgnsOfSource(MethodNodeWrapper constructorNode) {
    ArrayList<AssignableNode> assignmentsFound = new ArrayList<AssignableNode>();

    Collection<Node> assignmentNodes =
        NodeProvider.getSubNodes(
            constructorNode.getWrappedNode(), LocalAsgnNode.class, InstAsgnNode.class);
    for (Node currentNode : assignmentNodes) {

      AssignableNode currentAssignment = (AssignableNode) currentNode;
      Node valueNode = currentAssignment.getValueNode();
      MethodCallNodeWrapper valueWrapper = new MethodCallNodeWrapper(valueNode);
      if (valueWrapper.getType() == MethodCallNodeWrapper.INVALID_TYPE) {
        continue;
      }

      if (valueWrapper.getName().equals("new")
          && valueWrapper.getReceiverNode() instanceof ConstNode
          && ((ConstNode) valueWrapper.getReceiverNode())
              .getName()
              .equals(sourceClass.getName())) { // $NON-NLS-1$
        assignmentsFound.add(currentAssignment);
      }
    }
    return assignmentsFound;
  }
 private Node getMethodCallNode() {
   Node receiverNode;
   if (oldMethod.isClassMethod()) {
     receiverNode = NodeFactory.createConstNode(config.getDestinationClassNode().getName());
   } else {
     receiverNode =
         NodeFactory.createInstVarNode(config.getFieldInSourceClassOfTypeDestinationClass());
   }
   ArgsNodeWrapper argsNode = oldMethod.getArgsNode();
   ArrayNode arrayNode = NodeFactory.createArrayNode();
   for (String argName : argsNode.getArgsList()) {
     arrayNode.add(NodeFactory.createLocalVarNode(argName));
   }
   if (config.doesNewMethodNeedsReferenceToSourceClass()) {
     arrayNode.add(NodeFactory.createSelfNode());
   }
   return NodeFactory.createCallNode(
       receiverNode, config.getMovedMethodName(), (arrayNode.size() == 0) ? null : arrayNode);
 }
 public DelegateMethodEditProvider(MoveMethodConfig config) {
   super(false);
   this.config = config;
   oldMethod = config.getMethodNode();
   scopePos = NodeProvider.unwrap(oldMethod.getBodyNode());
 }