-
Notifications
You must be signed in to change notification settings - Fork 874
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
PHP: Improve enum cases #6825
PHP: Improve enum cases #6825
Conversation
- Add the `isBacked()` method to the `CaseElement` and the `EnumCaseElement` interfaces - Don't add values of non-backed enums to the code completion documentation - Index whether it is an enum case of a backed enum as a boolean value - Fix/Add unit tests - Increment spec version
@@ -289,15 +341,41 @@ private void checkStatements(List<Statement> statements, EnumDeclaration node) { | |||
incorrectEnumProperties.add((FieldsDeclaration) statement); | |||
} else if (statement instanceof UseTraitStatement) { | |||
useTraits.put(node, (UseTraitStatement) statement); | |||
} else if (statement instanceof CaseDeclaration) { | |||
checkCaseDeclaration((CaseDeclaration) statement, isBackedEnum); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: an extra empty line perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
incorrectNonBackedEnumCases.add(caseDeclaration); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: an extra empty line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:no empty line after this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice and useful improvement! 👍
I'll fix them later. Thank you, Tomas! |
- Fix the `IncorrectEnumHintErorr` - Cases of non-backed enum must not have a value (e.g. the following is a fatal error: `enum NonBacked {case EXAMPLE = 1;}`) - Cases of backed enum must have a value (e.g. the following is a fatal error: `enum Backed: int {case EXAMPLE;}`) - Add/Fix unit tests
There is an error in the following example because `case B = self::` is not a complete statement. Thus, the result of parsing doesn't recognize the enum declaration. This means that some features don't work correctly. (e.g. The enum declaration doesn't exist in the navigator. The code completion doesn't work.) ```php enum Example: int { case A = 1; case B = self:: } ``` To improve this, add the `ASTErrorExpression` as a result of an enum case initializer part. - Fix the parser - Add unit tests
00870b5
to
52127d6
Compare
Add the enum case icon
CC Light
Before:
After:
Navigator Light
Before:
After:
CC Dark
Before:
After:
Navigator Dark
After:
Before:
Improve the code completion documentation for enum cases
isBacked()
method to theCaseElement
and theEnumCaseElement
interfacesBefore:
After:
Check an initializer of an enum case
IncorrectEnumHintErorr
is a fatal error:
enum NonBacked {case EXAMPLE = 1;}
)fatal error:
enum Backed: int {case EXAMPLE;}
)Before:
After:
Improve the code completion for enum cases
There is an error in the following example because
case B = self::
is not a complete statement.Thus, the result of parsing doesn't recognize the enum declaration.
This means that some features don't work correctly.
(e.g. The enum declaration doesn't exist in the navigator. The code completion doesn't work.)
To improve this, add the
ASTErrorExpression
as a result of an enum case initializer part.Before:
After: