Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 112079 Details for
Bug 246682
Inconsistent parser/scanner encoding for commentStart position
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
v01.txt (text/plain), 12.91 KB, created by
Frederic Fusier
on 2008-09-09 10:01:58 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2008-09-09 10:01:58 EDT
Size:
12.91 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/compiler/SourceElementParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementParser.java,v >retrieving revision 1.87 >diff -u -r1.87 SourceElementParser.java >--- model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 27 Jun 2008 16:04:07 -0000 1.87 >+++ model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 9 Sep 2008 13:35:13 -0000 >@@ -135,11 +135,17 @@ > > if (this.modifiersSourceStart >= 0) { > // eliminate comments located after modifierSourceStart if positionned >- while (lastComment >= 0 && Math.abs(this.scanner.commentStarts[lastComment]) > this.modifiersSourceStart) lastComment--; >+ while (lastComment >= 0) { >+ int commentSourceStart = this.scanner.commentStarts[lastComment]; >+ if (commentSourceStart < 0) commentSourceStart = -commentSourceStart; >+ if (commentSourceStart <= this.modifiersSourceStart) break; >+ lastComment--; >+ } > } > if (lastComment >= 0) { > // consider all remaining leading comments to be part of current declaration >- this.modifiersSourceStart = Math.abs(this.scanner.commentStarts[0]); >+ this.modifiersSourceStart = this.scanner.commentStarts[0]; >+ if (this.modifiersSourceStart < 0) this.modifiersSourceStart = -this.modifiersSourceStart; > > // check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored) > while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions >Index: model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java,v >retrieving revision 1.27 >diff -u -r1.27 DocumentElementParser.java >--- model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java 27 Jun 2008 16:04:07 -0000 1.27 >+++ model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java 9 Sep 2008 13:35:13 -0000 >@@ -68,17 +68,16 @@ > > //since jdk1.2 look only in the last java doc comment... > nextComment : for (lastCommentIndex = this.scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){ >- //look for @deprecated into the first javadoc comment preceeding the declaration >+ // skip all non-javadoc comments or those which are after the last modifier > int commentSourceStart = this.scanner.commentStarts[lastCommentIndex]; >- // javadoc only (non javadoc comment have negative end positions.) >- if (this.modifiersSourceStart != -1 && this.modifiersSourceStart < commentSourceStart) { >+ if (commentSourceStart < 0 || // line comment >+ this.scanner.commentStops[lastCommentIndex] < 0 || // block comment >+ (this.modifiersSourceStart != -1 && this.modifiersSourceStart < commentSourceStart)) // the comment is after the modifier >+ { > continue nextComment; > } >- if (this.scanner.commentStops[lastCommentIndex] < 0) { >- continue nextComment; >- } >- deprecated = >- this.javadocParser.checkDeprecation(lastCommentIndex); >+ // check comment >+ deprecated = this.javadocParser.checkDeprecation(lastCommentIndex); > break nextComment; > } > if (deprecated) { >@@ -87,6 +86,7 @@ > // modify the modifier source start to point at the first comment > if (commentPtr >= 0) { > this.declarationSourceStart = this.scanner.commentStarts[0]; >+ if (this.declarationSourceStart < 0) this.declarationSourceStart = -this.declarationSourceStart; > } > } > /* >Index: model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java,v >retrieving revision 1.25 >diff -u -r1.25 CommentRecorderParser.java >--- model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java 27 Jun 2008 16:03:57 -0000 1.25 >+++ model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java 9 Sep 2008 13:35:13 -0000 >@@ -14,6 +14,7 @@ > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > import org.eclipse.jdt.internal.compiler.parser.Parser; >+import org.eclipse.jdt.internal.compiler.parser.Scanner; > import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; > import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; > >@@ -54,7 +55,7 @@ > nextComment : for (lastCommentIndex = this.scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){ > //look for @deprecated into the first javadoc comment preceeding the declaration > int commentSourceStart = this.scanner.commentStarts[lastCommentIndex]; >- // javadoc only (non javadoc comment have negative end positions.) >+ // javadoc only (non javadoc comment have negative start and/or end positions.) > if ((commentSourceStart < 0) || > (this.modifiersSourceStart != -1 && this.modifiersSourceStart < commentSourceStart) || > (this.scanner.commentStops[lastCommentIndex] < 0)) >@@ -108,26 +109,6 @@ > super.consumeInterfaceHeader(); > } > >- /** >- * Insure that start position is always positive. >- * @see org.eclipse.jdt.internal.compiler.parser.Parser#containsComment(int, int) >- */ >- public boolean containsComment(int sourceStart, int sourceEnd) { >- int iComment = this.scanner.commentPtr; >- for (; iComment >= 0; iComment--) { >- int commentStart = this.scanner.commentStarts[iComment]; >- if (commentStart < 0) { >- commentStart = -commentStart; >- } >- // ignore comments before start >- if (commentStart < sourceStart) continue; >- // ignore comments after end >- if (commentStart > sourceEnd) continue; >- return true; >- } >- return false; >- } >- > /* (non-Javadoc) > * @see org.eclipse.jdt.internal.compiler.parser.Parser#endParse(int) > */ >@@ -239,7 +220,7 @@ > * @see org.eclipse.jdt.internal.compiler.parser.Parser#initializeScanner() > */ > public void initializeScanner() { >- this.scanner = new CommentRecorderScanner( >+ this.scanner = new Scanner( > false /*comment*/, > false /*whitespace*/, > this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/, >Index: model/org/eclipse/jdt/internal/core/util/CommentRecorderScanner.java >=================================================================== >RCS file: model/org/eclipse/jdt/internal/core/util/CommentRecorderScanner.java >diff -N model/org/eclipse/jdt/internal/core/util/CommentRecorderScanner.java >--- model/org/eclipse/jdt/internal/core/util/CommentRecorderScanner.java 27 Jun 2008 16:03:57 -0000 1.6 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,44 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2004, 2006 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jdt.internal.core.util; >- >-import org.eclipse.jdt.internal.compiler.parser.Scanner; >- >-/** >- * Internal scanner used for DOM AST nodes. >- * >- * @since 3.0 >- */ >-public class CommentRecorderScanner extends Scanner { >- >- public CommentRecorderScanner( >- boolean tokenizeComments, >- boolean tokenizeWhiteSpace, >- boolean checkNonExternalizedStringLiterals, >- long sourceLevel, >- char[][] taskTags, >- char[][] taskPriorities, >- boolean isTaskCaseSensitive) { >- super(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, sourceLevel, taskTags, taskPriorities, isTaskCaseSensitive); >- } >- >- /** >- * Set start position negative for line comments. >- * @see org.eclipse.jdt.internal.compiler.parser.Scanner#recordComment(int) >- */ >- public void recordComment(int token) { >- super.recordComment(token); >- if (token == TokenNameCOMMENT_LINE) { >- // for comment line both positions are negative >- this.commentStarts[this.commentPtr] = -this.commentStarts[this.commentPtr]; >- } >- } >-} >Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v >retrieving revision 1.392 >diff -u -r1.392 Parser.java >--- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 9 Sep 2008 10:00:41 -0000 1.392 >+++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 9 Sep 2008 13:35:12 -0000 >@@ -1110,11 +1110,17 @@ > > if (this.modifiersSourceStart >= 0) { > // eliminate comments located after modifierSourceStart if positionned >- while (lastComment >= 0 && this.scanner.commentStarts[lastComment] > this.modifiersSourceStart) lastComment--; >+ while (lastComment >= 0) { >+ int commentSourceStart = this.scanner.commentStarts[lastComment]; >+ if (commentSourceStart < 0) commentSourceStart = -commentSourceStart; >+ if (commentSourceStart <= this.modifiersSourceStart) break; >+ lastComment--; >+ } > } > if (lastComment >= 0) { > // consider all remaining leading comments to be part of current declaration > this.modifiersSourceStart = this.scanner.commentStarts[0]; >+ if (this.modifiersSourceStart < 0) this.modifiersSourceStart = -this.modifiersSourceStart; > > // check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored) > while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions >@@ -8050,6 +8056,7 @@ > int iComment = this.scanner.commentPtr; > for (; iComment >= 0; iComment--) { > int commentStart = this.scanner.commentStarts[iComment]; >+ if (commentStart < 0) commentStart = -commentStart; > // ignore comments before start > if (commentStart < sourceStart) continue; > // ignore comments after end >@@ -8472,9 +8479,10 @@ > public int[] getJavaDocPositions() { > > int javadocCount = 0; >- for (int i = 0, max = this.scanner.commentPtr; i <= max; i++){ >- // javadoc only (non javadoc comment have negative end positions.) >- if (this.scanner.commentStops[i] > 0){ >+ int max = this.scanner.commentPtr; >+ for (int i = 0; i <= max; i++){ >+ // javadoc only (non javadoc comment have negative start and/or end positions.) >+ if (this.scanner.commentStarts[i] >= 0 && this.scanner.commentStops[i] > 0) { > javadocCount++; > } > } >@@ -8482,11 +8490,15 @@ > > int[] positions = new int[2*javadocCount]; > int index = 0; >- for (int i = 0, max = this.scanner.commentPtr; i <= max; i++){ >- // javadoc only (non javadoc comment have negative end positions.) >- if (this.scanner.commentStops[i] > 0){ >- positions[index++] = this.scanner.commentStarts[i]; >- positions[index++] = this.scanner.commentStops[i]-1; //stop is one over >+ for (int i = 0; i <= max; i++){ >+ // javadoc only (non javadoc comment have negative start and/or end positions.) >+ int commentStart = this.scanner.commentStarts[i]; >+ if (commentStart >= 0) { >+ int commentStop = this.scanner.commentStops[i]; >+ if (commentStop > 0){ >+ positions[index++] = commentStart; >+ positions[index++] = commentStop-1; //stop is one over >+ } > } > } > return positions; >Index: compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java,v >retrieving revision 1.192 >diff -u -r1.192 Scanner.java >--- compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java 23 Jul 2008 13:25:39 -0000 1.192 >+++ compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java 9 Sep 2008 13:35:13 -0000 >@@ -2552,12 +2552,16 @@ > > public void recordComment(int token) { > // compute position >+ int commentStart = this.startPosition; > int stopPosition = this.currentPosition; > switch (token) { > case TokenNameCOMMENT_LINE: >+ // both positions are negative >+ commentStart = -this.startPosition; > stopPosition = -this.lastCommentLinePosition; > break; > case TokenNameCOMMENT_BLOCK: >+ // only end position is negative > stopPosition = -this.currentPosition; > break; > } >@@ -2571,7 +2575,7 @@ > System.arraycopy(this.commentTagStarts, 0, this.commentTagStarts = new int[newLength], 0, length); > } > this.commentStops[this.commentPtr] = stopPosition; >- this.commentStarts[this.commentPtr] = this.startPosition; >+ this.commentStarts[this.commentPtr] = commentStart; > } > > /**
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 246682
: 112079