| author | Tomasz Zarna | 2012-08-16 09:37:58 (EDT) |
|---|---|---|
| committer | Tomasz Zarna | 2012-08-16 09:39:18 (EDT) |
| commit | dd3a6a98242c687aed252b98c981915e1ab56c45 (patch) (side-by-side diff) | |
| tree | ef4021a25a38242b67b21dd283b3bb05f76306d8 | |
| parent | 4b0b5e4ba4fc84b55ca6c20dd4ad4ee385e312fc (diff) | |
| download | eclipse.jdt.core-dd3a6a98242c687aed252b98c981915e1ab56c45.zip eclipse.jdt.core-dd3a6a98242c687aed252b98c981915e1ab56c45.tar.gz eclipse.jdt.core-dd3a6a98242c687aed252b98c981915e1ab56c45.tar.bz2 | |
Synchronized block in switch causes fall-through comment to be ignoredrefs/changes/17/7217/7
Bug: 387146
Change-Id: I3606af0f7c12c1ee05a3250214223d4ce6d66a72
5 files changed, 104 insertions, 7 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 6e782c5..b5de00b 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 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 @@ -1306,4 +1306,38 @@ public class ScannerTest extends AbstractRegressionTest { "Invalid unicode\n" + "----------\n"); } + // 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); + } + } } 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 6e7a0b5..3f50e7a 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 @@ -1113,7 +1113,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; @@ -7193,7 +7193,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)); @@ -7448,7 +7448,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 ';' @@ -9227,7 +9228,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; @@ -10786,6 +10787,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() { |

