Skip to content

Commit

Permalink
Adding more comments and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jarthana committed Nov 6, 2023
1 parent 61ce950 commit 1ffde0a
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public static char[] formatTextBlock(char[][] lines, int indent, boolean follows
// And remove all trailing whitespace
// Finally append the \n at the end of the line (except the last line)
int trail = length;
// Only the last line is really prefixed to the expression
// Only the last line is really prefixed to the embedded
// expression in a string template
if (!precedesExp || i < (size -1)) {
for(;trail > 0;) {
if (!ScannerHelper.isWhitespace(l[trail-1])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10046,14 +10046,17 @@ private void consumeTemplate(int token) {
int oldStart = this.scanner.startPosition;
// What we get from the scanner for text block content will
// not contain the text for the embedded expression. This ensures
// that the whitespace from those expressions don't meddle with the
// that the whitespace from those expressions don't mess with the
// formatting of the outer text block.
// First get the common indentation for the entire text block
int indent = 0;
boolean isMultiline = token == TerminalTokens.TokenNameTextBlockTemplate;
if (isMultiline) {
char[][] lines = this.scanner.getCurrentTextBlockAsLines();
indent = TextBlock.getTextBlockIndent(lines);
}
// Process the text fragments one by one with the common indentation
// to get the right formatting for each of them.
int start, end;
int[] positions = this.scanner.fragPositions;
int pointer = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public void test027() {
options.put(CompilerOptions.OPTION_ReportUnusedLocal, old1);
}
}
public void test028() {
public void test027a() {
Map<String,String> options = getCompilerOptions(false);
String old1 = options.get(CompilerOptions.OPTION_ReportUnusedLocal);
options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR);
Expand Down Expand Up @@ -751,6 +751,94 @@ public void test028() {
options.put(CompilerOptions.OPTION_ReportUnusedLocal, old1);
}
}
public void test028() {
Map<String,String> options = getCompilerOptions(false);
String old1 = options.get(CompilerOptions.OPTION_ReportUnusedPrivateMember);
options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
try {
runNegativeTest(
new String[] {
"X.java",
"public class X {\n"
+ " private String abc = \"abc\"; // unused\n"
+ " private String def = \"def\"; // unused\n"
+ " public void main(String[] args) {\n"
+ " String s = STR.\"A simple String \\{def}\";\n"
+ " System.out.println(s);\n"
+ " }\n"
+ "}"
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" private String abc = \"abc\"; // unused\n" +
" ^^^\n" +
"The value of the field X.abc is not used\n" +
"----------\n",
null,
false,
options);
} finally {
options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, old1);
}
}
public void test028a() {
Map<String,String> options = getCompilerOptions(false);
String old1 = options.get(CompilerOptions.OPTION_ReportUnusedPrivateMember);
options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
try {
runNegativeTest(
new String[] {
"X.java",
"public class X {\n"
+ " private String abc = \"abc\"; // unused\n"
+ " private String def = \"def\"; // unused\n"
+ " public void main(String[] args) {\n"
+ " String s = STR.\"A simple String \\{clone(def)}\";\n"
+ " System.out.println(s);\n"
+ " }\n"
+ " public String clone(String s) {\n"
+ " return s;\n"
+ " }\n"
+ "}"
},
"----------\n" +
"1. ERROR in X.java (at line 2)\n" +
" private String abc = \"abc\"; // unused\n" +
" ^^^\n" +
"The value of the field X.abc is not used\n" +
"----------\n",
null,
false,
options);
} finally {
options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, old1);
}
}
public void test028b() {
Map<String,String> options = getCompilerOptions(false);
String old1 = options.get(CompilerOptions.OPTION_ReportUnusedPrivateMember);
options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
try {
runConformTest(
new String[] {
"X.java",
"public class X {\n"
+ " private String abc = \"abc\"; // unused\n"
+ " public void main(String[] args) {\n"
+ " String s = STR.\"A simple String \\{clone(abc)}\";\n"
+ " System.out.println(s);\n"
+ " }\n"
+ " public String clone(String s) {\n"
+ " return \"clone\";\n"
+ " }\n"
+ "}"
},
"A simple String clone",
options);
} finally {
options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, old1);
}
}
public void test029() {
runConformTest(
new String[] {
Expand Down Expand Up @@ -1129,4 +1217,33 @@ public static void main(String[] args) {
"true",
getCompilerOptions());
}
// 3 levels of nested test blocks with string templates and a method invocation
public void test044() {
runConformTest(
new String[] {
"X.java",
"""
public class X {
public static void main(String argv[]) {
String s = STR.\"""
\\{
STR.\"""
\\{
clone(\"""
abcdefg
\""")
}\"""
}\""";
System.out.println(s.equals("clone"));
}
public static String clone(String s) {
return "clone"; //$NON-NLS-1$
}
}
"""
},
"true",
getCompilerOptions());
}
}

0 comments on commit 1ffde0a

Please sign in to comment.