This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 108030

Summary: Not possible to detect to which FoldOperation an instance of Fold belongs to
Product: editor Reporter: Marek Fukala <mfukala>
Component: Code foldingAssignee: Miloslav Metelka <mmetelka>
Status: RESOLVED FIXED    
Severity: blocker CC: jjancura
Priority: P3 Keywords: API, API_REVIEW_FAST
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: Patch adding FoldOperation.owns(Fold)

Description Marek Fukala 2007-06-25 15:28:33 UTC
Having a possibility to detect to which FoldOperation an instance of Fold belongs to, resp. which FoldManager created
the Fold would easy usecases when there are more FoldManager implementations bound to one mimetype.

Currently the problem can be partially solved by using Fold.getFoldType() which however returns an instance of final
class so no class instance resolution can be used. The problem gets worser in case of a generic FoldManager
implementation like Schlieman has which creates the FoldType-s based on some external metadata.

The only generic way I found is:

                        Fold f = fold.getFold (i);
                        try {
                            operation.getExtraInfo(f);
                            //no ISE thrown - my fold
                            l.add (f.getType());
                        } catch (IllegalStateException e) {
                            //not my fold
                        }

If for example getExtraInfo() is called on fold which wasn't created by this FoldManager, the ISE it thrown, so I know
that this is not my fold. This solution is IMHO no elegant enought, I would expect something like:

Fold.isCreatedBy(FoldOperation) or somethin similar.
Comment 1 Vitezslav Stejskal 2007-06-26 13:18:16 UTC
Marku, how important is fixing this issue? Does it block other issues? It's likely to require a small API change. Using
exceptions for flow control is an antipattern we should avoid of course. Feel free to make it P2 if it's important to
fix it soon.
Comment 2 Marek Fukala 2007-06-26 14:01:48 UTC
It would be nice if resolved to the upcoming beta, or at least to final release. Not critical.
Comment 3 Miloslav Metelka 2008-03-03 14:24:58 UTC
I've implemented FoldOperation.owns(Fold). Diff attached. Marku if you need it into 6.1 please raise the priority. Thanks.
Comment 4 Miloslav Metelka 2008-03-03 14:25:59 UTC
Created attachment 57677 [details]
Patch adding FoldOperation.owns(Fold)
Comment 5 Marek Fukala 2008-03-03 16:35:14 UTC
So far it looks like I do not really need it. So if it takes too much of your time now we can put it off to 6.next. The
patch look fine to me.
Comment 6 Miloslav Metelka 2008-03-04 11:58:32 UTC
No, I have it prepared on disk so I just commit it.
http://hg.netbeans.org/main?cmd=changeset;node=3fc9a480f2f3