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

Bug 64684

Summary: DocumentSetupParticipants (easily) interfere with each other
Product: [Eclipse Project] Platform Reporter: David Williams <david_williams>
Component: AntAssignee: Darin Wright <darin.eclipse>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: Darin_Swanson, kai-uwe_maetzel, thatnitind, wbeckwith
Version: 3.0   
Target Milestone: 3.0 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description David Williams CLA 2004-05-29 18:46:30 EDT
Again, I've marked as 'blocker' simply because seems to prevent my implementing 
DocumentSetup participation, and I think exposes a tiny design issue with 
document setup participants (or, at least exposes my total misunderstanding of 
what its for :)

This is related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=64683, but is 
not really dependent on it. I think would be easy to "see" just conceptually, or 
with many simple test cases. 

First, to clarify background, I've created a DocumentFactory for my content type 
definition, and that does indeed work and an instance of my document does get 
created. 

But then, I tried to implement a a document setup participant for 
general/generic case of "xml", and in doing so, mimiced the ant based 
DocumentSetupParticipant, where the document partitioner is set and connected on 
the document. 

Its easy to see this is an error, though, since only one partitioner can be 
set/connected to a document (or causes runtme assert error). At least, that is, 
using the setDocumentPartitioner API. I know one "work around" would be for me 
and the ant editor to use a different API,
setDocumentPartitioner(String partitioning, IDocumentPartitioner partitioner),
but I'd guess that's not the only source of potential conflict? Or is it?
I guess I'm not sure of the use case that caused this "setup" extension to be 
created 
independently of the factory method that creates the document in the first 
place. If it was just for different partitionsers, then indeed the fix would be 
to document that, and document that participants must used the 
IDocumentExention3 interface. 

Another, partial "work around" for immediate problem would be for the ant editor 
to remove "xml" from their setup extension [that is, they are recognized as a 
participant, since they specify .xml extension in addition to ant content type], 
which really should not be necessary once 64683 is fixed. But this does not 
address the larger issue of participant conflicts. 

Thanks for reading, sorry in advance if I've just misunderstood intent of 
'document setup'.
Comment 1 Kai-Uwe Maetzel CLA 2004-06-02 12:52:36 EDT
to be investigated
Comment 2 Kai-Uwe Maetzel CLA 2004-06-03 12:20:34 EDT
I'll update Javadoc. Please keep in mind that Javadoc is not yet complete.

The extension point is for allowing plug-ins to participate in the process of 
setting up documents. Emphasis on "participate". Thus the same sharing rule 
applies as for every other oridinary extension point: Add, don't replace. This 
means that every participant has to setup the document in a way that does not 
conflict with the interest of others. Thus, the only valid way approach is to 
work with the contract introduced by IDocumentExtension3 (which actually has 
been invented for exactly this case).

Thus, when your setup participant fails in the described scenario, this is the 
expected behavior. This also means that you as well as Ant have to adapt the 
contributed setup participants.
Comment 3 David Williams CLA 2004-06-03 13:09:03 EDT
Ok, thanks Kai. I'll reopen this under "ant" component, to be sure that 
particular setup participant get's changed (to either not setup partitioning 
there, or to use the "addPartitioner" approach. [Darin, sorry, if this has 
already been done, but I'm not in a position to check head today, and just 
wanted to be sure this didn't get lost]. And, BTW, we will make similar changes.
[Alternatively, I susppose the setup participant in this case could just check 
to see if the instanceof document is one that its really interested in?]

Also ... the use case for using setup partitioner at all is still unclear to 
me, I'd appreciate some mention/javadoc for that. In the past, we've always 
initialized partioner when the document was created. Is there a reason not to 
do that?
Comment 4 Darin Swanson CLA 2004-06-03 13:16:57 EDT
Thanks David and Kai.
Comment 5 Darin Swanson CLA 2004-06-03 19:06:46 EDT
So just to ensure I am on the right page:
The AntDocumentSetupParticipant setup(IDocument) method should look like:

public void setup(IDocument document) {
  if (document != null) {
    IDocumentPartitioner partitioner = createDocumentPartitioner();
    if (document instanceof IDocumentExtension3) {
      IDocumentExtension3 extension3= (IDocumentExtension3) document;
      extension3.setDocumentPartitioner(ANT_PARTITIONING, partitioner);
    } else {
      document.setDocumentPartitioner(partitioner);
    }
    partitioner.connect(document);
  }
}
Comment 6 Darin Swanson CLA 2004-06-04 02:08:13 EDT
I have released changes for the Ant component to head and will be in the 
200406040800 build

Changes to:

AbstractAntSourceViewerConfiguration: overrode 
getConfiguredDocumentPartitioning and set the partioning for the reconciler

XmlFormatter: changed the partitioning for the MultiPassContentFormatter

AntDocumentSetupParticipant: made a participant :-) by using the 
IDocumentExtension3 functionality and defining the partitioning

AntEditorDocumentProvider: changed to use a forwarding doc provider with the 
correct partitioning.

AntStorageDocumentProvider: changed setup to make use of the 
IDocumentExtension3 functionality
Comment 7 Dani Megert CLA 2004-06-04 10:11:28 EDT
*** Bug 64910 has been marked as a duplicate of this bug. ***
Comment 8 Darin Swanson CLA 2004-06-04 11:42:37 EDT
Please verify DarinW.
Comment 9 David Williams CLA 2004-06-09 01:22:16 EDT
I'd like to re-open. Sorry I haven't looked closely before, but tonight noticed 
that your fix still interferes with non-DocumentExtension3 documents. 
For non-DocumentExention3 documents, an assert is still thrown in the "else" 
clause below. My thought would be to do nothing if its not a DocumentExention3 
document. I'm re-opening with slightly lowered severity, since we are due to 
change our document/partitioner too, but currently this is preventing us from 
using "setup" extension. And, I'll remind that this is related to 64683 since 
your "ant setup" participates in ALL xml documents. 
 

			if (document instanceof IDocumentExtension3) {
				IDocumentExtension3 extension3= (IDocumentExtension3) document;
				extension3.setDocumentPartitioner(ANT_PARTITIONING, partitioner);
			} else {
				document.setDocumentPartitioner(partitioner);
			}
Comment 10 Darin Swanson CLA 2004-06-09 01:25:02 EDT
Seems reasonable...I will look at it more tomorrow.
I was following the coding of the other participants...so others may want to 
revisit there code as well :-)
Comment 11 Darin Swanson CLA 2004-06-09 18:26:03 EDT
I changed the AntDocumentSetupParicipant to only be concerned with 
IDocumentExtension3 documents.
Comment 12 Darin Swanson CLA 2004-06-09 18:27:57 EDT
Back to verify. 
Note comment #7 for a test case.
Comment 13 Darin Wright CLA 2004-06-10 17:36:51 EDT
Verified.