Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » introducing typedef and const in java
introducing typedef and const in java [message #1709990] Fri, 02 October 2015 14:07 Go to next message
Ricky Rick is currently offline Ricky RickFriend
Messages: 4
Registered: October 2015
Junior Member
Hi,

preface:
I'm basically looking out for some way of making java support a const and a typedef keyword.
const: the const known from c++, that prevents writing-access to objects, that are marked as const
typedef: also known e.g. from c++ to create alias names for types.

xtext seems to be pretty able to do it, but I can't find anything on google regarding my concern. Although some other people also already asked for const and typedef in java.

main question
So before spending too many hours trying xtext out, I wanted to ask, if anybody has any experience using xtext to create the support for typedef and const in java?

regards
Re: introducing typedef and const in java [message #1710016 is a reply to message #1709990] Fri, 02 October 2015 16:41 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hey Ricky,

I don't know what you mean by "const for Java". Java is always pass-by-value, so it is always what C++ calls "const".

Aliasing can be done quite easily through the ScopeProvider.

Cheers,
Stefan
Re: introducing typedef and const in java [message #1710018 is a reply to message #1710016] Fri, 02 October 2015 16:58 Go to previous messageGo to next message
Ricky Rick is currently offline Ricky RickFriend
Messages: 4
Registered: October 2015
Junior Member
I'll better provide an example for the const:
class MyStringClass { }
class Foo {
    private MyStringClass privateObject;
    MyStringClass getPrivateObject()
    { 
         return privateObject; 
    }
}

public static void main()
{
    Foo foo = new Foo();
    MyStringClass = foo.getPrivateObject();
}


The class Foo has no control over what happens to the privateObject anymore. In c++ you could return a "const MyStringClass"-Reference instead and prevent any changes to and through the MyStringClass.

[Updated on: Fri, 02 October 2015 16:59]

Report message to a moderator

Re: introducing typedef and const in java [message #1710020 is a reply to message #1710018] Fri, 02 October 2015 17:25 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

I see, so you would have to annotate every method to indicate "this will not change the argument". How would you deal with all the existing methods in the JDK that do not have this information?

Xbase actually has a validation that is very similar. It flags expressions when they have no side effects and the return value is not used. That should give you an idea how you could build the const feature.
Re: introducing typedef and const in java [message #1710021 is a reply to message #1710020] Fri, 02 October 2015 17:36 Go to previous messageGo to next message
Ricky Rick is currently offline Ricky RickFriend
Messages: 4
Registered: October 2015
Junior Member
that validation-feature sounds pretty much like the one, I'm searching for!

Quote:
How would you deal with all the existing methods in the JDK that do not have this information?

Probably wrap around it and annotate myself.

To not make it forgotton:
How about the typedef-feature? Do you have idea for that? Or a "will take about x hours for a beginner to create that feature"-information?

regards
Re: introducing typedef and const in java [message #1710035 is a reply to message #1710021] Fri, 02 October 2015 19:26 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

It depends on how powerful those aliases are.

Simple name mappings like

import java.math.BigDecimal as decimal


are easily handled in the ScopeProvider.

Replacing whole type references like

type People is List<Person>


would require advanced knowledge of the Xbase typesystem.
Re: introducing typedef and const in java [message #1710124 is a reply to message #1710035] Sun, 04 October 2015 18:54 Go to previous message
Ricky Rick is currently offline Ricky RickFriend
Messages: 4
Registered: October 2015
Junior Member
Thank you for your estimation!
As you didn't mention it, it seems that nobody else tried that before me :/
Previous Topic:Ecore file from Xtext instance Models
Next Topic:SVG export for Xtext Syntax Graph
Goto Forum:
  


Current Time: Thu Mar 28 20:09:42 GMT 2024

Powered by FUDForum. Page generated in 0.02392 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top