View | Details | Raw Unified | Return to bug 199668 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java (-3 / +15 lines)
Lines 43-49 Link Here
43
43
44
	static {
44
	static {
45
//		TESTS_NAMES = new String[] {"test0578"};
45
//		TESTS_NAMES = new String[] {"test0578"};
46
//		TESTS_NUMBERS =  new int[] { 606 };
46
//		TESTS_NUMBERS =  new int[] { 608 };
47
	}
47
	}
48
	public static Test suite() {
48
	public static Test suite() {
49
		return buildModelTestSuite(ASTConverterTest2.class);
49
		return buildModelTestSuite(ASTConverterTest2.class);
Lines 5501-5508 Link Here
5501
				"  }\n" +
5501
				"  }\n" +
5502
				"}"
5502
				"}"
5503
			);
5503
			);
5504
			ASTNode cu = buildAST(null, workingCopy, false, true);
5504
			ASTNode node = buildAST(null, workingCopy, false, true);
5505
			assertNotNull("Should get an AST", cu);
5505
			assertNotNull("Should get an AST", node);
5506
			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
5507
			node = getASTNode((CompilationUnit) node, 0, 0, 0);
5508
			assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType());
5509
			ForStatement forStatement = (ForStatement) node;
5510
			List initializers = forStatement.initializers();
5511
			assertEquals("Wrong size", 1, initializers.size());
5512
			VariableDeclarationExpression expression = (VariableDeclarationExpression) initializers.get(0);
5513
			List fragments = expression.fragments();
5514
			assertEquals("Wrong size", 1, fragments.size());
5515
			VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
5516
			assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
5517
			assertTrue("Should be a recovered fragment", isRecovered(expression));
5506
		} finally {
5518
		} finally {
5507
			if (workingCopy != null)
5519
			if (workingCopy != null)
5508
				workingCopy.discardWorkingCopy();
5520
				workingCopy.discardWorkingCopy();
(-)dom/org/eclipse/jdt/core/dom/ASTRecoveryPropagator.java (-2 / +22 lines)
Lines 359-364 Link Here
359
		}
359
		}
360
	}
360
	}
361
	
361
	
362
	public void endVisit(ForStatement node) {
363
		endVisitNode(node);
364
		List initializers = node.initializers();
365
		if (initializers.size() == 1) {
366
			Expression expression = (Expression) initializers.get(0);
367
			if (expression.getNodeType() == ASTNode.VARIABLE_DECLARATION_EXPRESSION) {
368
				VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) expression;
369
				List fragments = variableDeclarationExpression.fragments();
370
				for (int i = 0, max = fragments.size(); i <max; i++) {
371
					VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(i);
372
					SimpleName simpleName = fragment.getName();
373
					if (CharOperation.equals(RecoveryScanner.FAKE_IDENTIFIER, simpleName.getIdentifier().toCharArray())) {
374
						fragments.remove(fragment);
375
						variableDeclarationExpression.setFlags(variableDeclarationExpression.getFlags() | ASTNode.RECOVERED);
376
					}
377
				}
378
			}
379
		}
380
	}
381
362
	public void endVisit(VariableDeclarationStatement node) {
382
	public void endVisit(VariableDeclarationStatement node) {
363
		endVisitNode(node);
383
		endVisitNode(node);
364
		List fragments = node.fragments();
384
		List fragments = node.fragments();
Lines 371-378 Link Here
371
				SimpleName simpleName = (SimpleName) expression;
391
				SimpleName simpleName = (SimpleName) expression;
372
				if (CharOperation.equals(RecoveryScanner.FAKE_IDENTIFIER, simpleName.getIdentifier().toCharArray())) {
392
				if (CharOperation.equals(RecoveryScanner.FAKE_IDENTIFIER, simpleName.getIdentifier().toCharArray())) {
373
					fragment.setInitializer(null);
393
					fragment.setInitializer(null);
374
					fragment.setFlags(node.getFlags() | ASTNode.RECOVERED);
394
					fragment.setFlags(fragment.getFlags() | ASTNode.RECOVERED);
375
				}			
395
				}
376
			}
396
			}
377
		}
397
		}
378
	}
398
	}
(-)dom/org/eclipse/jdt/core/dom/ASTConverter.java (-22 / +13 lines)
Lines 378-397 Link Here
378
378
379
	protected void checkAndAddMultipleLocalDeclaration(org.eclipse.jdt.internal.compiler.ast.Statement[] stmts, int index, List blockStatements) {
379
	protected void checkAndAddMultipleLocalDeclaration(org.eclipse.jdt.internal.compiler.ast.Statement[] stmts, int index, List blockStatements) {
380
		if (index > 0
380
		if (index > 0
381
			&& stmts[index - 1] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
381
				&& stmts[index - 1] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
382
				org.eclipse.jdt.internal.compiler.ast.LocalDeclaration local1 = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) stmts[index - 1];
382
			org.eclipse.jdt.internal.compiler.ast.LocalDeclaration local1 = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) stmts[index - 1];
383
				org.eclipse.jdt.internal.compiler.ast.LocalDeclaration local2 = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) stmts[index];
383
			org.eclipse.jdt.internal.compiler.ast.LocalDeclaration local2 = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) stmts[index];
384
				if (local2.name == RecoveryScanner.FAKE_IDENTIFIER) // workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=199668
384
			if (local1.declarationSourceStart == local2.declarationSourceStart) {
385
					return;
385
				// we have a multiple local declarations
386
				if (local1.declarationSourceStart == local2.declarationSourceStart) {
386
				// We retrieve the existing VariableDeclarationStatement to add the new VariableDeclarationFragment
387
					// we have a multiple local declarations
387
				VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) blockStatements.get(blockStatements.size() - 1);
388
					// We retrieve the existing VariableDeclarationStatement to add the new VariableDeclarationFragment
388
				variableDeclarationStatement.fragments().add(convertToVariableDeclarationFragment((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index]));
389
					VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) blockStatements.get(blockStatements.size() - 1);
389
			} else {
390
					variableDeclarationStatement.fragments().add(convertToVariableDeclarationFragment((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index]));
390
				// we can create a new FieldDeclaration
391
				} else {
391
				blockStatements.add(convertToVariableDeclarationStatement((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index]));
392
					// we can create a new FieldDeclaration
392
			}
393
					blockStatements.add(convertToVariableDeclarationStatement((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index]));
394
				}
395
		} else {
393
		} else {
396
			// we can create a new FieldDeclaration
394
			// we can create a new FieldDeclaration
397
			blockStatements.add(convertToVariableDeclarationStatement((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index]));
395
			blockStatements.add(convertToVariableDeclarationStatement((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index]));
Lines 1739-1754 Link Here
1739
			// we know that we have at least one initialization
1737
			// we know that we have at least one initialization
1740
			if (initializations[0] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
1738
			if (initializations[0] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
1741
				org.eclipse.jdt.internal.compiler.ast.LocalDeclaration initialization = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) initializations[0];
1739
				org.eclipse.jdt.internal.compiler.ast.LocalDeclaration initialization = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) initializations[0];
1742
				if (initialization.name == RecoveryScanner.FAKE_IDENTIFIER) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=199668) 
1743
					return null;
1744
				}
1745
				VariableDeclarationExpression variableDeclarationExpression = convertToVariableDeclarationExpression(initialization);
1740
				VariableDeclarationExpression variableDeclarationExpression = convertToVariableDeclarationExpression(initialization);
1746
				int initializationsLength = initializations.length;
1741
				int initializationsLength = initializations.length;
1747
				for (int i = 1; i < initializationsLength; i++) {
1742
				for (int i = 1; i < initializationsLength; i++) {
1748
					initialization = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)initializations[i];
1743
					initialization = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)initializations[i];
1749
					if (initialization.name != RecoveryScanner.FAKE_IDENTIFIER) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=199668) 
1744
					variableDeclarationExpression.fragments().add(convertToVariableDeclarationFragment(initialization));
1750
						variableDeclarationExpression.fragments().add(convertToVariableDeclarationFragment(initialization));
1751
					}
1752
				}
1745
				}
1753
				if (initializationsLength != 1) {
1746
				if (initializationsLength != 1) {
1754
					int start = variableDeclarationExpression.getStartPosition();
1747
					int start = variableDeclarationExpression.getStartPosition();
Lines 2380-2387 Link Here
2380
		}
2373
		}
2381
		if (statement instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
2374
		if (statement instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
2382
			org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)statement;
2375
			org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)statement;
2383
			if (localDeclaration.name == RecoveryScanner.FAKE_IDENTIFIER) // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=199668
2384
				return null;
2385
			return convertToVariableDeclarationStatement(localDeclaration);
2376
			return convertToVariableDeclarationStatement(localDeclaration);
2386
		}
2377
		}
2387
		if (statement instanceof org.eclipse.jdt.internal.compiler.ast.AssertStatement) {
2378
		if (statement instanceof org.eclipse.jdt.internal.compiler.ast.AssertStatement) {

Return to bug 199668