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

Collapse All | Expand All

(-)dom/org/eclipse/jdt/core/dom/ASTConverter.java (-18 / +30 lines)
Lines 122-128 Link Here
122
		}
122
		}
123
	}
123
	}
124
124
125
	protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration, AbstractTypeDeclaration typeDecl) {
125
	protected void buildBodyDeclarations(
126
			org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration,
127
			AbstractTypeDeclaration typeDecl,
128
			boolean isInterface) {
126
		// add body declaration in the lexical order
129
		// add body declaration in the lexical order
127
		org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = typeDeclaration.memberTypes;
130
		org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = typeDeclaration.memberTypes;
128
		org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = typeDeclaration.fields;
131
		org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = typeDeclaration.fields;
Lines 177-183 Link Here
177
				case 1 :
180
				case 1 :
178
					methodsIndex++;
181
					methodsIndex++;
179
					if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
182
					if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
180
						typeDecl.bodyDeclarations().add(convert(nextMethodDeclaration));
183
						typeDecl.bodyDeclarations().add(convert(isInterface, nextMethodDeclaration));
181
					}
184
					}
182
					break;
185
					break;
183
				case 2 :
186
				case 2 :
Lines 249-255 Link Here
249
				case 1 :
252
				case 1 :
250
					methodsIndex++;
253
					methodsIndex++;
251
					if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
254
					if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
252
						enumDeclaration.bodyDeclarations().add(convert(nextMethodDeclaration));
255
						enumDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration));
253
					}
256
					}
254
					break;
257
					break;
255
				case 2 :
258
				case 2 :
Lines 316-322 Link Here
316
				case 1 :
319
				case 1 :
317
					methodsIndex++;
320
					methodsIndex++;
318
					if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
321
					if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
319
						anonymousClassDeclaration.bodyDeclarations().add(convert(nextMethodDeclaration));
322
						anonymousClassDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration));
320
					}
323
					}
321
					break;
324
					break;
322
				case 2 :
325
				case 2 :
Lines 415-421 Link Here
415
		}
418
		}
416
	}
419
	}
417
420
418
	public ASTNode convert(org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) {
421
	public ASTNode convert(boolean isInterface, org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) {
419
		checkCanceled();
422
		checkCanceled();
420
		if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) {
423
		if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) {
421
			return convert((org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration);
424
			return convert((org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration);
Lines 457-462 Link Here
457
		}
460
		}
458
		org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null;
461
		org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null;
459
		if (isConstructor) {
462
		if (isConstructor) {
463
			if (isInterface) {
464
				// interface cannot have a constructor
465
				methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
466
			}
460
			org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration;
467
			org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration;
461
			explicitConstructorCall = constructorDeclaration.constructorCall;
468
			explicitConstructorCall = constructorDeclaration.constructorCall;
462
			switch(this.ast.apiLevel) {
469
			switch(this.ast.apiLevel) {
Lines 481-499 Link Here
481
				methodDecl.setExtraDimensions(extraDimensions);
488
				methodDecl.setExtraDimensions(extraDimensions);
482
				setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions);
489
				setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions);
483
			} else {
490
			} else {
491
				// no return type for a method that is not a constructor
492
				methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
484
				switch(this.ast.apiLevel) {
493
				switch(this.ast.apiLevel) {
485
					case AST.JLS2_INTERNAL :
486
						methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
487
						break;
488
					case AST.JLS3 :
494
					case AST.JLS3 :
489
						methodDecl.setReturnType2(null);
495
						methodDecl.setReturnType2(null);
490
				}
496
				}
491
			}
497
			}
492
		}
498
		}
493
		int declarationSourceStart = methodDeclaration.declarationSourceStart;
499
		int declarationSourceStart = methodDeclaration.declarationSourceStart;
494
		int declarationSourceEnd = methodDeclaration.bodyEnd;
500
		int bodyEnd = methodDeclaration.bodyEnd;
495
		methodDecl.setSourceRange(declarationSourceStart, declarationSourceEnd - declarationSourceStart + 1);
501
		methodDecl.setSourceRange(declarationSourceStart, bodyEnd - declarationSourceStart + 1);
496
		int closingPosition = retrieveRightBraceOrSemiColonPosition(methodDeclaration.bodyEnd + 1, methodDeclaration.declarationSourceEnd);
502
		int declarationSourceEnd = methodDeclaration.declarationSourceEnd;
503
		int rightBraceOrSemiColonPositionStart = bodyEnd == declarationSourceEnd ? bodyEnd : bodyEnd + 1;
504
		int closingPosition = retrieveRightBraceOrSemiColonPosition(rightBraceOrSemiColonPositionStart, declarationSourceEnd);
497
		if (closingPosition != -1) {
505
		if (closingPosition != -1) {
498
			int startPosition = methodDecl.getStartPosition();
506
			int startPosition = methodDecl.getStartPosition();
499
			methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1);
507
			methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1);
Lines 502-508 Link Here
502
510
503
			start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart);
511
			start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart);
504
			if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start
512
			if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start
505
			end = retrieveRightBrace(methodDeclaration.bodyEnd, methodDeclaration.declarationSourceEnd);
513
			end = retrieveRightBrace(methodDeclaration.bodyEnd, declarationSourceEnd);
506
			Block block = null;
514
			Block block = null;
507
			if (start != -1 && end != -1) {
515
			if (start != -1 && end != -1) {
508
				/*
516
				/*
Lines 528-541 Link Here
528
					}
536
					}
529
				}
537
				}
530
			}
538
			}
531
			if (block != null && (Modifier.isAbstract(methodDecl.getModifiers()) || Modifier.isNative(methodDecl.getModifiers()))) {
539
			if (block != null
540
					&& (Modifier.isAbstract(methodDecl.getModifiers())
541
							|| Modifier.isNative(methodDecl.getModifiers())
542
							|| isInterface)) {
532
				methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
543
				methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
533
			}
544
			}
534
		} else {
545
		} else {
535
			// syntax error in this method declaration
546
			// syntax error in this method declaration
536
			methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
547
			methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
537
			if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) {
548
			if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) {
538
				start = retrieveStartBlockPosition(methodHeaderEnd, declarationSourceEnd);
549
				start = retrieveStartBlockPosition(methodHeaderEnd, bodyEnd);
539
				if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start
550
				if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start
540
				end = methodDeclaration.bodyEnd;
551
				end = methodDeclaration.bodyEnd;
541
				// try to get the best end position
552
				// try to get the best end position
Lines 708-714 Link Here
708
		typeDecl.setName(typeName);
719
		typeDecl.setName(typeName);
709
		typeDecl.setSourceRange(typeDeclaration.declarationSourceStart, typeDeclaration.bodyEnd - typeDeclaration.declarationSourceStart + 1);
720
		typeDecl.setSourceRange(typeDeclaration.declarationSourceStart, typeDeclaration.bodyEnd - typeDeclaration.declarationSourceStart + 1);
710
721
711
		buildBodyDeclarations(typeDeclaration, typeDecl);
722
		buildBodyDeclarations(typeDeclaration, typeDecl, false);
712
		// The javadoc comment is now got from list store in compilation unit declaration
723
		// The javadoc comment is now got from list store in compilation unit declaration
713
		if (this.resolveBindings) {
724
		if (this.resolveBindings) {
714
			recordNodes(typeDecl, typeDeclaration);
725
			recordNodes(typeDecl, typeDeclaration);
Lines 970-976 Link Here
970
			} else if(node instanceof org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) {
981
			} else if(node instanceof org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) {
971
				AbstractMethodDeclaration nextMethodDeclaration = (AbstractMethodDeclaration) node;
982
				AbstractMethodDeclaration nextMethodDeclaration = (AbstractMethodDeclaration) node;
972
				if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
983
				if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
973
					typeDecl.bodyDeclarations().add(convert(nextMethodDeclaration));
984
					typeDecl.bodyDeclarations().add(convert(false, nextMethodDeclaration));
974
				}
985
				}
975
			} else if(node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
986
			} else if(node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
976
				org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
987
				org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
Lines 2662-2668 Link Here
2662
		if (typeDeclaration.modifiersSourceStart != -1) {
2673
		if (typeDeclaration.modifiersSourceStart != -1) {
2663
			setModifiers(typeDecl, typeDeclaration);
2674
			setModifiers(typeDecl, typeDeclaration);
2664
		}
2675
		}
2665
		typeDecl.setInterface(kind == org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.INTERFACE_DECL);
2676
		boolean isInterface = kind == org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.INTERFACE_DECL;
2677
		typeDecl.setInterface(isInterface);
2666
		final SimpleName typeName = new SimpleName(this.ast);
2678
		final SimpleName typeName = new SimpleName(this.ast);
2667
		typeName.internalSetIdentifier(new String(typeDeclaration.name));
2679
		typeName.internalSetIdentifier(new String(typeDeclaration.name));
2668
		typeName.setSourceRange(typeDeclaration.sourceStart, typeDeclaration.sourceEnd - typeDeclaration.sourceStart + 1);
2680
		typeName.setSourceRange(typeDeclaration.sourceStart, typeDeclaration.sourceEnd - typeDeclaration.sourceStart + 1);
Lines 2708-2714 Link Here
2708
					}
2720
					}
2709
			}
2721
			}
2710
		}
2722
		}
2711
		buildBodyDeclarations(typeDeclaration, typeDecl);
2723
		buildBodyDeclarations(typeDeclaration, typeDecl, isInterface);
2712
		if (this.resolveBindings) {
2724
		if (this.resolveBindings) {
2713
			recordNodes(typeDecl, typeDeclaration);
2725
			recordNodes(typeDecl, typeDeclaration);
2714
			recordNodes(typeName, typeDeclaration);
2726
			recordNodes(typeName, typeDeclaration);
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (-1 / +1 lines)
Lines 3967-3973 Link Here
3967
        Statement statement = (Statement) statements.get(0);
3967
        Statement statement = (Statement) statements.get(0);
3968
        assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, statement.getNodeType());
3968
        assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, statement.getNodeType());
3969
        ConstructorInvocation constructorInvocation = (ConstructorInvocation) statement;
3969
        ConstructorInvocation constructorInvocation = (ConstructorInvocation) statement;
3970
        checkSourceRange(constructorInvocation, "x.<String> this();", source);
3970
        checkSourceRange(constructorInvocation, "x.<String> this();", source, true/*expectMalformed*/);
3971
        assertTrue("Node is not malformed", isMalformed(constructorInvocation));
3971
        assertTrue("Node is not malformed", isMalformed(constructorInvocation));
3972
    }
3972
    }
3973
3973
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java (-3 / +3 lines)
Lines 6943-6949 Link Here
6943
				"public void fails() {\n" + //$NON-NLS-1$
6943
				"public void fails() {\n" + //$NON-NLS-1$
6944
				"		foo()\n" + //$NON-NLS-1$
6944
				"		foo()\n" + //$NON-NLS-1$
6945
				"	}"; //$NON-NLS-1$
6945
				"	}"; //$NON-NLS-1$
6946
		checkSourceRange(methodDeclaration, expectedSource, source);
6946
		checkSourceRange(methodDeclaration, expectedSource, source, true/*expectMalformed*/);
6947
		Block block = methodDeclaration.getBody();
6947
		Block block = methodDeclaration.getBody();
6948
		expectedSource =
6948
		expectedSource =
6949
				"{\n" + //$NON-NLS-1$
6949
				"{\n" + //$NON-NLS-1$
Lines 6999-7005 Link Here
6999
				"public void fails() {\n" + //$NON-NLS-1$
6999
				"public void fails() {\n" + //$NON-NLS-1$
7000
				"		foo()\n" + //$NON-NLS-1$
7000
				"		foo()\n" + //$NON-NLS-1$
7001
				"	}"; //$NON-NLS-1$
7001
				"	}"; //$NON-NLS-1$
7002
		checkSourceRange(methodDeclaration, expectedSource, source);
7002
		checkSourceRange(methodDeclaration, expectedSource, source, true/*expectMalformed*/);
7003
		Block block = methodDeclaration.getBody();
7003
		Block block = methodDeclaration.getBody();
7004
		expectedSource =
7004
		expectedSource =
7005
				"{\n" + //$NON-NLS-1$
7005
				"{\n" + //$NON-NLS-1$
Lines 8182-8188 Link Here
8182
			"		z\n" +  //$NON-NLS-1$
8182
			"		z\n" +  //$NON-NLS-1$
8183
			"	}\n" +  //$NON-NLS-1$
8183
			"	}\n" +  //$NON-NLS-1$
8184
			"}"; //$NON-NLS-1$
8184
			"}"; //$NON-NLS-1$
8185
		checkSourceRange(node, expectedSource, source);
8185
		checkSourceRange(node, expectedSource, source, true/*expectMalformed*/);
8186
		int methodEndPosition = node.getStartPosition() + node.getLength();
8186
		int methodEndPosition = node.getStartPosition() + node.getLength();
8187
		node = getASTNode(compilationUnit, 0);
8187
		node = getASTNode(compilationUnit, 0);
8188
		assertNotNull("not null", node); //$NON-NLS-1$
8188
		assertNotNull("not null", node); //$NON-NLS-1$
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java (-4 / +4 lines)
Lines 35-41 Link Here
35
	}
35
	}
36
36
37
	static {
37
	static {
38
//		TESTS_NUMBERS = new int[] { 305 };
38
//		TESTS_NUMBERS = new int[] { 339 };
39
	}
39
	}
40
	public static Test suite() {
40
	public static Test suite() {
41
		return buildModelTestSuite(ASTConverterTest.class);
41
		return buildModelTestSuite(ASTConverterTest.class);
Lines 7116-7122 Link Here
7116
				"public void fails() {\n" + //$NON-NLS-1$
7116
				"public void fails() {\n" + //$NON-NLS-1$
7117
				"		foo()\n" + //$NON-NLS-1$
7117
				"		foo()\n" + //$NON-NLS-1$
7118
				"	}"; //$NON-NLS-1$
7118
				"	}"; //$NON-NLS-1$
7119
		checkSourceRange(methodDeclaration, expectedSource, source);
7119
		checkSourceRange(methodDeclaration, expectedSource, source, true/*expectMalformed*/);
7120
		Block block = methodDeclaration.getBody();
7120
		Block block = methodDeclaration.getBody();
7121
		expectedSource =
7121
		expectedSource =
7122
				"{\n" + //$NON-NLS-1$
7122
				"{\n" + //$NON-NLS-1$
Lines 7171-7177 Link Here
7171
				"public void fails() {\n" + //$NON-NLS-1$
7171
				"public void fails() {\n" + //$NON-NLS-1$
7172
				"		foo()\n" + //$NON-NLS-1$
7172
				"		foo()\n" + //$NON-NLS-1$
7173
				"	}"; //$NON-NLS-1$
7173
				"	}"; //$NON-NLS-1$
7174
		checkSourceRange(methodDeclaration, expectedSource, source);
7174
		checkSourceRange(methodDeclaration, expectedSource, source, true/*expectMalformed*/);
7175
		Block block = methodDeclaration.getBody();
7175
		Block block = methodDeclaration.getBody();
7176
		expectedSource =
7176
		expectedSource =
7177
				"{\n" + //$NON-NLS-1$
7177
				"{\n" + //$NON-NLS-1$
Lines 8350-8356 Link Here
8350
			"		z\n" +  //$NON-NLS-1$
8350
			"		z\n" +  //$NON-NLS-1$
8351
			"	}\n" +  //$NON-NLS-1$
8351
			"	}\n" +  //$NON-NLS-1$
8352
			"}"; //$NON-NLS-1$
8352
			"}"; //$NON-NLS-1$
8353
		checkSourceRange(node, expectedSource, source);
8353
		checkSourceRange(node, expectedSource, source, true /*expectMalformed*/);
8354
		int methodEndPosition = node.getStartPosition() + node.getLength();
8354
		int methodEndPosition = node.getStartPosition() + node.getLength();
8355
		node = getASTNode(compilationUnit, 0);
8355
		node = getASTNode(compilationUnit, 0);
8356
		assertNotNull("not null", node); //$NON-NLS-1$
8356
		assertNotNull("not null", node); //$NON-NLS-1$
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java (-4 / +4 lines)
Lines 1908-1914 Link Here
1908
		assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
1908
		assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
1909
		MethodDeclaration methodDeclaration = (MethodDeclaration) node;
1909
		MethodDeclaration methodDeclaration = (MethodDeclaration) node;
1910
		assertTrue("Is a constructor", !methodDeclaration.isConstructor());
1910
		assertTrue("Is a constructor", !methodDeclaration.isConstructor());
1911
		checkSourceRange(methodDeclaration, "private void foo(){", source);
1911
		checkSourceRange(methodDeclaration, "private void foo(){", source, true/*expectMalformed*/);
1912
		node = getASTNode(compilationUnit, 0, 1);
1912
		node = getASTNode(compilationUnit, 0, 1);
1913
		assertNotNull("No node", node);
1913
		assertNotNull("No node", node);
1914
		assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
1914
		assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
Lines 3125-3131 Link Here
3125
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3125
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3126
		MethodDeclaration declaration = (MethodDeclaration) node;
3126
		MethodDeclaration declaration = (MethodDeclaration) node;
3127
		assertTrue("A constructor", !declaration.isConstructor());
3127
		assertTrue("A constructor", !declaration.isConstructor());
3128
		checkSourceRange(declaration, "public method(final int parameter);", source);
3128
		checkSourceRange(declaration, "public method(final int parameter);", source, true/*expectMalformed*/);
3129
	}
3129
	}
3130
3130
3131
	/**
3131
	/**
Lines 3143-3149 Link Here
3143
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3143
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3144
		MethodDeclaration declaration = (MethodDeclaration) node;
3144
		MethodDeclaration declaration = (MethodDeclaration) node;
3145
		assertTrue("A constructor", !declaration.isConstructor());
3145
		assertTrue("A constructor", !declaration.isConstructor());
3146
		checkSourceRange(declaration, "public method(final int parameter) {     }", source);
3146
		checkSourceRange(declaration, "public method(final int parameter) {     }", source, true/*expectMalformed*/);
3147
	}
3147
	}
3148
3148
3149
	/**
3149
	/**
Lines 3280-3286 Link Here
3280
		assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3280
		assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3281
		MethodDeclaration declaration = (MethodDeclaration) node;
3281
		MethodDeclaration declaration = (MethodDeclaration) node;
3282
		assertTrue("Not a constructor", declaration.isConstructor());
3282
		assertTrue("Not a constructor", declaration.isConstructor());
3283
		checkSourceRange(declaration, "public A();", source);
3283
		checkSourceRange(declaration, "public A();", source, true /*expectMalformed*/);
3284
	}
3284
	}
3285
3285
3286
	/**
3286
	/**
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java (-7 / +24 lines)
Lines 122-128 Link Here
122
	static {
122
	static {
123
//		TESTS_NAMES = new String[] {"test0602"};
123
//		TESTS_NAMES = new String[] {"test0602"};
124
//		TESTS_RANGE = new int[] { 713, -1 };
124
//		TESTS_RANGE = new int[] { 713, -1 };
125
//		TESTS_NUMBERS =  new int[] { 719 };
125
//		TESTS_NUMBERS =  new int[] { 504, 505, 512, 720 };
126
	}
126
	}
127
	public static Test suite() {
127
	public static Test suite() {
128
		return buildModelTestSuite(ASTConverterTestAST3_2.class);
128
		return buildModelTestSuite(ASTConverterTestAST3_2.class);
Lines 1988-1994 Link Here
1988
		assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
1988
		assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
1989
		MethodDeclaration methodDeclaration = (MethodDeclaration) node;
1989
		MethodDeclaration methodDeclaration = (MethodDeclaration) node;
1990
		assertTrue("Is a constructor", !methodDeclaration.isConstructor());
1990
		assertTrue("Is a constructor", !methodDeclaration.isConstructor());
1991
		checkSourceRange(methodDeclaration, "private void foo(){", source);
1991
		checkSourceRange(methodDeclaration, "private void foo(){", source, true/*expectMalformed*/);
1992
		node = getASTNode(compilationUnit, 0, 1);
1992
		node = getASTNode(compilationUnit, 0, 1);
1993
		assertNotNull("No node", node);
1993
		assertNotNull("No node", node);
1994
		assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
1994
		assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
Lines 3203-3209 Link Here
3203
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3203
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3204
		MethodDeclaration declaration = (MethodDeclaration) node;
3204
		MethodDeclaration declaration = (MethodDeclaration) node;
3205
		assertTrue("A constructor", !declaration.isConstructor());
3205
		assertTrue("A constructor", !declaration.isConstructor());
3206
		checkSourceRange(declaration, "public method(final int parameter);", source);
3206
		checkSourceRange(declaration, "public method(final int parameter);", source, true/*expectMalformed*/);
3207
	}
3207
	}
3208
3208
3209
	/**
3209
	/**
Lines 3221-3227 Link Here
3221
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3221
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3222
		MethodDeclaration declaration = (MethodDeclaration) node;
3222
		MethodDeclaration declaration = (MethodDeclaration) node;
3223
		assertTrue("A constructor", !declaration.isConstructor());
3223
		assertTrue("A constructor", !declaration.isConstructor());
3224
		checkSourceRange(declaration, "public method(final int parameter) {     }", source);
3224
		checkSourceRange(declaration, "public method(final int parameter) {     }", source, true/*expectMalformed*/);
3225
	}
3225
	}
3226
3226
3227
	/**
3227
	/**
Lines 3358-3364 Link Here
3358
		assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3358
		assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
3359
		MethodDeclaration declaration = (MethodDeclaration) node;
3359
		MethodDeclaration declaration = (MethodDeclaration) node;
3360
		assertTrue("Not a constructor", declaration.isConstructor());
3360
		assertTrue("Not a constructor", declaration.isConstructor());
3361
		checkSourceRange(declaration, "public A();", source);
3361
		checkSourceRange(declaration, "public A();", source, true/*expectMalformed*/);
3362
	}
3362
	}
3363
3363
3364
	/**
3364
	/**
Lines 5493-5499 Link Here
5493
			node = getASTNode(compilationUnit, 0, 0);
5493
			node = getASTNode(compilationUnit, 0, 0);
5494
			assertEquals("wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
5494
			assertEquals("wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
5495
			FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
5495
			FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
5496
			checkSourceRange(fieldDeclaration, "d String[][]", source.toCharArray());
5496
			checkSourceRange(fieldDeclaration, "d String[][]", source.toCharArray(), true/*expectMalformed*/);
5497
			Type type = fieldDeclaration.getType();
5497
			Type type = fieldDeclaration.getType();
5498
			assertTrue("Not a simple type", type.isSimpleType());
5498
			assertTrue("Not a simple type", type.isSimpleType());
5499
			List fragments = fieldDeclaration.fragments();
5499
			List fragments = fieldDeclaration.fragments();
Lines 7243-7249 Link Here
7243
		List fragments = fieldDeclaration.fragments();
7243
		List fragments = fieldDeclaration.fragments();
7244
		assertEquals("wrong size", 1, fragments.size());
7244
		assertEquals("wrong size", 1, fragments.size());
7245
		VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
7245
		VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
7246
		checkSourceRange(fragment, "s =  {\"\",,,", source);
7246
		checkSourceRange(fragment, "s =  {\"\",,,", source, true/*expectMalformed*/);
7247
		assertTrue("Not initializer", fragment.getInitializer() == null);
7247
		assertTrue("Not initializer", fragment.getInitializer() == null);
7248
		assertTrue("Not a malformed node", isMalformed(fragment));
7248
		assertTrue("Not a malformed node", isMalformed(fragment));
7249
	}
7249
	}
Lines 10556-10559 Link Here
10556
			}
10556
			}
10557
		}
10557
		}
10558
	}
10558
	}
10559
	/**
10560
	 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=47396
10561
	 */
10562
	public void test0720() throws JavaModelException {
10563
		ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0720", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
10564
		char[] source = sourceUnit.getSource().toCharArray();
10565
		ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
10566
		assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
10567
		CompilationUnit unit = (CompilationUnit) result;
10568
		assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
10569
		ASTNode node = getASTNode(unit, 1, 0);
10570
		assertNotNull(node);
10571
		assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
10572
		MethodDeclaration declaration = (MethodDeclaration) node;
10573
		assertTrue("A constructor", !declaration.isConstructor());
10574
		checkSourceRange(declaration, "public void method(final int parameter) {     }", source, true/*expectMalformed*/);
10575
	}
10559
}
10576
}
(-)src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java (-1 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 559-564 Link Here
559
	}
559
	}
560
560
561
	protected void checkSourceRange(ASTNode node, String expectedContents, char[] source) {
561
	protected void checkSourceRange(ASTNode node, String expectedContents, char[] source) {
562
		checkSourceRange(node, expectedContents, source, false);
563
	}
564
	protected void checkSourceRange(ASTNode node, String expectedContents, char[] source, boolean expectMalformed) {
562
		assertNotNull("The node is null", node); //$NON-NLS-1$
565
		assertNotNull("The node is null", node); //$NON-NLS-1$
563
		assertTrue("The node(" + node.getClass() + ").getLength() == 0", node.getLength() != 0); //$NON-NLS-1$ //$NON-NLS-2$
566
		assertTrue("The node(" + node.getClass() + ").getLength() == 0", node.getLength() != 0); //$NON-NLS-1$ //$NON-NLS-2$
564
		assertTrue("The node.getStartPosition() == -1", node.getStartPosition() != -1); //$NON-NLS-1$
567
		assertTrue("The node.getStartPosition() == -1", node.getStartPosition() != -1); //$NON-NLS-1$
Lines 568-573 Link Here
568
		System.arraycopy(source, start, actualContents, 0, length);
571
		System.arraycopy(source, start, actualContents, 0, length);
569
		String actualContentsString = new String(actualContents);
572
		String actualContentsString = new String(actualContents);
570
		assertSourceEquals("Unexpected source", Util.convertToIndependantLineDelimiter(expectedContents), Util.convertToIndependantLineDelimiter(actualContentsString));
573
		assertSourceEquals("Unexpected source", Util.convertToIndependantLineDelimiter(expectedContents), Util.convertToIndependantLineDelimiter(actualContentsString));
574
		if (expectMalformed) {
575
			assertTrue("Is not malformed", isMalformed(node));
576
		} else {
577
			assertFalse("Is malformed", isMalformed(node));
578
		}
571
	}
579
	}
572
580
573
	protected boolean isMalformed(ASTNode node) {
581
	protected boolean isMalformed(ASTNode node) {
(-)workspace/Converter/src/test0720/A.java (+14 lines)
Added Link Here
1
package test0720;
2
3
public class A
4
{
5
   public A()
6
   {
7
      
8
   }
9
10
}
11
interface B
12
{
13
   public void method(final int parameter) {     }
14
}

Return to bug 331736