eclipse-xtext / eclipse-xtext/xtext

Feature Request: Mark extensions as "extension only"

Open
#2,279 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

In order to build beautiful APIs / internal DSLs with Xtend, it would be great to mark extensions as "extension only".

"extension only" means that you can only use the methods by appending the first method parameter.

Example:
I have this class:

class Element {
}

and this extension class:

interface ElementExtensions {
  def String getName(Element element)
}

and this class which uses oth types:

class Example {

  extension ElementExtensions 

  def void exampleMethod() {
    val element = new Element
    element.name // <-- Great!
    getName(element) // <-- shouldn't be possible
  }
}

I would like to have another keyword (or an annotation) to mark the extension as "extension only" which means that I can only use it by calling it like a method which is declared by the first parameter type. Of course fields and non-parameterized methods still have to be called "directly".

In my opinion this offers the possibility to wrute beautiful, extendable APIs without providing possibilities which are not intended (like getName(element) in the example).

As another positive side effect the proposals are restricted as you do not need to propose all the features provided by extensions.

Kind regards
Oliver

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not identify implementation files, tests, or an entry point. Start by locating Xtend extension resolution and proposal handling, then define the keyword or annotation behavior so extension methods remain callable through their first parameter while direct calls are rejected; add coverage for both forms and for fields or methods without parameters.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.