1 4 package org.terracotta.dso.editors.tree; 5 6 import org.eclipse.jdt.core.IClassFile; 7 import org.eclipse.jdt.core.IType; 8 import org.eclipse.jdt.core.JavaModelException; 9 10 import org.terracotta.dso.PatternHelper; 11 12 import java.util.ArrayList ; 13 import java.util.Arrays ; 14 15 import javax.swing.tree.TreeNode ; 16 17 23 24 public class ClassFileNode extends JavaProjectNode { 25 private IClassFile m_classFile; 26 private String m_signature; 27 private String m_moduleName; 28 private boolean m_showFields; 29 private boolean m_showMethods; 30 private boolean m_showTypes; 31 private TypeNode m_typeNode; 32 33 public ClassFileNode(IClassFile classFile) { 34 this(classFile, true, true, true); 35 } 36 37 public ClassFileNode( 38 IClassFile classFile, 39 boolean showFields, 40 boolean showMethods, 41 boolean showTypes) 42 { 43 super(classFile); 44 45 m_classFile = classFile; 46 m_moduleName = internalGetType().getElementName()+".class"; 47 m_signature = showMethods ? PatternHelper.getExecutionPattern(internalGetType()) : 48 PatternHelper.getWithinPattern(internalGetType()); 49 m_showFields = showFields; 50 m_showMethods = showMethods; 51 m_showTypes = showTypes; 52 } 53 54 public int getChildCount() { 55 return 1; 56 } 57 58 public TreeNode getChildAt(int index) { 59 if(m_typeNode == null) { 60 m_typeNode = buildTypeNode(); 61 } 62 63 return m_typeNode; 64 } 65 66 private TypeNode buildTypeNode() { 67 IType type = internalGetType(); 68 return new TypeNode(type, m_showFields, m_showMethods, m_showTypes); 69 } 70 71 public String getSignature() { 72 return m_signature; 73 } 74 75 public String [] getFields() { 76 ArrayList <String > list = new ArrayList <String >(); 77 int childCount = getChildCount(); 78 79 for(int i = 0; i < childCount; i++) { 80 list.addAll(Arrays.asList(((TypeNode)getChildAt(i)).getFields())); 81 } 82 83 return list.toArray(new String [0]); 84 } 85 86 public String toString() { 87 return m_moduleName; 88 } 89 90 private IType internalGetType() { 91 try { 92 return m_classFile.getType(); 93 } catch(JavaModelException jme) { 94 jme.printStackTrace(); 95 return null; 96 } 97 } 98 } 99 | Popular Tags |