KickJava   Java API By Example, From Geeks To Geeks.

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


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.IMethod;
7 import org.eclipse.jdt.core.Signature;
8
9 import org.terracotta.dso.PatternHelper;
10
11 /**
12  * A TreeNode that represents a Java method.
13  *
14  * @see JavaProjectNode
15  */

16
17 public class MethodNode extends JavaProjectNode {
18   private IMethod m_method;
19   private String JavaDoc m_moniker;
20   private String JavaDoc m_signature;
21   
22   public MethodNode(IMethod method) {
23     super(method);
24
25     m_method = method;
26     m_moniker = buildMoniker(method);
27     m_signature = buildSignature(method);
28   }
29   
30   private static String JavaDoc buildSignature(IMethod method) {
31     return PatternHelper.getExecutionPattern(method);
32   }
33   
34   private static String JavaDoc buildMoniker(IMethod method) {
35     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
36     String JavaDoc paramTypes[] = getParameterTypes(method);
37     
38     sb.append(method.getElementName());
39     sb.append("(");
40     
41     for(int i = 0; i < paramTypes.length; i++) {
42       sb.append(paramTypes[i]);
43
44       if(i < paramTypes.length-1) {
45         sb.append(", ");
46       }
47     }
48     sb.append(")");
49     
50     return sb.toString();
51   }
52   
53   private static String JavaDoc[] getParameterTypes(IMethod method) {
54     String JavaDoc[] typeSigs = method.getParameterTypes();
55     String JavaDoc[] types = new String JavaDoc[typeSigs.length];
56     
57     for(int i= 0; i < typeSigs.length; i++) {
58       types[i]= Signature.getSimpleName(Signature.toString(typeSigs[i]));
59     }
60     
61     return types;
62   }
63   
64   public IMethod getMethod() {
65     return m_method;
66   }
67
68   public String JavaDoc getSignature() {
69     return m_signature;
70   }
71   
72   public String JavaDoc[] getFields() {
73     return new String JavaDoc[0];
74   }
75   
76   public String JavaDoc toString() {
77     return m_moniker;
78   }
79 }
80
Popular Tags