Skip to content

PHP 8.4 Support: #[\Deprecated] Attribute#8139

Merged
junichi11 merged 2 commits intoapache:masterfrom
junichi11:php84-deprecated-attribute
Jan 11, 2025
Merged

PHP 8.4 Support: #[\Deprecated] Attribute#8139
junichi11 merged 2 commits intoapache:masterfrom
junichi11:php84-deprecated-attribute

Conversation

@junichi11
Copy link
Copy Markdown
Member

@junichi11 junichi11 commented Jan 11, 2025

PHP 8.4 Support: #[\Deprecated] Attribute (Part 1)

nb-php84-deprecated-attribute-constant

nb-php84-deprecated-attribute-incorrect-class

nb-php84-deprecated-attribute-incorrect-field

Minor imporovement for SemanticAnalysis

  • Use Set.contains() instead of a for-each loop

- 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
@junichi11 junichi11 added the PHP [ci] enable extra PHP tests (php/php.editor) label Jan 11, 2025
@junichi11 junichi11 added this to the NB25 milestone Jan 11, 2025
break;
}
}
isDeprecated = getDeprecatedTypes().contains(fullyQualifiedName);
Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

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() {
Copy link
Copy Markdown
Member Author

@junichi11 junichi11 Jan 11, 2025

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().

Comment on lines +268 to +281
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;
Copy link
Copy Markdown
Member Author

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|...]().

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 👍

@junichi11 junichi11 requested a review from tmysik January 11, 2025 02:39
@junichi11 junichi11 mentioned this pull request Jan 11, 2025
4 tasks
Copy link
Copy Markdown
Member

@tmysik tmysik left a 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.

@junichi11
Copy link
Copy Markdown
Member Author

@tmysik Thank you for your time! Merging...

@junichi11 junichi11 merged commit 0b5cc44 into apache:master Jan 11, 2025
@junichi11 junichi11 deleted the php84-deprecated-attribute branch January 11, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PHP [ci] enable extra PHP tests (php/php.editor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants