Bug 6117 - CodeFormatter - impossible to set indentation level and position mapping w/o deprecated methods
Summary: CodeFormatter - impossible to set indentation level and position mapping w/o ...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 2.0 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-11-20 12:21 EST by Claude Knaus CLA
Modified: 2002-01-14 11:50 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claude Knaus CLA 2001-11-20 12:21:58 EST
CodeFormatter.setIndentationLevel() is deprecated. The only way to specify
an indentation level w/o using deprecated methods is to use the static
convenience method to format(String, int, Map). However, the static method 
offers no way of mapping positions. There should be a way to have all features
w/o requiring to use deprecated methods.
Comment 1 Olivier Thomann CLA 2001-12-05 11:51:14 EST
I think we should set the initial indentation level using the formatter options. 
Then you don't need to use the format(String, int, Map) method anymore and this 
method should be deprecated.
To set the mapping positions it should be done through setPositionsToMap(int[] 
positions). And after formatting you get them back using int[] 
getMappedPositions().

Is this fine for you? Philippe, any comment?
Comment 2 Claude Knaus CLA 2001-12-06 03:55:56 EST
I don't think the indentation level is a format option. A format option
is something global (user preference), while the indentation level is specific 
to the format operation. It has a tight relationship with the string to be
formatted and its context. Depending on where you want to insert the string, 
the indentation level changes.

The position mapping is something optional, so I'm fine with the setter/getter.
However, I was wondering, why the CodeFormatter creates a new array. It could
do the mapping in-place. If the client really needs another array, it can do
so by copying the old array itself.

I purpose the following 'API':

   public CodeFormatter(); // defaults to empty options
   public CodeFormatter(Map options);

   public void format(String string); // defauls to indentation level == 0
   public void format(String string, int indentationLevel);

   public void setPositionsToMap(int[] positions);

I'm not sure what the splitting has to do with formatting. It should be a
different class, IMHO. Something like CodeSplitter?
Comment 3 Olivier Thomann CLA 2001-12-06 10:57:23 EST
In fact it might be a good idea to split into two components the code formatting 
and the line splitting. I think we need to investiguate how to rewrite the code 
formatter which is extremely difficult to maintain. That explains all the 
problems I have to fix the position mapping.
Your API looks good to me. I'll see with Philippe if we change them.
Comment 4 Philipe Mulet CLA 2001-12-12 09:55:02 EST
Sounds like a fair change. 
Comment 5 Olivier Thomann CLA 2001-12-12 13:02:54 EST
Why do you want methods that returns void? You don't want to get the formatted 
string back?

   public CodeFormatter(); // defaults to empty options
     I won't change this one. It is still deprecated. You should always call the
CodeFormatter(JavaCore.getOptions());

  public void format(String string); // defauls to indentation level == 0
  public void format(String string, int indentationLevel);

Let me know if you want the return type of these two methods to be String.
Comment 6 Claude Knaus CLA 2001-12-12 13:30:48 EST
uh, that's a bug. Of course they should return String :)
Comment 7 Olivier Thomann CLA 2001-12-12 13:50:12 EST
I added the requested API and I removed some convenient static methods.
I will send you the new formatter code and let me know if this is close to what 
you want.
Comment 8 Olivier Thomann CLA 2001-12-14 12:30:35 EST
Changed API released in HEAD. Please make all concerned people aware of these 
changes in ZRH.