summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorTomasz Zarna2012-08-20 15:56:44 (EDT)
committer Stephan Herrmann2012-08-20 15:56:44 (EDT)
commitc0b7ec7ac86ca976e8dafca35f37afdb3d3303ce (patch)
treeaa666cd5f5319307f856ec7ebf34e1f53926856d
parente9740a5d5d266d4ab1f1481408252eab08091df9 (diff)
downloadeclipse.jdt.core-c0b7ec7ac86ca976e8dafca35f37afdb3d3303ce.zip
eclipse.jdt.core-c0b7ec7ac86ca976e8dafca35f37afdb3d3303ce.tar.gz
eclipse.jdt.core-c0b7ec7ac86ca976e8dafca35f37afdb3d3303ce.tar.bz2
Synchronized block in switch causes fall-through comment to be ignored
Bug: 387146 Merge conflicts resolved in: org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java38
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java58
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java12
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/ToolFactory.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java3
5 files changed, 105 insertions, 8 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
index 74070b2..a5c80e6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
@@ -1310,8 +1310,42 @@ public class ScannerTest extends AbstractRegressionTest {
"Invalid unicode\n" +
"----------\n");
}
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383062
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=387146
public void test061() {
+ IScanner scanner = ToolFactory.createScanner(
+ true,
+ true,
+ true,
+ JavaCore.VERSION_1_4,
+ JavaCore.VERSION_1_4);
+ final char[] source = "case 1:\nsynchronized (someLock){}\n//$FALL-THROUGH$\ncase 2:".toCharArray();
+ scanner.setSource(source);
+ scanner.resetTo(0, source.length - 1);
+ try {
+ assertEquals("Wrong token", ITerminalSymbols.TokenNamecase, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameIntegerLiteral, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameCOLON, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNamesynchronized, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameLPAREN, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameIdentifier, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameRPAREN, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameLBRACE, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameRBRACE, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameCOMMENT_LINE, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNamecase, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameIntegerLiteral, scanner.getNextToken());
+ assertEquals("Wrong token", ITerminalSymbols.TokenNameCOLON, scanner.getNextToken());
+ } catch (InvalidInputException e) {
+ assertTrue("Should not fail with InvalidInputException", false);
+ }
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383062
+ public void test062() {
IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_4);
char[] source = "->".toCharArray(); //$NON-NLS-1$
scanner.setSource(source);
@@ -1325,7 +1359,7 @@ public class ScannerTest extends AbstractRegressionTest {
assertEquals("Expecting ->", ITerminalSymbols.TokenNameARROW, token);
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383062
- public void test062() {
+ public void test063() {
IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_4);
char[] source = "::".toCharArray(); //$NON-NLS-1$
scanner.setSource(source);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
index db54f85..6d1e3ea 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
@@ -2563,6 +2563,64 @@ public void test383643() {
options
);
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=387146 - the fall-through comment is ignored
+public void test387146a() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR);
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n" +
+ " private Object someLock;\n" +
+ " public void foo1(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1:\n" +
+ " synchronized (someLock) {\n" +
+ " System.out.println();\n" +
+ " }\n" +
+ " //$FALL-THROUGH$\n" +
+ " case 2:\n" +
+ " System.out.println();\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "",
+ null,
+ true,
+ options);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=387146 - the fall-through comment is respected
+public void test387146b() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR);
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n" +
+ " private boolean someFlag;\n" +
+ " public void foo1(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1:\n" +
+ " if (someFlag) {\n" +
+ " System.out.println();\n" +
+ " }\n" +
+ " //$FALL-THROUGH$\n" +
+ " case 2:\n" +
+ " System.out.println();\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "",
+ null,
+ true,
+ options);
+}
public static Class testClass() {
return SwitchTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index 3afdccf..aa7d315 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -1241,7 +1241,7 @@ public void checkComment() {
int lastComment = this.scanner.commentPtr;
if (this.modifiersSourceStart >= 0) {
- // eliminate comments located after modifierSourceStart if positionned
+ // eliminate comments located after modifierSourceStart if positioned
while (lastComment >= 0) {
int commentSourceStart = this.scanner.commentStarts[lastComment];
if (commentSourceStart < 0) commentSourceStart = -commentSourceStart;
@@ -8518,7 +8518,7 @@ protected void consumeSingleTypeImportDeclarationName() {
}
protected void consumeStatementBreak() {
// BreakStatement ::= 'break' ';'
- // break pushs a position on this.intStack in case there is no label
+ // break pushes a position on this.intStack in case there is no label
pushOnAstStack(new BreakStatement(null, this.intStack[this.intPtr--], this.endStatementPosition));
@@ -8773,7 +8773,8 @@ protected void consumeStatementSynchronized() {
this.intStack[this.intPtr--],
this.endStatementPosition);
}
- resetModifiers();
+ this.modifiers = ClassFileConstants.AccDefault;
+ this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
}
protected void consumeStatementThrow() {
// ThrowStatement ::= 'throw' Expression ';'
@@ -10662,7 +10663,7 @@ public void initialize() {
this.initialize(false);
}
public void initialize(boolean initializeNLS) {
- //positionning the parser for a new compilation unit
+ //positioning the parser for a new compilation unit
//avoiding stack reallocation and all that....
this.astPtr = -1;
this.astLengthPtr = -1;
@@ -12332,6 +12333,9 @@ private void reportSyntaxErrorsForSkippedMethod(TypeDeclaration[] types){
}
}
}
+/**
+ * Reset modifiers buffer and comment stack. Should be call only for nodes that claim both.
+ */
protected void resetModifiers() {
this.modifiers = ClassFileConstants.AccDefault;
this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ToolFactory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ToolFactory.java
index f03ec1c..f402fec 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ToolFactory.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ToolFactory.java
@@ -498,7 +498,7 @@ public class ToolFactory {
* would report assert keywords ({@link ITerminalSymbols#TokenNameassert}). Java 1.4 has introduced
* a new 'assert' keyword.
* @param complianceLevel This is used to support the Unicode 4.0 character sets. if set to 1.5 or above,
- * the Unicode 4.0 is supporte, otherwise Unicode 3.0 is supported.
+ * the Unicode 4.0 is supported, otherwise Unicode 3.0 is supported.
* @return a scanner
* @see org.eclipse.jdt.core.compiler.IScanner
*
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java
index 41d51c3..f789b58 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 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
@@ -258,6 +258,7 @@ public class CommentRecorderParser extends Parser {
}
/* (non-Javadoc)
* Save all source comments currently stored before flushing them.
+ * this.scanner.commentPtr is expected *not* yet being reset before calling this method.
* @see org.eclipse.jdt.internal.compiler.parser.Parser#resetModifiers()
*/
protected void resetModifiers() {