View | Details | Raw Unified | Return to bug 246682
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/compiler/SourceElementParser.java (-2 / +8 lines)
Lines 135-145 Link Here
135
135
136
	if (this.modifiersSourceStart >= 0) {
136
	if (this.modifiersSourceStart >= 0) {
137
		// eliminate comments located after modifierSourceStart if positionned
137
		// eliminate comments located after modifierSourceStart if positionned
138
		while (lastComment >= 0 && Math.abs(this.scanner.commentStarts[lastComment]) > this.modifiersSourceStart) lastComment--;
138
		while (lastComment >= 0) {
139
			int commentSourceStart = this.scanner.commentStarts[lastComment];
140
			if (commentSourceStart < 0) commentSourceStart = -commentSourceStart;
141
			if (commentSourceStart <= this.modifiersSourceStart) break;
142
			lastComment--;
143
		}
139
	}
144
	}
140
	if (lastComment >= 0) {
145
	if (lastComment >= 0) {
141
		// consider all remaining leading comments to be part of current declaration
146
		// consider all remaining leading comments to be part of current declaration
142
		this.modifiersSourceStart = Math.abs(this.scanner.commentStarts[0]);
147
		this.modifiersSourceStart = this.scanner.commentStarts[0];
148
		if (this.modifiersSourceStart < 0) this.modifiersSourceStart = -this.modifiersSourceStart;
143
149
144
		// check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)
150
		// check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)
145
		while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
151
		while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
(-)model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java (-8 / +8 lines)
Lines 68-84 Link Here
68
68
69
	//since jdk1.2 look only in the last java doc comment...
69
	//since jdk1.2 look only in the last java doc comment...
70
	nextComment : for (lastCommentIndex = this.scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){
70
	nextComment : for (lastCommentIndex = this.scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){
71
		//look for @deprecated into the first javadoc comment preceeding the declaration
71
		// skip all non-javadoc comments or those which are after the last modifier
72
		int commentSourceStart = this.scanner.commentStarts[lastCommentIndex];
72
		int commentSourceStart = this.scanner.commentStarts[lastCommentIndex];
73
		// javadoc only (non javadoc comment have negative end positions.)
73
		if (commentSourceStart < 0 || // line comment
74
		if (this.modifiersSourceStart != -1 && this.modifiersSourceStart < commentSourceStart) {
74
			this.scanner.commentStops[lastCommentIndex] < 0 || // block comment
75
			(this.modifiersSourceStart != -1 && this.modifiersSourceStart < commentSourceStart)) // the comment is after the modifier
76
		{
75
			continue nextComment;
77
			continue nextComment;
76
		}
78
		}
77
		if (this.scanner.commentStops[lastCommentIndex] < 0) {
79
		// check comment
78
			continue nextComment;
80
		deprecated = this.javadocParser.checkDeprecation(lastCommentIndex);
79
		}
80
		deprecated =
81
			this.javadocParser.checkDeprecation(lastCommentIndex);
82
		break nextComment;
81
		break nextComment;
83
	}
82
	}
84
	if (deprecated) {
83
	if (deprecated) {
Lines 87-92 Link Here
87
	// modify the modifier source start to point at the first comment
86
	// modify the modifier source start to point at the first comment
88
	if (commentPtr >= 0) {
87
	if (commentPtr >= 0) {
89
		this.declarationSourceStart = this.scanner.commentStarts[0];
88
		this.declarationSourceStart = this.scanner.commentStarts[0];
89
		if (this.declarationSourceStart < 0) this.declarationSourceStart = -this.declarationSourceStart;
90
	}
90
	}
91
}
91
}
92
/*
92
/*
(-)model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java (-22 / +3 lines)
Lines 14-19 Link Here
14
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
14
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
15
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
15
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
16
import org.eclipse.jdt.internal.compiler.parser.Parser;
16
import org.eclipse.jdt.internal.compiler.parser.Parser;
17
import org.eclipse.jdt.internal.compiler.parser.Scanner;
17
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
18
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
18
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
19
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
19
20
Lines 54-60 Link Here
54
		nextComment : for (lastCommentIndex = this.scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){
55
		nextComment : for (lastCommentIndex = this.scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){
55
			//look for @deprecated into the first javadoc comment preceeding the declaration
56
			//look for @deprecated into the first javadoc comment preceeding the declaration
56
			int commentSourceStart = this.scanner.commentStarts[lastCommentIndex];
57
			int commentSourceStart = this.scanner.commentStarts[lastCommentIndex];
57
			// javadoc only (non javadoc comment have negative end positions.)
58
			// javadoc only (non javadoc comment have negative start and/or end positions.)
58
			if ((commentSourceStart < 0) ||
59
			if ((commentSourceStart < 0) ||
59
				(this.modifiersSourceStart != -1 && this.modifiersSourceStart < commentSourceStart) ||
60
				(this.modifiersSourceStart != -1 && this.modifiersSourceStart < commentSourceStart) ||
60
				(this.scanner.commentStops[lastCommentIndex] < 0))
61
				(this.scanner.commentStops[lastCommentIndex] < 0))
Lines 108-133 Link Here
108
		super.consumeInterfaceHeader();
109
		super.consumeInterfaceHeader();
109
	}
110
	}
110
111
111
	/**
112
	 * Insure that start position is always positive.
113
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#containsComment(int, int)
114
	 */
115
	public boolean containsComment(int sourceStart, int sourceEnd) {
116
		int iComment = this.scanner.commentPtr;
117
		for (; iComment >= 0; iComment--) {
118
			int commentStart = this.scanner.commentStarts[iComment];
119
			if (commentStart < 0) {
120
				commentStart = -commentStart;
121
			}
122
			// ignore comments before start
123
			if (commentStart < sourceStart) continue;
124
			// ignore comments after end
125
			if (commentStart > sourceEnd) continue;
126
			return true;
127
		}
128
		return false;
129
	}
130
131
	/* (non-Javadoc)
112
	/* (non-Javadoc)
132
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#endParse(int)
113
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#endParse(int)
133
	 */
114
	 */
Lines 239-245 Link Here
239
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#initializeScanner()
220
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#initializeScanner()
240
	 */
221
	 */
241
	public void initializeScanner() {
222
	public void initializeScanner() {
242
		this.scanner = new CommentRecorderScanner(
223
		this.scanner = new Scanner(
243
				false /*comment*/,
224
				false /*comment*/,
244
				false /*whitespace*/,
225
				false /*whitespace*/,
245
				this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/,
226
				this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/,
(-)model/org/eclipse/jdt/internal/core/util/CommentRecorderScanner.java (-44 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core.util;
12
13
import org.eclipse.jdt.internal.compiler.parser.Scanner;
14
15
/**
16
 * Internal scanner used for DOM AST nodes.
17
 *
18
 * @since 3.0
19
 */
20
public class CommentRecorderScanner extends Scanner {
21
22
	public CommentRecorderScanner(
23
		boolean tokenizeComments,
24
		boolean tokenizeWhiteSpace,
25
		boolean checkNonExternalizedStringLiterals,
26
		long sourceLevel,
27
		char[][] taskTags,
28
		char[][] taskPriorities,
29
		boolean isTaskCaseSensitive) {
30
		super(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, sourceLevel, taskTags, taskPriorities, isTaskCaseSensitive);
31
	}
32
33
	/**
34
	 * Set start position negative for line comments.
35
	 * @see org.eclipse.jdt.internal.compiler.parser.Scanner#recordComment(int)
36
	 */
37
	public void recordComment(int token) {
38
		super.recordComment(token);
39
		if (token == TokenNameCOMMENT_LINE) {
40
			// for comment line both positions are negative
41
			this.commentStarts[this.commentPtr] = -this.commentStarts[this.commentPtr];
42
		}
43
	}
44
}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-9 / +21 lines)
Lines 1110-1120 Link Here
1110
1110
1111
	if (this.modifiersSourceStart >= 0) {
1111
	if (this.modifiersSourceStart >= 0) {
1112
		// eliminate comments located after modifierSourceStart if positionned
1112
		// eliminate comments located after modifierSourceStart if positionned
1113
		while (lastComment >= 0 && this.scanner.commentStarts[lastComment] > this.modifiersSourceStart) lastComment--;
1113
		while (lastComment >= 0) {
1114
			int commentSourceStart = this.scanner.commentStarts[lastComment];
1115
			if (commentSourceStart < 0) commentSourceStart = -commentSourceStart;
1116
			if (commentSourceStart <= this.modifiersSourceStart) break;
1117
			lastComment--;
1118
		}
1114
	}
1119
	}
1115
	if (lastComment >= 0) {
1120
	if (lastComment >= 0) {
1116
		// consider all remaining leading comments to be part of current declaration
1121
		// consider all remaining leading comments to be part of current declaration
1117
		this.modifiersSourceStart = this.scanner.commentStarts[0];
1122
		this.modifiersSourceStart = this.scanner.commentStarts[0];
1123
		if (this.modifiersSourceStart < 0) this.modifiersSourceStart = -this.modifiersSourceStart;
1118
1124
1119
		// check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)
1125
		// check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)
1120
		while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
1126
		while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
Lines 8050-8055 Link Here
8050
	int iComment = this.scanner.commentPtr;
8056
	int iComment = this.scanner.commentPtr;
8051
	for (; iComment >= 0; iComment--) {
8057
	for (; iComment >= 0; iComment--) {
8052
		int commentStart = this.scanner.commentStarts[iComment];
8058
		int commentStart = this.scanner.commentStarts[iComment];
8059
		if (commentStart < 0) commentStart = -commentStart;
8053
		// ignore comments before start
8060
		// ignore comments before start
8054
		if (commentStart < sourceStart) continue;
8061
		if (commentStart < sourceStart) continue;
8055
		// ignore comments after end
8062
		// ignore comments after end
Lines 8472-8480 Link Here
8472
public int[] getJavaDocPositions() {
8479
public int[] getJavaDocPositions() {
8473
8480
8474
	int javadocCount = 0;
8481
	int javadocCount = 0;
8475
	for (int i = 0, max = this.scanner.commentPtr; i <= max; i++){
8482
	int max = this.scanner.commentPtr;
8476
		// javadoc only (non javadoc comment have negative end positions.)
8483
	for (int i = 0; i <= max; i++){
8477
		if (this.scanner.commentStops[i] > 0){
8484
		// javadoc only (non javadoc comment have negative start and/or end positions.)
8485
		if (this.scanner.commentStarts[i] >= 0 && this.scanner.commentStops[i] > 0) {
8478
			javadocCount++;
8486
			javadocCount++;
8479
		}
8487
		}
8480
	}
8488
	}
Lines 8482-8492 Link Here
8482
8490
8483
	int[] positions = new int[2*javadocCount];
8491
	int[] positions = new int[2*javadocCount];
8484
	int index = 0;
8492
	int index = 0;
8485
	for (int i = 0, max = this.scanner.commentPtr; i <= max; i++){
8493
	for (int i = 0; i <= max; i++){
8486
		// javadoc only (non javadoc comment have negative end positions.)
8494
		// javadoc only (non javadoc comment have negative start and/or end positions.)
8487
		if (this.scanner.commentStops[i] > 0){
8495
		int commentStart = this.scanner.commentStarts[i];
8488
			positions[index++] = this.scanner.commentStarts[i];
8496
		if (commentStart >= 0) {
8489
			positions[index++] = this.scanner.commentStops[i]-1; //stop is one over
8497
			int commentStop = this.scanner.commentStops[i];
8498
			if (commentStop > 0){
8499
				positions[index++] = commentStart;
8500
				positions[index++] = commentStop-1; //stop is one over
8501
			}
8490
		}
8502
		}
8491
	}
8503
	}
8492
	return positions;
8504
	return positions;
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java (-1 / +5 lines)
Lines 2552-2563 Link Here
2552
2552
2553
public void recordComment(int token) {
2553
public void recordComment(int token) {
2554
	// compute position
2554
	// compute position
2555
	int commentStart = this.startPosition;
2555
	int stopPosition = this.currentPosition;
2556
	int stopPosition = this.currentPosition;
2556
	switch (token) {
2557
	switch (token) {
2557
		case TokenNameCOMMENT_LINE:
2558
		case TokenNameCOMMENT_LINE:
2559
			// both positions are negative
2560
			commentStart = -this.startPosition;
2558
			stopPosition = -this.lastCommentLinePosition;
2561
			stopPosition = -this.lastCommentLinePosition;
2559
			break;
2562
			break;
2560
		case TokenNameCOMMENT_BLOCK:
2563
		case TokenNameCOMMENT_BLOCK:
2564
			// only end position is negative
2561
			stopPosition = -this.currentPosition;
2565
			stopPosition = -this.currentPosition;
2562
			break;
2566
			break;
2563
	}
2567
	}
Lines 2571-2577 Link Here
2571
		System.arraycopy(this.commentTagStarts, 0, this.commentTagStarts = new int[newLength], 0, length);
2575
		System.arraycopy(this.commentTagStarts, 0, this.commentTagStarts = new int[newLength], 0, length);
2572
	}
2576
	}
2573
	this.commentStops[this.commentPtr] = stopPosition;
2577
	this.commentStops[this.commentPtr] = stopPosition;
2574
	this.commentStarts[this.commentPtr] = this.startPosition;
2578
	this.commentStarts[this.commentPtr] = commentStart;
2575
}
2579
}
2576
2580
2577
/**
2581
/**

Return to bug 246682