KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > editors > tree > FieldNode


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.editors.tree;
5
6 import org.eclipse.jdt.core.IField;
7 import org.eclipse.jdt.core.IType;
8 import org.eclipse.jdt.core.JavaModelException;
9 import org.eclipse.jdt.core.Signature;
10
11 import org.terracotta.dso.PatternHelper;
12
13 /**
14  * A TreeNode that represents a Java field, or instance variable.
15  *
16  * @see JavaProjectNode
17  * @see org.eclipse.jdt.core.IField
18  */

19
20 public class FieldNode extends JavaProjectNode {
21   private IField m_field;
22   private String JavaDoc m_moniker;
23   private String JavaDoc m_fullName;
24   
25   public FieldNode(IField field) {
26     super(field);
27     
28     IType parentType = field.getDeclaringType();
29     String JavaDoc name = field.getElementName();
30     String JavaDoc type = getTypeSignature(field);
31     
32     m_field = field;
33     m_moniker = type != null ? name +" : "+type : name;
34     m_fullName = PatternHelper.getFullyQualifiedName(parentType)+"."+name;
35   }
36   
37   private static String JavaDoc getTypeSignature(IField field) {
38     try {
39       String JavaDoc result = field.getTypeSignature();
40       return Signature.getSimpleName(Signature.toString(result));
41     } catch(JavaModelException jme) {
42       return null;
43     }
44   }
45   
46   public IField getField() {
47     return m_field;
48   }
49   
50   public String JavaDoc toString() {
51     return m_moniker;
52   }
53
54   public String JavaDoc getSignature() {
55     return getFullyQualifiedName();
56   }
57   
58   public String JavaDoc[] getFields() {
59     return new String JavaDoc[] {getFullyQualifiedName()};
60   }
61   
62   public String JavaDoc getFullyQualifiedName() {
63     return m_fullName;
64   }
65 }
66
Popular Tags