Skip to content

Commit 7c4bd1a

Browse files
authored
Merge pull request #8991 from mbien/find-enum-constructor-usage-fix
Fixes find-usages and call-hierarchy on enum constructors.
2 parents 39844dd + 49d04ad commit 7c4bd1a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

java/refactoring.java/src/org/netbeans/modules/refactoring/java/WhereUsedElement.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public static WhereUsedElement create(CompilationInfo compiler, TreePath tree, b
162162
return create(compiler, tree, null, inTest, inPlatform, inDependency, inImport);
163163
}
164164

165+
@SuppressWarnings({"NestedAssignment", "AssignmentToMethodParameter"})
165166
public static WhereUsedElement create(CompilationInfo compiler, TreePath tree, JavaWhereUsedFilters.ReadWrite access, boolean inTest, boolean inPlatform, boolean inDependency, AtomicBoolean inImport) {
166167
CompilationUnitTree unit = tree.getCompilationUnit();
167168
CharSequence content = compiler.getSnapshot().getText();
@@ -195,9 +196,7 @@ public static WhereUsedElement create(CompilationInfo compiler, TreePath tree, J
195196
if (TreeUtilities.CLASS_TREE_KINDS.contains(t.getKind())) {
196197
int[] pos = treeUtils.findNameSpan((ClassTree)t);
197198
if (pos == null) {
198-
Tree tr = tree.getParentPath().getLeaf();
199-
if (tr instanceof NewClassTree) {
200-
NewClassTree newClass = (NewClassTree) tr;
199+
if (tree.getParentPath().getLeaf() instanceof NewClassTree newClass) {
201200
start = (int) sp.getStartPosition(unit, newClass.getIdentifier());
202201
end = (int) sp.getEndPosition(unit, newClass.getIdentifier());
203202
} else {
@@ -207,7 +206,7 @@ public static WhereUsedElement create(CompilationInfo compiler, TreePath tree, J
207206
start = end = (int) sp.getStartPosition(unit, t);
208207
}
209208
// #213723 hotfix, happens for enum values
210-
if(start < 0) {
209+
if(start < 0 || end < 0) {
211210
TreePath parentPath = tree.getParentPath();
212211
if(parentPath != null && (parentPath = parentPath.getParentPath()) != null
213212
&& parentPath.getLeaf().getKind() == Tree.Kind.VARIABLE) {

0 commit comments

Comments
 (0)