### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java,v retrieving revision 1.117 diff -u -r1.117 DefaultCodeFormatterConstants.java --- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 31 Aug 2010 07:03:07 -0000 1.117 +++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 31 Aug 2010 14:43:07 -0000 @@ -1288,11 +1288,69 @@ * @see JavaCore#INSERT * @see JavaCore#DO_NOT_INSERT * @since 3.4 + * @deprecated + * All new options must be enabled to activate old strategy + * {@link #FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD} + * {@link #FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD} + * {@link #FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE} + * {@link #FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE} */ public static final String FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_after_annotation_on_member";//$NON-NLS-1$ /** *
+	 * FORMATTER / Option to insert a new line after an annotation on a field declaration
+	 *     - option id:         "org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field"
+	 *     - possible values:   { INSERT, DO_NOT_INSERT }
+	 *     - default:           INSERT
+	 * 
+ * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.7 + */ + public static final String FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_after_annotation_on_field";//$NON-NLS-1$ + + /** + *
+	 * FORMATTER / Option to insert a new line after an annotation on a method declaration
+	 *     - option id:         "org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method"
+	 *     - possible values:   { INSERT, DO_NOT_INSERT }
+	 *     - default:           INSERT
+	 * 
+ * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.7 + */ + public static final String FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_after_annotation_on_method";//$NON-NLS-1$ + + /** + *
+	 * FORMATTER / Option to insert a new line after an annotation on a package declaration
+	 *     - option id:         "org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package"
+	 *     - possible values:   { INSERT, DO_NOT_INSERT }
+	 *     - default:           INSERT
+	 * 
+ * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.7 + */ + public static final String FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_after_annotation_on_package";//$NON-NLS-1$ + + /** + *
+	 * FORMATTER / Option to insert a new line after an annotation on a type declaration
+	 *     - option id:         "org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type"
+	 *     - possible values:   { INSERT, DO_NOT_INSERT }
+	 *     - default:           INSERT
+	 * 
+ * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.7 + */ + public static final String FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE = JavaCore.PLUGIN_ID + ".formatter.insert_new_line_after_annotation_on_type";//$NON-NLS-1$ + + /** + *
 	 * FORMATTER / Option to insert a new line after an annotation on a parameter
 	 *     - option id:         "org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter"
 	 *     - possible values:   { INSERT, DO_NOT_INSERT }
@@ -3849,6 +3907,35 @@
 	}
 
 	/**
+	 * Return an array of compatible constants for an obsolete constant.
+	 * 
+	 * @param name The name of the obsolete constant
+	 * @return The list as a non-empty array of the compatible constants or
+	 * null if the constant is not obsolete.
+	 */
+	public static String[] getCompatibleConstants(String name) {
+		if (FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER.equals(name)) {
+			return new String[] {
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD,
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD,
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE,
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE
+			};
+		}
+		if (FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION.equals(name)) {
+			return new String[] {
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD,
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD,
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE,
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE,
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE,
+				FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER
+			};
+		}
+		return null;
+	}
+
+	/**
 	 * 

Return the indentation style of the given alignment value. * The given alignment value should be created using the createAlignmentValue(boolean, int, int) * API. Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v retrieving revision 1.235 diff -u -r1.235 CodeFormatterVisitor.java --- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 20 May 2010 09:41:48 -0000 1.235 +++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 31 Aug 2010 14:43:09 -0000 @@ -561,7 +561,7 @@ Alignment memberAlignment = this.scribe.getMemberAlignment(); this.scribe.printComment(); - this.scribe.printModifiers(fieldDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_MEMBER); + this.scribe.printModifiers(fieldDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_FIELD); this.scribe.space(); /* * Field type @@ -675,7 +675,7 @@ Alignment fieldAlignment = this.scribe.getMemberAlignment(); this.scribe.printComment(); - this.scribe.printModifiers(multiFieldDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_MEMBER); + this.scribe.printModifiers(multiFieldDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_FIELD); this.scribe.space(); multiFieldDeclaration.declarations[0].type.traverse(this, scope); @@ -911,7 +911,7 @@ this.scribe.printComment(); int line = this.scribe.line; - this.scribe.printModifiers(typeDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_MEMBER); + this.scribe.printModifiers(typeDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_TYPE); if (this.scribe.line > line) { // annotations introduced new line, but this is not a line wrapping @@ -2443,7 +2443,7 @@ * Print comments to get proper line number */ this.scribe.printComment(); - this.scribe.printModifiers(annotationTypeMemberDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_MEMBER); + this.scribe.printModifiers(annotationTypeMemberDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_METHOD); this.scribe.space(); /* * Print the method return type @@ -3070,7 +3070,7 @@ this.scribe.printEmptyLines(blankLinesBeforePackage); } - this.scribe.printModifiers(currentPackage.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_MEMBER); + this.scribe.printModifiers(currentPackage.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_PACKAGE); this.scribe.space(); // dump the package keyword this.scribe.printNextToken(TerminalTokens.TokenNamepackage); @@ -3306,7 +3306,7 @@ */ this.scribe.printComment(); int line = this.scribe.line; - this.scribe.printModifiers(constructorDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_MEMBER); + this.scribe.printModifiers(constructorDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_METHOD); if (this.scribe.line > line) { // annotations introduced new line, but this is not a line wrapping // see 158267 @@ -3523,7 +3523,7 @@ */ this.scribe.printComment(); final int line = this.scribe.line; - this.scribe.printModifiers(enumConstant.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_MEMBER); + this.scribe.printModifiers(enumConstant.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_FIELD); this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, false); formatEnumConstantArguments( enumConstant, @@ -4219,7 +4219,7 @@ do { try { - this.scribe.printModifiers(methodDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_MEMBER); + this.scribe.printModifiers(methodDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_METHOD); int fragmentIndex = 0; this.scribe.alignFragment(methodDeclAlignment, fragmentIndex); Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v retrieving revision 1.108 diff -u -r1.108 DefaultCodeFormatterOptions.java --- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 20 May 2010 09:41:48 -0000 1.108 +++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 31 Aug 2010 14:43:11 -0000 @@ -135,7 +135,10 @@ public boolean indent_switchstatements_compare_to_switch; public int indentation_size; - public boolean insert_new_line_after_annotation_on_member; + public boolean insert_new_line_after_annotation_on_type; + public boolean insert_new_line_after_annotation_on_field; + public boolean insert_new_line_after_annotation_on_method; + public boolean insert_new_line_after_annotation_on_package; public boolean insert_new_line_after_annotation_on_parameter; public boolean insert_new_line_after_annotation_on_local_variable; public boolean insert_new_line_after_label; @@ -421,7 +424,10 @@ options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES, this.indent_switchstatements_compare_to_cases ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, this.indent_switchstatements_compare_to_switch ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, Integer.toString(this.indentation_size)); - options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER, this.insert_new_line_after_annotation_on_member ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE, this.insert_new_line_after_annotation_on_type ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, this.insert_new_line_after_annotation_on_field ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, this.insert_new_line_after_annotation_on_method ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, this.insert_new_line_after_annotation_on_package ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, this.insert_new_line_after_annotation_on_parameter ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, this.insert_new_line_after_annotation_on_local_variable ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, this.insert_new_line_after_opening_brace_in_array_initializer? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); @@ -2028,16 +2034,41 @@ this.comment_clear_blank_lines_in_block_comment = DefaultCodeFormatterConstants.TRUE.equals(commentClearBlankLinesInBlockCommentOption); } } - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=122247 + // New line after annotations final Object insertNewLineAfterAnnotationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION); - if (insertNewLineAfterAnnotationOption != null) { // check if deprecated option was used - this.insert_new_line_after_annotation_on_member = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOption); - this.insert_new_line_after_annotation_on_parameter = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOption); - this.insert_new_line_after_annotation_on_local_variable = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOption); + if (insertNewLineAfterAnnotationOption != null) { // check if deprecated 3.1 option was used + boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOption); + this.insert_new_line_after_annotation_on_type = insert; + this.insert_new_line_after_annotation_on_field = insert; + this.insert_new_line_after_annotation_on_method = insert; + this.insert_new_line_after_annotation_on_package = insert; + this.insert_new_line_after_annotation_on_parameter = insert; + this.insert_new_line_after_annotation_on_local_variable = insert; } else { final Object insertNewLineAfterAnnotationOnMemberOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER); - if (insertNewLineAfterAnnotationOnMemberOption != null) { // otherwhise, use the new options - this.insert_new_line_after_annotation_on_member = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMemberOption); + if (insertNewLineAfterAnnotationOnMemberOption != null) { // check if deprecated 3.4 option was used + boolean insert = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMemberOption); + this.insert_new_line_after_annotation_on_type = insert; + this.insert_new_line_after_annotation_on_field = insert; + this.insert_new_line_after_annotation_on_method = insert; + this.insert_new_line_after_annotation_on_package = insert; + } else { // otherwise use new options + final Object insertNewLineAfterAnnotationOnTypeOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE); + if (insertNewLineAfterAnnotationOnTypeOption != null) { + this.insert_new_line_after_annotation_on_type = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnTypeOption); + } + final Object insertNewLineAfterAnnotationOnFieldOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD); + if (insertNewLineAfterAnnotationOnFieldOption != null) { + this.insert_new_line_after_annotation_on_field = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnFieldOption); + } + final Object insertNewLineAfterAnnotationOnMethodOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD); + if (insertNewLineAfterAnnotationOnMethodOption != null) { + this.insert_new_line_after_annotation_on_method = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnMethodOption); + } + final Object insertNewLineAfterAnnotationOnPackageOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE); + if (insertNewLineAfterAnnotationOnPackageOption != null) { + this.insert_new_line_after_annotation_on_package = JavaCore.INSERT.equals(insertNewLineAfterAnnotationOnPackageOption); + } } final Object insertNewLineAfterAnnotationOnParameterOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER); if (insertNewLineAfterAnnotationOnParameterOption != null) { @@ -2126,7 +2157,10 @@ this.indent_switchstatements_compare_to_cases = true; this.indent_switchstatements_compare_to_switch = true; this.indentation_size = 4; - this.insert_new_line_after_annotation_on_member = true; + this.insert_new_line_after_annotation_on_type = true; + this.insert_new_line_after_annotation_on_field = true; + this.insert_new_line_after_annotation_on_method = true; + this.insert_new_line_after_annotation_on_package = true; this.insert_new_line_after_annotation_on_parameter = false; this.insert_new_line_after_annotation_on_local_variable = true; this.insert_new_line_after_opening_brace_in_array_initializer = false; @@ -2401,7 +2435,10 @@ this.indent_switchstatements_compare_to_cases = true; this.indent_switchstatements_compare_to_switch = false; this.indentation_size = 4; - this.insert_new_line_after_annotation_on_member = true; + this.insert_new_line_after_annotation_on_type = true; + this.insert_new_line_after_annotation_on_field = true; + this.insert_new_line_after_annotation_on_method = true; + this.insert_new_line_after_annotation_on_package = true; this.insert_new_line_after_annotation_on_parameter = false; this.insert_new_line_after_annotation_on_local_variable = true; this.insert_new_line_after_opening_brace_in_array_initializer = false; Index: formatter/org/eclipse/jdt/internal/formatter/ICodeFormatterConstants.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/ICodeFormatterConstants.java,v retrieving revision 1.2 diff -u -r1.2 ICodeFormatterConstants.java --- formatter/org/eclipse/jdt/internal/formatter/ICodeFormatterConstants.java 27 Jun 2008 16:04:08 -0000 1.2 +++ formatter/org/eclipse/jdt/internal/formatter/ICodeFormatterConstants.java 31 Aug 2010 14:43:11 -0000 @@ -24,12 +24,21 @@ /** annotation on unspecified source*/ public static final int ANNOTATION_UNSPECIFIED = 0; - /** annotation on a member (type, method, field) */ - public static final int ANNOTATION_ON_MEMBER = 1; + /** annotation on a type */ + public static final int ANNOTATION_ON_TYPE = 1; + + /** annotation on a field */ + public static final int ANNOTATION_ON_FIELD = 2; + + /** annotation on a method */ + public static final int ANNOTATION_ON_METHOD = 3; + + /** annotation on a package */ + public static final int ANNOTATION_ON_PACKAGE = 4; /** annotation on a parameter */ - public static final int ANNOTATION_ON_PARAMETER = 2; + public static final int ANNOTATION_ON_PARAMETER = 5; /** annotation on a local variable */ - public static final int ANNOTATION_ON_LOCAL_VARIABLE = 3; + public static final int ANNOTATION_ON_LOCAL_VARIABLE = 6; } Index: formatter/org/eclipse/jdt/internal/formatter/Scribe.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java,v retrieving revision 1.217 diff -u -r1.217 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 31 Aug 2010 07:03:07 -0000 1.217 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 31 Aug 2010 14:43:13 -0000 @@ -4514,8 +4514,23 @@ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=122247 boolean shouldAddNewLine = false; switch (annotationSourceKind) { - case ICodeFormatterConstants.ANNOTATION_ON_MEMBER : - if (this.formatter.preferences.insert_new_line_after_annotation_on_member) { + case ICodeFormatterConstants.ANNOTATION_ON_TYPE : + if (this.formatter.preferences.insert_new_line_after_annotation_on_type) { + shouldAddNewLine = true; + } + break; + case ICodeFormatterConstants.ANNOTATION_ON_FIELD : + if (this.formatter.preferences.insert_new_line_after_annotation_on_field) { + shouldAddNewLine = true; + } + break; + case ICodeFormatterConstants.ANNOTATION_ON_METHOD : + if (this.formatter.preferences.insert_new_line_after_annotation_on_method) { + shouldAddNewLine = true; + } + break; + case ICodeFormatterConstants.ANNOTATION_ON_PACKAGE : + if (this.formatter.preferences.insert_new_line_after_annotation_on_package) { shouldAddNewLine = true; } break; Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.454 diff -u -r1.454 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 21 Jul 2010 14:13:46 -0000 1.454 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 31 Aug 2010 14:43:15 -0000 @@ -2074,6 +2074,16 @@ // backward compatibility addDeprecatedOptions(options); + try { + final IEclipsePreferences eclipsePreferences = this.preferencesLookup[PREF_INSTANCE]; + String[] instanceKeys = eclipsePreferences.keys(); + for (int i=0, length=instanceKeys.length; i + * Nothing is done if the given option is not obsolete or if no migration has been + * specified for it. + *

+ * Migration is only setup for formatter options. + *

+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=308000" + * + * @param options The options map to update + * @param optionName The old option name to update + * @param optionValue The value of the old option name + */ + public void migrateObsoleteOption(Map options, String optionName, String optionValue) { + + // Migrate formatter options + String[] compatibleConstants = DefaultCodeFormatterConstants.getCompatibleConstants(optionName); + if (compatibleConstants != null) { + for (int i=0, length=compatibleConstants.length; i < length; i++) { + options.put(compatibleConstants[i], optionValue); + } + return; + } + } + // Do not modify without modifying getDefaultOptions() private Hashtable getDefaultOptionsNoInitialization() { Map defaultOptionsMap = new CompilerOptions().getMap(); // compiler defaults Index: model/org/eclipse/jdt/internal/core/JavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v retrieving revision 1.434 diff -u -r1.434 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 30 Aug 2010 10:53:26 -0000 1.434 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 31 Aug 2010 14:43:16 -0000 @@ -1637,7 +1637,8 @@ // Get project specific options JavaModelManager.PerProjectInfo perProjectInfo = null; Hashtable projectOptions = null; - HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames; + JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager(); + HashSet optionNames = javaModelManager.optionNames; try { perProjectInfo = getPerProjectInfo(); projectOptions = perProjectInfo.options; @@ -1651,8 +1652,13 @@ for (int i = 0; i < propertyNames.length; i++){ String propertyName = propertyNames[i]; String value = projectPreferences.get(propertyName, null); - if (value != null && optionNames.contains(propertyName)){ - projectOptions.put(propertyName, value.trim()); + if (value != null) { + if (optionNames.contains(propertyName)){ + projectOptions.put(propertyName, value.trim()); + } else { + // Maybe an obsolete preference, try to migrate it... + javaModelManager.migrateObsoleteOption(projectOptions, propertyName, value.trim()); + } } } // cache project options #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java,v retrieving revision 1.260 diff -u -r1.260 FormatterRegressionTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 20 May 2010 09:41:37 -0000 1.260 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 31 Aug 2010 14:43:23 -0000 @@ -10364,7 +10364,10 @@ final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); preferences.line_separator = "\n";//$NON-NLS-1$ - preferences.insert_new_line_after_annotation_on_member = false; + preferences.insert_new_line_after_annotation_on_type = false; + preferences.insert_new_line_after_annotation_on_field = false; + preferences.insert_new_line_after_annotation_on_method = false; + preferences.insert_new_line_after_annotation_on_package = false; preferences.insert_new_line_after_annotation_on_parameter = true; DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences); IRegion[] regions = new IRegion[] { @@ -10378,7 +10381,10 @@ final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); preferences.line_separator = "\n";//$NON-NLS-1$ - preferences.insert_new_line_after_annotation_on_member = false; + preferences.insert_new_line_after_annotation_on_type = false; + preferences.insert_new_line_after_annotation_on_field = false; + preferences.insert_new_line_after_annotation_on_method = false; + preferences.insert_new_line_after_annotation_on_package = false; preferences.insert_new_line_after_annotation_on_parameter = false; DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences); IRegion[] regions = new IRegion[] { @@ -10393,7 +10399,10 @@ final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); preferences.line_separator = "\n";//$NON-NLS-1$ - preferences.insert_new_line_after_annotation_on_member = false; + preferences.insert_new_line_after_annotation_on_type = false; + preferences.insert_new_line_after_annotation_on_field = false; + preferences.insert_new_line_after_annotation_on_method = false; + preferences.insert_new_line_after_annotation_on_package = false; preferences.insert_new_line_after_annotation_on_parameter = true; preferences.insert_new_line_after_annotation_on_local_variable = false; Hashtable javaCoreOptions = JavaCore.getOptions(); @@ -10419,7 +10428,10 @@ public void test707() { final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); - preferences.insert_new_line_after_annotation_on_member = true; + preferences.insert_new_line_after_annotation_on_type = true; + preferences.insert_new_line_after_annotation_on_field = true; + preferences.insert_new_line_after_annotation_on_method = true; + preferences.insert_new_line_after_annotation_on_package = true; preferences.insert_new_line_after_annotation_on_parameter = true; preferences.insert_new_line_after_annotation_on_local_variable = false; preferences.line_separator = "\n";//$NON-NLS-1$ @@ -10447,7 +10459,10 @@ final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); preferences.line_separator = "\n";//$NON-NLS-1$ - preferences.insert_new_line_after_annotation_on_member = true; + preferences.insert_new_line_after_annotation_on_type = true; + preferences.insert_new_line_after_annotation_on_field = true; + preferences.insert_new_line_after_annotation_on_method = true; + preferences.insert_new_line_after_annotation_on_package = true; preferences.insert_new_line_after_annotation_on_parameter = false; preferences.insert_new_line_after_annotation_on_local_variable = false; Hashtable javaCoreOptions = JavaCore.getOptions(); @@ -10473,7 +10488,10 @@ public void test709() { final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); - preferences.insert_new_line_after_annotation_on_member = false; + preferences.insert_new_line_after_annotation_on_type = false; + preferences.insert_new_line_after_annotation_on_field = false; + preferences.insert_new_line_after_annotation_on_method = false; + preferences.insert_new_line_after_annotation_on_package = false; preferences.insert_new_line_after_annotation_on_parameter = false; preferences.insert_new_line_after_annotation_on_local_variable = false; preferences.line_separator = "\n";//$NON-NLS-1$ @@ -10500,7 +10518,10 @@ public void test710() { final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); - preferences.insert_new_line_after_annotation_on_member = false; + preferences.insert_new_line_after_annotation_on_type = false; + preferences.insert_new_line_after_annotation_on_field = false; + preferences.insert_new_line_after_annotation_on_method = false; + preferences.insert_new_line_after_annotation_on_package = false; preferences.insert_new_line_after_annotation_on_parameter = true; preferences.insert_new_line_after_annotation_on_local_variable = true; preferences.line_separator = "\n";//$NON-NLS-1$ @@ -10527,7 +10548,10 @@ public void test711() { final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); - preferences.insert_new_line_after_annotation_on_member = false; + preferences.insert_new_line_after_annotation_on_type = false; + preferences.insert_new_line_after_annotation_on_field = false; + preferences.insert_new_line_after_annotation_on_method = false; + preferences.insert_new_line_after_annotation_on_package = false; preferences.insert_new_line_after_annotation_on_parameter = false; preferences.insert_new_line_after_annotation_on_local_variable = true; preferences.line_separator = "\n";//$NON-NLS-1$ @@ -10726,4 +10750,173 @@ "}\n" ); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=308000 +public void test725() { + this.formatterPrefs = null; + this.formatterOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + String source = + "@Deprecated package pack;\n" + + "public class Test {\n" + + " @Deprecated Test(String s) {}\n" + + " @Deprecated String label;\n" + + " @Deprecated void foo() {}\n" + + " @Deprecated interface I {}\n" + + "}\n"; + formatSource(source, + "@Deprecated\n" + + "package pack;\n" + + "\n" + + "public class Test {\n" + + " @Deprecated\n" + + " Test(String s) {\n" + + " }\n" + + "\n" + + " @Deprecated\n" + + " String label;\n" + + "\n" + + " @Deprecated\n" + + " void foo() {\n" + + " }\n" + + "\n" + + " @Deprecated\n" + + " interface I {\n" + + " }\n" + + "}\n" + ); +} +public void test726() { + this.formatterPrefs = null; + this.formatterOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_TYPE, DefaultCodeFormatterConstants.FALSE); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_FIELD, DefaultCodeFormatterConstants.FALSE); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_METHOD, DefaultCodeFormatterConstants.FALSE); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PACKAGE, DefaultCodeFormatterConstants.FALSE); + String source = + "@Deprecated package pack;\n" + + "public class Test {\n" + + " @Deprecated Test(String s) {}\n" + + " @Deprecated String label;\n" + + " @Deprecated void foo() {}\n" + + " @Deprecated interface I {}\n" + + "}\n"; + formatSource(source, + "@Deprecated package pack;\n" + + "\n" + + "public class Test {\n" + + " @Deprecated Test(String s) {\n" + + " }\n" + + "\n" + + " @Deprecated String label;\n" + + "\n" + + " @Deprecated void foo() {\n" + + " }\n" + + "\n" + + " @Deprecated interface I {\n" + + " }\n" + + "}\n" + ); +} + +/** + * @deprecated Use a deprecated formatter option. + */ +public void test727() { + this.formatterPrefs = null; + this.formatterOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, DefaultCodeFormatterConstants.TRUE); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER, DefaultCodeFormatterConstants.FALSE); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER, DefaultCodeFormatterConstants.FALSE); + String source = + "@Deprecated package pack;\n" + + "public class Test {\n" + + " @Deprecated Test(String s) {}\n" + + " @Deprecated String label;\n" + + " @Deprecated void foo() {}\n" + + " @Deprecated interface I {}\n" + + "}\n"; + formatSource(source, + "@Deprecated package pack;\n" + + "\n" + + "public class Test {\n" + + " @Deprecated Test(String s) {\n" + + " }\n" + + "\n" + + " @Deprecated String label;\n" + + "\n" + + " @Deprecated void foo() {\n" + + " }\n" + + "\n" + + " @Deprecated interface I {\n" + + " }\n" + + "}\n" + ); +} + +/** + * @deprecated Use a deprecated formatter option. + */ +public void test728() { + this.formatterPrefs = null; + this.formatterOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION, DefaultCodeFormatterConstants.FALSE); + String source = + "@Deprecated package pack;\n" + + "public class Test {\n" + + " @Deprecated Test(String s) {}\n" + + " @Deprecated String label;\n" + + " @Deprecated void foo() {}\n" + + " @Deprecated interface I {}\n" + + "}\n"; + formatSource(source, + "@Deprecated package pack;\n" + + "\n" + + "public class Test {\n" + + " @Deprecated Test(String s) {\n" + + " }\n" + + "\n" + + " @Deprecated String label;\n" + + "\n" + + " @Deprecated void foo() {\n" + + " }\n" + + "\n" + + " @Deprecated interface I {\n" + + " }\n" + + "}\n" + ); +} +public void testONLY_729() { + this.formatterPrefs = null; + String profilePath = getResource("profiles", "b308000.xml"); + this.formatterOptions = DecodeCodeFormatterPreferences.decodeCodeFormatterOptions(profilePath, "b308000"); + assertNotNull("No preferences", this.formatterOptions); + String source = + "package p;\n" + + "\n" + + "@Deprecated public class C {\n" + + " @Deprecated public static void main(@Deprecated String[] args) {\n" + + " @Deprecated int i= 2;\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n"; + formatSource(source, + "package p;\n" + + "\n" + + "@Deprecated public class C {\n" + + " @Deprecated public static void main(@Deprecated String[] args) {\n" + + " @Deprecated\n" + + " int i = 2;\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n" + ); +} + } Index: workspace/Formatter/profiles/b308000.xml =================================================================== RCS file: workspace/Formatter/profiles/b308000.xml diff -N workspace/Formatter/profiles/b308000.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/Formatter/profiles/b308000.xml 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +