1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 32 33 34 import java.lang.reflect.Method ; 35 36 44 public class ExternalMethod extends ExternalDefinition implements IMethod { 45 private Method _javaMethod; 46 private ISignature _signature; 47 48 public ExternalMethod(Method javaMethod) { 49 _javaMethod = javaMethod; 50 _signature = new ExternalSignature(_javaMethod.getParameterTypes()); 51 } 52 53 public String getName() { 54 return _javaMethod.getName(); 55 } 56 57 62 public IClass getType() { 63 IClass result = null; 64 if (_javaMethod.getReturnType().isArray()) { 65 result = new ArrayDef(new ExternalClass(_javaMethod.getReturnType().getComponentType())); 66 } 67 else { 68 result = new ExternalClass(_javaMethod.getReturnType()); 69 } 70 71 return result; 72 } 73 74 79 public ISignature getSignature() { 80 return _signature; 81 } 82 83 public boolean hasSameSignature(ISignature signature) { 84 return _signature.isSame(signature); 85 } 86 87 public boolean hasCompatibleSignature(ISignature signature) { 88 return signature.isCompatibleWith(getSignature()); 89 } 90 91 public String getQualifiedName() { 92 return getName() + getSignature(); 93 } 94 95 public Method getJavaMethod() { 96 return _javaMethod; 97 } 98 99 public IClass[] getExceptions() { 100 Class [] javaExceptions = getJavaMethod().getExceptionTypes(); 101 IClass[] result = new IClass[javaExceptions.length]; 102 103 for (int i = 0; i < result.length; i++) { 104 result[i] = new ExternalClass(javaExceptions[i]); 105 } 106 107 return result; 108 } 109 110 public String toString() { 111 return getQualifiedName(); 112 } 113 114 public boolean equals(Object o) { 115 boolean result = false; 116 117 if (o instanceof ExternalMethod) { 118 ExternalMethod compared = (ExternalMethod)o; 119 result = getJavaMethod().equals(compared.getJavaMethod()); 120 } 121 122 return result; 123 } 124 125 public int hashCode() { 126 return getJavaMethod().hashCode(); 127 } 128 } 129 | Popular Tags |