Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2019-10-16 11:28:27 +0000
committerJay Arthanareeswaran2019-10-16 11:47:51 +0000
commitba59a29d7bb455f98495dc317d2e9b1dbc78925c (patch)
tree14837497e28bd68820d9a7b858dff20a97edb96f
parent55f0650606275cab67b539f058d1e4130fba021e (diff)
downloadeclipse.jdt.core-ba59a29d7bb455f98495dc317d2e9b1dbc78925c.tar.gz
eclipse.jdt.core-ba59a29d7bb455f98495dc317d2e9b1dbc78925c.tar.xz
eclipse.jdt.core-ba59a29d7bb455f98495dc317d2e9b1dbc78925c.zip
Bug 552105 - [13] Text block indentation not preserved on running the
application Change-Id: I2b8979666292aff63eae31797942b7ffe18ad20f Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java6
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java36
2 files changed, 37 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
index 0c2046c9e8..82a5bcc103 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
@@ -632,6 +632,10 @@ public char[] getCurrentTextBlock() {
List<char[]> list = new ArrayList<>(lines.length);
for(int i = 0; i < lines.length; i++) {
char[] line = lines[i];
+ if (i + 1 == size && line.length == 0) {
+ list.add(line);
+ break;
+ }
char[][] sub = CharOperation.splitOn('\r', line);
for (char[] cs : sub) {
if (cs.length > 0) {
@@ -658,7 +662,7 @@ public char[] getCurrentTextBlock() {
}
}
}
- if (!blank) {
+ if (!blank || (i+1 == size)) {
if (prefix < 0 || whitespaces < prefix) {
prefix = whitespaces;
}
diff --git a/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java
index 7b5c1d1cb9..4e994b3a08 100644
--- a/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java
+++ b/org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java
@@ -235,7 +235,7 @@ public class TextBlockTest extends AbstractRegressionTest {
" line 1\n" +
" line 2\r" +
" \r" +
- " line 3\n\"\"\";\n" +
+ " line 3\"\"\";\n" +
" public static void main(String[] args) {\n" +
" System.out.println(textb);\n" +
" }\n" +
@@ -249,6 +249,35 @@ public class TextBlockTest extends AbstractRegressionTest {
new String[] {"--enable-preview"});
}
/*
+ * Positive - Multi line text block with varying indentation
+ * and \n and \r
+ */
+ public void test008a() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static String textb = \"\"\"\n" +
+ " line 1\n" +
+ " line 2\r" +
+ " \r" +
+ " line 3\n\"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(\"<\");\n" +
+ " System.out.print(textb);\n" +
+ " System.out.print(\">\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "< line 1\n" +
+ " line 2\n" +
+ " \n" +
+ " line 3\n" +
+ ">", // the trailing whitespace is trimmed by the test framework
+ null,
+ new String[] {"--enable-preview"});
+ }
+ /*
* positive - using unescaped '"' in text block
*/
public void test009() {
@@ -468,7 +497,7 @@ public class TextBlockTest extends AbstractRegressionTest {
*/
@SuppressWarnings("removal")
public void test016b() {
- String text = " <html>\n" +
+ String text = "<html>\n" +
" <body>\n" +
" <p>Hello, world</p>\n" +
" </body>\n" +
@@ -723,8 +752,7 @@ public class TextBlockTest extends AbstractRegressionTest {
" public static void main(String[] args) {\n" +
" System.out.println(textb);\n" +
" }\n" +
- " } \n" +
- " \"\"\"\n" +
+ " }\"\"\"" +
" }, \n" +
" \"\",\n" +
" null,\n" +

Back to the top