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.
Use contains() instead of a for-each loop. I think it's better.
| } | ||
|
|
||
| private Set<TypeElement> getDeprecatedTypes() { | ||
| private Set<QualifiedName> getDeprecatedTypes() { |
There was a problem hiding this comment.
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.
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.
Have you tried to "measure" it? Just curious. I don't expect any performance problems.
There was a problem hiding this comment.
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.
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
tmysik
left a comment
There was a problem hiding this comment.
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)
SemanticAnalysisPHPDoc comments) instead of getting deprecated flags from an index.
That way, it should also improve performance.
IncorrectDeprecatedAttributeHintErrorbecause "Deprecated"attribute cannot target type and field
Minor imporovement for SemanticAnalysis
Set.contains()instead of a for-each loop