1 package ch.ethz.prose.crosscut; 22 import java.lang.IllegalAccessException ; 23 import java.io.Serializable ; 24 import java.lang.InstantiationException ; 25 import java.lang.reflect.Method ; 26 import java.lang.Error ; 27 import java.lang.Class ; 28 import ch.ethz.inf.util.Logger; 29 import java.lang.SecurityException ; 30 import java.lang.ArrayIndexOutOfBoundsException ; 31 35 51 class MethodCutSignaturePattern extends SignaturePattern implements Serializable 52 { 53 private final MethodCut methodCut; 54 55 56 57 76 protected MethodCutSignaturePattern(MethodCut crsc) throws MissingInformationException 77 { 78 this.methodCut = crsc; 79 initFromMethod(crsc.getClass(),"METHOD_ARGS",REST.class,MethodCut.class); 80 } 81 82 83 84 85 86 91 protected boolean matchesParameters(Method actualMethod) 92 { 93 if (signatureCathegory == SIGNATURE__EMPTY) 94 return true; 95 else 96 return 97 doMatchLength(actualMethod) && 98 doMatchSignature(actualMethod); 99 } 100 101 private Class [] subarray(Class [] arr, int index) 102 { 103 Class [] result = new Class [arr.length - index]; 104 System.arraycopy(arr,index,result,0,result.length); 105 return result; 106 } 107 108 private boolean doMatchSignature(Method actualMethod) throws Error 109 { 110 boolean signatureOK = true; 111 Class [] params = actualMethod.getParameterTypes(); 112 for(int j=1; j< signature.length && signatureOK; j++) 113 { 114 int adviceParamPos = j; 115 int actualParamPos = j - 1; 116 117 try 118 { 119 if (isAssignable(subarray(params,actualParamPos), signature[adviceParamPos])) 120 signatureOK = true; 121 else if (isAssignable(params[actualParamPos], signature[adviceParamPos])) 122 { 123 signatureOK = true; 125 if (adviceParamPos + 1 == signature.length) 126 { 127 signatureOK = ( signature.length == params.length + 1 ); 128 } 129 } 130 else 131 signatureOK = false; 132 133 } 134 catch(ArrayIndexOutOfBoundsException e) 135 { 136 signatureOK = false; 137 } 138 } 139 return signatureOK; 140 } 141 142 private boolean doMatchLength(Method actualMethod) 143 { 144 Class [] params = actualMethod.getParameterTypes(); 145 return ( (signature.length ==1 && params.length == 0) || signature.length >1); 146 } 147 148 149 public String toString() 150 { 151 return methodObj.toString(); 152 } 153 } 154
| Popular Tags
|