eclipse-archived/ceylon

Suggestion: Single annotation instead of 'shared' and 'restricted'.

Closed this issue · 1 comments

It would be great to have one and more powerful annotation instead (or as alternative)of two 'shared' and 'restricted':

shared abstract class VisibilityLevel() of outside | limited | subclass {}

"[Default] The element is visible outside block"
shared object outside extends VisibilityLevel() {}

"The visibility of element is restricted by package or module"
shared object limited extends VisibilityLevel() {}

"The element is visible only in subclasses"
shared object subclass extends VisibilityLevel() {}

shared final sealed annotation class PublicAnnotation(VisibilityLevel level = outside, Module* modules)
satisfies OptionalAnnotation<PublicAnnotation,
FunctionOrValueDeclaration
| ClassOrInterfaceDeclaration
| ConstructorDeclaration
| Package> {}

shared annotation PublicAnnotation public(VisibilityLevel level = outside, Module* modules)
=> PublicAnnotation(level, *modules);

void privateFunction() {

}

"Same with 'shared' annotation"
public void publicFunction() {

}

public(subclass) void protectedFunction() {

}

"Same with 'restricted' annotation"
public(limited) void packageRestrictedFunction() {

}

"Same with 'restricted' annotation"
public(limited, 'module') void moduleRestrictedFunction() {

}

This was an option we considered at the time we introduced restricted, and ultimately decided against. At this point I definitely don't want to introduce a second way to do the same thing (or deprecate restricted). Besides, I'm very happy with the current design.