Bug 77352 - [misc] Provide "alternate representations" in editor, e.g. BigDecimal as if operator overloading
Summary: [misc] Provide "alternate representations" in editor, e.g. BigDecimal as if o...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-31 16:56 EST by Ben Youngdahl CLA
Modified: 2009-04-14 09:47 EDT (History)
3 users (show)

See Also:


Attachments
a simple operator overload test result (38.04 KB, image/png)
2009-04-11 14:52 EDT, Xiang Qinxian CLA
no flags Details
oo simple implementation (18.55 KB, patch)
2009-04-11 15:00 EDT, Xiang Qinxian CLA
no flags Details | Diff
relative to the text patch effect (141.58 KB, image/jpeg)
2009-04-14 05:58 EDT, Xiang Qinxian CLA
no flags Details
operator overload patch for jdt.core.compiler.ast (26.83 KB, patch)
2009-04-14 06:10 EDT, Xiang Qinxian CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Youngdahl CLA 2004-10-31 16:56:52 EST
Operator overloading does not look like it will be making its way into the Java
platform anytime soon.   This means that financial math involving BigDecimal
tends to look rather messy compared to what it might look like if operator
overloading was available.

I think Eclipse has an opportunity to help the comprehension of programs by
providing alternate representations for Java code, syntactical sugar if you
will.     Eclipse could identify sections of code that might be more clearly
understood with an alternate representation, and then provide a means for users
to switch that chunk to the alternate form.  At all times the actual text
written to disk would be the *canonical Java form*.  The user could potentially
edit the code in the alternate form and then know that the correct Java form was
written to disk, toggling back and forth to understand the relation between what
they see and what they get.

For example, the user might see:
   a * b - c 
rather than
   a.multiply(b).minus(c)

So how would Eclipse know that BigDecimal.multiply is the "*" operator? 
Metadata, either Java 5.0 annotations, or in the case of system classes,
seperate annotation data.

One of the tough things about C++ operator overloading is that it is hard to
look at the code and understand what overloaded operators are called and with
what precedence -- i.e. the actual behavior can remain hidden.  This feature
aims to tackle that by saying that the actual code on disk is the real deal --
exactly what will run in canonical Java.  It's just the representation in the
editor that can be toggled to show the alternate viewing/editing form which may
simplify the comprehension for the reader.

Anyways, just thought I'd share this idea.  Thanks for making such a great IDE.
Comment 1 Dani Megert CLA 2004-11-01 12:53:02 EST
This also affects Compare and eventually formatting i.e. would the alternate
representation be formatted.
Comment 2 Dani Megert CLA 2007-06-22 09:59:22 EDT
Get rid of deprecated state.
Comment 3 Xiang Qinxian CLA 2009-04-11 14:52:07 EDT
Created attachment 131550 [details]
a simple operator overload test result
Comment 4 Xiang Qinxian CLA 2009-04-11 15:00:00 EDT
Created attachment 131551 [details]
oo simple implementation 

At beginning, I want to employ CompilationPariticipant to handle.
After coding, I found I not want rewrite to source code of editor, 
and don't know how to apply change to jdt dom AST.
So redoing it from parser, get this way.
Another issue, 
List list;
list+"abc" jdt recog to a single assignment expression, and no other info, 
I not think it as good way.
Maybe someone have interest to talk this:)
Comment 5 Dani Megert CLA 2009-04-14 04:02:57 EDT
I can't see any effect in the editor when using your patch.
Comment 6 Xiang Qinxian CLA 2009-04-14 05:56:08 EDT
Comment on attachment 131550 [details]
a simple operator overload test result

I make a wrong choice for the picture
Comment 7 Xiang Qinxian CLA 2009-04-14 05:58:41 EDT
Created attachment 131752 [details]
relative to the text patch effect

should be this picture
Comment 8 Xiang Qinxian CLA 2009-04-14 06:03:04 EDT
(In reply to comment #5)
> I can't see any effect in the editor when using your patch.
> 

the patch is my first try, you should pass compilation of the binaryExpression of assignment expression.
After this, I added tries for method argument and combine binar expression, and the assignment.
more details, please see http://code.google.com/p/oo-jdt
or the lastest patch I also attatched
Comment 9 Dani Megert CLA 2009-04-14 06:04:35 EDT
>or the lastest patch I also attatched
Can't see it here.
Comment 10 Xiang Qinxian CLA 2009-04-14 06:10:12 EDT
Created attachment 131756 [details]
operator overload patch for jdt.core.compiler.ast

the patch added method argument, combined binaryexpression, and this single assignment which jdt report Syntax error.
More, the operator overload built on jdt normal process, so default syntax the patch not add any additional behavor, f.e.
list+ "abc" + 3
jdt handle "abc"+3 success
so the patch just resolve:
 list + a(=["abc"+3])
so the list item should be "abc3"
Comment 11 Xiang Qinxian CLA 2009-04-14 06:15:12 EDT
(In reply to comment #9)
> >or the lastest patch I also attatched
> Can't see it here.
> 

Right I uploaded it. Indeed, my now workspace used it.
BTW, I log it at http://www.jroller.com/qinxianscript
and I sure it's some kind of reason this blog://
http://www.dzone.com/links/why_java_doesnt_need_operator_overloading_and_ver.html
hahaha

Comment 12 Dani Megert CLA 2009-04-14 08:51:20 EDT
Sorry, I still can't see a difference in the editor. Do you have an example that would show me what your patch does?
Comment 13 Markus Keller CLA 2009-04-14 09:25:56 EDT
(In reply to comment #10)
> Created an attachment (id=131756) [details]
> operator overload patch for jdt.core.compiler.ast

It looks like your patch is changing the AST, which is a definite no-go (we cannot invent our own Java dialect).

The intention of this bug is to only modify the representation in the editor (not the file on disk, etc.). But to be honest, I doubt that this is feasible without major changes to the Java editor, since all code that deals with offsets would have to take the modifications into account.
Comment 14 Xiang Qinxian CLA 2009-04-14 09:41:13 EDT
(In reply to comment #12)
> Sorry, I still can't see a difference in the editor. Do you have an example
> that would show me what your patch does?
> 

Yes, there is a jar 
http://oo-jdt.googlecode.com/files/org.eclipse.jdt.core_3.5.0.v_946.jar
the binary show:
BigInteger a, b;
a=a+b;

it not handle assignment and combine binary expression.
there is screenshot:
http://oo-jdt.googlecode.com/files/operatoroverload2.jpg
or 
http://code.google.com/p/oo-jdt/
Comment 15 Xiang Qinxian CLA 2009-04-14 09:47:34 EDT
(In reply to comment #13)
> (In reply to comment #10)
> > Created an attachment (id=131756) [details] [details]
> > operator overload patch for jdt.core.compiler.ast
> 
> It looks like your patch is changing the AST, which is a definite no-go (we
> cannot invent our own Java dialect).
> 
Yes, the way do changed AST. the main idea just try the aproach:
When InvalidOperator problem or ParsingErrorInvalidToken(InvalidAssignment) error, just try to MessageSend resolve.

> The intention of this bug is to only modify the representation in the editor
> (not the file on disk, etc.). But to be honest, I doubt that this is feasible
> without major changes to the Java editor, since all code that deals with
> offsets would have to take the modifications into account.
> 
Yes, the way diff from the intention of this bug.
through, the offsets do in account.