-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider replacing all enum
types with classes containing static constants
#645
Comments
Also, returning So, the limitations of using Java However, could not we try to come up with an alternative approach that would still be type-safe and object-oriented, e.g. by generating wrapper classes for enumerations with Xtend? It might then be used consistently for both integer- and string-based enumerations. |
Just as a sketch, what if this declaration in Xtend: /**
* A notebook cell kind.
* <p>
* Since 3.17.0
*/
@JsonRpcEnum
class NotebookCellKind {
/**
* A markup-cell is formatted source that is used for display.
*/
public static val Markup = 1;
/**
* A code-cell is source code.
*/
public static val Code = 2;
} would have been translated to the following class in Java: /**
* A notebook cell kind.
* <p>
* Since 3.17.0
*/
public final class NotebookCellKind {
/**
* A markup-cell is formatted source that is used for display.
*/
public static final NotebookCellKind Markup = new NotebookCellKind(1);
/**
* A code-cell is source code.
*/
public static final NotebookCellKind Code = new NotebookCellKind(2);
private final int value;
public static NotebookCellKind forValue(int value) {
switch (value) {
case 1:
return Markup;
case 2:
return Code;
default:
return new NotebookCellKind(value);
}
}
private NotebookCellKind(int value) {
this.value = value;
}
public int getValue() {
return value;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
NotebookCellKind other = (NotebookCellKind)obj;
return value == other.value;
}
@Override
public int hashCode() {
return value;
}
@Override
public String toString() {
switch (value) {
case 1:
return "Markup";
case 2:
return "Code";
default:
return "Unknown value: " + value;
}
}
} |
The convention we currently use in LSP4J is to have
enum
types for the integer-based enumerations and classes containing static constants for the string-based enumerations.I propose we make them all classes containing static constants. There are three reasons I can express for this change.
Protocol.xtend
instead of having to create separate Java files for eachenum
.enum
would becomenull
and thus not be preserved.This would be a breaking change.
The text was updated successfully, but these errors were encountered: