1 11 12 package org.eclipse.ui.views.bookmarkexplorer; 13 14 import com.ibm.icu.text.DateFormat; 15 import java.util.Date ; 16 17 import org.eclipse.core.resources.IMarker; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IPath; 20 21 24 class MarkerUtil { 25 26 29 private MarkerUtil() { 30 } 31 32 35 static int getCharEnd(IMarker marker) { 36 return marker.getAttribute(IMarker.CHAR_END, -1); 37 } 38 39 42 static int getCharStart(IMarker marker) { 43 return marker.getAttribute(IMarker.CHAR_START, -1); 44 } 45 46 49 static String getContainerName(IMarker marker) { 50 IPath path = marker.getResource().getFullPath(); 51 int n = path.segmentCount() - 1; if (n <= 0) { 53 return ""; } 55 int len = 0; 56 for (int i = 0; i < n; ++i) { 57 len += path.segment(i).length(); 58 } 59 if (n > 1) { 61 len += n - 1; 62 } 63 StringBuffer sb = new StringBuffer (len); 64 for (int i = 0; i < n; ++i) { 65 if (i != 0) { 66 sb.append('/'); 67 } 68 sb.append(path.segment(i)); 69 } 70 return sb.toString(); 71 } 72 73 76 static int getLineNumber(IMarker marker) { 77 return marker.getAttribute(IMarker.LINE_NUMBER, -1); 78 } 79 80 83 static String getLocation(IMarker marker) { 84 return marker.getAttribute(IMarker.LOCATION, ""); } 86 87 91 static String getMessage(IMarker marker) { 92 return marker.getAttribute(IMarker.MESSAGE, ""); } 94 95 100 static int getNumericValue(String value) { 101 boolean negative = false; 102 int i = 0; 103 int len = value.length(); 104 105 if (i < len && value.charAt(i) == '#') { 108 ++i; 109 } 110 111 if (i < len && value.charAt(i) == '-') { 112 negative = true; 113 ++i; 114 } 115 116 int result = 0; 117 while (i < len) { 118 int digit = Character.digit(value.charAt(i++), 10); 119 if (digit < 0) { 120 return result; 121 } 122 result = result * 10 + digit; 123 } 124 if (negative) { 125 result = -result; 126 } 127 return result; 128 } 129 130 135 136 140 static String getResourceName(IMarker marker) { 141 return marker.getResource().getName(); 142 } 143 144 147 static String getCreationTime(IMarker marker) { 148 try { 149 return DateFormat.getDateTimeInstance(DateFormat.LONG, 150 DateFormat.MEDIUM).format( 151 new Date (marker.getCreationTime())); 152 } catch (CoreException e) { 153 return null; 154 } 155 } 156 } 157 | Popular Tags |