KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > runtime > reflect > FieldSignatureImpl


1 /* *******************************************************************
2  * Copyright (c) 1999-2001 Xerox Corporation,
3  * 2002 Palo Alto Research Center, Incorporated (PARC).
4  * All rights reserved.
5  * This program and the accompanying materials are made available
6  * under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * Xerox/PARC initial implementation
12  * ******************************************************************/

13
14
15 package org.aspectj.runtime.reflect;
16  
17 import java.lang.reflect.Field JavaDoc;
18
19 import org.aspectj.lang.reflect.FieldSignature;
20
21 public class FieldSignatureImpl extends MemberSignatureImpl implements FieldSignature {
22     Class JavaDoc fieldType;
23     private Field JavaDoc field;
24     
25     FieldSignatureImpl(int modifiers, String JavaDoc name, Class JavaDoc declaringType,
26         Class JavaDoc fieldType)
27     {
28         super(modifiers, name, declaringType);
29         this.fieldType = fieldType;
30     }
31     
32     FieldSignatureImpl(String JavaDoc stringRep) {
33         super(stringRep);
34     }
35     
36     public Class JavaDoc getFieldType() {
37         if (fieldType == null) fieldType = extractType(3);
38         return fieldType;
39     }
40     
41     protected String JavaDoc createToString(StringMaker sm) {
42         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
43         buf.append(sm.makeModifiersString(getModifiers()));
44         if (sm.includeArgs) buf.append(sm.makeTypeName(getFieldType()));
45         if (sm.includeArgs) buf.append(" ");
46         buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
47         buf.append(".");
48         buf.append(getName());
49         return buf.toString();
50     }
51     
52     /* (non-Javadoc)
53      * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
54      */

55     public Field JavaDoc getField() {
56         if (field == null) {
57             try {
58                 field = getDeclaringType().getDeclaredField(getName());
59             } catch (Exception JavaDoc ex) {
60                 ; // nothing we can do, caller will see null
61
}
62         }
63         return field;
64     }
65 }
66
Popular Tags