Eclipse: Java Enum auto-completion of switch case?

It has been in Eclipse for ages. It's admittedly only a bit hard to find. First start with.

It has been in Eclipse for ages. It's admittedly only a bit hard to find. First start with switch (myEnum) { } Then go with your cursor to the line with the switch keyword and press Ctrl+1 and choose Add missing case statements.

This way it will insert any possible case. You'd expect this option to be available inside the statement blocks as well, but no.

Eclipse has so many features that are awesome but hard to find. Are there any good quick references? There was a recent SO thread that had a lot of good tips.

– Jonathon Apr 11 '10 at 23:27 @Jon: stackoverflow. Com/questions/54886/hidden-features-of-eclipse – BalusC Apr 11 '10 at 23:28.

You can add your own code templates using: Windows->Preferences->Java->Editor->Templates. Once you have added a code template, type enough characters of the template name to make it unique; type CTRL+Space; and your defined code will replace the template name characters. The template for switch is predefined in Eclipse Galileo.

Sw+CTRL+Space should give you a switch statement. You might have to adapt an existing template to give you the switch-enum combination.

I don't know if it's possible to do this as a template, because the template would have to know which enum type you were using. But you could write a little script to print out the statement for you, and then just copy its output into your source file. Public class SwitchWriter { public static void printSwitchStatement(String varName, Class E) { System.out.

Format("switch(%s) {\n", varName); for (Object o : E. GetEnumConstants()) { System.out. Format("case %s:\n // TODO: Auto-generated switch statement stub\n break;\n", o); } System.out.

Println("default:\n // TODO: Auto-generated switch statement stub\n}"); } } Output of SwitchWriter. PrintSwitchStatement("action", java.awt.Desktop.Action. Class): switch(action) { case OPEN: // TODO: Auto-generated switch statement stub break; case EDIT: // TODO: Auto-generated switch statement stub break; case PRINT: // TODO: Auto-generated switch statement stub break; case MAIL: // TODO: Auto-generated switch statement stub break; case BROWSE: // TODO: Auto-generated switch statement stub break; default: // TODO: Auto-generated switch statement stub }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions