Bug 569606 - Cannot use Detail Formatters on class object types when using "this" keyword
Summary: Cannot use Detail Formatters on class object types when using "this" keyword
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.18   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation, example, ui
Depends on:
Blocks:
 
Reported: 2020-12-09 15:06 EST by Taro Kyo CLA
Modified: 2020-12-09 16:03 EST (History)
0 users

See Also:


Attachments
Screenshot (67.32 KB, image/png)
2020-12-09 15:06 EST, Taro Kyo CLA
no flags Details
Correct usage of Detail Formatters (52.10 KB, image/png)
2020-12-09 16:03 EST, Taro Kyo CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Taro Kyo CLA 2020-12-09 15:06:09 EST
Created attachment 285010 [details]
Screenshot

Eclipse Version: 2020-12 RC1 (4.18.0 RC1)
Build id: 20201203-2138
Java 8 LTS

Steps to reproduce:


1. Create a simple program, and set a breakpoint anywhere. The program must import "java.time.*" to make use of the class object "OffsetDateTime".

2. Debug the program and make sure the breakpoint is hit.

3. In the Expressions view, type in "OffsetDateTime.now()". This should show up as an "OffsetDateTime" object, which you can inspect and view by expanding the field.

4. Right-click on the "OffsetDateTime.now()", and select "Edit Detail Formatter".

5. Type in the text field the following:       "this.toString()"

6. Click "Apply and Close".

7. Observe the result displays: "Evaluations must contain either an expression or a block of well-formed statements"

See attachment of my screen capture.

When searching online on how to use Detail Formatters, there is clearly a lack of resources available to explain what is supported and what isn't supported in Detail Formatters.

When an evaluated object in the Expressions view is given, what do you do to pass in that evaluated object into the Detail Formatter, so that it can be used further to obtain the data necessary to print to the screen?

The goal for me is to be able to use Detail Formatter to print out "OffsetDateTime.now().toString()" without having to type them in the Expressions view. Clearly, this isn't working.
Comment 1 Taro Kyo CLA 2020-12-09 16:02:04 EST
WAIT WAIT WAIT


The Expressions view contains 3 things:

1. The Expressions column.
2. The Values column.
3. The Values text area (also known as the Detail Formatter output).

I have always misunderstood what the "Values" column is used for, and why it sometimes print values, strings, and reference IDs (e.g. "(id = 319)"). Never understood why it does that.

(The Values column is only 1 line tall, therefore it is pointless to have multiple lines showing the evaluated results.)

Every detail formatter outputs will go in the Values text area. No exceptions.

In the Detail Formatter, you are not supposed to use "this" and "return" keywords. Both of them are implied when writing the Detail Formatter, as the Detail Formatter is used to "override" the default "toString()" method, and it's written as a code snippet, not as a full Java method.

Code snippets, what are they? 

A statement or a code block which consists of:

- No "this" keyword.
- No "return" keyword.
- None of other keywords you find in a normal Java application.
- Only the class member fields and methods associated with the object in which we are override its "toString()" method with. These are displayed when invoking the Content Assist inside the "Edit Detail Formatter" text area.
- Not allowed to use any local variables outside of the object type we are using to override the "toString()" with.
- Can allow the usage of fully canonical class names and static methods.

You never will get to read about this on other online resources out there at all.

When folks mention to use the Content Assist inside the Detail Formatter, they are not telling you to read up Content Assist and know what syntax to use inside the Detail Formatter. It's more of, what "can" you really use in the Detail Formatter" and only those things listed in the Content Assist can ever be used in the Detail Formatter.

Content Assist does not tell you to not use "this" or "return" or other keywords  at all. You don't use keywords at all.
Comment 2 Taro Kyo CLA 2020-12-09 16:03:58 EST
Created attachment 285011 [details]
Correct usage of Detail Formatters

Appends the previous comment.