Domanda

I have java code that isn't visually structured properly, all the code ~1000 words is all on a single line.

Is there a way to fix the structure where the functions and the spacing for sub functions are formatted visually ...?

Thanks,

È stato utile?

Soluzione

Different IDEs have different shortcuts to reformat code. If you're using:

Netbeans - Ctrl + Shift + F. Eclipse - Ctrl + A to highlight all code, and Ctrl + I to indent it. Or you could just hold down Ctrl + Shift + F

Edit: Check this out if my answer was not sufficient.

Altri suggerimenti

You also able to use this online formatter:

PrettyPrinter

Depends on the editor you're using. If you're using an IDE like Eclipse, there will be a "code cleanup" function, which will attempt to format your code to the current preferences.

If you're using vi or emacs - not so much, as far as I know.

Jalopy is a source code formatter for the Sun Java programming language.

It layouts any valid Java source code according to some widely configurable rules; to meet a certain coding style without putting a formatting burden on individual developers.

Jalopy's functionality covers:

- Brace style transformation
- Fine-grained white space settings
- Indentation
- Intelligent line wrapping
- Code separation
- Javadoc auto-generation
- Header/Footer templates
- Powerful command-line interface
- Several Plug-ins

Any Java IDE will have a way to reformat code.

A lot of "programmer-friendly" text editors have a "java mode" that supports code reformatting.

There are a few command-line Java indent / indenter tools around ... if you'd care to scan through the Google search results. (Search for "java indenter tool" or "java formatter tool".)

If you are using Eclipse:

Preferences -> Java -> Code Style -> Formatter -> edit -> Line Wrapping tab -> Set "Maximum line width" to 80 or some other limits

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top