Skip to content

Commit 62dd506

Browse files
kysmith-csgiloveeclipse
authored andcommitted
Cleanup JavaVariableLabelProvider
1 parent d5f5113 commit 62dd506

File tree

1 file changed

+25
-49
lines changed

1 file changed

+25
-49
lines changed

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelProvider.java

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,14 @@ public JavaVariableLabelProvider() {
8181
}
8282
}
8383

84-
/* (non-Javadoc)
85-
* @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getValueText(org.eclipse.debug.core.model.IVariable, org.eclipse.debug.core.model.IValue)
86-
*/
8784
@Override
8885
protected String getValueText(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
89-
if (value instanceof IJavaValue) {
90-
return fLabelProvider.getFormattedValueText((IJavaValue) value);
86+
if (value instanceof IJavaValue javaValue) {
87+
return fLabelProvider.getFormattedValueText(javaValue);
9188
}
9289
return super.getValueText(variable, value, context);
9390
}
9491

95-
/* (non-Javadoc)
96-
* @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getValueTypeName(org.eclipse.debug.core.model.IVariable, org.eclipse.debug.core.model.IValue)
97-
*/
9892
@Override
9993
protected String getValueTypeName(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
10094
String typeName= DebugUIMessages.JDIModelPresentation_unknown_type__2;
@@ -114,19 +108,15 @@ protected FontData getFontData(TreePath elementPath, IPresentationContext presen
114108
return result;
115109
}
116110
var element = elementPath.getLastSegment();
117-
if (element instanceof IJavaVariable) {
118-
var variable = (IJavaVariable) element;
111+
if (element instanceof IJavaVariable variable) {
119112
var value = variable.getValue();
120-
if (value instanceof IJavaObject && ((IJavaObject) value).getLabel() != null) {
113+
if (value instanceof IJavaObject javaObject && javaObject.getLabel() != null) {
121114
return new FontData(result.getName(), result.getHeight(), result.getStyle() ^ SWT.BOLD);
122115
}
123116
}
124117
return result;
125118
}
126119

127-
/* (non-Javadoc)
128-
* @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getVariableTypeName(org.eclipse.debug.core.model.IVariable)
129-
*/
130120
@Override
131121
protected String getVariableTypeName(IVariable variable, IPresentationContext context) throws CoreException {
132122
String typeName= DebugUIMessages.JDIModelPresentation_unknown_type__2;
@@ -143,7 +133,7 @@ protected String getVariableTypeName(IVariable variable, IPresentationContext co
143133
* Returns if the the specified presentation context is showing qualified names or not
144134
* @return true if the presentation context is showing qualified names, false otherwise
145135
*/
146-
private Boolean isShowQualfiiedNames(IPresentationContext context) {
136+
private Boolean isShowQualifiedNames(IPresentationContext context) {
147137
Boolean qualified = fQualifiedNameSettings.get(context.getId());
148138
if (qualified == null) {
149139
qualified = Boolean.valueOf(Platform.getPreferencesService().getBoolean(
@@ -156,14 +146,11 @@ private Boolean isShowQualfiiedNames(IPresentationContext context) {
156146
return qualified;
157147
}
158148

159-
/* (non-Javadoc)
160-
* @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getColumnText(org.eclipse.debug.core.model.IVariable, org.eclipse.debug.core.model.IValue, java.lang.String, org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext)
161-
*/
162149
@Override
163150
protected String getColumnText(IVariable variable, IValue value, IPresentationContext context, String columnId) throws CoreException {
164151
if (JavaVariableColumnPresentation.COLUMN_INSTANCE_ID.equals(columnId)) {
165-
if (value instanceof JDIObjectValue) {
166-
long uniqueId = ((JDIObjectValue)value).getUniqueId();
152+
if (value instanceof JDIObjectValue objectValue) {
153+
long uniqueId = objectValue.getUniqueId();
167154
if (uniqueId >= 0) {
168155
StringBuilder buffer = new StringBuilder();
169156
buffer.append(uniqueId);
@@ -173,28 +160,26 @@ protected String getColumnText(IVariable variable, IValue value, IPresentationCo
173160
return ""; //$NON-NLS-1$
174161
}
175162
if (JavaVariableColumnPresentation.COLUMN_INSTANCE_COUNT.equals(columnId)) {
176-
if (value instanceof IJavaObject) {
177-
IJavaType jType = ((IJavaObject)value).getJavaType();
178-
if (jType == null && variable instanceof IJavaVariable) {
179-
jType = ((IJavaVariable)variable).getJavaType();
163+
if (value instanceof IJavaObject javaObject) {
164+
IJavaType jType = javaObject.getJavaType();
165+
if (jType == null && variable instanceof IJavaVariable javaVariable) {
166+
jType = javaVariable.getJavaType();
180167
}
181-
if (jType instanceof IJavaReferenceType) {
182-
if (!(jType instanceof IJavaInterfaceType)) {
183-
long count = ((IJavaReferenceType)jType).getInstanceCount();
184-
if (count == -1) {
185-
return DebugUIMessages.JavaVariableLabelProvider_0;
186-
}
187-
StringBuilder buffer = new StringBuilder();
188-
buffer.append(count);
189-
return buffer.toString();
168+
if (jType instanceof IJavaReferenceType refType && !(jType instanceof IJavaInterfaceType)) {
169+
long count = refType.getInstanceCount();
170+
if (count == -1) {
171+
return DebugUIMessages.JavaVariableLabelProvider_0;
190172
}
173+
StringBuilder buffer = new StringBuilder();
174+
buffer.append(count);
175+
return buffer.toString();
191176
}
192177
}
193178
return ""; //$NON-NLS-1$
194179
}
195180
if (JavaVariableColumnPresentation.COLUMN_LABEL.equals(columnId)) {
196-
if (value instanceof IJavaObject) {
197-
String label = ((IJavaObject) value).getLabel();
181+
if (value instanceof IJavaObject javaObject) {
182+
String label = javaObject.getLabel();
198183
if (label != null) {
199184
return label;
200185
}
@@ -209,7 +194,7 @@ protected String getColumnText(IVariable variable, IValue value, IPresentationCo
209194
*/
210195
@Override
211196
protected void retrieveLabel(ILabelUpdate update) throws CoreException {
212-
Boolean showQ = isShowQualfiiedNames(update.getPresentationContext());
197+
Boolean showQ = isShowQualifiedNames(update.getPresentationContext());
213198
fQualifiedNames = showQ.booleanValue();
214199
fLabelProvider.setAttribute(JDIModelPresentation.DISPLAY_QUALIFIED_NAMES, showQ);
215200
super.retrieveLabel(update);
@@ -230,9 +215,6 @@ private void determineSerializationMode(String value) {
230215
}
231216
}
232217

233-
/* (non-Javadoc)
234-
* @see org.eclipse.debug.internal.ui.model.elements.VariableLabelProvider#getLabel(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
235-
*/
236218
@Override
237219
protected String getLabel(TreePath elementPath, IPresentationContext context, String columnId) throws CoreException {
238220
if (columnId == null) {
@@ -245,9 +227,6 @@ protected String getLabel(TreePath elementPath, IPresentationContext context, St
245227
return super.getLabel(elementPath, context, columnId);
246228
}
247229

248-
/* (non-Javadoc)
249-
* @see org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider#getRule(org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate)
250-
*/
251230
@Override
252231
protected ISchedulingRule getRule(ILabelUpdate update) {
253232
IJavaStackFrame frame = null;
@@ -260,11 +239,11 @@ protected ISchedulingRule getRule(ILabelUpdate update) {
260239
break;
261240
case SERIALIZE_SOME:
262241
Object element = update.getElement();
263-
if (element instanceof IJavaVariable) {
242+
if (element instanceof IJavaVariable javaVariable) {
264243
try {
265-
IValue value = ((IJavaVariable)element).getValue();
266-
if (value instanceof IJavaValue) {
267-
if (!fLabelProvider.isShowLabelDetails((IJavaValue)value)) {
244+
IValue value = javaVariable.getValue();
245+
if (value instanceof IJavaValue javaValue) {
246+
if (!fLabelProvider.isShowLabelDetails(javaValue)) {
268247
input = update.getViewerInput();
269248
frame = (IJavaStackFrame) DebugPlugin.getAdapter(input, IJavaStackFrame.class);
270249
}
@@ -280,9 +259,6 @@ protected ISchedulingRule getRule(ILabelUpdate update) {
280259
return null;
281260
}
282261

283-
/* (non-Javadoc)
284-
* @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
285-
*/
286262
@Override
287263
public void preferenceChange(PreferenceChangeEvent event) {
288264
if (event.getKey().endsWith(IJDIPreferencesConstants.PREF_SHOW_QUALIFIED_NAMES)) {

0 commit comments

Comments
 (0)