Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367343

Summary: FastPartitioner computePartitions / length 0 fails at starting boundary
Product: [Eclipse Project] Platform Reporter: M Dahlem <dahlem.marc>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert
Version: 3.7Keywords: needinfo
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:
Attachments:
Description Flags
partitionscanner that detects java comments
none
JUnit testcase for the partitionscanner none

Description M Dahlem CLA 2011-12-21 10:48:09 EST
Build Identifier: M20110909-1335

Hi,

By developing a plugin I found out, that the contenttype at an offset is not the same like the computed region with legthn 0 at this offset computed all with an FastPartitionner.

It is not only the contenttype what differs, it is the same result by computing an partition at this offset.

Like I could see in the code of FastPartitioner line 628 the for-loop fails, because startIndex and endIndex contains both the same value and therefore the partition is of the default partition type.

"for (int i= startIndex; i < endIndex; i++) {[...]".

Greetz
Adreamus

Reproducible: Always

Steps to Reproduce:
1. create FastPartitionScanner and connect with an ID at an documentPorivder

2. set a comment /* */ as rule for a partition and add a comment to the document

3. compute regions at boundary 0 and length 0:

ITypedRegion[] regions = computePartitioning(ID, 0, 0, false);

4. compute Partition at offset 0: 

ITypedRegion regtest = getPartition(ID,0,false);

5. compare to each other, you can find out, that the array contains only the default partition and the partition at offset the correct partition type.
Comment 1 Dani Megert CLA 2011-12-21 11:12:52 EST
Could you attach an example or test case that allows to reproduce this?

Can you tell where it actually surfaces as a problem to the user?
Comment 2 M Dahlem CLA 2012-01-03 06:39:37 EST
Hi,

Regular eclipse users are not effected by this bug, it affects only developers.

In my case the code looked like this:


[..]
ITypedRegion partRegions = getPartitioning(DefaulPartitionerID, offset, false);

String partRegionName = region.getType();
		}

if (!(partRegionName.equals(RelevantPartitionID)) {
    //not relevant
    return false;
}

ITypedRegion[] regions = computePartitioning(SubPartitionerID, offset, length, false);

//compute region names

[...]

if (regionNames.contains(RelevantSubPartID)) {
    return true;
} else {
    return false;
}
[...]


Lets say the document contains the default partitions "EMPTY LINE" und "TEXT LINE". Only "TEXT LINES" are relevant default partitions.

And in this textline are two SubPartitions: "CODE" and "COMMENT".

The method should return TRUE if the offset is in an textLine and the whole region (offset till offset + length) contains at minimum one subpartition "COMMENT".

But if the comment starts at an offset where the textline also starts, and the length is 0, the "getPartition(..)" gets an "TEXTLINE", but computePartition(..) returns an "DEFAULT CONTENT TYPE".

Example:
line 1:                                              <-- EMPTY LINE
line 2:abcdefg                                       <-- TEXTLINE (CODE)
line 3:                                              <-- EMPTY LINE
line 4:/* hijklmn */                                 <-- TEXTLINE (COMMENT)


If we compute "getPartition(DEFAULTPARTITIONER, 14 (offset at begin of line 4), false)" the result is a Region with contenttype "TEXTLINE".

If we compute now "computePartitioning(SUBPARTIID, 14, 0, false);" the result is NOT "COMMENT", it is "default partition type".

I try to produce an runnable example and attach it to this bug.

Greetz
Adreamus
Comment 3 M Dahlem CLA 2012-01-03 09:06:19 EST
Created attachment 208935 [details]
partitionscanner that detects java comments
Comment 4 M Dahlem CLA 2012-01-03 09:10:15 EST
Created attachment 208936 [details]
JUnit testcase for the partitionscanner

This JUnit testcase has three tests:

(1) A test for the getPartition(partitioning, boundaryoffset, false)

(2) A test for the computePartitionings(partitioning, boundaryoffset, 0, false)
=> fails

(3) A test for checking, if the computedRegion and getRegion are the same for length 0 at an boundary offset
Comment 5 Dani Megert CLA 2012-01-05 11:10:02 EST
I looked at the test case and the current behavior is expected. If the position is between two partitions and the length is 0 we take the partition that is on the left.