Skip to content

Commit ffd2074

Browse files
committed
Add deprecated modifier when indexing from DOM
1 parent e06f5bc commit ffd2074

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/DOMToIndexVisitor.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public boolean visit(TypeDeclaration type) {
5656
.map(String::toCharArray)
5757
.toArray(char[][]::new);
5858
if (type.isInterface()) {
59-
this.sourceIndexer.addInterfaceDeclaration(type.getModifiers(), this.packageName, simpleName(type.getName()), enclosing, ((List<Type>)type.superInterfaceTypes()).stream().map(this::name).toArray(char[][]::new), parameterTypeSignatures, isSecondary(type));
59+
this.sourceIndexer.addInterfaceDeclaration(type.getModifiers() | maybeDeprecated(type), this.packageName, simpleName(type.getName()), enclosing, ((List<Type>)type.superInterfaceTypes()).stream().map(this::name).toArray(char[][]::new), parameterTypeSignatures, isSecondary(type));
6060
} else {
61-
this.sourceIndexer.addClassDeclaration(type.getModifiers(), this.packageName, simpleName(type.getName()), enclosing, type.getSuperclassType() == null ? null : name(type.getSuperclassType()),
61+
this.sourceIndexer.addClassDeclaration(type.getModifiers() | maybeDeprecated(type), this.packageName, simpleName(type.getName()), enclosing, type.getSuperclassType() == null ? null : name(type.getSuperclassType()),
6262
((List<Type>)type.superInterfaceTypes()).stream().map(this::name).toArray(char[][]::new), parameterTypeSignatures, isSecondary(type));
6363
if (type.bodyDeclarations().stream().noneMatch(member -> member instanceof MethodDeclaration method && method.isConstructor())) {
6464
this.sourceIndexer.addDefaultConstructorDeclaration(type.getName().getIdentifier().toCharArray(),
65-
this.packageName, type.getModifiers(), 0);
65+
this.packageName, type.getModifiers() | maybeDeprecated(type), 0);
6666
}
6767
if (type.getSuperclassType() != null) {
6868
this.sourceIndexer.addConstructorReference(name(type.getSuperclassType()), 0);
@@ -80,7 +80,7 @@ public void endVisit(TypeDeclaration type) {
8080
@Override
8181
public boolean visit(EnumDeclaration type) {
8282
char[][] enclosing = this.enclosingTypes.stream().map(AbstractTypeDeclaration::getName).map(SimpleName::getIdentifier).map(String::toCharArray).toArray(char[][]::new);
83-
this.sourceIndexer.addEnumDeclaration(type.getModifiers(), this.packageName, type.getName().getIdentifier().toCharArray(), enclosing, Enum.class.getName().toCharArray(), ((List<Type>)type.superInterfaceTypes()).stream().map(this::name).toArray(char[][]::new), isSecondary(type));
83+
this.sourceIndexer.addEnumDeclaration(type.getModifiers() | maybeDeprecated(type), this.packageName, type.getName().getIdentifier().toCharArray(), enclosing, Enum.class.getName().toCharArray(), ((List<Type>)type.superInterfaceTypes()).stream().map(this::name).toArray(char[][]::new), isSecondary(type));
8484
this.enclosingTypes.add(type);
8585
return true;
8686
}
@@ -98,7 +98,7 @@ public boolean visit(EnumConstantDeclaration enumConstant) {
9898
@Override
9999
public boolean visit(AnnotationTypeDeclaration type) {
100100
char[][] enclosing = this.enclosingTypes.stream().map(AbstractTypeDeclaration::getName).map(SimpleName::getIdentifier).map(String::toCharArray).toArray(char[][]::new);
101-
this.sourceIndexer.addAnnotationTypeDeclaration(type.getModifiers(), this.packageName, type.getName().getIdentifier().toCharArray(), enclosing, isSecondary(type));
101+
this.sourceIndexer.addAnnotationTypeDeclaration(type.getModifiers() | maybeDeprecated(type), this.packageName, type.getName().getIdentifier().toCharArray(), enclosing, isSecondary(type));
102102
this.enclosingTypes.add(type);
103103
return true;
104104
}
@@ -116,7 +116,7 @@ private boolean isSecondary(AbstractTypeDeclaration type) {
116116
public boolean visit(RecordDeclaration recordDecl) {
117117
this.enclosingTypes.add(recordDecl);
118118
// copied processing of TypeDeclaration
119-
this.sourceIndexer.addClassDeclaration(recordDecl.getModifiers(), this.packageName, recordDecl.getName().getIdentifier().toCharArray(), null, null,
119+
this.sourceIndexer.addClassDeclaration(recordDecl.getModifiers() | maybeDeprecated(recordDecl), this.packageName, recordDecl.getName().getIdentifier().toCharArray(), null, null,
120120
((List<Type>)recordDecl.superInterfaceTypes()).stream().map(this::name).toArray(char[][]::new), null, false);
121121
return true;
122122
}
@@ -155,7 +155,7 @@ public boolean visit(MethodDeclaration method) {
155155
parameterTypes,
156156
parameterNames,
157157
returnType,
158-
method.getModifiers(),
158+
method.getModifiers() | maybeDeprecated(method),
159159
this.packageName,
160160
0 /* TODO What to put here? */,
161161
exceptionTypes,
@@ -164,7 +164,7 @@ public boolean visit(MethodDeclaration method) {
164164
} else {
165165
this.sourceIndexer.addConstructorDeclaration(method.getName().getFullyQualifiedName().toCharArray(),
166166
method.parameters().size(),
167-
null, parameterTypes, parameterNames, method.getModifiers(), this.packageName, currentType().getModifiers(), exceptionTypes, 0);
167+
null, parameterTypes, parameterNames, method.getModifiers() | maybeDeprecated(method), this.packageName, currentType().getModifiers(), exceptionTypes, 0);
168168
}
169169
return true;
170170
}
@@ -339,7 +339,6 @@ public boolean visit(SimpleName name) {
339339
// TODO (cf SourceIndexer and SourceIndexerRequestor)
340340
// * Lambda: addIndexEntry/addClassDeclaration
341341
// * FieldReference
342-
// * Deprecated
343342

344343
@Override
345344
public boolean visit(MethodRef methodRef) {
@@ -423,4 +422,28 @@ public boolean visit(OpensDirective node) {
423422
return true;
424423
}
425424

425+
private int maybeDeprecated(BodyDeclaration declaration) {
426+
return hasDeprecated(declaration.modifiers()) || hasDeprecated(declaration.getJavadoc()) ? org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.AccDeprecated : 0;
427+
}
428+
private boolean hasDeprecated(List<?> modifiers) {
429+
if (modifiers == null) {
430+
return false;
431+
}
432+
return modifiers.stream()
433+
.filter(Annotation.class::isInstance)
434+
.map(Annotation.class::cast)
435+
.map(Annotation::getTypeName)
436+
.map(Name::getFullyQualifiedName)
437+
.anyMatch("Deprecated"::equals);
438+
}
439+
private boolean hasDeprecated(Javadoc javadoc) {
440+
if (javadoc == null) {
441+
return false;
442+
}
443+
return ((List<?>)javadoc.tags()).stream()
444+
.filter(TagElement.class::isInstance)
445+
.map(TagElement.class::cast)
446+
.map(TagElement::getTagName)
447+
.anyMatch(TagElement.TAG_DEPRECATED::equals);
448+
}
426449
}

0 commit comments

Comments
 (0)