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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (-5 / +30 lines)
Lines 46-52 Link Here
46
	}
46
	}
47
47
48
	static {
48
	static {
49
//		TESTS_NUMBERS = new int[] { 284 };
49
//		TESTS_NUMBERS = new int[] { 286 };
50
//		TESTS_RANGE = new int[] { 277, -1 };
50
//		TESTS_RANGE = new int[] { 277, -1 };
51
//		TESTS_NAMES = new String[] {"test0204"};
51
//		TESTS_NAMES = new String[] {"test0204"};
52
	}
52
	}
Lines 9451-9462 Link Here
9451
		assertEquals("Not a compilation unit", IJavaElement.COMPILATION_UNIT, javaElement.getElementType());
9451
		assertEquals("Not a compilation unit", IJavaElement.COMPILATION_UNIT, javaElement.getElementType());
9452
		assertNotNull("No parent", javaElement.getParent());
9452
		assertNotNull("No parent", javaElement.getParent());
9453
	}
9453
	}
9454
	
9454
9455
	
9456
	/*
9455
	/*
9457
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=203342
9456
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=203342
9458
	 */
9457
	 */
9459
	public void _test0284() throws JavaModelException {
9458
	public void test0284() throws JavaModelException {
9460
		String contents =
9459
		String contents =
9461
			"public class X {\n" + 
9460
			"public class X {\n" + 
9462
			"	public static final double VAR = 0x0.0000000000001P-1022;\n" + 
9461
			"	public static final double VAR = 0x0.0000000000001P-1022;\n" + 
Lines 9484-9490 Link Here
9484
	 * @test That the qualified name of the default value does not contain any '$' character
9483
	 * @test That the qualified name of the default value does not contain any '$' character
9485
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=187430"
9484
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=187430"
9486
	 */
9485
	 */
9487
	public void testBug187430() throws JavaModelException {
9486
	public void test0285() throws JavaModelException {
9488
    	this.workingCopy = getWorkingCopy("/Converter15/src/b187430/Test.java", true/*resolve*/);
9487
    	this.workingCopy = getWorkingCopy("/Converter15/src/b187430/Test.java", true/*resolve*/);
9489
    	String contents =
9488
    	String contents =
9490
    		"package b187430;\n" +
9489
    		"package b187430;\n" +
Lines 9512-9515 Link Here
9512
		ITypeBinding iTypeBinding = (ITypeBinding) defaultValue;
9511
		ITypeBinding iTypeBinding = (ITypeBinding) defaultValue;
9513
		assertEquals("Unexpected default value", "b187430.A.B", iTypeBinding.getQualifiedName());
9512
		assertEquals("Unexpected default value", "b187430.A.B", iTypeBinding.getQualifiedName());
9514
	}
9513
	}
9514
9515
	/*
9516
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=212857
9517
	 */
9518
	public void test0286() throws JavaModelException {
9519
		String contents =
9520
			"public class X {\n" + 
9521
			"	void m(@SuppressWarnings({\"unused\", \"bla\"}) int arg) {}\n" + 
9522
			"}";
9523
		this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
9524
		ASTNode node = buildAST(
9525
			contents,
9526
			this.workingCopy,
9527
			false);
9528
		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
9529
		CompilationUnit unit = (CompilationUnit) node;
9530
		String expectedProblems =
9531
			"Unnecessary @SuppressWarnings(\"unused\")\n" + 
9532
			"Unsupported @SuppressWarnings(\"bla\")";
9533
		assertProblemsSize(unit, 2, expectedProblems);
9534
		node = getASTNode(unit, 0, 0);
9535
		assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
9536
		MethodDeclaration methodDeclaration = (MethodDeclaration) node;
9537
		Block body = methodDeclaration.getBody();
9538
		checkSourceRange(body, "{}", contents);
9539
	}
9515
}
9540
}
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java (-1 / +66 lines)
Lines 120-126 Link Here
120
	static {
120
	static {
121
//		TESTS_NAMES = new String[] {"test0602"};
121
//		TESTS_NAMES = new String[] {"test0602"};
122
//		TESTS_RANGE = new int[] { 670, -1 };
122
//		TESTS_RANGE = new int[] { 670, -1 };
123
//		TESTS_NUMBERS =  new int[] { 687 };
123
//		TESTS_NUMBERS =  new int[] { 689 };
124
	}
124
	}
125
	public static Test suite() {
125
	public static Test suite() {
126
		return buildModelTestSuite(ASTConverterTestAST3_2.class);
126
		return buildModelTestSuite(ASTConverterTestAST3_2.class);
Lines 9550-9553 Link Here
9550
				workingCopy.discardWorkingCopy();
9550
				workingCopy.discardWorkingCopy();
9551
		}
9551
		}
9552
	}
9552
	}
9553
9554
	/*
9555
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=212857
9556
	 */
9557
	public void test0688() throws JavaModelException {
9558
		ICompilationUnit workingCopy = null;
9559
		try {
9560
			String contents =
9561
				"public class X {\n" + 
9562
				"	protected String foo(String string)\n" + 
9563
				"		return null;\n" + 
9564
				"	}\n" + 
9565
				"}";
9566
			workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
9567
			ASTNode node = buildAST(
9568
				contents,
9569
				workingCopy,
9570
				false);
9571
			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
9572
			CompilationUnit unit = (CompilationUnit) node;
9573
			assertProblemsSize(unit, 1, "Syntax error on token \")\", { expected after this token");
9574
			node = getASTNode(unit, 0, 0);
9575
			assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
9576
			MethodDeclaration methodDeclaration = (MethodDeclaration) node;
9577
			Block body = methodDeclaration.getBody();
9578
			String expectedOutput = "return null;\n" + 
9579
			"	}";
9580
			checkSourceRange(body, expectedOutput, contents);
9581
		} finally {
9582
			if (workingCopy != null)
9583
				workingCopy.discardWorkingCopy();
9584
		}
9585
	}
9586
	/*
9587
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=212857
9588
	 */
9589
	public void test0689() throws JavaModelException {
9590
		ICompilationUnit workingCopy = null;
9591
		try {
9592
			String contents =
9593
				"public class X {\n" + 
9594
				"	protected String foo(String string)\n" + 
9595
				"		if (string == null) { return null; } else { return string; }\n" + 
9596
				"	}\n" + 
9597
				"}";
9598
			workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
9599
			ASTNode node = buildAST(
9600
				contents,
9601
				workingCopy,
9602
				false);
9603
			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
9604
			CompilationUnit unit = (CompilationUnit) node;
9605
			assertProblemsSize(unit, 1, "Syntax error on token \")\", { expected after this token");
9606
			node = getASTNode(unit, 0, 0);
9607
			assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
9608
			MethodDeclaration methodDeclaration = (MethodDeclaration) node;
9609
			Block body = methodDeclaration.getBody();
9610
			String expectedOutput = "if (string == null) { return null; } else { return string; }\n" + 
9611
			"	}";
9612
			checkSourceRange(body, expectedOutput, contents);
9613
		} finally {
9614
			if (workingCopy != null)
9615
				workingCopy.discardWorkingCopy();
9616
		}
9617
	}
9553
}
9618
}
(-)dom/org/eclipse/jdt/core/dom/ASTConverter.java (-8 / +45 lines)
Lines 487-501 Link Here
487
487
488
			org.eclipse.jdt.internal.compiler.ast.Statement[] statements = methodDeclaration.statements;
488
			org.eclipse.jdt.internal.compiler.ast.Statement[] statements = methodDeclaration.statements;
489
			
489
			
490
			start = retrieveStartBlockPosition(methodDeclaration.sourceStart, declarationSourceEnd);
490
			startPosition = methodDeclaration.sourceEnd + 1;
491
			end = retrieveEndBlockPosition(methodDeclaration.sourceStart, methodDeclaration.declarationSourceEnd);
491
			if (parameters != null) {
492
				if (thrownExceptions != null) {
493
					List thrownExceptionsList = methodDecl.thrownExceptions();
494
					ASTNode exception = (ASTNode) thrownExceptionsList.get(thrownExceptionsList.size() - 1);
495
					startPosition = exception.getStartPosition() + exception.getLength();
496
				} else {
497
					List parameterList = methodDecl.parameters();
498
					ASTNode lastParameter = (ASTNode) parameterList.get(parameterList.size() - 1);
499
					startPosition = lastParameter.getStartPosition() + lastParameter.getLength();
500
				}
501
			} else if (thrownExceptions != null) {
502
				List thrownExceptionsList = methodDecl.thrownExceptions();
503
				ASTNode exception = (ASTNode) thrownExceptionsList.get(thrownExceptionsList.size() - 1);
504
				startPosition = exception.getStartPosition() + exception.getLength();
505
			}
506
			start = retrieveStartBlockPosition(startPosition, declarationSourceEnd);
492
			Block block = null;
507
			Block block = null;
493
			if (start != -1 && end != -1) {
508
			if (start != -1) {
494
				/*
509
				/*
495
				 * start or end can be equal to -1 if we have an interface's method.
510
				 * start or end can be equal to -1 if we have an interface's method.
496
				 */
511
				 */
497
				block = new Block(this.ast);
512
				block = new Block(this.ast);
498
				block.setSourceRange(start, end - start + 1);
513
				block.setSourceRange(start, closingPosition - start + 1);
499
				methodDecl.setBody(block);
514
				methodDecl.setBody(block);
500
			}
515
			}
501
			if (block != null && (statements != null || explicitConstructorCall != null)) {
516
			if (block != null && (statements != null || explicitConstructorCall != null)) {
Lines 520-526 Link Here
520
		} else {
535
		} else {
521
			// syntax error in this method declaration
536
			// syntax error in this method declaration
522
			if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) {
537
			if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) {
523
				start = retrieveStartBlockPosition(methodDeclaration.sourceStart, declarationSourceEnd);
538
				int startPosition = methodDeclaration.sourceEnd + 1;
539
				if (parameters != null) {
540
					if (thrownExceptions != null) {
541
						List thrownExceptionsList = methodDecl.thrownExceptions();
542
						ASTNode exception = (ASTNode) thrownExceptionsList.get(thrownExceptionsList.size() - 1);
543
						startPosition = exception.getStartPosition() + exception.getLength();
544
					} else {
545
						List parameterList = methodDecl.parameters();
546
						ASTNode lastParameter = (ASTNode) parameterList.get(parameterList.size() - 1);
547
						startPosition = lastParameter.getStartPosition() + lastParameter.getLength();
548
					}
549
				} else if (thrownExceptions != null) {
550
					List thrownExceptionsList = methodDecl.thrownExceptions();
551
					ASTNode exception = (ASTNode) thrownExceptionsList.get(thrownExceptionsList.size() - 1);
552
					startPosition = exception.getStartPosition() + exception.getLength();
553
				}
554
				start = retrieveStartBlockPosition(startPosition, declarationSourceEnd);
524
				end = methodDeclaration.bodyEnd;
555
				end = methodDeclaration.bodyEnd;
525
				// try to get the best end position
556
				// try to get the best end position
526
				CategorizedProblem[] problems = methodDeclaration.compilationResult().problems;
557
				CategorizedProblem[] problems = methodDeclaration.compilationResult().problems;
Lines 533-539 Link Here
533
						}
564
						}
534
					}
565
					}
535
				}
566
				}
536
				int startPosition = methodDecl.getStartPosition();
567
				startPosition = methodDecl.getStartPosition();
537
				methodDecl.setSourceRange(startPosition, end - startPosition + 1);
568
				methodDecl.setSourceRange(startPosition, end - startPosition + 1);
538
				if (start != -1 && end != -1) {
569
				if (start != -1 && end != -1) {
539
					/*
570
					/*
Lines 543-549 Link Here
543
					block.setSourceRange(start, end - start + 1);
574
					block.setSourceRange(start, end - start + 1);
544
					methodDecl.setBody(block);
575
					methodDecl.setBody(block);
545
				}
576
				}
546
			}			
577
			}
547
		}
578
		}
548
579
549
		org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = methodDeclaration.typeParameters();
580
		org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = methodDeclaration.typeParameters();
Lines 4296-4305 Link Here
4296
		this.scanner.resetTo(start, end);
4327
		this.scanner.resetTo(start, end);
4297
		try {
4328
		try {
4298
			int token;
4329
			int token;
4299
			while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4330
			loop: while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4300
				switch(token) {
4331
				switch(token) {
4332
					case TerminalTokens.TokenNameWHITESPACE://110
4333
					case TerminalTokens.TokenNameRPAREN://110
4334
					case TerminalTokens.TokenNameLPAREN://110
4335
						continue loop;
4301
					case TerminalTokens.TokenNameLBRACE://110
4336
					case TerminalTokens.TokenNameLBRACE://110
4302
						return this.scanner.startPosition;
4337
						return this.scanner.startPosition;
4338
					default:
4339
						return this.scanner.startPosition;
4303
				}
4340
				}
4304
			}
4341
			}
4305
		} catch(InvalidInputException e) {
4342
		} catch(InvalidInputException e) {

Return to bug 212857