Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs15Tests.java')
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs15Tests.java798
1 files changed, 0 insertions, 798 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 8f56122ed8..d58c02074b 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
@@ -21,7 +21,6 @@ import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -32,11 +31,6 @@ import org.eclipse.jdt.core.search.ReferenceMatch;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.TypeReferenceMatch;
-import org.eclipse.jdt.internal.core.LocalVariable;
-import org.eclipse.jdt.internal.core.ResolvedSourceField;
-import org.eclipse.jdt.internal.core.ResolvedSourceType;
-import org.eclipse.jdt.internal.core.SourceField;
-import org.eclipse.jdt.internal.core.SourceMethod;
import org.eclipse.jdt.internal.core.SourceType;
import junit.framework.Test;
@@ -400,797 +394,5 @@ public class JavaSearchBugs15Tests extends AbstractJavaSearchTests {
}
}
- // Record related tests for Java 15
- // 0 reference of the component in compact constructor
- public void testBug558812_001() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " }\n" +
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
- //1 reference of the component in compact constructor
- // Java 15 - should give 0 reference
- public void testBug558812_002() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
- //2 reference of the component in compact constructor
- // Java 15 - only 1 - although code compiles no more but it should give 1 result
- public void testBug558812_003() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " this.comp_=11;\n" +
- " }\n" +
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("src/X.java Point(int) [comp_] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
- //3 reference of the component in compact constructor
- //Java 15 only 1 this.comp_ reference should be given
- public void testBug558812_004() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " this.comp_=comp_;\n" +
- " }\n" +
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("src/X.java Point(int) [comp_] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
- //0 reference of the component in canonical constructor
- public void testBug558812_005() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point (int a) {\n" +
- " }\n" +
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
- //1 reference of the component in canonical constructor
- public void testBug558812_006() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point (int a) {\n" +
- " comp_=11;\n" +
- " }\n" +
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("src/X.java Point(int) [comp_] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
- //1 reference of the component in canonical constructor - part2
- public void testBug558812_007() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point (int a) {\n" +
- " // comp_=11;\n" +
- " this.comp_=a;\n" +
- " }\n" +
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("src/X.java Point(int) [comp_] EXACT_MATCH");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
- //1 reference of the component in compact constructor - clashing method parameter
- // Java 15 - 0 reference
- public void testBug558812_008() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( int comp_) { \n"+
- "} \n"+
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
-
- //1 reference of the component in compact constructor - clashing method's local variable
- // Java 15 - 0 reference
- public void testBug558812_009() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int comp_=11;\n" +
- "} \n"+
- "}\n"
- );
- IJavaProject javaProject = this.workingCopies[0].getJavaProject(); //assuming single project for all working copies
- String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
- try {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- search("comp_", FIELD, REFERENCES);
- assertSearchResults("");
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
- }
-
- // more test case
- // test case of comp_ selection in compact constructor
- // selection - select record type
- public void testBug558812_010() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int 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*/Point";
- int start = str.indexOf(selection);
- int length = selection.length();
-
- IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
- assertTrue(elements.length ==1);
- //TODO: check if record
- }
-
- //selection - select local field in a method in record
- public void testBug558812_011() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int /* here*/compp_=11;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/compp_";
- 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 LocalVariable);
-
- }
-
- //selection - select local field in a compact constructor in record
- public void testBug558812_012() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int comp_) { \n" +
- " public Point {\n" +
- " /* here*/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 LocalVariable);
-
- }
-
- //selection - select local field in a compact constructor in record
- public void testBug558812_013() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int comp_) { \n" +
- " public Point {\n" +
- " /* here*/this.comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=11;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/this.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 ResolvedSourceField);
- }
-
- //selection - select field in a method in record ( using this)
- public void testBug558812_014() throws CoreException {
-
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int comp_) { \n" +
- " public Point {\n" +
- " /* here*/comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=/* here*/this.comp_;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/this.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 ResolvedSourceField);
- }
-
- //selection - select field in a method in record ( without this)
- public void testBug558812_015() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=/* here2*/comp_;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here2*/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 ResolvedSourceField);
- ResolvedSourceField sm = (ResolvedSourceField)elements[0];
- IJavaElement parent = sm.getParent();
- SourceType st = (SourceType)parent;
- assertTrue(st.isRecord());
- }
-
- //changed for Java 15
- public void testBug558812_016() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " /*here2*/comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=comp_;\n" +
- " int compp2_=comp_;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/*here2*/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 LocalVariable);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java Point(int) [comp_] EXACT_MATCH");
- }
- //java 15 change
- public void testBug558812_016a() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=comp_;\n" +
- " int compp2_=comp_;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "comp_";
- int start = str.lastIndexOf(selection);
- int length = selection.length();
-
- IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
- assertTrue(elements.length ==1);
- assertTrue(elements[0] instanceof IField);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java void Point.method() [comp_] EXACT_MATCH\n" +
- "src/X.java void Point.method() [comp_] EXACT_MATCH");
- }
-
- public void testBug558812_017() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " /*here2*/comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=comp_;\n" +
- " int compp2_=comp_;\n" +
- " int compp3_=this.comp_;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/*here2*/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 LocalVariable);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java Point(int) [comp_] EXACT_MATCH");
-
- }
- //java 15 change
- public void testBug558812_017a() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=comp_;\n" +
- " int compp2_=comp_;\n" +
- " int compp3_=this.comp_;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "comp_";
- int start = str.lastIndexOf(selection);
- int length = selection.length();
-
- IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
- assertTrue(elements.length ==1);
- assertTrue(elements[0] instanceof IField);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java void Point.method() [comp_] EXACT_MATCH\n" +
- "src/X.java void Point.method() [comp_] EXACT_MATCH\n" +
- "src/X.java void Point.method() [comp_] EXACT_MATCH");
- }
-
- //selection - select CC type
- public void testBug558812_018() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public /* here*/Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- " public Point (int a, int b){\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=11;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/Point";
- 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 SourceMethod);
- SourceMethod sm = (SourceMethod)elements[0];
- IJavaElement parent = sm.getParent();
- SourceType st = (SourceType)parent;
- assertTrue(st.isRecord());
- }
-
- //selection - select CC type and search
- public void testBug558812_019() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public /* here*/Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- " public Point (int a, int b){\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=11;\n" +
- " Point p = new Point(1) ;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/Point";
- 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 SourceMethod);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java void Point.method() [new Point(1)] EXACT_MATCH");
- }
-
- //selection - select non-CC type and search
- public void testBug558812_020() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- " public /* here*/Point (int a, int b){\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=11;\n" +
- " Point p = new Point(1) ;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/Point";
- 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 SourceMethod);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults("");
- }
-
- //selection - select non-CC type and search- 2
- public void testBug558812_021() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- " public /* here*/Point (int a, int b){\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=11;\n" +
- " Point p = new Point(1) ;\n" +
- " Point p = new Point(1,2) ;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/Point";
- 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 SourceMethod);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java void Point.method() [new Point(1,2)] EXACT_MATCH");
- }
-
- //selection - select CC type and search- 2
- public void testBug558812_022() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp_) { \n" +
- " public /* here*/Point {\n" +
- " comp_=11;\n" +
- " }\n" +
- " public Point (int a, int b){\n" +
- " comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " int compp_=11;\n" +
- " Point p = new Point(1) ;\n" +
- " Point p = new Point(1,2) ;\n" +
- "} \n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/* here*/Point";
- 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 SourceMethod);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java void Point.method() [new Point(1)] EXACT_MATCH");
- }
-
- //selection - select local field in a compact constructor in record and search1
- public void testBug558812_23() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int comp_) { \n" +
- " public Point {\n" +
- " /* here*/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 LocalVariable);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java Point(int) [comp_] EXACT_MATCH");
- }
-
- //selection - select local field in a compact constructor in record and search2
- public void testBug558812_24() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int comp_) { \n" +
- " public Point {\n" +
- " /* here*/comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " comp_=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 LocalVariable);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java Point(int) [comp_] EXACT_MATCH");
-
- }
-
- //selection - select local field in a compact constructor in record and search3
- // java 15 change
- public void testBug558812_25() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record /* here*/Point(int comp_) { \n" +
- " public Point {\n" +
- " /* here*/comp_=11;\n" +
- " }\n" +
- "public void method ( ) { \n"+
- " comp_=11;\n" +
- " int a=this.comp_;\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 LocalVariable);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java Point(int) [comp_] EXACT_MATCH");
- }
-
- //selection - select record in another file
- public void testBug558812_26() throws CoreException {
- IJavaProject project1 = createJavaProject("JavaSearchBugs14", new String[] {"src"}, new String[] {"JCL14_LIB"}, "bin", "14");
- try {
- Map<String, String> options = project1.getOptions(false);
- options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_14);
- project1.setOptions(options);
- project1.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- project1.open(null);
- createFolder("/JavaSearchBugs14/src/pack11");
- String fileContent = "package pack11;\n" +
- "public record X11() {\n" +
- "}\n";
- String fileContent2 = "package pack11;\n" +
- "public class X12 {\n" +
- "/*here*/X11 p =null;\n"+
- "}\n";
-
- createFile("/JavaSearchBugs14/src/pack11/X11.java", fileContent);
- createFile("/JavaSearchBugs14/src/pack11/X12.java",fileContent2);
- ICompilationUnit unit = getCompilationUnit("/JavaSearchBugs14/src/pack11/X12.java");
- String x11 = "/*here*/X11";
- int start = fileContent2.indexOf(x11);
- IJavaElement[] elements = unit.codeSelect(start, x11.length());
- assertTrue(elements.length ==1);
- assertTrue(elements[0] instanceof ResolvedSourceType);
- boolean record = ((ResolvedSourceType)elements[0]).isRecord();
- assertTrue(record);
- } finally {
- deleteProject(project1);
- }
- }
-
- //selection - select parameter in normal constructor matching component name
- public void testBug558812_27() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record X(int a) {\n" +
- "public X { \n"+
- " this.a = a; \n"+
- " }\n"+
- "public X(int/*here*/a, int b) { // select the a here\n"+
- "this.a = a;\n"+
- "}\n"+
- "}\n"
- );
-
- String str = this.workingCopies[0].getSource();
- String selection = "/*here*/a";
- 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 LocalVariable);
- search(elements[0], REFERENCES, EXACT_RULE);
- assertSearchResults(
- "src/X.java X(int, int) [a] EXACT_MATCH");
- }
-
- public void testBug560486_028() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public record Point(int comp) { \n" +
- "public void method ( ) { \n"+
- "/*here*/comp(); \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 SourceType));
- assertTrue((elements[0] instanceof SourceField));
- }
-
-
}

Back to the top