junichi11 commented on code in PR #8139:
URL: https://github.com/apache/netbeans/pull/8139#discussion_r1911803883
##########
php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java:
##########
@@ -228,94 +224,61 @@ public ASTNodeColoring(ASTNode identifier,
Set<ColoringAttributes> coloring) {
private final Map<UnusedIdentifier, ASTNodeColoring>
privateUnusedMethods;
// this is holder of blocks, which has to be scanned for usages in the
class.
private final Map<TypeInfo, List<Block>> needToScan = new HashMap<>();
-
private final Snapshot snapshot;
-
private final Model model;
-
- private Set<TypeElement> deprecatedTypes;
-
- private Set<MethodElement> deprecatedMethods;
-
- private Set<FieldElement> deprecatedFields;
-
- private Set<TypeConstantElement> deprecatedConstants;
-
- private Set<EnumCaseElement> deprecatedEnumCases;
-
- private Set<FunctionElement> deprecatedFunctions;
-
+ private final Program program;
+ private Set<QualifiedName> deprecatedTypes;
// last visited type declaration
private TypeInfo typeInfo;
-
- public SemanticHighlightVisitor(Map<OffsetRange,
Set<ColoringAttributes>> highlights, Snapshot snapshot, Model model) {
+ public SemanticHighlightVisitor(Map<OffsetRange,
Set<ColoringAttributes>> highlights, Snapshot snapshot, Model model, Program
program) {
this.highlights = highlights;
privateUnusedConstants = new HashMap<>();
privateFieldsUnused = new HashMap<>();
privateUnusedMethods = new HashMap<>();
this.snapshot = snapshot;
this.model = model;
+ this.program = program;
}
- private Set<TypeElement> getDeprecatedTypes() {
+ private Set<QualifiedName> getDeprecatedTypes() {
if (isCancelled()) {
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
if (deprecatedTypes == null) {
- deprecatedTypes =
ElementFilter.forDeprecated(true).filter(model.getIndexScope().getIndex().getTypes(NameKind.empty()));
+ deprecatedTypes = getDeprecatedFQTypeNames();
}
return Collections.unmodifiableSet(deprecatedTypes);
}
- private Set<MethodElement> getDeprecatedMethods() {
- if (isCancelled()) {
- return Collections.EMPTY_SET;
- }
- if (deprecatedMethods == null) {
- deprecatedMethods =
ElementFilter.forDeprecated(true).filter(model.getIndexScope().getIndex().getMethods(NameKind.empty()));
- }
- return Collections.unmodifiableSet(deprecatedMethods);
- }
-
- private Set<FunctionElement> getDeprecatedFunctions() {
- if (isCancelled()) {
- return Collections.EMPTY_SET;
- }
- if (deprecatedFunctions == null) {
- deprecatedFunctions =
ElementFilter.forDeprecated(true).filter(model.getIndexScope().getIndex().getFunctions(NameKind.empty()));
- }
- return Collections.unmodifiableSet(deprecatedFunctions);
- }
-
- private Set<FieldElement> getDeprecatedFields() {
- if (isCancelled()) {
- return Collections.EMPTY_SET;
- }
- if (deprecatedFields == null) {
- deprecatedFields =
ElementFilter.forDeprecated(true).filter(model.getIndexScope().getIndex().getFields(NameKind.empty()));
- }
- return Collections.unmodifiableSet(deprecatedFields);
- }
-
- private Set<TypeConstantElement> getDeprecatedConstants() {
+ private Set<QualifiedName> getDeprecatedFQTypeNames() {
if (isCancelled()) {
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
- if (deprecatedConstants == null) {
- deprecatedConstants =
ElementFilter.forDeprecated(true).filter(model.getIndexScope().getIndex().getTypeConstants(NameKind.empty()));
+ Set<QualifiedName> names = new HashSet<>();
+ Set<TypeElement> types =
model.getIndexScope().getIndex().getTypes(NameKind.empty());
+ for (TypeElement type : types) {
+ if (type.isDeprecated()) {
+ names.add(type.getFullyQualifiedName());
+ }
}
- return Collections.unmodifiableSet(deprecatedConstants);
+ return names;
}
- private Set<EnumCaseElement> getDeprecatedEnumCases() {
- if (isCancelled()) {
- return Collections.EMPTY_SET;
- }
- if (deprecatedEnumCases == null) {
- deprecatedEnumCases =
ElementFilter.forDeprecated(true).filter(model.getIndexScope().getIndex().getEnumCases(NameKind.empty()));
+ 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;
Review 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|...]()`.
##########
php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java:
##########
@@ -228,94 +224,61 @@ public ASTNodeColoring(ASTNode identifier,
Set<ColoringAttributes> coloring) {
private final Map<UnusedIdentifier, ASTNodeColoring>
privateUnusedMethods;
// this is holder of blocks, which has to be scanned for usages in the
class.
private final Map<TypeInfo, List<Block>> needToScan = new HashMap<>();
-
private final Snapshot snapshot;
-
private final Model model;
-
- private Set<TypeElement> deprecatedTypes;
-
- private Set<MethodElement> deprecatedMethods;
-
- private Set<FieldElement> deprecatedFields;
-
- private Set<TypeConstantElement> deprecatedConstants;
-
- private Set<EnumCaseElement> deprecatedEnumCases;
-
- private Set<FunctionElement> deprecatedFunctions;
-
+ private final Program program;
+ private Set<QualifiedName> deprecatedTypes;
// last visited type declaration
private TypeInfo typeInfo;
-
- public SemanticHighlightVisitor(Map<OffsetRange,
Set<ColoringAttributes>> highlights, Snapshot snapshot, Model model) {
+ public SemanticHighlightVisitor(Map<OffsetRange,
Set<ColoringAttributes>> highlights, Snapshot snapshot, Model model, Program
program) {
this.highlights = highlights;
privateUnusedConstants = new HashMap<>();
privateFieldsUnused = new HashMap<>();
privateUnusedMethods = new HashMap<>();
this.snapshot = snapshot;
this.model = model;
+ this.program = program;
}
- private Set<TypeElement> getDeprecatedTypes() {
+ private Set<QualifiedName> getDeprecatedTypes() {
Review Comment:
Changed to use `contains()`.
##########
php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java:
##########
@@ -952,12 +810,7 @@ private boolean isDeprecatedType(QualifiedName
qualifiedName, int offset) {
if (!isCancelled() && isResolveDeprecatedElements()) {
VariableScope variableScope = model.getVariableScope(offset);
QualifiedName fullyQualifiedName =
VariousUtils.getFullyQualifiedName(qualifiedName, offset, variableScope);
- for (TypeElement typeElement : getDeprecatedTypes()) {
- if
(typeElement.getFullyQualifiedName().equals(fullyQualifiedName)) {
- isDeprecated = true;
- break;
- }
- }
+ isDeprecated =
getDeprecatedTypes().contains(fullyQualifiedName);
Review Comment:
Use `contains()` instead of a for-each loop. I think it's better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists