1 11 package org.eclipse.jdt.internal.ui.compare; 12 13 import org.eclipse.swt.graphics.Image; 14 15 import org.eclipse.jface.resource.ImageDescriptor; 16 17 import org.eclipse.jface.text.IDocument; 18 19 import org.eclipse.compare.ITypedElement; 20 import org.eclipse.compare.structuremergeviewer.DocumentRangeNode; 21 22 import org.eclipse.jdt.core.IJavaElement; 23 24 import org.eclipse.jdt.internal.ui.JavaPlugin; 25 26 30 class JavaNode extends DocumentRangeNode implements ITypedElement { 31 32 public static final int CU= 0; 33 public static final int PACKAGE= 1; 34 public static final int IMPORT_CONTAINER= 2; 35 public static final int IMPORT= 3; 36 public static final int INTERFACE= 4; 37 public static final int CLASS= 5; 38 public static final int ENUM= 6; 39 public static final int ANNOTATION= 7; 40 public static final int FIELD= 8; 41 public static final int INIT= 9; 42 public static final int CONSTRUCTOR= 10; 43 public static final int METHOD= 11; 44 45 private int fInitializerCount= 1; 46 47 55 public JavaNode(JavaNode parent, int type, String name, int start, int length) { 56 super(parent, type, JavaCompareUtilities.buildID(type, name), parent.getDocument(), start, length); 57 parent.addChild(this); 58 } 59 60 65 public JavaNode(IDocument document) { 66 super(CU, JavaCompareUtilities.buildID(CU, "root"), document, 0, document.getLength()); } 68 69 public String getInitializerCount() { 70 return Integer.toString(fInitializerCount++); 71 } 72 73 77 public String extractMethodName() { 78 String id= getId(); 79 int pos= id.indexOf('('); 80 if (pos > 0) 81 return id.substring(1, pos); 82 return id.substring(1); 83 } 84 85 89 public String extractArgumentList() { 90 String id= getId(); 91 int pos= id.indexOf('('); 92 if (pos >= 0) 93 return id.substring(pos+1); 94 return id.substring(1); 95 } 96 97 101 public String getName() { 102 103 switch (getTypeCode()) { 104 case INIT: 105 return CompareMessages.JavaNode_initializer; 106 case IMPORT_CONTAINER: 107 return CompareMessages.JavaNode_importDeclarations; 108 case CU: 109 return CompareMessages.JavaNode_compilationUnit; 110 case PACKAGE: 111 return CompareMessages.JavaNode_packageDeclaration; 112 } 113 return getId().substring(1); } 115 116 119 public String getType() { 120 return "java2"; } 122 123 128 public Image getImage() { 129 130 ImageDescriptor id= null; 131 132 switch (getTypeCode()) { 133 case CU: 134 id= JavaCompareUtilities.getImageDescriptor(IJavaElement.COMPILATION_UNIT); 135 break; 136 case PACKAGE: 137 id= JavaCompareUtilities.getImageDescriptor(IJavaElement.PACKAGE_DECLARATION); 138 break; 139 case IMPORT: 140 id= JavaCompareUtilities.getImageDescriptor(IJavaElement.IMPORT_DECLARATION); 141 break; 142 case IMPORT_CONTAINER: 143 id= JavaCompareUtilities.getImageDescriptor(IJavaElement.IMPORT_CONTAINER); 144 break; 145 case CLASS: 146 id= JavaCompareUtilities.getTypeImageDescriptor(true); 147 break; 148 case INTERFACE: 149 id= JavaCompareUtilities.getTypeImageDescriptor(false); 150 break; 151 case INIT: 152 id= JavaCompareUtilities.getImageDescriptor(IJavaElement.INITIALIZER); 153 break; 154 case CONSTRUCTOR: 155 case METHOD: 156 id= JavaCompareUtilities.getImageDescriptor(IJavaElement.METHOD); 157 break; 158 case FIELD: 159 id= JavaCompareUtilities.getImageDescriptor(IJavaElement.FIELD); 160 break; 161 case ENUM: 162 id= JavaCompareUtilities.getEnumImageDescriptor(); 163 break; 164 case ANNOTATION: 165 id= JavaCompareUtilities.getAnnotationImageDescriptor(); 166 break; 167 } 168 return JavaPlugin.getImageDescriptorRegistry().get(id); 169 } 170 171 174 public String toString() { 175 return getType() + ": " + getName() + "[" + getRange().offset + "+" + getRange().length + "]"; } 178 } 179 180 | Popular Tags |