Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2010-04-21 18:04:13 -0400
committerStephan Herrmann2010-04-21 18:04:13 -0400
commit0717d57fe4d108ab39a073439c314436fe5d8a9a (patch)
tree6bb18dfe49cbf07b2ae334f7f22eb243fa43e3da /org.eclipse.jdt.core.tests.model
parented07f3b80ee18c1625d42f5824fe018f349aadfe (diff)
downloadorg.eclipse.objectteams-0717d57fe4d108ab39a073439c314436fe5d8a9a.tar.gz
org.eclipse.objectteams-0717d57fe4d108ab39a073439c314436fe5d8a9a.tar.xz
org.eclipse.objectteams-0717d57fe4d108ab39a073439c314436fe5d8a9a.zip
update jdt.core tests to v_A45
Diffstat (limited to 'org.eclipse.jdt.core.tests.model')
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java6
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java7
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java309
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java28
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java73
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java108
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/BindingKeyTests.java9
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java36
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java170
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java53
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java365
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java277
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java24
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java108
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java258
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java20
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java28
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java61
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java49
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java102
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java103
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java228
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java11
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/CodeCorrection/src/CorrectLocalVariable2.java6
25 files changed, 2311 insertions, 130 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
index 90b92ba51..127d9e6ab 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
@@ -662,9 +662,8 @@ public class ASTConverter15Test extends ConverterTestSetup {
CompilationUnit compilationUnit = (CompilationUnit) result;
String expectedProblems =
"Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" +
- "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" +
"Pair is a raw type. References to generic type Pair<A,B> should be parameterized";
- assertProblemsSize(compilationUnit, 3, expectedProblems);
+ assertProblemsSize(compilationUnit, 2, expectedProblems);
ASTNode node = getASTNode(compilationUnit, 0, 5);
assertEquals("Wrong first character", '<', source[node.getStartPosition()]);
}
@@ -890,9 +889,8 @@ public class ASTConverter15Test extends ConverterTestSetup {
CompilationUnit compilationUnit = (CompilationUnit) result;
String expectedProblems =
"Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" +
- "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" +
"Pair is a raw type. References to generic type Pair<A,B> should be parameterized";
- assertProblemsSize(compilationUnit, 3, expectedProblems);
+ assertProblemsSize(compilationUnit, 2, expectedProblems);
ASTNode node = getASTNode(compilationUnit, 0, 5);
assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
MethodDeclaration methodDeclaration = (MethodDeclaration) node;
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java
index a4a823d68..bafdf1f6a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java
@@ -7685,11 +7685,10 @@ public class ASTConverterTestAST3_2 extends ConverterTestSetup {
true);
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
CompilationUnit unit = (CompilationUnit) node;
- assertProblemsSize(
- unit,
+ assertEquals(
+ "Wrong problem size",
2,
- "Object.equ cannot be resolved to a variable\n" +
- "Syntax error, insert \"AssignmentOperator Expression\" to complete Expression");
+ unit.getProblems().length);
node = getASTNode(unit, 0, 0);
assertEquals("Not a field declaration statement", ASTNode.INITIALIZER, node.getNodeType());
Initializer initializer = (Initializer) node;
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
index 6e1542e9f..a2594ebd8 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
@@ -14,6 +14,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.formatter.CodeFormatter;
+import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
@@ -6145,6 +6146,21 @@ public void testBug287833c() {
}
/**
+ * @bug 295825: [formatter] Commentaries are running away after formatting are used
+ * @test Verify that block comment stay unchanged when text starts with a star
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295825"
+ */
+public void testBug295825() {
+ String source =
+ "public class A {\n" +
+ " /* * command */\n" +
+ " void method() {\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source);
+}
+
+/**
* @bug 300379: [formatter] Fup of bug 287833
* @test Verify that the leading '{' is not deleted while formatting
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=300379"
@@ -6239,4 +6255,297 @@ public void testBug304705b() {
"}\n");
}
+/**
+ * @bug 305281: [formatter] Turning off formatting changes comment's formatting
+ * @test Verify that turning off formatting in a javadoc does not screw up its indentation
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305281"
+ */
+public void testBug305281() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "format: OFF");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "format: ON");
+ String source =
+ "public class test {\n" +
+ "\n" +
+ " /**\n" +
+ " * @param args\n" +
+ " * format: OFF\n" +
+ " */\n" +
+ " public static void main(String[] args) {\n" +
+ " do {\n" +
+ " } while (false);\n" +
+ " for (;;) {\n" +
+ " }\n" +
+ " // format: ON\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "public class test {\n" +
+ "\n" +
+ " /**\n" +
+ " * @param args\n" +
+ " * format: OFF\n" +
+ " */\n" +
+ " public static void main(String[] args) {\n" +
+ " do {\n" +
+ " } while (false);\n" +
+ " for (;;) {\n" +
+ " }\n" +
+ " // format: ON\n" +
+ " }\n" +
+ "}\n");
+}
+
+/**
+ * @bug 305371: [formatter] Unexpected indentation of line comment
+ * @test Verify that comments with too different indentation are not considered as contiguous
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305371"
+ */
+public void testBug305371() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
+ String source =
+ "class X01 {\n" +
+ "// unformatted comment !\n" +
+ " // formatted comment !\n" +
+ "}\n";
+ formatSource(source,
+ "class X01 {\n" +
+ "// unformatted comment !\n" +
+ " // formatted comment !\n" +
+ "}\n");
+}
+public void testBug305371b() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
+ String source =
+ "class X02 {\n" +
+ " // formatted comment !\n" +
+ "// unformatted comment !\n" +
+ "}\n";
+ formatSource(source,
+ "class X02 {\n" +
+ " // formatted comment !\n" +
+ "// unformatted comment !\n" +
+ "}\n");
+}
+public void testBug305371c() {
+ String source =
+ "class X03 {\n" +
+ " // formatted comment 1\n" +
+ " // formatted comment 2\n" +
+ "}\n";
+ formatSource(source,
+ "class X03 {\n" +
+ " // formatted comment 1\n" +
+ " // formatted comment 2\n" +
+ "}\n");
+}
+public void testBug305371d() {
+ String source =
+ "class X04 {\n" +
+ " // formatted comment 1\n" +
+ " // formatted comment 2\n" +
+ "}\n";
+ formatSource(source,
+ "class X04 {\n" +
+ " // formatted comment 1\n" +
+ " // formatted comment 2\n" +
+ "}\n");
+}
+
+/**
+ * @bug 305518: [formatter] Line inside <pre> tag is wrongly indented by one space when starting just after the star
+ * @test Verify formatting of a <pre> tag section keep lines right indented
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305518"
+ */
+public void testBug305518() {
+ String source =
+ "public interface Test {\n" +
+ "/**\n" +
+ " * <pre>\n" +
+ " * A\n" +
+ " * / \\\n" +
+ " * B C\n" +
+ " * / \\ / \\\n" +
+ " *D E F G\n" +
+ " * </pre>\n" +
+ " */\n" +
+ "public void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface Test {\n" +
+ " /**\n" +
+ " * <pre>\n" +
+ " * A\n" +
+ " * / \\\n" +
+ " * B C\n" +
+ " * / \\ / \\\n" +
+ " * D E F G\n" +
+ " * </pre>\n" +
+ " */\n" +
+ " public void foo();\n" +
+ "}\n");
+}
+public void testBug305518_wksp2_01() {
+ String source =
+ "public class X01 {\n" +
+ "/**\n" +
+ " <P> This is an example of starting and shutting down the Network Server in the example\n" +
+ " above with the API.\n" +
+ " <PRE>\n" +
+ " \n" +
+ " NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName(\"myhost\"),1621)\n" +
+ "\n" +
+ " serverControl.shutdown();\n" +
+ " </PRE>\n" +
+ "\n" +
+ " \n" +
+ "*/\n" +
+ "public void foo() {}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X01 {\n" +
+ " /**\n" +
+ " * <P>\n" +
+ " * This is an example of starting and shutting down the Network Server in\n" +
+ " * the example above with the API.\n" +
+ " * \n" +
+ " * <PRE>\n" +
+ " * \n" +
+ " * NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName(\"myhost\"),1621)\n" +
+ " * \n" +
+ " * serverControl.shutdown();\n" +
+ " * </PRE>\n" +
+ " */\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}\n");
+}
+public void testBug305518_wksp2_02() {
+ String source =
+ "public class X02 {\n" +
+ "/**\n" +
+ " * Represents namespace name:\n" +
+ " * <pre>e.g.<pre>MyNamespace;\n" +
+ " *MyProject\\Sub\\Level;\n" +
+ " *namespace\\MyProject\\Sub\\Level;\n" +
+ " */\n" +
+ "public void foo() {}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X02 {\n" +
+ " /**\n" +
+ " * Represents namespace name:\n" +
+ " * \n" +
+ " * <pre>e.g.\n" +
+ " * \n" +
+ " * <pre>\n" +
+ " * MyNamespace;\n" +
+ " * MyProject\\Sub\\Level;\n" +
+ " * namespace\\MyProject\\Sub\\Level;\n" +
+ " */\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}\n");
+}
+public void testBug305518_wksp2_03() {
+ String source =
+ "public class X03 {\n" +
+ "/**\n" +
+ "* <PRE>\n" +
+ "* String s = ... ; // get string from somewhere\n" +
+ "* byte [] compressed = UnicodeCompressor.compress(s);\n" +
+ "* </PRE>\n" +
+ " */\n" +
+ "public void foo() {}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X03 {\n" +
+ " /**\n" +
+ " * <PRE>\n" +
+ " * String s = ... ; // get string from somewhere\n" +
+ " * byte [] compressed = UnicodeCompressor.compress(s);\n" +
+ " * </PRE>\n" +
+ " */\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}\n");
+}
+
+/**
+ * @bug 305830: [formatter] Turning off formatting changes comment's formatting
+ * @test Verify that turning off formatting in a javadoc does not screw up its indentation
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305830"
+ */
+public void testBug305830() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "40");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "40");
+ String source =
+ "public class X01 {\n" +
+ "void foo() {\n" +
+ "bar(\"a non-nls string\", 0 /*a comment*/); //$NON-NLS-1$\n" +
+ "}\n" +
+ "void bar(String string, int i) {\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X01 {\n" +
+ " void foo() {\n" +
+ " bar(\"a non-nls string\", 0 /*a comment*/); //$NON-NLS-1$\n" +
+ " }\n" +
+ "\n" +
+ " void bar(String string, int i) {\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug305830b() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "40");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "40");
+ String source =
+ "public class X02 {\n" +
+ "void foo() {\n" +
+ "bar(\"str\", 0 /*a comment*/); //$NON-NLS-1$\n" +
+ "}\n" +
+ "void bar(String string, int i) {\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X02 {\n" +
+ " void foo() {\n" +
+ " bar(\"str\", 0 /* a comment */); //$NON-NLS-1$\n" +
+ " }\n" +
+ "\n" +
+ " void bar(String string, int i) {\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug305830c() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "40");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "40");
+ String source =
+ "public class X03 {\n" +
+ "void foo() {\n" +
+ "bar(\"str\", 0 /* a comment */); //$NON-NLS-1$\n" +
+ "}\n" +
+ "void bar(String string, int i) {\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X03 {\n" +
+ " void foo() {\n" +
+ " bar(\"str\", 0 /* a comment */); //$NON-NLS-1$\n" +
+ " }\n" +
+ "\n" +
+ " void bar(String string, int i) {\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java
index e58ca3185..508c65c5f 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java
@@ -919,7 +919,7 @@ public void testBlockComments13() throws JavaModelException {
"public class X13 {\r\n" +
"\r\n" +
"protected void handleWarningToken(String token, boolean isEnabling) {\r\n" +
- " if (token.equals(\"pkgDefaultMethod___\") || token.equals(\"packageDefaultMethod___\")/*backward compatible*/ ) { //$NON-NLS-1$ //$NON-NLS-2$\r\n" +
+ " if (token.equals(\"pkgDefaultMethod___\") || token.equals(\"packageDefaultMethod___\")/*_backward_ _compatible_*/ ) {\r\n" +
" }\r\n" +
"}\r\n" +
"}\r\n";
@@ -927,19 +927,19 @@ public void testBlockComments13() throws JavaModelException {
// 1) split comment block starts one tab before to avoid possible words over the max line length
// note that in this peculiar this was not necessary as even the first word is over the max line length!
formatSource(source,
- "package test.comments.block;\r\n" +
- "\r\n" +
- "public class X13 {\r\n" +
- "\r\n" +
- " protected void handleWarningToken(String token, boolean isEnabling) {\r\n" +
- " if (token.equals(\"pkgDefaultMethod___\") || token.equals(\"packageDefaultMethod___\")/*\r\n" +
- " * backward\r\n" +
- " * compatible\r\n" +
- " */) { //$NON-NLS-1$ //$NON-NLS-2$\r\n" +
- " }\r\n" +
- " }\r\n" +
- "}\r\n",
- false /* do not repeat */
+ "package test.comments.block;\n" +
+ "\n" +
+ "public class X13 {\n" +
+ "\n" +
+ " protected void handleWarningToken(String token, boolean isEnabling) {\n" +
+ " if (token.equals(\"pkgDefaultMethod___\")\n" +
+ " || token.equals(\"packageDefaultMethod___\")/*\n" +
+ " * _backward_\n" +
+ " * _compatible_\n" +
+ " */) {\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
);
}
public void testBlockComments14() throws JavaModelException {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java
index 90911f163..54c9fe11d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java
@@ -12,11 +12,13 @@ package org.eclipse.jdt.core.tests.formatter;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
@@ -206,6 +208,7 @@ public class FormatterMassiveRegressionTests extends FormatterRegressionTests {
private final int testIndex;
// Cleaning
+ private static boolean LIST = false;
private final static Map MAX_FILES = new HashMap();
// Formatting behavior
@@ -392,9 +395,50 @@ protected static Test suite(File inputDir, String profile, Map directories) {
}
};
File[] allFiles = (File[]) directories.get(inputDir);
+ File listFile = new File(inputDir.getParentFile(), inputDir.getName()+".lst");
+ BufferedWriter listFileWriter = null;
if (allFiles == null) {
- System.out.print("Get all files from "+inputDir+"...");
- allFiles = ModelTestsUtil.getAllFiles(inputDir, filter);
+ System.out.print("Get all files from ");
+ if (LIST || !listFile.exists()) {
+ // Get the files list
+ System.out.print(inputDir+"...");
+ allFiles = ModelTestsUtil.getAllFiles(inputDir, filter);
+ // Delete the files list
+ if (listFile.exists()) {
+ listFile.delete();
+ }
+ // Initialize the files list writer
+ listFileWriter = new BufferedWriter(new FileWriter(listFile));
+ listFileWriter.write(Integer.toString(allFiles.length));
+ listFileWriter.newLine();
+ } else {
+ System.out.print("stored list in "+listFile.getPath()+"...");
+ BufferedReader listFileReader = new BufferedReader(new InputStreamReader(new FileInputStream(listFile.getAbsolutePath())));
+ try {
+ // First line is the number of files
+ String line = listFileReader.readLine();
+ int maxFiles = Integer.parseInt(line);
+ // Following lines are the files path
+ allFiles = new File[maxFiles];
+ for (int i=0; i<maxFiles; i++) {
+ allFiles[i] = new File(inputDir, listFileReader.readLine());
+ if (!allFiles[i].exists()) {
+ throw new IOException("Cannot find file "+allFiles[i]);
+ }
+ }
+ }
+ catch (NumberFormatException nfe) {
+ nfe.printStackTrace();
+ return null;
+ }
+ catch (IOException ioe) {
+ ioe.printStackTrace();
+ return null;
+ }
+ finally {
+ listFileReader.close();
+ }
+ }
directories.put(inputDir, allFiles);
System.out.println("done");
}
@@ -409,11 +453,23 @@ protected static Test suite(File inputDir, String profile, Map directories) {
// }
// Add one test per found file
- for (int i=0; i<maxFiles[0]; i++) {
- if (CLEAN) {
- suite.addTest(new FormatterMassiveRegressionTests(inputDir, allFiles[i], i, profiles, false/*do not compare while cleaning*/));
- } else {
- suite.addTest(new FormatterMassiveRegressionTests(inputDir, allFiles[i], i, profiles, CAN_COMPARE));
+ try {
+ final int inputDirPathLength = inputDir.getPath().length()+1;
+ for (int i=0; i<maxFiles[0]; i++) {
+ if (CLEAN) {
+ suite.addTest(new FormatterMassiveRegressionTests(inputDir, allFiles[i], i, profiles, false/*do not compare while cleaning*/));
+ } else {
+ suite.addTest(new FormatterMassiveRegressionTests(inputDir, allFiles[i], i, profiles, CAN_COMPARE));
+ }
+ if (listFileWriter != null) {
+ listFileWriter.write(allFiles[i].getPath().substring(inputDirPathLength));
+ listFileWriter.newLine();
+ }
+ }
+ }
+ finally {
+ if (listFileWriter != null) {
+ listFileWriter.close();
}
}
} catch (Exception e) {
@@ -466,6 +522,7 @@ private static String buildProfileString() {
}
private static int initProfiles(String profile) {
+ if (profile == null || profile.length() == 0) return 0;
StringTokenizer tokenizer = new StringTokenizer(profile, ",");
int profiles = 0;
while (tokenizer.hasMoreTokens()) {
@@ -532,6 +589,8 @@ private static void initDirectories(File inputDir, int profiles, boolean verify)
String token = tokenizer.nextToken();
if (token.equals("clean")) {
CLEAN = true;
+ } else if (token.equals("list")) {
+ LIST = true;
} else if (token.equals("tmp")) {
if (JDT_CORE_HEAD) {
TEMP_OUTPUT = "HEAD";
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
index 0fa79d8b1..d3e6b2bfc 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
@@ -183,6 +183,8 @@ private static Class[] getAllTestClasses() {
// Util tests
UtilTests.class,
+
+ JavaCoreOptionsTests.class,
};
Class[] deprecatedClasses = getDeprecatedJDOMTestClasses();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
index dd50eb158..cf7c479da 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
@@ -20,6 +20,7 @@ import junit.framework.Test;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IClasspathAttribute;
@@ -580,4 +581,111 @@ public class AttachedJavadocTests extends ModifyingResourceTests {
}
}
}
+ /**
+ * @bug 304394: IJavaElement#getAttachedJavadoc(IProgressMonitor) should support referenced entries
+ * Test that javadoc is picked up from the referenced classpath entry when the javadoc location is added
+ * to that entry
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304394"
+ * @throws Exception
+ */
+ public void testBug304394() throws Exception {
+ setJavadocLocationAttribute("specialDoc");
+ IClasspathEntry[] savedEntries = null;
+ try {
+ IClasspathEntry[] entries = this.project.getRawClasspath();
+ savedEntries = (IClasspathEntry[]) entries.clone();
+ IClasspathEntry chainedJar = null;
+ int max = entries.length;
+ for (int i = 0; i < max; i++) {
+ final IClasspathEntry entry = entries[i];
+ if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
+ && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
+ && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
+
+ chainedJar = entries[i];
+ addLibrary(this.project, "/lib/chaining.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: test6.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+ IPath jarPath = this.project.getPath().append("lib").append("chaining.jar");
+ entries[i] = JavaCore.newLibraryEntry(jarPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath());
+ break;
+ }
+ }
+
+ this.project.setRawClasspath(entries, new IClasspathEntry[]{chainedJar}, this.project.getOutputLocation(), null);
+ waitForAutoBuild();
+
+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
+ IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
+ IType type = classFile.getType();
+ IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$
+ String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
+ assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
+ } finally {
+ // restore classpath
+ if (savedEntries != null) {
+ this.project.setRawClasspath(savedEntries, null);
+ }
+ removeLibrary(this.project, "/lib/chaining.jar", null);
+ }
+ }
+ /**
+ * Additional test for bug 304394.
+ * Test that javadoc is picked up from the raw classpath entry when the referenced entry doesn't
+ * contain the javadoc location attrribute.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304394"
+ * @throws Exception
+ */
+ public void testBug304394a() throws Exception {
+ setJavadocLocationAttribute("specialDoc");
+ IClasspathEntry[] savedEntries = null;
+ try {
+ IClasspathEntry[] entries = this.project.getRawClasspath();
+ savedEntries = (IClasspathEntry[]) entries.clone();
+ IClasspathEntry chainedJar = null;
+ int max = entries.length;
+ for (int i = 0; i < max; i++) {
+ final IClasspathEntry entry = entries[i];
+ if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
+ && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
+ && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
+
+ chainedJar = entries[i];
+ addLibrary(this.project, "/lib/chaining.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: test6.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+ IPath jarPath = this.project.getPath().append("lib").append("chaining.jar");
+ entries[i] = JavaCore.newLibraryEntry(jarPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
+ break;
+ }
+ }
+
+ chainedJar = JavaCore.newLibraryEntry(chainedJar.getPath(), null, null, null, null, chainedJar.isExported());
+ this.project.setRawClasspath(entries, new IClasspathEntry[]{chainedJar}, this.project.getOutputLocation(), null);
+ waitForAutoBuild();
+
+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
+ IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
+ IType type = classFile.getType();
+ IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$
+ String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
+ assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
+ } finally {
+ // restore classpath
+ if (savedEntries != null) {
+ this.project.setRawClasspath(savedEntries, null);
+ }
+ removeLibrary(this.project, "/lib/chaining.jar", null);
+ }
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/BindingKeyTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/BindingKeyTests.java
index 2d38cd017..f319d03a9 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/BindingKeyTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/BindingKeyTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -621,4 +621,11 @@ public class BindingKeyTests extends AbstractJavaModelTests {
"LX;&LX~Box<!LX~Box;{0}*232;!LX~Box;{1}*232;>;.value)!LX~Box;{0}*232;"
);
}
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=209479
+ */
+ public void test055() {
+ assertFalse("Should not be a raw type", new BindingKey("Ltest/ZZ<Ljava/lang/Object>;").isRawType());
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java
index 30f9e463b..3243cbc01 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java
@@ -1289,4 +1289,40 @@ public void testBug302455() throws CoreException, InterruptedException {
deleteProject("P");
}
}
+
+/**
+ * @bug 306477: Indexer(?) fails to recognise enum as a type
+ * @test Ensure that enum secondary type are well indexed
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=306477"
+ */
+public void testBug306477() throws Exception {
+ try {
+ // create test case
+ IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
+ createFolder("/P/p");
+ createFile(
+ "/P/p/Alice.java",
+ "package p;\n" +
+ "class Alice {\n" +
+ " Object j = Bob.CHARLIE;\n" +
+ "}\n"
+ );
+ createFile(
+ "/P/p/Misc.java",
+ "package p;\n" +
+ "enum Bob {\n" +
+ " CHARLIE;\n" +
+ "}\n"
+ );
+
+ // find secondary enum
+ IType type = project.findType("p.Bob", new NullProgressMonitor());
+ assertElementEquals("We should have found the secondary enum 'Bob'!",
+ "Bob [in Misc.java [in p [in <project root> [in P]]]]",
+ type
+ );
+ } finally {
+ deleteProject("P");
+ }
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
index 67e351f84..5111a6f8f 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
@@ -4881,7 +4881,7 @@ public void testNoResourceChange05() throws CoreException {
*/
public void testNoResourceChange06() throws CoreException {
ILogListener listener = new ILogListener(){
- private StringBuffer buffer = new StringBuffer();
+ private final StringBuffer buffer = new StringBuffer();
public void logging(IStatus status, String plugin) {
this.buffer.append(status);
this.buffer.append('\n');
@@ -6157,7 +6157,12 @@ public void testBug252341a() throws Exception {
// Test referenced entries for a particular entry appear in the right order and the referencingEntry
// attribute has the correct value
- IClasspathEntry[] chains = JavaCore.getReferencedClasspathEntries(rawClasspath[2], p);
+ IClasspathEntry[] chains = JavaCore.getReferencedClasspathEntries(rawClasspath[2], null);
+ assertClasspathEquals(chains,
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ chains = JavaCore.getReferencedClasspathEntries(rawClasspath[2], p);
assertClasspathEquals(chains,
"/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
"/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
@@ -6520,63 +6525,152 @@ public void testBug304081a() throws Exception {
}
}
/**
- * Additional tests for 304081
- * When the JAR, which is part of a classpath container, references other JAR via
- * MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true
- * for the referenced classpath entries.
+ * @bug 302949: FUP of 302949
+ * Test that
+ * 1) non-chaining jars are cached during classpath resolution and can be retrieved later on
+ * 2) A full save (after resetting the non chaining jars cache) caches the non-chaining jars information
+ * 3) when a project is deleted, the non-chaining jar cache is reset.
*
- * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081"
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305122"
* @throws Exception
*/
-public void testBug304081b() throws Exception {
- File libDir = null;
+public void testBug305122() throws Exception {
try {
IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin");
- IClasspathEntry[] classpath = new IClasspathEntry[1];
- libDir = new File(proj.getResource().getLocation().toPortableString());
- File libJar = new File(libDir, "container.jar");
-
- addLibrary(proj, "container.jar", null, new String[0],
+ IClasspathEntry[] classpath = new IClasspathEntry[2];
+
+ addLibrary(proj, "nonchaining.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n",
+ },
+ JavaCore.VERSION_1_4);
+ addLibrary(proj, "chaining.jar", null, new String[0],
new String[] {
"META-INF/MANIFEST.MF",
"Manifest-Version: 1.0\n" +
- "Class-Path: lib1.jar\n",
+ "Class-Path: chained.jar\n",
},
JavaCore.VERSION_1_4);
- createFile("/P/lib1.jar", "");
+
+ classpath[0] = JavaCore.newLibraryEntry(new Path("/P/nonchaining.jar"), null, null);
+ classpath[1] = JavaCore.newLibraryEntry(new Path("/P/chaining.jar"), null, null);
+ createFile("/P/chained.jar", "");
- ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID);
- String libraryName = "TestUserLibrary";
- IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID);
- UserLibraryClasspathContainer containerSuggestion = new UserLibraryClasspathContainer(libraryName);
- initializer.requestClasspathContainerUpdate(containerPath.append(libraryName), null, containerSuggestion);
+ proj.setRawClasspath(classpath, null);
+ waitForAutoBuild();
+ JavaModelManager manager = JavaModelManager.getJavaModelManager();
+ assertTrue("Non chaining Jar", manager.isNonChainingJar(classpath[0].getPath()));
+ assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[1].getPath()));
+
+ ((JavaProject)proj).resetResolvedClasspath();
+ proj.getResolvedClasspath(true);
+ manager = JavaModelManager.getJavaModelManager();
+ assertTrue("Non chaining Jar", manager.isNonChainingJar(classpath[0].getPath()));
+ assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[1].getPath()));
- IEclipsePreferences preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID);
- String propertyName = JavaModelManager.CP_USERLIBRARY_PREFERENCES_PREFIX+"TestUserLibrary";
- StringBuffer propertyValue = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<userlibrary systemlibrary=\"false\" version=\"1\">\r\n<archive");
- propertyValue.append(" path=\"" + libJar.getAbsolutePath());
- propertyValue.append("\"/>\r\n</userlibrary>\r\n");
- preferences.put(propertyName, propertyValue.toString());
- preferences.flush();
+ ((JavaProject)proj).resetResolvedClasspath();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ workspace.save(true, null);
+ assertTrue("Non chaining Jar", manager.isNonChainingJar(classpath[0].getPath()));
+ assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[1].getPath()));
- classpath[0] = JavaCore.newContainerEntry(containerSuggestion.getPath());
+ this.deleteProject("P");
+ assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[0].getPath()));
+ assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[1].getPath()));
+ } finally {
+ IProject proj = this.getProject("P");
+ if ( proj != null && proj.exists())
+ this.deleteProject("P");
+ }
+}
+/**
+ * @bug 308150: JAR with invalid Class-Path entry in MANIFEST.MF crashes the project
+ * Test that an invalid referenced library entry in the Class-Path of the MANIFEST doesn't
+ * create any exceptions and is NOT added to the resolved classpath.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=308150"
+ * @throws Exception
+ */
+public void testBug308150() throws Exception {
+ try {
+
+ IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin");
+ IClasspathEntry[] classpath = new IClasspathEntry[1];
+
+ // The Class-Path references an entry that points to the workspace root (hence invalid)
+ addLibrary(proj, "invalid.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: ../..\n",
+ },
+ JavaCore.VERSION_1_4);
+
+ classpath[0] = JavaCore.newLibraryEntry(new Path("/P/invalid.jar"), null, null);
proj.setRawClasspath(classpath, null);
waitForAutoBuild();
- IProject project = getWorkspaceRoot().getProject("P");
- IResource resource = project.getFile("container.jar");
- assertTrue(proj.isOnClasspath(resource));
- IJavaElement element = proj.getPackageFragmentRoot(resource);
- assertTrue(proj.isOnClasspath(element));
+ IClasspathEntry[] resolvedClasspath = proj.getResolvedClasspath(true);
- resource = project.getFile("lib1.jar");
- assertTrue(proj.isOnClasspath(resource));
- element = proj.getPackageFragmentRoot(resource);
- assertTrue(proj.isOnClasspath(element));
+ assertClasspathEquals(resolvedClasspath,
+ "/P/invalid.jar[CPE_LIBRARY][K_BINARY][isExported:false]");
+ } finally {
+ this.deleteProject("P");
+ }
+}
+/**
+ * @bug 305037: missing story for attributes of referenced JARs in classpath containers
+ * Test that attributes set on referenced libraries of variable entries via MANIFEST are persisted
+ * and can be retrieved
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037"
+ * @throws Exception
+ */
+public void testBug305037() throws Exception {
+ File libDir = null;
+ try {
+
+ IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin");
+ IPath libPath = proj.getResource().getLocation();
+ JavaCore.setClasspathVariable("MyVar", libPath, null);
+ libDir = new File(libPath.toPortableString());
+ IClasspathEntry[] classpath = new IClasspathEntry[1];
+ File libJar = new File(libDir, "variable.jar");
+ libJar.createNewFile();
+ addLibrary(proj, "variable.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib1.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+
+ createFile("/P/lib1.jar", "");
+
+ classpath = proj.getResolvedClasspath(true);
+ assertClasspathEquals(classpath,
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/variable.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ IClasspathEntry[] chains = JavaCore.getReferencedClasspathEntries(classpath[1], null);
+ assertClasspathEquals(chains, "/P/lib1.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+ ((ClasspathEntry)chains[0]).sourceAttachmentPath = new Path("/P/efg.zip");
+ ((ClasspathEntry)chains[0]).sourceAttachmentRootPath = new Path("/src2");
+
+ IClasspathAttribute javadocLoc = JavaCore.newClasspathAttribute("javadoc_location", "/P/efg.zip");
+ ((ClasspathEntry)chains[0]).extraAttributes = new IClasspathAttribute[]{javadocLoc};
+
+ proj.setRawClasspath(proj.getRawClasspath(), chains, proj.getOutputLocation(), null);
+ classpath = proj.getResolvedClasspath(true);
+ assertClasspathEquals(classpath,
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/efg.zip][rootPath:/src2][isExported:true][attributes:javadoc_location=/P/efg.zip]\n" +
+ "/P/variable.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
} finally {
this.deleteProject("P");
+ JavaCore.removeClasspathVariable("MyVar", null);
}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java
index a8bf135ed..fb7e4fe67 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java
@@ -10,14 +10,25 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.model;
-import junit.framework.*;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.jdt.core.*;
+import junit.framework.Test;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.CorrectionEngine;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaModelMarker;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.IProblem;
-import org.eclipse.jdt.core.search.*;
-
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.core.search.SearchPattern;
+import org.eclipse.jdt.core.search.TypeNameRequestor;
public class CodeCorrectionTests extends AbstractJavaModelTests {
public static boolean DEBUG = false;
@@ -54,7 +65,7 @@ public static String[] getProjectNames() {
public void setUpSuite() throws Exception {
super.setUpSuite();
- IJavaProject project = setUpJavaProject("CodeCorrection");
+ IJavaProject project = setUpJavaProject("CodeCorrection", "1.5");
// dummy query for waiting until the indexes are ready
SearchEngine engine = new SearchEngine();
@@ -659,6 +670,32 @@ public void testCorrectLocalVariable1() throws JavaModelException {
""+end,
requestor.getEnds());
}
+public void testCorrectLocalVariable2() throws JavaModelException {
+ CorrectionEngine engine = new CorrectionEngine(JavaCore.getOptions());
+ CodeCorrectionTestsRequestor requestor = new CodeCorrectionTestsRequestor();
+ ICompilationUnit cu= getCompilationUnit("CodeCorrection", "src", "", "CorrectLocalVariable2.java");
+ IMarker[] markers = getMarkers(cu);
+ assertTrue("should have one problem",markers.length == 1);
+ engine.computeCorrections(markers[0], null, 0, requestor);
+
+ String src = cu.getSource();
+ String error = "ba\\ud842\\udf9fr";
+ int start = src.lastIndexOf(error);
+ int end = start + error.length();
+
+ assertEquals(
+ "should have one suggestion",
+ "ba\ud842\udf9fr0",
+ requestor.getSuggestions());
+ assertEquals(
+ "a start of a suggestion is not correct",
+ ""+start,
+ requestor.getStarts());
+ assertEquals(
+ "a end of a suggestion is not correct",
+ ""+end,
+ requestor.getEnds());
+}
public void testCorrectArgument1() throws JavaModelException {
CorrectionEngine engine = new CorrectionEngine(JavaCore.getOptions());
CodeCorrectionTestsRequestor requestor = new CodeCorrectionTestsRequestor();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
index 76da97dae..a2eb9762b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -4928,4 +4928,367 @@ public void test0166() throws JavaModelException {
"completion token location=UNKNOWN",
result.context);
}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=236306
+public void test0167() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src3/test/X.java",
+ "package test;\n" +
+ "import java.text.MessageFormat;\n" +
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " String fooBar = \"Hi\";" +
+ " String furchtbar= MessageFormat.format\n" +
+ " }\n" +
+ "}");
+
+ String str = this.workingCopies[0].getSource();
+ int tokenStart = str.lastIndexOf("format");
+ int tokenEnd = tokenStart + "format".length() - 1;
+ int cursorLocation = str.lastIndexOf("format") + "format".length();
+
+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
+ String jclPath = getExternalJCLPathString();
+ assertResults(
+ "completion offset="+(cursorLocation)+"\n" +
+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
+ "completion token=\"format\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ljava.lang.String;}\n" +
+ "expectedTypesKeys={Ljava/lang/String;}\n" +
+ "completion token location=UNKNOWN\n" +
+ "enclosingElement=foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" +
+ "visibleElements={\n" +
+ " fooBar [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ "}",
+ result.context);
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=236306
+public void test0168() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src3/test/X.java",
+ "package test;\n" +
+ "import java.text.MessageFormat;\n" +
+ "public class X {\n" +
+ " public String format(String str, Object... args) {\n" +
+ " return \"hello\";\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " String fooBar = \"Hi\";" +
+ " String furchtbar= this.format\n" +
+ " }\n" +
+ "}");
+
+ String str = this.workingCopies[0].getSource();
+ int tokenStart = str.lastIndexOf("format");
+ int tokenEnd = tokenStart + "format".length() - 1;
+ int cursorLocation = str.lastIndexOf("format") + "format".length();
+
+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
+ String jclPath = getExternalJCLPathString();
+ assertResults(
+ "completion offset="+(cursorLocation)+"\n" +
+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
+ "completion token=\"format\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ljava.lang.String;}\n" +
+ "expectedTypesKeys={Ljava/lang/String;}\n" +
+ "completion token location=UNKNOWN\n" +
+ "enclosingElement=foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" +
+ "visibleElements={\n" +
+ " fooBar [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " format(String, Object[]) {key=Ltest/X;.format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ "}",
+ result.context);
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=236306
+public void test0169() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src3/test/X.java",
+ "package test;\n" +
+ "import java.text.MessageFormat;\n" +
+ "public class X {\n" +
+ " public String format(String str, Object... args) {\n" +
+ " return \"hello\";\n" +
+ " }\n" +
+ " public String methods(String str, String s) {\n" +
+ " return \"hello\";\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " X x = new X();\n" +
+ " String fooBar = \"Hi\";\n" +
+ " String furchtbar= x.methods(fooBar, format\n" +
+ " }\n" +
+ "}");
+
+ String str = this.workingCopies[0].getSource();
+ int tokenStart = str.lastIndexOf("format");
+ int tokenEnd = tokenStart + "format".length() - 1;
+ int cursorLocation = str.lastIndexOf("format") + "format".length();
+
+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
+ String jclPath = getExternalJCLPathString();
+ assertResults(
+ "completion offset="+(cursorLocation)+"\n" +
+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
+ "completion token=\"format\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ljava.lang.String;}\n" +
+ "expectedTypesKeys={Ljava/lang/String;}\n" +
+ "completion token location=UNKNOWN\n" +
+ "enclosingElement=foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" +
+ "visibleElements={\n" +
+ " x [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " fooBar [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " methods(String, String) {key=Ltest/X;.methods(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " format(String, Object[]) {key=Ltest/X;.format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ "}",
+ result.context);
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=236306
+public void test0170() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src3/test/X.java",
+ "package test;\n" +
+ "public class X {\n" +
+ " public String format(String str, Object... args) {\n" +
+ " return \"hello\";\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " String fooBar = \"Hi\";\n" +
+ " String furchtbar= format\n" +
+ " }\n" +
+ "}");
+
+ String str = this.workingCopies[0].getSource();
+ int tokenStart = str.lastIndexOf("format");
+ int tokenEnd = tokenStart + "format".length() - 1;
+ int cursorLocation = str.lastIndexOf("format") + "format".length();
+
+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
+ String jclPath = getExternalJCLPathString();
+ assertResults(
+ "completion offset="+(cursorLocation)+"\n" +
+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
+ "completion token=\"format\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ljava.lang.String;}\n" +
+ "expectedTypesKeys={Ljava/lang/String;}\n" +
+ "completion token location=UNKNOWN\n" +
+ "enclosingElement=foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" +
+ "visibleElements={\n" +
+ " fooBar [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " format(String, Object[]) {key=Ltest/X;.format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ "}",
+ result.context);
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=236306
+public void test0171() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src3/test/X.java",
+ "package test;\n" +
+ "import java.text.MessageFormat;\n" +
+ "public class X {\n" +
+ " public String format(String str, Object... args) {\n" +
+ " return \"hello\";\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " String fooBar = \"Hi\";\n" +
+ " String furchtbar= new String(MessageFormat.format\n" +
+ " }\n" +
+ "}");
+
+ String str = this.workingCopies[0].getSource();
+ int tokenStart = str.lastIndexOf("format");
+ int tokenEnd = tokenStart + "format".length() - 1;
+ int cursorLocation = str.lastIndexOf("format") + "format".length();
+
+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
+ String jclPath = getExternalJCLPathString();
+ assertResults(
+ "completion offset="+(cursorLocation)+"\n" +
+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
+ "completion token=\"format\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures=null\n" +
+ "expectedTypesKeys=null\n" +
+ "completion token location=UNKNOWN\n" +
+ "enclosingElement=foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" +
+ "visibleElements={\n" +
+ " fooBar [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " format(String, Object[]) {key=Ltest/X;.format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ "}",
+ result.context);
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=236306
+public void test0172() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src3/test/X.java",
+ "package test;\n" +
+ "import java.text.MessageFormat;\n" +
+ "public class X {\n" +
+ " public String format(String str, Object... args) {\n" +
+ " return \"hello\";\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " String fooBar = \"Hi\";\n" +
+ " int i = 1;\n" +
+ " String furchtbar= (i < 1) ? fooBar : format\n" +
+ " }\n" +
+ "}");
+
+ String str = this.workingCopies[0].getSource();
+ int tokenStart = str.lastIndexOf("format");
+ int tokenEnd = tokenStart + "format".length() - 1;
+ int cursorLocation = str.lastIndexOf("format") + "format".length();
+
+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
+ String jclPath = getExternalJCLPathString();
+ assertResults(
+ "completion offset="+(cursorLocation)+"\n" +
+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
+ "completion token=\"format\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures=null\n" +
+ "expectedTypesKeys=null\n" +
+ "completion token location={STATEMENT_START}\n" +
+ "enclosingElement=foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" +
+ "visibleElements={\n" +
+ " fooBar [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " i [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " format(String, Object[]) {key=Ltest/X;.format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ "}",
+ result.context);
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=236306
+public void test0173() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src3/test/X.java",
+ "package test;\n" +
+ "import java.text.MessageFormat;\n" +
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " String fooBar = \"Hi\";\n" +
+ " String furchtbar= (fooBar = String.format\n" +
+ " }\n" +
+ "}");
+
+ String str = this.workingCopies[0].getSource();
+ int tokenStart = str.lastIndexOf("format");
+ int tokenEnd = tokenStart + "format".length() - 1;
+ int cursorLocation = str.lastIndexOf("format") + "format".length();
+
+ CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
+ String jclPath = getExternalJCLPathString();
+ assertResults(
+ "completion offset="+(cursorLocation)+"\n" +
+ "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
+ "completion token=\"format\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ljava.lang.String;}\n" +
+ "expectedTypesKeys={Ljava/lang/String;}\n" +
+ "completion token location=UNKNOWN\n" +
+ "enclosingElement=foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" +
+ "visibleElements={\n" +
+ " fooBar [in foo() [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
+ " foo() {key=Ltest/X;.foo()V} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
+ " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
+ " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
+ "}",
+ result.context);
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
index 90b9b58c3..3e84f39ef 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
@@ -20766,4 +20766,281 @@ public void testBug287939d() throws JavaModelException {
"returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
requestor.getResults());
}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634
+public void testBug202634a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void bar(){" +
+ " System.out.println(\"bar\");\n" +
+ " }\n" +
+ " void foo() {\n" +
+ " sup\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "sup";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int start1 = str.lastIndexOf("sup");
+ int end1 = start1 + "sup".length();
+
+ assertResults(
+ "super[KEYWORD]{super, null, null, super, null, replace[" + start1 + ", " + end1 +"], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634
+public void testBug202634b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "package test;\n" +
+ "public class Test {\n" +
+ " void foo() {\n" +
+ " sup\n" +
+ " }\n" +
+ " public static void bar(){" +
+ " System.out.println(\"bar\");\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "sup";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int start1 = str.lastIndexOf("sup");
+ int end1 = start1 + "sup".length();
+
+ assertResults(
+ "super[KEYWORD]{super, null, null, super, null, replace[" + start1 + ", " + end1 +"], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634
+public void testBug202634c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void bar(){" +
+ " System.out.println(\"bar\");\n" +
+ " }\n" +
+ " {" +
+ " sup" +
+ " }" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "sup";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int start1 = str.lastIndexOf("sup");
+ int end1 = start1 + "sup".length();
+
+ assertResults(
+ "super[KEYWORD]{super, null, null, super, null, replace[" + start1 + ", " + end1 +"], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634
+public void testBug202634d() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void bar(){" +
+ " System.out.println(\"bar\");\n" +
+ " }\n" +
+ " Test() {" +
+ " sup" +
+ " }" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "sup";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int start1 = str.lastIndexOf("sup");
+ int end1 = start1 + "sup".length();
+
+ assertResults(
+ "super[KEYWORD]{super, null, null, super, null, replace[" + start1 + ", " + end1 +"], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" +
+ "super[METHOD_REF<CONSTRUCTOR>]{super(), Ljava.lang.Object;, ()V, super, null, replace[" + start1 + ", " + end1 + "], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634
+public void testBug202634e() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void bar(){" +
+ " System.out.println(\"bar\");\n" +
+ " }\n" +
+ " {" +
+ " thi" +
+ " }" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "thi";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int start1 = str.lastIndexOf("thi");
+ int end1 = start1 + "thi".length();
+
+ assertResults(
+ "this[KEYWORD]{this, null, null, this, null, replace[" + start1 + ", " + end1 +"], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634
+public void testBug202634f() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void bar(){" +
+ " System.out.println(\"bar\");\n" +
+ " }\n" +
+ " Test() {" +
+ " thi" +
+ " }" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "thi";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int start1 = str.lastIndexOf("thi");
+ int end1 = start1 + "thi".length();
+
+ assertResults(
+ "this[KEYWORD]{this, null, null, this, null, replace[" + start1 + ", " + end1 +"], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}",
+ requestor.getResults());
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=307337
+public void testBug307337() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/TestBug307337.java",
+ "package test;\n" +
+ "public class TestBug307337 {\n" +
+ " Object obj = new Object() {\n" +
+ " TestBug307337\n" +
+ " };\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ requestor.setRequireExtendedContext(true);
+ requestor.setComputeEnclosingElement(true);
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "TestBug307337";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ assertResults(
+ "expectedTypesSignatures=null\n" +
+ "expectedTypesKeys=null\n" +
+ "enclosingElement=<anonymous #1> {key=Ltest/TestBug307337$64;} [in obj [in TestBug307337 [in [Working copy] TestBug307337.java [in test [in src [in Completion]]]]]]",
+ requestor.getContext());
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292087
+// To verify that anonymous class in array initializer doesnt cause
+// grief to content assist
+public void testBug292087() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Try.java",
+ "package test;\n" +
+ "public class Try extends Thread{\n" +
+ " public Runnable member[] = { new Runnable (){\n" +
+ " public void run() {}\n" +
+ " }\n" +
+ " };\n" +
+ " Tr\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "Tr";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ assertResults(
+ // without the fix no proposals obtained.
+ "Tr[POTENTIAL_METHOD_DECLARATION]{Tr, Ltest.Try;, ()V, Tr, null, 14}\n" +
+ "transient[KEYWORD]{transient, null, null, transient, null, 14}\n" +
+ "Try[TYPE_REF]{Try, test, Ltest.Try;, null, null, 27}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249704
+public void testBug249704() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Try.java",
+ "package test;\n" +
+ "import java.util.Arrays;\n" +
+ "public class Try {\n" +
+ " Object obj = new Object() {\n" +
+ " public void method() {\n" +
+ " Object obj = new Object() {\n" +
+ " int a = 1;\n" +
+ " public void anotherMethod() {\n" +
+ " try {}\n" +
+ " catch (Throwable e) {}\n" +
+ " Arrays.sort(new String[]{\"\"});\n" +
+ " }\n" +
+ " };\n" +
+ " e\n" +
+ " }\n" +
+ " };\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "e";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ assertResults(
+ // without the fix no proposals obtained.
+ "Error[TYPE_REF]{Error, java.lang, Ljava.lang.Error;, null, null, 17}\n" +
+ "Exception[TYPE_REF]{Exception, java.lang, Ljava.lang.Exception;, null, null, 17}\n" +
+ "equals[METHOD_REF]{Try.this.equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 24}\n" +
+ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 27}",
+ requestor.getResults());
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java
index 55aae2fa0..b3f687015 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java
@@ -13790,5 +13790,29 @@ public void test274466() throws JavaModelException {
(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}",
requestor.getResults());
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=307486
+public void testLabel() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/label/Test.java",
+ "package label;"+
+ "public class Test {\n" +
+ " void foo() {\n" +
+ " \ud842\udf9fabc :\n" +
+ " while (true) {\n" +
+ " break \ud842\udf9fabc;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "break";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length() + 1;
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ assertResults(
+ "\ud842\udf9fabc[LABEL_REF]{\ud842\udf9fabc, null, null, \ud842\udf9fabc, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
+ requestor.getResults());
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java
new file mode 100644
index 000000000..319b0875b
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+import java.util.Hashtable;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.compiler.CharOperation;
+/**
+ * Tests JavaCore options
+ */
+public class JavaCoreOptionsTests extends ModifyingResourceTests {
+
+public static Test suite() {
+ return buildModelTestSuite(JavaCoreOptionsTests.class);
+}
+
+// Use this static initializer to specify subset for tests
+// All specified tests which do not belong to the class are skipped...
+static {
+// TESTS_NUMBERS = new int[] { 4 };
+}
+
+public JavaCoreOptionsTests(String name) {
+ super(name);
+}
+public void test1() {
+ Hashtable options = JavaCore.getOptions();
+ try {
+ Hashtable currentOptions = new Hashtable(options);
+ currentOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "HIGH,HIGH");
+ currentOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO");
+ JavaCore.setOptions(currentOptions);
+
+ Hashtable options2 = JavaCore.getOptions();
+ String taskTagsValue = (String) options2.get(JavaCore.COMPILER_TASK_TAGS);
+ String taskPrioritiesValue = (String) options2.get(JavaCore.COMPILER_TASK_PRIORITIES);
+ char[][] taskPriorities = CharOperation.splitAndTrimOn(',', taskPrioritiesValue.toCharArray());
+ char[][] taskTags = CharOperation.splitAndTrimOn(',', taskTagsValue.toCharArray());
+ assertEquals("wrong size", 1, taskPriorities.length);
+ assertEquals("wrong size", 1, taskTags.length);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+}
+public void test2() {
+ Hashtable options = JavaCore.getOptions();
+ try {
+ Hashtable currentOptions = new Hashtable(options);
+ currentOptions.remove(JavaCore.COMPILER_TASK_PRIORITIES);
+ currentOptions.remove(JavaCore.COMPILER_TASK_TAGS);
+ JavaCore.setOptions(currentOptions);
+
+ Hashtable options2 = JavaCore.getOptions();
+ String taskTagsValue = (String) options2.get(JavaCore.COMPILER_TASK_TAGS);
+ String taskPrioritiesValue = (String) options2.get(JavaCore.COMPILER_TASK_PRIORITIES);
+ assertNull("wrong value", taskTagsValue);
+ assertNull("wrong value", taskPrioritiesValue);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+}
+public void test3() {
+ Hashtable options = JavaCore.getOptions();
+ try {
+ Hashtable currentOptions = new Hashtable(options);
+ currentOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "HIGH,HIGH");
+ currentOptions.remove(JavaCore.COMPILER_TASK_TAGS);
+ JavaCore.setOptions(currentOptions);
+
+ Hashtable options2 = JavaCore.getOptions();
+ String taskTagsValue = (String) options2.get(JavaCore.COMPILER_TASK_TAGS);
+ String taskPrioritiesValue = (String) options2.get(JavaCore.COMPILER_TASK_PRIORITIES);
+ assertNull("wrong value", taskTagsValue);
+ assertNull("wrong value", taskPrioritiesValue);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+}
+public void test4() {
+ Hashtable options = JavaCore.getOptions();
+ try {
+ Hashtable currentOptions = new Hashtable(options);
+ currentOptions.remove(JavaCore.COMPILER_TASK_PRIORITIES);
+ currentOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO");
+ JavaCore.setOptions(currentOptions);
+
+ Hashtable options2 = JavaCore.getOptions();
+ String taskTagsValue = (String) options2.get(JavaCore.COMPILER_TASK_TAGS);
+ String taskPrioritiesValue = (String) options2.get(JavaCore.COMPILER_TASK_PRIORITIES);
+ assertNull("wrong value", taskTagsValue);
+ assertNull("wrong value", taskPrioritiesValue);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+}
+}
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
index 8a676f8e3..bd2a22bc3 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
@@ -61,6 +61,7 @@ public class JavaSearchBugsTests extends AbstractJavaSearchTests {
// Debug
static {
// org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
+// TESTS_NAMES = new String[] {"testBug306223"};
}
public JavaSearchBugsTests(String name) {
@@ -10960,7 +10961,9 @@ public void testBug286379c() throws CoreException {
return false;
}
}
-
+ // print statement to debug random failures of this test
+ System.out.println("Forbidden reference at the start of the test is " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
+
IContentType javaContentType = Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE);
TestResourceChangeListener changeListener = new TestResourceChangeListener();
try {
@@ -11002,9 +11005,13 @@ public void testBug286379c() throws CoreException {
// Wait to be sure that indexes are ready after the new resource was added
waitUntilIndexesReady();
+ // print statement to debug random failures of this test
+ System.out.println("Forbidden reference before first exit " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
// Restart to let the indexes to be refreshed
simulateExit();
- simulateRestart();
+ simulateRestart();
+ // print statement to debug random failures of this test
+ System.out.println("Forbidden reference after first restart " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
waitUntilIndexesReady();
// Search for the new type with new extension
@@ -11024,9 +11031,13 @@ public void testBug286379c() throws CoreException {
// Delete the file specification
javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC);
+ // print statement to debug random failures of this test
+ System.out.println("Forbidden reference before second exit " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
// Restarting should update the index file to remove the references of any .torem files
simulateExit();
- simulateRestart();
+ simulateRestart();
+ // print statement to debug random failures of this test
+ System.out.println("Forbidden reference after second restart " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
waitUntilIndexesReady();
// Search for the new type with new extension
@@ -11541,4 +11552,245 @@ public void testBug304841b() throws Exception {
getWorkspace().setDescription(preferences);
}
}
+
+/**
+ * @bug 306196: [search] NPE while searching for annotation references in
+ * rt.jar of JRE 6.0
+ * @test Ensure that no NPE occurs when searching for both ANNOTATION_TYPE
+ * and TYPE references from an inner enum declared in a binary type.
+ * This same test also ensures that there is no NPE even if the source
+ * has a method that does not exist in the class file.
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=306196"
+ */
+public void testBug306196() throws Exception {
+ final String libPath = "/JavaSearchBugs/lib/b306196.jar";
+ addLibraryEntry(JAVA_PROJECT, libPath, false);
+ try {
+ IPackageFragmentRoot root = getPackageFragmentRoot(libPath);
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { root });
+ SearchPattern leftPattern = createPattern("*", ANNOTATION_TYPE, REFERENCES, false);
+ SearchPattern rightPattern = createPattern("*", TYPE, REFERENCES, false);
+ new SearchEngine().search(SearchPattern.createOrPattern( leftPattern, rightPattern),
+ new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
+ this.resultCollector, null);
+ assertSearchResults("lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
+ + "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
+ + "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
+ + "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
+ + "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
+ + "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
+ + "lib/b306196.jar java.lang.String pkg.B306196$anEnum.aFunc(java.lang.Object) EXACT_MATCH\n"
+ + "lib/b306196.jar java.lang.String pkg.B306196$anEnum.aFunc(java.lang.Object) EXACT_MATCH");
+ } finally {
+ removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
+ }
+}
+
+/**
+ * @bug 306223: [search] Searching for annotation references report all type references
+ * @test Ensures the following -
+ * 1. Search for annotation references does not report type references
+ * 2. Search for annotation references even report a non-annotation references to an annotation type
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=306223"
+ */
+public void testBug306223a() throws CoreException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
+ "import b306223.MyAnnot;\n"+
+ "@MyAnnot\n" +
+ "public class TestAnnot {\n" +
+ "MyAnnot annon;\n" +
+ "String test;\n" +
+ "void foo(String str) {\n" +
+ "this.test = str;\n" +
+ "}\n" +
+ "}\n"
+ );
+ this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java",
+ "@interface MyAnnot {}\n");
+ SearchPattern pattern = SearchPattern.createPattern(
+ "*",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b306223/Test.java [b306223.MyAnnot] EXACT_MATCH\n" +
+ "src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH\n" +
+ "src/b306223/Test.java b306223.TestAnnot.annon [MyAnnot] EXACT_MATCH"
+ );
+}
+/**
+ * This ensures that using ANNOTATION_TYPE_REFERENCE as fine grain constant reports only
+ * annotations and not any other references to an annotation type
+ */
+public void testBug306223b() throws CoreException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
+ "import b306223.MyAnnot;\n"+
+ "@MyAnnot\n" +
+ "public class TestAnnot {\n" +
+ "MyAnnot annon;\n" +
+ "String test;\n" +
+ "void foo(String str) {\n" +
+ "this.test = str;\n" +
+ "}\n" +
+ "}\n"
+ );
+ this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java",
+ "@interface MyAnnot {}\n");
+ SearchPattern pattern = SearchPattern.createPattern(
+ "*",
+ ANNOTATION_TYPE,
+ REFERENCES|ANNOTATION_TYPE_REFERENCE,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH"
+ );
+}
+
+/**
+ * This test ensures that search for enum references does not report type references.
+ */
+public void testBug306223c() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
+ "public class TestEnum {\n" +
+ " String foo(MyEnum e) {\n" +
+ " switch (e) {\n"+
+ " case ONE:\n" +
+ " return \"1\";\n" +
+ " case TWO:\n" +
+ " return \"2\";\n" +
+ " default:\n" +
+ " return \"-1\";\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+
+ "enum MyEnum {\n" +
+ " ONE, TWO\n" +
+ "}\n"
+ );
+
+ SearchPattern pattern = SearchPattern.createPattern(
+ "*",
+ ENUM,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b306223/Test.java String b306223.TestEnum.foo(MyEnum) [MyEnum] EXACT_MATCH"
+ );
+}
+/**
+ * This test ensures that a reference search of ANNOTATION_TYPE should report POTENTIAL_MATCH
+ * for unknown references types.
+ */
+public void testBug306223d() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
+ "public class TestAnnot {\n" +
+ "Zork annon;\n" +
+ "}\n"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "*",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b306223/Test.java b306223.TestAnnot.annon [Zork] POTENTIAL_MATCH"
+ );
+}
+/**
+ * This test ensures that an ANNOTATION_TYPE reference search for a non-existing
+ * type does not report any other references
+ */
+public void testBug306223e() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
+ "public class Test {\n" +
+ " Zork x;\n" +
+ "}\n"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "abc",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults("");
+}
+/**
+ * This test ensures that a TYPE reference search reports EXACT_MATCH
+ * for missing types
+ */
+public void testBug306223f() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
+ "public class Test {\n" +
+ " Zork x;\n" +
+ "}\n"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "*",
+ TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b306223/Test.java b306223.Test.x [Zork] EXACT_MATCH"
+ );
+}
+/**
+ * This test ensures that a TYPE reference search for a non-existing
+ * type does not report any other references
+ */
+public void testBug306223g() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
+ "public class Test {\n" +
+ " Zork x;\n" +
+ "}\n"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "abc",
+ TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults("");
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java
index 065d3b953..63a5bdf45 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java
@@ -2587,5 +2587,25 @@ public void testInterfaceX() throws JavaModelException {
elements
);
}
+public void test306078() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Resolve/src/A.java",
+ "public class A { private static final int X = 0; }");
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Resolve/src/B.java",
+ "public class B { int x = A.X; }");
+
+ String str = this.workingCopies[1].getSource();
+ int start = str.lastIndexOf("X");
+ int length = "X".length();
+ IJavaElement[] elements = this.workingCopies[1].codeSelect(start, length, this.wcOwner);
+ assertElementsEqual(
+ "Unexpected elements",
+ "X [in A [in [Working copy] A.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java
index 2d8b6576c..5a30f9240 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests_1_5.java
@@ -27,7 +27,7 @@ static {
// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
//TESTS_NAMES = new String[] { "test0095" };
// Numbers of tests to run: "test<number>" will be run for each number of this array
- //TESTS_NUMBERS = new int[] { 13 };
+ //TESTS_NUMBERS = new int[] { 124 };
// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last }
//TESTS_RANGE = new int[] { 16, -1 };
}
@@ -2936,4 +2936,30 @@ public void test0123() throws Exception {
true
);
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=308356
+public void test0124() throws Exception {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Resolve/src/Test.java",
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String str\ud842\udf9f = null;\n" +
+ " }\n" +
+ "}");
+
+ String str = this.workingCopies[0].getSource();
+ String CONST1 = "String ";
+ int start = str.indexOf("String ");
+ start += CONST1.length();
+ int start2 = str.indexOf(" =");
+ int length = start2 - start + 1;
+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length, this.wcOwner);
+
+ assertElementsEqual(
+ "Unexpected elements",
+ "str\ud842\udf9f [in main(String[]) [in Test [in [Working copy] Test.java [in <default> [in src [in Resolve]]]]]]",
+ elements,
+ true
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
index 9b5a6c3ba..921405676 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
@@ -3060,6 +3060,67 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
}
+ public void testIfStatementReplaceElse5() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" if (i == 0) {\n");
+ buf.append(" System.beep();\n");
+ buf.append(" } else {\n");
+ buf.append(" System.beep();\n");
+ buf.append(" System.beep();\n");
+ buf.append(" }\n");
+ buf.append(" // comment\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ AST ast= astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "E");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+ assertTrue("Number of statements not 1", statements.size() == 1);
+
+ {
+ // replace then statement by block , replace else with if statement (block)
+ IfStatement ifStatement= (IfStatement) statements.get(0);
+
+ Statement thenStatement= ifStatement.getThenStatement();
+ Statement elseStatement= ifStatement.getElseStatement();
+
+ Statement newElseStatement= (Statement) rewrite.createMoveTarget(thenStatement);
+ Statement newThenStatement= (Statement) rewrite.createMoveTarget(elseStatement);
+
+ rewrite.set(ifStatement, IfStatement.THEN_STATEMENT_PROPERTY, newThenStatement, null);
+ rewrite.set(ifStatement, IfStatement.ELSE_STATEMENT_PROPERTY, newElseStatement, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" if (i == 0) {\n");
+ buf.append(" System.beep();\n");
+ buf.append(" System.beep();\n");
+ buf.append(" }\n");
+ buf.append(" // comment\n");
+ buf.append(" else {\n");
+ buf.append(" System.beep();\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+
+ }
+
public void testLabeledStatement() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java
index b5b7c0f66..af152adc9 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java
@@ -153,7 +153,56 @@ public class ASTRewritingTypeDeclTest extends ASTRewritingTest {
assertEqualString(preview, buf.toString());
}
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754
+ public void testTypeDeclarationChange() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class C {}");
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+ {
+ // change to interface
+ TypeDeclaration type= findTypeDeclaration(astRoot, "C");
+
+ astRoot.recordModifications();
+ // change to interface
+ rewrite.set(type, TypeDeclaration.INTERFACE_PROPERTY, Boolean.TRUE, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public interface C {}");
+ assertEqualString(preview, buf.toString());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754
+ public void testTypeDeclarationChange2() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("@A(X.class) public class C {}");
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST3(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+ {
+ // change to interface
+ TypeDeclaration type= findTypeDeclaration(astRoot, "C");
+
+ astRoot.recordModifications();
+ // change to interface
+ rewrite.set(type, TypeDeclaration.INTERFACE_PROPERTY, Boolean.TRUE, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("@A(X.class) public interface C {}");
+ assertEqualString(preview, buf.toString());
+ }
public void testTypeDeclChanges2() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
index d53ac2a2a..7b5c862f6 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
@@ -334,6 +334,108 @@ public class ImportRewriteTest extends AbstractJavaModelTests {
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=306568
+ public void testAddImports6() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append(
+ "package pack1;\n" +
+ "\n" +
+ "import java.util.*;\n" +
+ "\n" +
+ "public class C {\n" +
+ " public static void main(String[] args) {\n" +
+ " HashMap h;\n" +
+ "\n" +
+ " Map.Entry e= null;\n" +
+ " Entry e2= null;\n" +
+ "\n" +
+ " System.out.println(\"hello\");\n" +
+ " }\n" +
+ "}");
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+
+ String[] order= new String[] { "java", "java.util", "com", "pack" };
+
+ ImportRewrite imports= newImportsRewrite(cu, order, 1, 1, true);
+ imports.setUseContextToFilterImplicitImports(true);
+ imports.addImport("java.util.Map.Entry");
+
+ apply(imports);
+
+ buf= new StringBuffer();
+ buf.append(
+ "package pack1;\n" +
+ "\n" +
+ "import java.util.*;\n" +
+ "import java.util.Map.Entry;\n" +
+ "\n" +
+ "public class C {\n" +
+ " public static void main(String[] args) {\n" +
+ " HashMap h;\n" +
+ "\n" +
+ " Map.Entry e= null;\n" +
+ " Entry e2= null;\n" +
+ "\n" +
+ " System.out.println(\"hello\");\n" +
+ " }\n" +
+ "}");
+ assertEqualString(cu.getSource(), buf.toString());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=309022
+ public void testAddImports7() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append(
+ "package pack1;\n" +
+ "\n" +
+ "import java.util.*;\n" +
+ "import java.util.Map.Entry;\n" +
+ "\n" +
+ "public class C {\n" +
+ " public static void main(String[] args) {\n" +
+ " HashMap h;\n" +
+ "\n" +
+ " Map.Entry e= null;\n" +
+ " Entry e2= null;\n" +
+ "\n" +
+ " PrintWriter pw;\n" +
+ " System.out.println(\"hello\");\n" +
+ " }\n" +
+ "}");
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+
+ String[] order= new String[] { "java", "java.util", "com", "pack" };
+
+ ImportRewrite imports= newImportsRewrite(cu, order, 1, 1, true);
+ imports.setUseContextToFilterImplicitImports(true);
+ imports.addImport("java.io.PrintWriter");
+
+ apply(imports);
+
+ buf= new StringBuffer();
+ buf.append(
+ "package pack1;\n" +
+ "\n" +
+ "import java.io.*;\n" +
+ "\n" +
+ "import java.util.*;\n" +
+ "import java.util.Map.Entry;\n" +
+ "\n" +
+ "public class C {\n" +
+ " public static void main(String[] args) {\n" +
+ " HashMap h;\n" +
+ "\n" +
+ " Map.Entry e= null;\n" +
+ " Entry e2= null;\n" +
+ "\n" +
+ " PrintWriter pw;\n" +
+ " System.out.println(\"hello\");\n" +
+ " }\n" +
+ "}");
+ assertEqualString(cu.getSource(), buf.toString());
+ }
public void testAddImportsWithGroupsOfUnmatched1() throws Exception {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java
index 89e302261..08aa7e5b7 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java
@@ -16,8 +16,12 @@ import junit.framework.Test;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageFragment;
-
-import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
public class ASTRewritingModifyingOtherTest extends ASTRewritingModifyingTest {
private static final Class THIS = ASTRewritingModifyingOtherTest.class;
@@ -186,49 +190,56 @@ public class ASTRewritingModifyingOtherTest extends ASTRewritingModifyingTest {
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754
+ public void test0005() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0005", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0005;\n");
+ buf.append("@A(X.class) public class C {}");
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, true, AST.JLS3);
+ astRoot.recordModifications();
+ {
+ // change to interface
+ astRoot.accept(new ASTVisitor() {
+ public boolean visit(TypeDeclaration node) {
+ node.setInterface(true);
+ return false;
+ }
+ });
+ }
+ String preview= evaluateRewrite(cu, astRoot);
+
+ buf= new StringBuffer();
+ buf.append("package test0005;\n");
+ buf.append("@A(X.class) public interface C {}");
+ assertEqualString(preview, buf.toString());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754
+ public void test0006() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0006", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0006;\n");
+ buf.append("public @A(X.class) class C {}");
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, true, AST.JLS3);
+ astRoot.recordModifications();
+ {
+ // change to interface
+ astRoot.accept(new ASTVisitor() {
+ public boolean visit(TypeDeclaration node) {
+ node.setInterface(true);
+ return false;
+ }
+ });
+ }
+ String preview= evaluateRewrite(cu, astRoot);
-// public void _test000X() throws Exception {
-// IPackageFragment pack1= fSourceFolder.createPackageFragment("test0004", false, null);
-// StringBuffer buf= new StringBuffer();
-// buf.append("package test0004;\n");
-// buf.append("\n");
-// buf.append("public class X {\n");
-// buf.append(" void foo(){\n");
-// buf.append(" //rien\n");
-// buf.append(" \n");
-// buf.append(" \n");
-// buf.append(" \n");
-// buf.append(" \n");
-// buf.append(" }\n");
-// buf.append("}\n");
-// ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
-//
-// CompilationUnit astRoot= parseCompilationUnit(cu, false);
-//
-// astRoot.recordModifications();
-//
-// AST a = astRoot.getAST();
-//
-// Comment[] comments = astRoot.getCommentTable();
-// Comment comment1 = comments[0];
-// Comment comment2 = a.newBlockComment();
-// comment2.setSourceRange(comment1.getStartPosition(), comment1.getLength() - 2);
-// comments[0] = comment2;
-//
-// String preview = evaluateRewrite(cu, astRoot);
-//
-// buf= new StringBuffer();
-// buf.append("package test0004;\n");
-// buf.append("\n");
-// buf.append("public class X {\n");
-// buf.append("\n");
-// buf.append("}\n");
-// buf.append("class Y {\n");
-// buf.append("\n");
-// buf.append("}\n");
-// buf.append("class Z {\n");
-// buf.append("\n");
-// buf.append("}\n");
-// assertEqualString(preview, buf.toString());
-// }
+ buf= new StringBuffer();
+ buf.append("package test0006;\n");
+ buf.append("public @A(X.class) interface C {}");
+ assertEqualString(preview, buf.toString());
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java
index b034f45fa..30a3af174 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -236,4 +236,230 @@ public class ASTRewritingModifyingReplaceTest extends ASTRewritingModifyingTest
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
+ public void test0007() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0007", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0007;\n");
+ buf.append("public class X {\n");
+ buf.append(" List/**/getUsers() {}\n");
+ buf.append("}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
+
+ astRoot.recordModifications();
+
+ AST ast = astRoot.getAST();
+
+ List types = astRoot.types();
+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
+
+ methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
+
+ String preview = evaluateRewrite(cu, astRoot);
+
+ buf= new StringBuffer();
+ buf.append("package test0007;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers() {}\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
+ public void test0008() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0008", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0008;\n");
+ buf.append("public class X {\n");
+ buf.append(" List /**/getUsers() {}\n");
+ buf.append("}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
+
+ astRoot.recordModifications();
+
+ AST ast = astRoot.getAST();
+
+ List types = astRoot.types();
+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
+
+ methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
+
+ String preview = evaluateRewrite(cu, astRoot);
+
+ buf= new StringBuffer();
+ buf.append("package test0008;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers() {}\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
+ public void test0009() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0009", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0009;\n");
+ buf.append("public class X {\n");
+ buf.append(" List/**/ getUsers() {}\n");
+ buf.append("}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
+
+ astRoot.recordModifications();
+
+ AST ast = astRoot.getAST();
+
+ List types = astRoot.types();
+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
+
+ methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
+
+ String preview = evaluateRewrite(cu, astRoot);
+
+ buf= new StringBuffer();
+ buf.append("package test0009;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers() {}\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
+ public void test0010() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0010", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0010;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers(List/**/list) {}\n");
+ buf.append("}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
+
+ astRoot.recordModifications();
+
+ AST ast = astRoot.getAST();
+
+ List types = astRoot.types();
+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
+ List parameters = methodDecl.parameters();
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT));
+
+ String preview = evaluateRewrite(cu, astRoot);
+
+ buf= new StringBuffer();
+ buf.append("package test0010;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers(int list) {}\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
+ public void test0011() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0011", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0011;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers(int i, List/**/list) {}\n");
+ buf.append("}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
+
+ astRoot.recordModifications();
+
+ AST ast = astRoot.getAST();
+
+ List types = astRoot.types();
+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
+ List parameters = methodDecl.parameters();
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT));
+
+ String preview = evaluateRewrite(cu, astRoot);
+
+ buf= new StringBuffer();
+ buf.append("package test0011;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers(int i, int list) {}\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
+ public void test0012() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0012", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0012;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers(int i, List.../**/list) {}\n");
+ buf.append("}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
+
+ astRoot.recordModifications();
+
+ AST ast = astRoot.getAST();
+
+ List types = astRoot.types();
+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
+ MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
+ List parameters = methodDecl.parameters();
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT));
+
+ String preview = evaluateRewrite(cu, astRoot);
+
+ buf= new StringBuffer();
+ buf.append("package test0012;\n");
+ buf.append("public class X {\n");
+ buf.append(" void getUsers(int i, int.../**/list) {}\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
+ public void test0013() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0013", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0013;\n");
+ buf.append("public class X {\n");
+ buf.append(" List/**/list;\n");
+ buf.append("}\n");
+
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
+
+ astRoot.recordModifications();
+
+ AST ast = astRoot.getAST();
+
+ List types = astRoot.types();
+ List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
+ FieldDeclaration fieldDeclaration= (FieldDeclaration) list.get(0);
+ fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT));
+
+ String preview = evaluateRewrite(cu, astRoot);
+
+ buf= new StringBuffer();
+ buf.append("package test0013;\n");
+ buf.append("public class X {\n");
+ buf.append(" int list;\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java
index 3dad46228..4a86e821d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java
@@ -82,10 +82,11 @@ public abstract class ASTRewritingModifyingTest extends AbstractJavaModelTests {
}
public CompilationUnit createCU(
ICompilationUnit unit,
- boolean resolveBindings) {
+ boolean resolveBindings,
+ int astLevel) {
try {
- ASTParser c = ASTParser.newParser(AST_INTERNAL_JLS2);
+ ASTParser c = ASTParser.newParser(astLevel);
c.setSource(unit);
c.setResolveBindings(resolveBindings);
ASTNode result = c.createAST(null);
@@ -96,6 +97,12 @@ public abstract class ASTRewritingModifyingTest extends AbstractJavaModelTests {
}
}
+ public CompilationUnit createCU(
+ ICompilationUnit unit,
+ boolean resolveBindings) {
+ return createCU(unit, resolveBindings, AST_INTERNAL_JLS2);
+ }
+
public CompilationUnit createCU(char[] source) {
if (source == null) {
throw new IllegalArgumentException();
diff --git a/org.eclipse.jdt.core.tests.model/workspace/CodeCorrection/src/CorrectLocalVariable2.java b/org.eclipse.jdt.core.tests.model/workspace/CodeCorrection/src/CorrectLocalVariable2.java
new file mode 100644
index 000000000..813aeb19f
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/CodeCorrection/src/CorrectLocalVariable2.java
@@ -0,0 +1,6 @@
+public class CorrectLocalVariable2 {
+ void foo(){
+ int ba\ud842\udf9fr0;
+ ba\ud842\udf9fr = 5;
+ }
+} \ No newline at end of file

Back to the top