1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import org.eclipse.swt.graphics.Image; 15 16 import org.eclipse.jface.viewers.ITableLabelProvider; 17 import org.eclipse.jface.viewers.LabelProvider; 18 19 import org.eclipse.jdt.internal.ui.JavaPluginImages; 20 21 import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation; 22 23 class LocationLabelProvider extends LabelProvider implements ITableLabelProvider { 24 private static final int COLUMN_ICON= 0; 25 private static final int COLUMN_LINE= 1; 26 private static final int COLUMN_INFO= 2; 27 28 LocationLabelProvider() { 29 } 31 32 35 public String getText(Object element) { 36 return getColumnText(element, COLUMN_INFO); 37 } 38 39 public Image getImage(Object element) { 40 return getColumnImage(element, COLUMN_ICON); 41 } 42 43 private String removeWhitespaceOutsideStringLiterals(CallLocation callLocation) { 44 StringBuffer buf = new StringBuffer (); 45 boolean withinString = false; 46 47 String s= callLocation.getCallText(); 48 for (int i = 0; i < s.length(); i++) { 49 char ch = s.charAt(i); 50 51 if (ch == '"') { 52 withinString = !withinString; 53 } 54 55 if (withinString) { 56 buf.append(ch); 57 } else if (Character.isWhitespace(ch)) { 58 if ((buf.length() == 0) || 59 !Character.isWhitespace(buf.charAt(buf.length() - 1))) { 60 if (ch != ' ') { 61 ch = ' '; 62 } 63 64 buf.append(ch); 65 } 66 } else { 67 buf.append(ch); 68 } 69 } 70 71 return buf.toString(); 72 } 73 74 77 public Image getColumnImage(Object element, int columnIndex) { 78 if (columnIndex == COLUMN_ICON) { 79 return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SEARCH_OCCURRENCE); 80 } 81 return null; 82 } 83 84 87 public String getColumnText(Object element, int columnIndex) { 88 if (element instanceof CallLocation) { 89 CallLocation callLocation= (CallLocation) element; 90 91 switch (columnIndex) { 92 case COLUMN_LINE: 93 int lineNumber= callLocation.getLineNumber(); 94 if (lineNumber == CallLocation.UNKNOWN_LINE_NUMBER) { 95 return CallHierarchyMessages.LocationLabelProvider_unknown; 96 } else { 97 return String.valueOf(lineNumber); 98 } 99 case COLUMN_INFO: 100 return removeWhitespaceOutsideStringLiterals(callLocation); 101 } 102 } 103 104 return ""; } 106 } 107 | Popular Tags |