1616import java .util .HashMap ;
1717import java .util .Map ;
1818
19+ import org .eclipse .core .runtime .Assert ;
1920import org .eclipse .core .runtime .CoreException ;
2021import org .eclipse .core .runtime .Platform ;
2122import org .eclipse .core .runtime .jobs .ISchedulingRule ;
5556 */
5657public class JavaVariableLabelProvider extends VariableLabelProvider implements IPreferenceChangeListener {
5758
58- private final static JDIModelPresentation fLabelProvider = new JDIModelPresentation ();
59+ private static JDIModelPresentation fLabelProvider = new JDIModelPresentation ();
5960
6061 /**
6162 * Map of view id to qualified name setting
@@ -113,10 +114,9 @@ protected FontData getFontData(TreePath elementPath, IPresentationContext presen
113114 return result ;
114115 }
115116 var element = elementPath .getLastSegment ();
116- if (element instanceof IJavaVariable ) {
117- var variable = (IJavaVariable ) element ;
117+ if (element instanceof IJavaVariable variable ) {
118118 var value = variable .getValue ();
119- if (value instanceof IJavaObject && (( IJavaObject ) value ) .getLabel () != null ) {
119+ if (value instanceof IJavaObject object && object .getLabel () != null ) {
120120 return new FontData (result .getName (), result .getHeight (), result .getStyle () ^ SWT .BOLD );
121121 }
122122 }
@@ -142,7 +142,7 @@ protected String getVariableTypeName(IVariable variable, IPresentationContext co
142142 * Returns if the the specified presentation context is showing qualified names or not
143143 * @return true if the presentation context is showing qualified names, false otherwise
144144 */
145- private Boolean isShowQualfiiedNames (IPresentationContext context ) {
145+ private Boolean isShowQualifiedNames (IPresentationContext context ) {
146146 Boolean qualified = fQualifiedNameSettings .get (context .getId ());
147147 if (qualified == null ) {
148148 qualified = Boolean .valueOf (Platform .getPreferencesService ().getBoolean (
@@ -161,8 +161,8 @@ private Boolean isShowQualfiiedNames(IPresentationContext context) {
161161 @ Override
162162 protected String getColumnText (IVariable variable , IValue value , IPresentationContext context , String columnId ) throws CoreException {
163163 if (JavaVariableColumnPresentation .COLUMN_INSTANCE_ID .equals (columnId )) {
164- if (value instanceof JDIObjectValue ) {
165- long uniqueId = (( JDIObjectValue ) value ) .getUniqueId ();
164+ if (value instanceof JDIObjectValue objectValue ) {
165+ long uniqueId = objectValue .getUniqueId ();
166166 if (uniqueId >= 0 ) {
167167 StringBuilder buffer = new StringBuilder ();
168168 buffer .append (uniqueId );
@@ -172,28 +172,26 @@ protected String getColumnText(IVariable variable, IValue value, IPresentationCo
172172 return "" ; //$NON-NLS-1$
173173 }
174174 if (JavaVariableColumnPresentation .COLUMN_INSTANCE_COUNT .equals (columnId )) {
175- if (value instanceof IJavaObject ) {
176- IJavaType jType = (( IJavaObject ) value ) .getJavaType ();
177- if (jType == null && variable instanceof IJavaVariable ) {
178- jType = (( IJavaVariable ) variable ) .getJavaType ();
175+ if (value instanceof IJavaObject object ) {
176+ IJavaType jType = object .getJavaType ();
177+ if (jType == null && variable instanceof IJavaVariable var ) {
178+ jType = var .getJavaType ();
179179 }
180- if (jType instanceof IJavaReferenceType ) {
181- if (!(jType instanceof IJavaInterfaceType )) {
182- long count = ((IJavaReferenceType )jType ).getInstanceCount ();
183- if (count == -1 ) {
184- return DebugUIMessages .JavaVariableLabelProvider_0 ;
185- }
186- StringBuilder buffer = new StringBuilder ();
187- buffer .append (count );
188- return buffer .toString ();
180+ if (jType instanceof IJavaReferenceType refType && !(jType instanceof IJavaInterfaceType )) {
181+ long count = refType .getInstanceCount ();
182+ if (count == -1 ) {
183+ return DebugUIMessages .JavaVariableLabelProvider_0 ;
189184 }
185+ StringBuilder buffer = new StringBuilder ();
186+ buffer .append (count );
187+ return buffer .toString ();
190188 }
191189 }
192190 return "" ; //$NON-NLS-1$
193191 }
194192 if (JavaVariableColumnPresentation .COLUMN_LABEL .equals (columnId )) {
195- if (value instanceof IJavaObject ) {
196- String label = (( IJavaObject ) value ) .getLabel ();
193+ if (value instanceof IJavaObject object ) {
194+ String label = object .getLabel ();
197195 if (label != null ) {
198196 return label ;
199197 }
@@ -208,7 +206,7 @@ protected String getColumnText(IVariable variable, IValue value, IPresentationCo
208206 */
209207 @ Override
210208 protected void retrieveLabel (ILabelUpdate update ) throws CoreException {
211- Boolean showQ = isShowQualfiiedNames (update .getPresentationContext ());
209+ Boolean showQ = isShowQualifiedNames (update .getPresentationContext ());
212210 fQualifiedNames = showQ .booleanValue ();
213211 fLabelProvider .setAttribute (JDIModelPresentation .DISPLAY_QUALIFIED_NAMES , showQ );
214212 super .retrieveLabel (update );
@@ -259,11 +257,11 @@ protected ISchedulingRule getRule(ILabelUpdate update) {
259257 break ;
260258 case SERIALIZE_SOME :
261259 Object element = update .getElement ();
262- if (element instanceof IJavaVariable ) {
260+ if (element instanceof IJavaVariable javaVariable ) {
263261 try {
264- IValue value = (( IJavaVariable ) element ) .getValue ();
265- if (value instanceof IJavaValue ) {
266- if (!fLabelProvider .isShowLabelDetails (( IJavaValue ) value )) {
262+ IValue value = javaVariable .getValue ();
263+ if (value instanceof IJavaValue javaValue ) {
264+ if (!fLabelProvider .isShowLabelDetails (javaValue )) {
267265 input = update .getViewerInput ();
268266 frame = (IJavaStackFrame ) DebugPlugin .getAdapter (input , IJavaStackFrame .class );
269267 }
@@ -290,4 +288,24 @@ public void preferenceChange(PreferenceChangeEvent event) {
290288 determineSerializationMode ((String ) event .getNewValue ());
291289 }
292290 }
293- }
291+
292+ /**
293+ * @return the model presentation used to display Java elements, never {@code null}
294+ * @since 3.14
295+ */
296+ protected static JDIModelPresentation getModelPresentation () {
297+ return fLabelProvider ;
298+ }
299+
300+ /**
301+ * Sets the model presentation used by this label provider to the specified object.
302+ *
303+ * @param presentation
304+ * the new presentation, may not be {@code null}
305+ * @since 3.14
306+ */
307+ protected static void setModelPresentation (final JDIModelPresentation presentation ) {
308+ Assert .isNotNull (presentation );
309+ fLabelProvider = presentation ;
310+ }
311+ }
0 commit comments