diff options
author | Vikas Chandra | 2020-09-04 04:15:57 +0000 |
---|---|---|
committer | Vikas Chandra | 2020-09-04 13:06:19 +0000 |
commit | d853c33dd09ccb6d7cb3e62c3eef6b0d2d721bc3 (patch) | |
tree | 5d16c48e375c981fb72972327f9079daf9615a73 | |
parent | ff6752786b17a8f5e248edd1260cc4e3f134d679 (diff) | |
download | eclipse.jdt.core-d853c33dd09ccb6d7cb3e62c3eef6b0d2d721bc3.tar.gz eclipse.jdt.core-d853c33dd09ccb6d7cb3e62c3eef6b0d2d721bc3.tar.xz eclipse.jdt.core-d853c33dd09ccb6d7cb3e62c3eef6b0d2d721bc3.zip |
field of a record
Change-Id: Ic0b0b397106f58709a9ee31a989fd3655b3a9e40
Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
3 files changed, 65 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs15Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs15Tests.java index 9badd0bd9f..7289e1fd85 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs15Tests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs15Tests.java @@ -1716,5 +1716,60 @@ public class JavaSearchBugs15Tests extends AbstractJavaSearchTests { this.resultCollector); } + public void test566507_componentSelectAndSearch() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", + "public record Point(int /* here*/comp_) { \n" + + " public Point {\n" + + " comp_=11;\n" + + " }\n" + + "public void method ( ) { \n"+ + " int compp_=11;\n" + + "} \n"+ + "}\n" + ); + + String str = this.workingCopies[0].getSource(); + String selection = "/* here*/comp_"; + int start = str.indexOf(selection); + int length = selection.length(); + + IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); + assertTrue(elements.length ==1); + assertTrue(elements[0] instanceof SourceField); + search(elements[0], REFERENCES, EXACT_RULE); + assertSearchResults( + "src/X.java Point(int) [comp_] EXACT_MATCH"); + + } + public void test566507_fieldSelectAndSearch() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", + "public record Point(int /* here*/comp_) { \n" + + " public static int staticF =0;\n" + + " public Point {\n" + + " comp_=11;\n" + + " staticF=11;\n" + + " }\n" + + "public void method ( ) { \n"+ + " int compp_=11;\n" + + "} \n"+ + "}\n" + ); + + String str = this.workingCopies[0].getSource(); + String selection = "staticF"; + int start = str.indexOf(selection); + int length = selection.length(); + + IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); + assertTrue(elements.length ==1); + assertTrue(elements[0] instanceof SourceField); + search(elements[0], ALL_OCCURRENCES, EXACT_RULE); + assertSearchResults( + "src/X.java Point.staticF [staticF] EXACT_MATCH\n" + + "src/X.java Point(int) [staticF] EXACT_MATCH"); + + } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java index 0762d59361..b1c28f4d68 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java @@ -954,7 +954,7 @@ public interface IType extends IMember, IAnnotatable { * @noreference This method is not intended to be referenced by clients as it is a part of Java preview feature. */ default IField[] getRecordComponents() throws JavaModelException { - return null; + return new IField[0]; } /** * Returns the record component with the specified name diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java index 8ee095c0ca..51f82007f0 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java @@ -14,6 +14,7 @@ package org.eclipse.jdt.internal.core; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -271,6 +272,14 @@ public void acceptField(char[] declaringTypePackageName, char[] declaringTypeNam if(type != null) { try { IField[] fields = type.getFields(); + if (type.isRecord()) { + IField[] comps = type.getRecordComponents(); + if(comps.length > 0) { + IField[] f = fields; + fields = Arrays.copyOf(f, f.length + comps.length); + System.arraycopy(comps, 0, fields, f.length, comps.length); + } + } for (int i = 0; i < fields.length; i++) { IField field = fields[i]; ISourceRange range = field.getNameRange(); |