1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 import java.util.Vector ; 32 33 34 35 41 42 public class MethodSignature implements ISignature{ 43 44 private IClass[] _argTypes = null; 45 46 public MethodSignature(IClass[] argTypes) { 47 _argTypes = argTypes; 48 } 49 50 public MethodSignature(Vector argTypes) { 51 _argTypes = new IClass[argTypes.size()]; 52 argTypes.toArray(_argTypes); 53 } 54 55 60 public IClass[] getParameters() { 61 return _argTypes; 62 } 63 64 73 public boolean isCompatibleWith(ISignature signature) { 74 boolean result = true; 75 76 IClass[] comparedArgTypes = signature.getParameters(); 77 if (_argTypes.length != comparedArgTypes.length) { 78 result = false; 79 } 80 else { 81 for (int i = 0; i < _argTypes.length; i++) { 82 if ((_argTypes[i] != null) 85 && !_argTypes[i].isCompatibleWith(comparedArgTypes[i])) 86 { 87 result = false; 88 break; 89 } 90 } 91 } 92 93 return result; 94 } 95 96 public boolean isSame(ISignature signature) { 97 return equals(signature); 98 } 99 100 107 public boolean equals(Object o) { 108 boolean result = false; 109 110 if (o instanceof MethodSignature) { 111 MethodSignature signature = (MethodSignature)o; 112 result = java.util.Arrays.equals(getParameters(), signature.getParameters()); 113 } 114 115 return result; 116 } 117 118 124 public String toString() { 125 StringBuffer result = new StringBuffer ( "(" ); 126 127 for ( int i = 0; i < _argTypes.length; i++ ) { 128 result.append( _argTypes[i] != null ? _argTypes[i].getName() : "[null]" ); 129 if ( i < (_argTypes.length - 1) ) { 130 result.append( ", " ); 131 } 132 } 133 result.append( ")" ); 134 135 return result.toString(); 136 } 137 138 } 139 | Popular Tags |