Bug 93433 - [formatter] Java code max line width not applied.
Summary: [formatter] Java code max line width not applied.
Status: RESOLVED DUPLICATE of bug 71766
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-02 13:48 EDT by Gary Gregory CLA
Modified: 2005-08-31 12:12 EDT (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 Gary Gregory CLA 2005-05-02 13:48:46 EDT
Version: 3.1.0
Build id: I20050401-1645

[formatter] Max line width not applied.
My max line width is defined as 120. The line below is 126 chars long (4 spaces
start the line).

    public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY =
getSystemProperty("java.util.prefs.PreferencesFactory");

After formatting the whole file or just that line, the line does not change. The
line could broken up as:

    public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY =
        getSystemProperty("java.util.prefs.PreferencesFactory");

or:

    public static final String 
        JAVA_UTIL_PREFS_PREFERENCES_FACTORY =
getSystemProperty("java.util.prefs.PreferencesFactory");

If it matters, the getSystemProperty method is:

    private static String getSystemProperty(String property) {
        try {
            return System.getProperty(property);
        } catch (SecurityException ex) {
            // we are not allowed to look at this property
            System.err.println(
                "Caught a SecurityException reading the system property '" +
property 
                + "'; the SystemUtils property value will default to null."
            );
            return null;
        }
    }
Comment 1 Gary Gregory CLA 2005-05-02 13:51:42 EDT
The following is not broken up either at length 120:

    public static String toString(Object object, ToStringStyle style, boolean
outputTransients, Class reflectUpToClass) {
        return new ReflectionToStringBuilder(object, style, null,
reflectUpToClass, outputTransients).toString();
    }

The first line above is 122 long.
Comment 2 Gary Gregory CLA 2005-05-02 14:18:58 EDT
The same 120 limit is not applied to:

    /**
     * <p>
     * Returns whether the named charset is supported.
     * </p>
     * <p>
     * This is similar to <a
     *
href="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html#isSupported(java.lang.String)">java.nio.charset.Charset.isSupported(String)</a>
     * </p>
     * 
     * @param name
     *            the name of the requested charset; may be either a canonical
name or an alias
     * @return <code>true</code> if, and only if, support for the named charset
is available in the current Java
     *         virtual machine
     * 
     * @see <a
href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
     *      encoding names</a>
     */

Note that the @see properly breaks the line appart in the <a>.
Comment 3 Dani Megert CLA 2005-05-02 17:06:34 EDT
re comment 2: please note that comment formatting and normal formatting have
different preferences and are different formatters (Java / Javadoc). I consider
this bug for the Java formatter. Please file a separate bug report if you see
the problem reported in comment 2 after confirming that you've set the comment
formatter line length preference.
Comment 4 Gary Gregory CLA 2005-05-02 17:22:44 EDT
Check, I have max line width set to 120 for both tabs "Line Wrapping" and
"Comments".
Comment 5 Gary Gregory CLA 2005-05-02 17:24:28 EDT
Created "https://bugs.eclipse.org/bugs/show_bug.cgi?id=93459" for Javadoc issue.
Comment 6 Dennis Klemann CLA 2005-06-25 18:22:15 EDT
I also encountered this problem:

    if((pMetricsData.getMetricsData().length < 22) || 
(pMetricsData.getMetricsData()[0].length < 2)) {

is 102 characters long. It doesn't get wrapped when "Maximum line width" is set 
to 100.
This is rather annoying, because the code gets "QAed" with Checkstyle, which 
always reports that the line is too long once I use the code formatting. :-(

I', using Eclipse 3.1M7 on WindowsXP.
Comment 7 Olivier Thomann CLA 2005-08-31 12:12:09 EDT
Problem in comment 0 is a dup of bug 71766.
Problem in comment 6 is a dup of bug 90238.

With fix for bug 71766, it would be split as:

    public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY =
        getSystemProperty("java.util.prefs.PreferencesFactory");

*** This bug has been marked as a duplicate of 71766 ***