1 14 package org.eclipse.jdt.internal.corext.refactoring.code; 15 16 import java.util.List ; 17 18 import org.eclipse.jdt.core.dom.ASTNode; 19 import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; 20 import org.eclipse.jdt.core.dom.ConstructorInvocation; 21 import org.eclipse.jdt.core.dom.Expression; 22 import org.eclipse.jdt.core.dom.IMethodBinding; 23 import org.eclipse.jdt.core.dom.MethodInvocation; 24 import org.eclipse.jdt.core.dom.SuperMethodInvocation; 25 26 public class Invocations { 27 28 public static List getArguments(ASTNode invocation) { 29 switch(invocation.getNodeType()) { 30 case ASTNode.METHOD_INVOCATION: 31 return ((MethodInvocation)invocation).arguments(); 32 case ASTNode.SUPER_METHOD_INVOCATION: 33 return ((SuperMethodInvocation)invocation).arguments(); 34 case ASTNode.CONSTRUCTOR_INVOCATION: 35 return ((ConstructorInvocation)invocation).arguments(); 36 default: 37 throw new IllegalArgumentException (invocation.toString()); 38 } 39 } 40 41 public static Expression getExpression(ASTNode invocation) { 42 switch(invocation.getNodeType()) { 43 case ASTNode.METHOD_INVOCATION: 44 return ((MethodInvocation)invocation).getExpression(); 45 case ASTNode.SUPER_METHOD_INVOCATION: 46 case ASTNode.CONSTRUCTOR_INVOCATION: 47 return null; 48 default: 49 throw new IllegalArgumentException (invocation.toString()); 50 } 51 } 52 53 public static boolean isInvocation(ASTNode node) { 54 int type= node.getNodeType(); 55 return type == ASTNode.METHOD_INVOCATION || type == ASTNode.SUPER_METHOD_INVOCATION || 56 type == ASTNode.CONSTRUCTOR_INVOCATION; 57 } 58 59 public static IMethodBinding resolveBinding(ASTNode invocation) { 60 switch(invocation.getNodeType()) { 61 case ASTNode.METHOD_INVOCATION: 62 return ((MethodInvocation)invocation).resolveMethodBinding(); 63 case ASTNode.SUPER_METHOD_INVOCATION: 64 return ((SuperMethodInvocation)invocation).resolveMethodBinding(); 65 case ASTNode.CONSTRUCTOR_INVOCATION: 66 return ((ConstructorInvocation)invocation).resolveConstructorBinding(); 67 default: 68 throw new IllegalArgumentException (invocation.toString()); 69 } 70 } 71 72 public static boolean isResolvedTypeInferredFromExpectedType(Expression invocation) { 73 switch(invocation.getNodeType()) { 74 case ASTNode.METHOD_INVOCATION: 75 return ((MethodInvocation) invocation).isResolvedTypeInferredFromExpectedType(); 76 case ASTNode.SUPER_METHOD_INVOCATION: 77 return ((SuperMethodInvocation) invocation).isResolvedTypeInferredFromExpectedType(); 78 case ASTNode.CONSTRUCTOR_INVOCATION: 79 return false; 80 default: 81 throw new IllegalArgumentException (invocation.toString()); 82 } 83 } 84 85 public static ChildListPropertyDescriptor getTypeArgumentsProperty(Expression invocation) { 86 switch(invocation.getNodeType()) { 87 case ASTNode.METHOD_INVOCATION: 88 return MethodInvocation.TYPE_ARGUMENTS_PROPERTY; 89 case ASTNode.SUPER_METHOD_INVOCATION: 90 return SuperMethodInvocation.TYPE_ARGUMENTS_PROPERTY; 91 case ASTNode.CONSTRUCTOR_INVOCATION: 92 return ConstructorInvocation.TYPE_ARGUMENTS_PROPERTY; 93 default: 94 throw new IllegalArgumentException (invocation.toString()); 95 } 96 } 97 } 98 | Popular Tags |