Recent Changes - Search:

edit SideBar

EclipseMembersSortOrder

An attempt at customizing Eclipse's "Members Sort Order".

The Eclipse cleanup facility can sort the members of a class. The sort order is controlled by (Mac OS X) Preferences -> Java -> Appearance -> Sort Order.

The sort order is:

  • Types
  • Static Fields
  • Static Initializers
  • Static Methods
  • Fields
  • Initializers
  • Constructors
  • Methods

There is a checkbox for "Sort Members in same category by visibility" which has the following order:

  • Public
  • Private
  • Protected
  • Default

Unfortunately, the Ptolemy II coding standard at http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/doc/coding/style.htm has a different order. Arguably, the Ptolemy coding standard should change, but perhaps it is possible to change the order in Eclipse. The Ptolemy order is:


public class ClassName ... {

    constructors

    ///////////////////////////////////////////////////////////////////
    ////                         public variables                  ////

    public variables, in alphabetical order

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public methods, in alphabetical order

    ///////////////////////////////////////////////////////////////////
    ////                         protected methods                 ////

    protected methods, in alphabetical order

    ///////////////////////////////////////////////////////////////////
    ////                         protected variables               ////

    protected variables, in alphabetical order

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private methods, in alphabetical order

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    private variables, in alphabetical order
}

The primary difference between the two classifications is that the Ptolemy style has all the public fieldds and methods first, then the protected methods and fields and then the private methods and fields. Types, Statics and Initializers are not specified. So, the order for Ptolemy might be:

  • Constructors
  • Public variables - Note that Public variables are before Public Methods because for actors, Public variables includes ports and parameters.
  • Public methods
  • Protected methods
  • Protected variables
  • Private methods
  • Private variables

Types (inner classes) and Statics would probably go in the appropriate visibility section:

  • Public constructors
  • Public statics - statics should be as early as possible because order matters
  • Public variables
  • Public methods
  • Public Types (inner classes)
  • Protected constructors
  • Protected methods
  • Protected types (inner classes)
  • Protected statics
  • Protected variables
  • Private constructors
  • Private statics
  • Private methods
  • Private variables

The Problem Statement

Modify the sort order so that we can specify the visibility of the members.

Current status

Eclipse bugs

Building Eclipse under Mac OS X

  1. Go to http://update.eclipse.org/downloads/
  2. Find the release in which you are interested. In my case, I wanted 3.5.1, so I clicked on 3.5.1 under "Latest Released"
  3. Click on "access the Source Builds page"
  4. Instructions for building 3.5.1 are at http://wiki.eclipse.org/Platform-releng-sourcebuild35#Supported_Platforms
  5. Create a new directory
    mkdir eclipse3.5.1
  6. Download the "Source Build (Source fetched via CVS) and unzip. I had problems with the 3.5.1 "Source Build (Source in .zip)", see below
    cd eclipse3.5.1
    unzip ~/Downloads/eclipse-sourceBuild-srcFetch-3.5.1.zip
  7. Download eclipse-SDK-3.5.1-macosx-carbon.tar.gz into the eclipse3.5.1/buildScripts directory

The build script (run in the step after the next step)will untar this file if the eclipse/ directory does not exist.

  1. Edit buildScripts/org.eclipse.releng.eclipsebuilder/eclipse/buildConfigs/sdk/srcBuild/build.properties
    J2SE-1.5=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/jce.jar
    J2SE-1.4=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/jce.jar
    CDC-1.0/Foundation-1.0=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/classes.jar
    CDC-1.1/Foundation-1.1=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/classes.jar
    OSGi/Minimum-1.2=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Classes/classes.jar
    JavaSE-1.6=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/jce.jar
    java15-home=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
  2. Run build, which will likely fail:
    export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
    export CVS_RSH=ssh
    ./build -os macosx -ws cocoa -arch x86
  3. In src/maps/org.eclipse.releng/maps/orbit.map, replace fullmoon.ottawa.ibm.com with www.eclipse.org/external (see below for details)
  4. Run the build command
    ./build -os macosx -ws cocoa -arch x86

Problems

./build: line 55: [: missing `]'

Problem: During build:

./build: line 55: [: missing `]'

Solution: change

[ "$os-$ws-$arch" = "hpux-motif-ia64_32"]

to

[ "$os-$ws-$arch" = "hpux-motif-ia64_32" ]

Error occurred while transforming repository.

Problem: During build of eclipse-sourceBuild-srcIncluded-3.5.1.zip

BUILD FAILED
/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:56: The following error occurred while executing this line:
/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:122: The following error occurred while executing this line:
/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:103: The following error occurred while executing this line:
/Users/cxh/src/eclipse/eclipse/plugins/org.eclipse.pde.build_3.5.1.R35x_20090820/scripts/build.xml:78: The following error occurred while executing this line:
/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/eclipse/buildConfigs/master-ecf/customTargets.xml:10: The following error occurred while executing this line:
/Users/cxh/src/eclipse/eclipse/plugins/org.eclipse.pde.build_3.5.1.R35x_20090820/scripts/genericTargets.xml:59: The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/fetch_master-ecf.xml:10: The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/fetch_master-ecf.xml:44: Error occurred while transforming repository.

Initial Solution: http://old.nabble.com/trouble-building-Eclipse-SDK-3.5.1-from-source-td26715114.html

" * replace all instances of "fullmoon.ottawa.ibm.com" with "www.eclipse.org/external" in src/maps/org.eclipse.releng/maps/orbit.map (this was necessary to avoid "Error occurred while transforming repository." problems which would otherwise halt the build)

Real Solution: Don't use eclipse-sourceBuild-srcIncluded-3.5.1.zip, use eclipse-sourceBuild-srcFetch-3.5.1.zip

cvs problem

The problem:

fetchElement:
[eclipse.fetch] Could not retrieve feature.xml and/or build.properties: cvs exited with error code 1
[eclipse.fetch] Command line was [Executing 'cvs' with arguments:
[eclipse.fetch] '-d:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse'
[eclipse.fetch] '-q'
[eclipse.fetch] 'export'
[eclipse.fetch] '-r'
[eclipse.fetch] 'v20080717'
[eclipse.fetch] 'org.eclipse.sdk.examples-feature/feature.xml'
[eclipse.fetch]
[eclipse.fetch] The ' characters around the executable and arguments are
[eclipse.fetch] not part of the command.

Looks like a problem on the cvs server:

bash-3.2$ touch foo
bash-3.2$ cvs -t -d:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse -q export -r v20080717 org.eclipse.sdk.examples-feature/feature.xml
  -> main: Session ID is ufBZKuOL4ClLOefu
  -> main loop with CVSROOT=/cvsroot/eclipse
  -> parse_tagdate ((null), (null), v20080717)
  -> safe_location( where=(null) )
  -> open_connection_to_server (:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse)
  -> Connecting to dev.eclipse.org(206.191.52.50):2401.
can't create temporary directory /tmp/cvs-serv32602
No space left on device
bash-3.2$ df -k /tmp
Filesystem   1024-blocks     Used Available Capacity  Mounted on
/dev/disk0s2   195025072 83067088 111701984    43%    /
bash-3.2$

The problem was likely on the Eclipse CVS server. After waiting, the problem went away. One issue is that it seems like even though I downloaded the SDK with source, the build is still using CVS. What if I was connected via a slow connection? The Eclipse3.6M4 org.eclipse.releng.eclipsebuilder/eclipse/buildConfigs/sdk/srcBuild/build.properties mentions skipFetch:

#uncomment skipFetch if you are running the eclipse-sourceBuild-srcIncluded-${buildId}.zip
#skipFetch=true

References to win32 and linux

Problem: The eclipse-sourceBuild-srcIncluded-3.5.1.zip build fails because win32 and linux sources are missing

/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:57: The following error occurred while executing this line:
/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:109: The following error occurred while executing this line:
/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/build.xml:34: The following error occurred while executing this line:
/Users/cxh/src/eclipse/eclipse/plugins/org.eclipse.pde.build_3.5.1.R35x_20090820/scripts/build.xml:36: The following error occurred while executing this line:
/Users/cxh/src/eclipse/eclipse/plugins/org.eclipse.pde.build_3.5.1.R35x_20090820/scripts/build.xml:105: The following error occurred while executing this line:
/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/eclipse/buildConfigs/master/customTargets.xml:18: The following error occurred while executing this line:
/Users/cxh/src/eclipse/org.eclipse.releng.eclipsebuilder/eclipse/buildConfigs/master/allElements.xml:16: The following error occurred while executing this line:
/Users/cxh/src/eclipse/eclipse/plugins/org.eclipse.pde.build_3.5.1.R35x_20090820/scripts/genericTargets.xml:114: The following error occurred while executing this line:
/Users/cxh/src/eclipse/eclipse/plugins/org.eclipse.pde.build_3.5.1.R35x_20090820/scripts/genericTargets.xml:124: The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/compile.master.xml:7:
The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.win32.win32.x86_64/build.xml:138: The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.win32.win32.x86_64/build.xml:65: srcdir "/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.win32.win32.x86_64/src/Eclipse SWT Accessibility/win32" does not exist!
The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.gtk.linux.x86_64/build.xml:149: The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.gtk.linux.x86_64/build.xml:65: srcdir "/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.gtk.linux.x86_64/src/Eclipse SWT/emulated/bidi" does not exist!
The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.gtk.linux.s390x/build.xml:150: The following error occurred while executing this line:
/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.gtk.linux.s390x/build.xml:66: srcdir "/Users/cxh/src/eclipse/src/plugins/org.eclipse.swt.gtk.linux.s390x/src/Eclipse SWT Mozilla/gtk" does not exist!

Solution? Try 3.6M4

3.6M4 fails: buildScripts/src/maps/org.eclipse.releng/maps not found

BUILD FAILED
/Users/cxh/src/eclipse3.6M4/buildScripts/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:54: The following error occurred while executing this line:
/Users/cxh/src/eclipse3.6M4/buildScripts/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:117: The following error occurred while executing this line:
/Users/cxh/src/eclipse3.6M4/buildScripts/eclipse/plugins/org.eclipse.pde.build_3.6.0.v20091204/scripts/build.xml:76: The following error occurred while executing this line:
/Users/cxh/src/eclipse3.6M4/buildScripts/org.eclipse.releng.eclipsebuilder/eclipse/buildConfigs/sdk.examples/customTargets.xml:102: /Users/cxh/src/eclipse3.6M4/buildScripts/src/maps/org.eclipse.releng/maps not found.

Total time: 0 seconds
Job found still running after platform shutdown. Jobs should be canceled by the plugin that scheduled them during shutdown: org.eclipse.core.internal.refresh.RefreshJob
Job found still running after platform shutdown. Jobs should be canceled by the plugin that scheduled them during shutdown: org.eclipse.core.internal.refresh.RefreshJob
An error has occurred. See the log file
/Users/cxh/Documents/workspace/.metadata/.log.

Solution: Try the 3.5.1 again

3.5.1: Can't find org.eclipse.ecf.provider.filetransfer.source_3.0.0.qualifier

Build with ~/Downloads/eclipse-sourceBuild-srcIncluded-3.5.1.zip and build.properties having skipFetch=true

/Users/cxh/src/eclipse3.5.1/buildScripts/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:56: The following error occurred while executing this line:
/Users/cxh/src/eclipse3.5.1/buildScripts/org.eclipse.releng.eclipsebuilder/buildFromSource.xml:130: The following error occurred while executing this line:
/Users/cxh/src/eclipse3.5.1/buildScripts/eclipse/plugins/org.eclipse.pde.build_3.5.1.R35x_20090820/scripts/build.xml:91: The following error occurred while executing this line:
/Users/cxh/src/eclipse3.5.1/buildScripts/org.eclipse.releng.eclipsebuilder/eclipse/buildConfigs/sdk/customTargets.xml:13: The following error occurred while executing this line:
/Users/cxh/src/eclipse3.5.1/buildScripts/eclipse/plugins/org.eclipse.pde.build_3.5.1.R35x_20090820/scripts/genericTargets.xml:106: Unable to find plug-in: org.eclipse.ecf.source_3.0.0.v20090831-1906. Please check the error log for more details.

Solution: build 3.5.1 from the "Source Build (Source fetched via CVS)" and replace fullmoon.ottawa.ibm.com with www.eclipse.org/external in src/maps/org.eclipse.releng/maps/orbit.map and rerun build

Real solution: It looks like the jar file is missing?

cd eclipse/plugins/
wget http://kde.mirrors.tds.net/pub/eclipse.org/rt/ecf/integration/platform/v2009-08-31_12-00-11/plugins/org.eclipse.ecf.filetransfer.source_3.0.0.v20090831-1906.jar

Could not create feature

[eclipse.buildScript] Could not create feature: file:/Users/cxh/src/eclipse3.5.1/buildScripts/src/features/org.eclipse.equinox.p2.user.ui.source/feature.xml.
[eclipse.buildScript] XML document structures must start and end within the same entity.
[eclipse.buildScript] Could not create feature: file:/Users/cxh/src/eclipse3.5.1/buildScripts/org.eclipse.releng.eclipsebuilder/../src/features/org.eclipse.equinox.p2.user.ui.source/feature.xml.
[eclipse.buildScript] Could not create feature: file:/Users/cxh/src/eclipse3.5.1/buildScripts/src/features/org.eclipse.equinox.p2.user.ui.source/feature.xml.

Solution: it looks like feature.xml was truncated:

bash-3.2$ cat /Users/cxh/src/eclipse3.5.1/buildScripts/src/features/org.eclipse.equinox.p2.user.ui.source/*.xml
<?xml version="1.0" encoding="UTF-8"?>
<feature id="org.eclipse.equinox.p2.user.ui.source" version="1.2.0.v20090729-7u7AFm3FbPbJP5rV7cCTt6x" label="%featureName" provider-name="%providerName" image="eclipse_update_120.jpg"    >
        <description >
                %description
        </description>
        <copyright >
                %copyright
        </copyright>
        <license url="%licenseURL">
                %license
        </license>
bash-3.2$

So I removed the org.eclipse.equinox.p2.user.ui.source directory and reran build.

Can't find ecf.provider.filetransfer.source_3.0.0 and httpclient.source_3.0.0

Problem:

[eclipse.buildScript] Unable to find plug-in: org.eclipse.ecf.provider.filetransfer.source_3.0.0.qualifier. Please check the error log for more details.
[eclipse.buildScript] Unable to find plug-in: org.eclipse.ecf.provider.filetransfer.httpclient.source_3.0.0.qualifier. Please check the error log for more details.

Solution, unjar the 3.0.1 version of these files, change the manifest and create new versions

cd src/plugins
mkdir tmp
cd tmp
jar -xf ../org.eclipse.ecf.provider.filetransfer.httpclient.source_3.0.1.v20090831-1906.jar
# Edit META-INF/MANIFEST and change 3.0.1 to 3.0.0
jar -cmf META-INF/MANIFEST.MF ../org.eclipse.ecf.provider.filetransfer.httpclient.source_3.0.1.v20090831-1906.jar .
rm -rf *
# do the same for filetransfer.source_3.0.0

Real Solution: It turns out that these messages can be ignored. I suspect that my problem was that CVS_RSH was not set. I've seen the above error messages in the log file of a successful build.

Eclipse files that are involved in the Members Sort Order

org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/corext/codemanipulation/SortMembersOperation.java
Defines the comparator used to sort
org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/preferences/MembersOrderPreferenceCache.java
Defines various constants
org.eclipse.jdt.ui/src/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
Defines the strings used in the dialog

The plan: Add a bunch of constants to represent the members at a finer level of detail. The visibility option will be ignored. This is a hack.

Edit - History - Print - Recent Changes - Search
Page last modified on December 18, 2009, at 11:25 PM