use of com.navercorp.pinpoint.profiler.instrument.GetterAnalyzer.GetterDetails in project pinpoint by naver.
the class JavassistClass method addGetter.
@Override
public void addGetter(String getterTypeName, String fieldName) throws InstrumentException {
try {
Class<?> getterType = pluginContext.injectClass(classLoader, getterTypeName);
GetterAnalyzer getterAnalyzer = new GetterAnalyzer();
GetterDetails getterDetails = getterAnalyzer.analyze(getterType);
CtField field = ctClass.getField(fieldName);
String fieldTypeName = JavaAssistUtils.javaClassNameToObjectName(getterDetails.getFieldType().getName());
if (!field.getType().getName().equals(fieldTypeName)) {
throw new IllegalArgumentException("Return type of the getter is different with the field type. getterMethod: " + getterDetails.getGetter() + ", fieldType: " + field.getType().getName());
}
CtMethod getterMethod = CtNewMethod.getter(getterDetails.getGetter().getName(), field);
if (getterMethod.getDeclaringClass() != ctClass) {
getterMethod = CtNewMethod.copy(getterMethod, ctClass, null);
}
ctClass.addMethod(getterMethod);
CtClass ctInterface = getCtClass(getterTypeName);
ctClass.addInterface(ctInterface);
} catch (Exception e) {
throw new InstrumentException("Failed to add getter: " + getterTypeName, e);
}
}
Aggregations