use of com.navercorp.pinpoint.profiler.instrument.AccessorAnalyzer.AccessorDetails in project pinpoint by naver.
the class JavassistClass method addField0.
private void addField0(String accessorTypeName, String initValExp) throws InstrumentException {
try {
Class<?> accessorType = pluginContext.injectClass(classLoader, accessorTypeName);
final AccessorAnalyzer accessorAnalyzer = new AccessorAnalyzer();
final AccessorDetails accessorDetails = accessorAnalyzer.analyze(accessorType);
Class<?> fieldType = accessorDetails.getFieldType();
String fieldTypeName = JavaAssistUtils.javaClassNameToObjectName(fieldType.getName());
final CtField newField = CtField.make("private " + fieldTypeName + " " + FIELD_PREFIX + JavaAssistUtils.javaClassNameToVariableName(accessorTypeName) + ";", ctClass);
if (initValExp == null) {
ctClass.addField(newField);
} else {
ctClass.addField(newField, initValExp);
}
final CtClass accessorInterface = getCtClass(accessorTypeName);
ctClass.addInterface(accessorInterface);
CtMethod getterMethod = CtNewMethod.getter(accessorDetails.getGetter().getName(), newField);
ctClass.addMethod(getterMethod);
CtMethod setterMethod = CtNewMethod.setter(accessorDetails.getSetter().getName(), newField);
ctClass.addMethod(setterMethod);
} catch (Exception e) {
throw new InstrumentException("Failed to add field with accessor [" + accessorTypeName + "]. Cause:" + e.getMessage(), e);
}
}
Aggregations