1 package org.apache.maven.plugin.cxx.utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.lang.reflect.Field;
22
23
24
25
26
27
28
29 public class ClassAccessHelper
30 {
31 public static <T> T getFieldValue( Object o, String fieldName, Class<T> cls )
32 throws NoSuchFieldException, IllegalAccessException
33 {
34 Field field = o.getClass().getDeclaredField( fieldName );
35 if ( null != field )
36 {
37 field.setAccessible( true );
38 Object value = field.get( o );
39 if ( null != value && cls.isInstance( value ) )
40 {
41 return (T) value;
42 }
43 }
44 return null;
45 }
46
47 public static <T> void setFieldValue( Object o, String fieldName, T value )
48 throws NoSuchFieldException, IllegalAccessException
49 {
50 Field field = o.getClass().getDeclaredField( fieldName );
51 if ( null != field )
52 {
53 field.setAccessible( true );
54 field.set( o, value );
55 }
56 }
57 }