use of com.newrelic.agent.instrumentation.methodmatchers.NameMethodMatcher in project newrelic-java-agent by newrelic.
the class MethodMatcherUtility method createMethodMatcher.
public static MethodMatcher createMethodMatcher(String className, Method method, Map<String, MethodMapper> classesToMethods, String extName) throws NoSuchMethodException, XmlException {
if (method == null) {
throw new XmlException("A method must be specified for a point cut in the extension.");
}
if (method.getReturnType() != null) {
if (Utils.isPrimitiveType(method.getReturnType())) {
throw new XmlException("The return type '" + method.getReturnType() + "' is not valid. Primitive types are not allowed.");
}
Type returnType = Type.getObjectType(method.getReturnType().replace('.', '/'));
if (!ExtensionConversionUtility.isReturnTypeOkay(returnType)) {
throw new XmlException("The return type '" + returnType.getClassName() + "' is not valid. Primitive types are not allowed.");
}
return new ExactReturnTypeMethodMatcher(returnType);
}
validateMethod(method, extName);
String methodName = method.getName();
if (methodName == null) {
throw new XmlException("A method name must be specified for a point cut in the extension.");
}
methodName = methodName.trim();
if (methodName.length() == 0) {
throw new XmlException("A method must be specified for a point cut in the extension.");
}
Parameters mParams = method.getParameters();
if (mParams == null || mParams.getType() == null) {
if (!isDuplicateMethod(className, methodName, null, classesToMethods)) {
return new NameMethodMatcher(methodName);
} else {
throw new NoSuchMethodException("Method " + methodName + " has already been added to a point cut and will " + "not be added again.");
}
} else {
String descriptor = MethodParameters.getDescriptor(mParams);
if (descriptor == null) {
throw new XmlException("Descriptor not being calculated correctly.");
}
String mDescriptor = descriptor.trim();
if (!isDuplicateMethod(className, methodName, mDescriptor, classesToMethods)) {
return ExactParamsMethodMatcher.createExactParamsMethodMatcher(methodName, descriptor);
} else {
throw new NoSuchMethodException("Method " + methodName + " has already been added to a point cut and will " + "not be added again.");
}
}
}
use of com.newrelic.agent.instrumentation.methodmatchers.NameMethodMatcher in project newrelic-java-agent by newrelic.
the class OptimizedClassMatcherTest method before.
@Before
public void before() {
initializeServiceManager();
OptimizedClassMatcherBuilder builder = OptimizedClassMatcherBuilder.newBuilder();
match1 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Collection.class), new ExactMethodMatcher("size", "()I"));
match2 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(List.class), new ExactMethodMatcher("get", "(I)Ljava/lang/Object;"));
match3 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(InvocationHandler.class), new ExactMethodMatcher("invoke", "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"));
match4 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Statement.class), new AllMethodsMatcher());
match5 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Runnable.class), OrMethodMatcher.getMethodMatcher(new NameMethodMatcher("run"), new ExactMethodMatcher("bogus", "()V")));
match6 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Map.class), new AccessMethodMatcher(Opcodes.ACC_PUBLIC));
match7 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(List.class), new ExactMethodMatcher("add", "(Ljava/lang/Object;)Z"));
annotationMatch = new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AnnotationMethodMatcher(Type.getType(MyAnnotation.class)));
// this is a bogus matcher to attempt to throw off match5
builder.addClassMethodMatcher(new DefaultClassAndMethodMatcher(createInterfaceMatcher(PreparedStatement.class), new NameMethodMatcher("run")));
builder.addClassMethodMatcher(match1);
builder.addClassMethodMatcher(match2);
builder.addClassMethodMatcher(match3);
builder.addClassMethodMatcher(match4);
builder.addClassMethodMatcher(match5);
builder.addClassMethodMatcher(match6);
builder.addClassMethodMatcher(match7);
builder.addClassMethodMatcher(annotationMatch);
this.matcher = builder.build();
}
Aggregations