-
Notifications
You must be signed in to change notification settings - Fork 865
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 8.4 Support: #[\Deprecated] Attribute #8139
PHP 8.4 Support: #[\Deprecated] Attribute #8139
Conversation
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/deprecated_attribute - Fix/Improve `SemanticAnalysis` - Get deprecated attributes or phpdoc tags from ASTNodes(Attributes and PHPDoc comments) instead of getting deprecated flags from an index. That way, it should also improve performance. - Add the `IncorrectDeprecatedAttributeHintError` because "Deprecated" attribute cannot target type and field - Add unit tests for the navigator, hints, and semantic analysis
- Use `Set.contains()` instead of a for-each loop
break; | ||
} | ||
} | ||
isDeprecated = getDeprecatedTypes().contains(fullyQualifiedName); |
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.
Use contains()
instead of a for-each loop. I think it's better.
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.
More readable, definitely.
} | ||
|
||
private Set<TypeElement> getDeprecatedTypes() { | ||
private Set<QualifiedName> getDeprecatedTypes() { |
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.
Changed this to use contains()
.
private boolean isDeprecatedDeclaration(ASTNode node) { | ||
boolean isDeprecated = false; | ||
if (!isCancelled() && isResolveDeprecatedElements()) { | ||
long startTime = 0; | ||
if (LOGGER.isLoggable(Level.FINE)) { | ||
startTime = System.currentTimeMillis(); | ||
} | ||
isDeprecated = VariousUtils.isDeprecated(model.getFileScope(), program, node); | ||
if (LOGGER.isLoggable(Level.FINE)) { | ||
long time = System.currentTimeMillis() - startTime; | ||
LOGGER.fine(String.format("isDeprecatedDeclaration() took %d ms", time)); // NOI18N | ||
} | ||
} | ||
return Collections.unmodifiableSet(deprecatedEnumCases); | ||
return isDeprecated; |
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.
Added instead of isDeprecated[Type|Method|...]Declaration()
.
We can check whether a target node has a "Deprecated" attribute/@deprecated
without getting all elements from an index. I hope this change also improves performance.
So, I removed getDeprecated[Methods|Constants|...]()
.
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.
Have you tried to "measure" it? Just curious. I don't expect any performance problems.
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.
I mean, just to check the times from logging you added, not to compare it to the previous implementation.
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.
Example:
#[Deprecated]
function deprecated(): void {
}
#[Deprecated("2.0.0", "use newFunction() instead")]
function deprecatedWithParam01(): void {
}
#[Deprecated(since: "2.0.0", message: "use newFunction() instead")]
function deprecatedWithParam02(): void {
}
#[\Deprecated]
function deprecatedFQN(): void {
}
#[\Deprecated("2.0.0", "use newFunction() instead")]
function deprecatedFQNWithParam01(): void {
}
#[\Deprecated(since: "2.0.0", message: "use newFunction() instead")]
function deprecatedFQNWithParam02(): void {
}
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
FINE [org.netbeans.modules.php.editor.csl.SemanticAnalysis]: isDeprecatedDeclaration() took 0 ms
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.
Looks great 👍
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.
The simplification looks nice. Many tests so we should be fine :) Thank you for all your work, @junichi11.
@tmysik Thank you for your time! Merging... |
PHP 8.4 Support: #[\Deprecated] Attribute (Part 1)
SemanticAnalysis
PHPDoc comments) instead of getting deprecated flags from an index.
That way, it should also improve performance.
IncorrectDeprecatedAttributeHintError
because "Deprecated"attribute cannot target type and field
Minor imporovement for SemanticAnalysis
Set.contains()
instead of a for-each loop