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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java (-11 / +118 lines)
Lines 113-128 Link Here
113
		// Run test cases subset
113
		// Run test cases subset
114
		COPY_DIR = false;
114
		COPY_DIR = false;
115
		System.err.println("WARNING: only subset of tests will be executed!!!");
115
		System.err.println("WARNING: only subset of tests will be executed!!!");
116
		suite.addTest(new ASTConverterJavadocTest("testBug93880_15a"));
116
		suite.addTest(new ASTConverterJavadocTest("testBug100041"));
117
		suite.addTest(new ASTConverterJavadocTest("testBug93880_15b"));
118
		suite.addTest(new ASTConverterJavadocTest("testBug93880_15c"));
119
		suite.addTest(new ASTConverterJavadocTest("testBug93880_15d"));
120
		suite.addTest(new ASTConverterJavadocTest("testBug93880_15e"));
121
		suite.addTest(new ASTConverterJavadocTest("testBug93880_14a"));
122
		suite.addTest(new ASTConverterJavadocTest("testBug93880_14b"));
123
		suite.addTest(new ASTConverterJavadocTest("testBug93880_14c"));
124
		suite.addTest(new ASTConverterJavadocTest("testBug93880_14d"));
125
		suite.addTest(new ASTConverterJavadocTest("testBug93880_14e"));
126
		return suite;
117
		return suite;
127
	}
118
	}
128
119
Lines 2822-2826 Link Here
2822
		parser.setSource(source.toCharArray());
2813
		parser.setSource(source.toCharArray());
2823
		parser.createAST(null);
2814
		parser.createAST(null);
2824
	}
2815
	}
2825
	
2816
2817
	/**
2818
	 * Bug 100041: [javadoc] Infinit loop in DocCommentParser
2819
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=100041"
2820
	 */
2821
	public void testBug100041() throws JavaModelException {
2822
		workingCopies = new ICompilationUnit[1];
2823
		workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b100041/X.java",
2824
			"package javadoc.b100041;\n" + 
2825
			"class X {\n" +
2826
			"	static Object object;\n" +
2827
			"	static void foo() {\n" +
2828
			"		/**\n" +
2829
			"		 * javadoc comment.\n" +
2830
			"		 */\n" +
2831
			"		if (object instanceof String) {\n" +
2832
			"			final String clr = null;\n" +
2833
			"		}\n" +
2834
			"	}\n" +
2835
			"}"
2836
		);
2837
		CompilationUnit compilUnit = verifyComments(workingCopies[0]);
2838
		if (docCommentSupport.equals(JavaCore.ENABLED)) {
2839
			// Get comment
2840
			List unitComments = compilUnit.getCommentList();
2841
			assertEquals("Wrong number of comments", 1, unitComments.size());
2842
			Comment comment = (Comment) unitComments.get(0);
2843
			int commentStart = comment.getStartPosition();
2844
			int commentEnd = commentStart+comment.getLength();
2845
2846
			// Get local variable declaration
2847
			ASTNode node = getASTNode(compilUnit, 0, 1, 0);
2848
			assertEquals("Expected if statement for node: "+node, ASTNode.IF_STATEMENT, node.getNodeType());
2849
			IfStatement ifStatement = (IfStatement) node;
2850
			assertTrue("Invalid start position for IfStatement: "+ifStatement, ifStatement.getStartPosition() > commentEnd);
2851
			Statement statement  = ifStatement.getThenStatement();
2852
			assertEquals("Expected block for node: "+statement, ASTNode.BLOCK, statement.getNodeType());
2853
			Block block = (Block) statement;
2854
			assertTrue("Invalid start position for Block: "+block, block.getStartPosition() > commentEnd);
2855
			List statements = block.statements();
2856
			assertEquals("Invalid number of statements for block: "+block, 1, statements.size());
2857
			statement = (Statement) statements.get(0);
2858
			assertEquals("Expected variable declaration statement for node: "+statement, ASTNode.VARIABLE_DECLARATION_STATEMENT, statement.getNodeType());
2859
			VariableDeclarationStatement varDecl = (VariableDeclarationStatement) statement;
2860
			assertTrue("Invalid start position for : VariableDeclarationStatement"+varDecl, varDecl.getStartPosition() > commentEnd);
2861
		}
2862
	}
2863
	public void testBug100041b() throws JavaModelException {
2864
		workingCopies = new ICompilationUnit[1];
2865
		workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b100041/X.java",
2866
			"package javadoc.b100041;\n" + 
2867
			"class X {\n" +
2868
			"	static Object object;\n" +
2869
			"	static void foo() {\n" +
2870
			"		/**\n" +
2871
			"		 * javadoc comment.\n" +
2872
			"		 */\n" +
2873
			"		if (object instanceof String)\n" +
2874
			"			return;\n" +
2875
			"	}\n" +
2876
			"}"
2877
		);
2878
		CompilationUnit compilUnit = verifyComments(workingCopies[0]);
2879
		if (docCommentSupport.equals(JavaCore.ENABLED)) {
2880
			// Get comment
2881
			List unitComments = compilUnit.getCommentList();
2882
			assertEquals("Wrong number of comments", 1, unitComments.size());
2883
			Comment comment = (Comment) unitComments.get(0);
2884
			int commentStart = comment.getStartPosition();
2885
			int commentEnd = commentStart+comment.getLength();
2886
2887
			// Get local variable declaration
2888
			ASTNode node = getASTNode(compilUnit, 0, 1, 0);
2889
			assertEquals("Expected if statement for node: "+node, ASTNode.IF_STATEMENT, node.getNodeType());
2890
			IfStatement ifStatement = (IfStatement) node;
2891
			assertTrue("Invalid start position for IfStatement: "+ifStatement, ifStatement.getStartPosition() > commentEnd);
2892
			Statement statement  = ifStatement.getThenStatement();
2893
			assertEquals("Expected block for node: "+statement, ASTNode.RETURN_STATEMENT, statement.getNodeType());
2894
			ReturnStatement returnStatement = (ReturnStatement) statement;
2895
			assertTrue("Invalid start position for Block: "+returnStatement, returnStatement.getStartPosition() > commentEnd);
2896
		}
2897
	}
2898
	public void testBug100041c() throws JavaModelException {
2899
		workingCopies = new ICompilationUnit[1];
2900
		workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b100041/Z.java",
2901
			"package javadoc.b100041;\n" + 
2902
			"public class Z {\n" + 
2903
			"	/**\n" + 
2904
			"	 * Z1\n" + 
2905
			"	 */\n" + 
2906
			"	class Z1 {}\n" + 
2907
			"	/**\n" + 
2908
			"	 * z1\n" + 
2909
			"	 */\n" + 
2910
			"	Z1 z1;\n" + 
2911
			"	/**\n" + 
2912
			"	 * @param object\n" + 
2913
			"	 */\n" + 
2914
			"	public static void foo(Object object) {\n" + 
2915
			"		/**\n" + 
2916
			"		 * Comment 1\n" + 
2917
			"		 */\n" + 
2918
			"		class ZZ {\n" + 
2919
			"			/**\n" + 
2920
			"			 * Comment 3\n" + 
2921
			"			 */\n" + 
2922
			"			ZZ zz;\n" + 
2923
			"			/**\n" + 
2924
			"			 * Comment 2\n" + 
2925
			"			 */\n" + 
2926
			"			public void bar() {}\n" + 
2927
			"		}\n" + 
2928
			"	}\n" + 
2929
			"}\n"
2930
		);
2931
		verifyComments(workingCopies[0]);
2932
	}
2826
}
2933
}

Return to bug 100041