Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 235750
Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/fix/Java50CleanUp.java (-15 / +40 lines)
Lines 66-73 Link Here
66
	 */
66
	 */
67
	protected ICleanUpFix createFix(CompilationUnit compilationUnit) throws CoreException {
67
	protected ICleanUpFix createFix(CompilationUnit compilationUnit) throws CoreException {
68
		boolean addAnotations= isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS);
68
		boolean addAnotations= isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS);
69
		boolean addOverride= isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE);
69
		return Java50Fix.createCleanUp(compilationUnit,
70
		return Java50Fix.createCleanUp(compilationUnit,
70
				addAnotations && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE),
71
				addAnotations && addOverride,
72
				addAnotations && addOverride && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION),
71
				addAnotations && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED),
73
				addAnotations && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED),
72
				isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES));
74
				isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES));
73
	}
75
	}
Lines 79-94 Link Here
79
		if (compilationUnit == null)
81
		if (compilationUnit == null)
80
			return null;
82
			return null;
81
83
84
		boolean addAnnotations= isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS);
85
		boolean addOverride= isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE);
82
		return Java50Fix.createCleanUp(compilationUnit, problems,
86
		return Java50Fix.createCleanUp(compilationUnit, problems,
83
				isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE),
87
				addAnnotations && addOverride,
84
				isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED),
88
				addAnnotations && addOverride && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION),
89
				addAnnotations && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED),
85
				isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES));
90
				isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES));
86
	}
91
	}
87
92
88
	private Map getRequiredOptions() {
93
	private Map getRequiredOptions() {
89
		Map result= new Hashtable();
94
		Map result= new Hashtable();
90
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE))
95
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
91
			result.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.WARNING);
96
			result.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.WARNING);
97
			if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION)) {
98
				result.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, JavaCore.ENABLED);
99
			}
100
		}
92
101
93
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED))
102
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED))
94
			result.put(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION, JavaCore.WARNING);
103
			result.put(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION, JavaCore.WARNING);
Lines 104-111 Link Here
104
	 */
113
	 */
105
	public String[] getStepDescriptions() {
114
	public String[] getStepDescriptions() {
106
		List result= new ArrayList();
115
		List result= new ArrayList();
107
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE))
116
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
108
			result.add(MultiFixMessages.Java50MultiFix_AddMissingOverride_description);
117
			result.add(MultiFixMessages.Java50MultiFix_AddMissingOverride_description);
118
			if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION)) {
119
				result.add("Add missing '@Override' annotations to implementations of interface methods");
120
			}
121
		}
109
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED))
122
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED))
110
			result.add(MultiFixMessages.Java50MultiFix_AddMissingDeprecated_description);
123
			result.add(MultiFixMessages.Java50MultiFix_AddMissingDeprecated_description);
111
		if (isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES))
124
		if (isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES))
Lines 128-138 Link Here
128
		}
141
		}
129
		buf.append("    public void foo() {}\n"); //$NON-NLS-1$
142
		buf.append("    public void foo() {}\n"); //$NON-NLS-1$
130
		buf.append("}\n"); //$NON-NLS-1$
143
		buf.append("}\n"); //$NON-NLS-1$
131
		buf.append("class ESub extends E {\n"); //$NON-NLS-1$
144
		buf.append("class ESub extends E implements Runnable {\n"); //$NON-NLS-1$
132
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
145
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
133
			buf.append("    @Override\n"); //$NON-NLS-1$
146
			buf.append("    @Override\n"); //$NON-NLS-1$
134
		}
147
		}
135
		buf.append("    public void foo() {}\n"); //$NON-NLS-1$
148
		buf.append("    public void foo() {}\n"); //$NON-NLS-1$
149
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS)
150
				&& isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)
151
				&& isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION)) {
152
			buf.append("    @Override\n"); //$NON-NLS-1$
153
		}
154
		buf.append("    public void run() {}\n"); //$NON-NLS-1$
136
		buf.append("}\n"); //$NON-NLS-1$
155
		buf.append("}\n"); //$NON-NLS-1$
137
156
138
		return buf.toString();
157
		return buf.toString();
Lines 144-157 Link Here
144
	public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) {
163
	public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) {
145
		int id= problem.getProblemId();
164
		int id= problem.getProblemId();
146
		
165
		
147
		if (Java50Fix.isMissingOverrideAnnotationProblem(id))
166
		if (Java50Fix.isMissingOverrideAnnotationProblem(id)) {
148
			return isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE);
167
			if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
149
168
				return ! Java50Fix.isMissingOverrideAnnotationInterfaceProblem(id) || isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION);
150
		if (Java50Fix.isMissingDeprecationProblem(id))
169
			}
170
			
171
		} else if (Java50Fix.isMissingDeprecationProblem(id)) {
151
			return isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED);
172
			return isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED);
152
173
			
153
		if (Java50Fix.isRawTypeReferenceProblem(id))
174
		} else if (Java50Fix.isRawTypeReferenceProblem(id)) {
154
			return isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES);
175
			return isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES);
176
		}
155
177
156
		return false;
178
		return false;
157
	}
179
	}
Lines 162-176 Link Here
162
	public int computeNumberOfFixes(CompilationUnit compilationUnit) {
184
	public int computeNumberOfFixes(CompilationUnit compilationUnit) {
163
		int result= 0;
185
		int result= 0;
164
		
186
		
165
		boolean addMissingOverride= isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE);
187
		boolean addAnnotations= isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS);
166
		boolean addMissingDeprecated= isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED);
188
		boolean addMissingOverride= addAnnotations && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE);
189
		boolean addMissingOverrideInterfaceMethods= addMissingOverride && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION);
190
		boolean addMissingDeprecated= addAnnotations && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED);
167
		boolean useTypeArgs= isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES);
191
		boolean useTypeArgs= isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES);
168
		
192
		
169
		IProblem[] problems= compilationUnit.getProblems();
193
		IProblem[] problems= compilationUnit.getProblems();
170
		for (int i= 0; i < problems.length; i++) {
194
		for (int i= 0; i < problems.length; i++) {
171
			int id= problems[i].getID();
195
			int id= problems[i].getID();
172
			if (addMissingOverride && Java50Fix.isMissingOverrideAnnotationProblem(id))
196
			if (addMissingOverride && Java50Fix.isMissingOverrideAnnotationProblem(id))
173
				result++;
197
				if (! Java50Fix.isMissingOverrideAnnotationInterfaceProblem(id) || addMissingOverrideInterfaceMethods)
198
					result++;
174
			if (addMissingDeprecated && Java50Fix.isMissingDeprecationProblem(id))
199
			if (addMissingDeprecated && Java50Fix.isMissingDeprecationProblem(id))
175
				result++;
200
				result++;
176
			if (useTypeArgs && Java50Fix.isRawTypeReferenceProblem(id))
201
			if (useTypeArgs && Java50Fix.isRawTypeReferenceProblem(id))
(-)ui/org/eclipse/jdt/internal/ui/fix/PotentialProgrammingProblemsCleanUp.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 115-121 Link Here
115
	public String getPreview() {
115
	public String getPreview() {
116
		StringBuffer buf= new StringBuffer();
116
		StringBuffer buf= new StringBuffer();
117
117
118
		buf.append("class E implements java.io.Serializable{\n"); //$NON-NLS-1$
118
		buf.append("class E implements java.io.Serializable {\n"); //$NON-NLS-1$
119
		if ((isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID) && isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_GENERATED))) {
119
		if ((isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID) && isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_GENERATED))) {
120
			buf.append("    private static final long serialVersionUID = -391484377137870342L;\n"); //$NON-NLS-1$
120
			buf.append("    private static final long serialVersionUID = -391484377137870342L;\n"); //$NON-NLS-1$
121
		} else if ((isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID) && isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_DEFAULT))) {
121
		} else if ((isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID) && isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_DEFAULT))) {
(-)core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java (+27 lines)
Lines 832-837 Link Here
832
	public static final String ADD_MISSING_ANNOTATIONS_OVERRIDE= "cleanup.add_missing_override_annotations"; //$NON-NLS-1$
832
	public static final String ADD_MISSING_ANNOTATIONS_OVERRIDE= "cleanup.add_missing_override_annotations"; //$NON-NLS-1$
833
833
834
	/**
834
	/**
835
	 * Add '@Override' annotation in front of methods that override or implement a superinterface method.
836
	 * <p>
837
	 * Example:
838
	 * 
839
	 * <pre>
840
	 *                   interface I {void foo();}
841
	 *                   class E implements I {
842
	 *                   	 void foo(); -&gt;  @Override void foo();
843
	 *                   }
844
	 * </pre>
845
	 * 
846
	 * Only has an effect if {@link #ADD_MISSING_ANNOTATIONS} and {@link #ADD_MISSING_ANNOTATIONS_OVERRIDE} are TRUE and
847
	 * the compiler compliance is 1.6 or higher.<br>
848
	 * <br>
849
	 * Possible values: {TRUE, FALSE}<br>
850
	 * 
851
	 * <br>
852
	 * 
853
	 * @see CleanUpOptions#TRUE
854
	 * @see CleanUpOptions#FALSE
855
	 * @since 3.6
856
	 */
857
	public static final String ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION= "cleanup.add_missing_override_annotations_interface_methods"; //$NON-NLS-1$
858
	
859
	/**
835
	 * Add '@Deprecated' annotation in front of deprecated members.
860
	 * Add '@Deprecated' annotation in front of deprecated members.
836
	 * <p>
861
	 * <p>
837
	 * Example:
862
	 * Example:
Lines 1127-1132 Link Here
1127
		//Missing Code
1152
		//Missing Code
1128
		options.setOption(ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE);
1153
		options.setOption(ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE);
1129
		options.setOption(ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE);
1154
		options.setOption(ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE);
1155
		options.setOption(ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION, CleanUpOptions.TRUE);
1130
		options.setOption(ADD_MISSING_ANNOTATIONS_DEPRECATED, CleanUpOptions.TRUE);
1156
		options.setOption(ADD_MISSING_ANNOTATIONS_DEPRECATED, CleanUpOptions.TRUE);
1131
1157
1132
		options.setOption(ADD_MISSING_SERIAL_VERSION_ID, CleanUpOptions.FALSE);
1158
		options.setOption(ADD_MISSING_SERIAL_VERSION_ID, CleanUpOptions.FALSE);
Lines 1206-1211 Link Here
1206
		//Missing Code
1232
		//Missing Code
1207
		options.setOption(ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE);
1233
		options.setOption(ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE);
1208
		options.setOption(ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE);
1234
		options.setOption(ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE);
1235
		options.setOption(ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION, CleanUpOptions.TRUE);
1209
		options.setOption(ADD_MISSING_ANNOTATIONS_DEPRECATED, CleanUpOptions.TRUE);
1236
		options.setOption(ADD_MISSING_ANNOTATIONS_DEPRECATED, CleanUpOptions.TRUE);
1210
1237
1211
		options.setOption(ADD_MISSING_SERIAL_VERSION_ID, CleanUpOptions.FALSE);
1238
		options.setOption(ADD_MISSING_SERIAL_VERSION_ID, CleanUpOptions.FALSE);
(-)core extension/org/eclipse/jdt/internal/corext/fix/Java50Fix.java (-12 / +21 lines)
Lines 157-162 Link Here
157
		return createFix(compilationUnit, problem, OVERRIDE, FixMessages.Java50Fix_AddOverride_description);
157
		return createFix(compilationUnit, problem, OVERRIDE, FixMessages.Java50Fix_AddOverride_description);
158
	}
158
	}
159
159
160
	public static boolean isMissingOverrideAnnotationInterfaceProblem(int id) {
161
		return id == IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation;
162
	}
163
	
160
	public static boolean isMissingOverrideAnnotationProblem(int id) {
164
	public static boolean isMissingOverrideAnnotationProblem(int id) {
161
		return id == IProblem.MissingOverrideAnnotation || id == IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation;
165
		return id == IProblem.MissingOverrideAnnotation || id == IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation;
162
	}
166
	}
Lines 205-210 Link Here
205
209
206
	public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit,
210
	public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit,
207
			boolean addOverrideAnnotation,
211
			boolean addOverrideAnnotation,
212
			boolean addOverrideInterfaceAnnotation,
208
			boolean addDeprecatedAnnotation,
213
			boolean addDeprecatedAnnotation,
209
			boolean rawTypeReference) {
214
			boolean rawTypeReference) {
210
215
Lines 224-230 Link Here
224
		}
229
		}
225
230
226
		if (addOverrideAnnotation)
231
		if (addOverrideAnnotation)
227
			createAddOverrideAnnotationOperations(compilationUnit, locations, operations);
232
			createAddOverrideAnnotationOperations(compilationUnit, addOverrideInterfaceAnnotation, locations, operations);
228
233
229
		if (addDeprecatedAnnotation)
234
		if (addDeprecatedAnnotation)
230
			createAddDeprecatedAnnotationOperations(compilationUnit, locations, operations);
235
			createAddDeprecatedAnnotationOperations(compilationUnit, locations, operations);
Lines 248-253 Link Here
248
253
249
	public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] problems,
254
	public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] problems,
250
			boolean addOverrideAnnotation,
255
			boolean addOverrideAnnotation,
256
			boolean addOverrideInterfaceAnnotation,
251
			boolean addDeprecatedAnnotation,
257
			boolean addDeprecatedAnnotation,
252
			boolean rawTypeReferences) {
258
			boolean rawTypeReferences) {
253
259
Lines 261-267 Link Here
261
		List/*<CompilationUnitRewriteOperation>*/ operations= new ArrayList();
267
		List/*<CompilationUnitRewriteOperation>*/ operations= new ArrayList();
262
268
263
		if (addOverrideAnnotation)
269
		if (addOverrideAnnotation)
264
			createAddOverrideAnnotationOperations(compilationUnit, problems, operations);
270
			createAddOverrideAnnotationOperations(compilationUnit, addOverrideInterfaceAnnotation, problems, operations);
265
271
266
		if (addDeprecatedAnnotation)
272
		if (addDeprecatedAnnotation)
267
			createAddDeprecatedAnnotationOperations(compilationUnit, problems, operations);
273
			createAddDeprecatedAnnotationOperations(compilationUnit, problems, operations);
Lines 296-314 Link Here
296
		}
302
		}
297
	}
303
	}
298
304
299
	private static void createAddOverrideAnnotationOperations(CompilationUnit compilationUnit, IProblemLocation[] locations, List result) {
305
	private static void createAddOverrideAnnotationOperations(CompilationUnit compilationUnit, boolean addOverrideInterfaceAnnotation, IProblemLocation[] locations, List result) {
300
		for (int i= 0; i < locations.length; i++) {
306
		for (int i= 0; i < locations.length; i++) {
301
			IProblemLocation problem= locations[i];
307
			IProblemLocation problem= locations[i];
308
			int problemId= problem.getProblemId();
302
			
309
			
303
			if (isMissingOverrideAnnotationProblem(problem.getProblemId())) {
310
			if (isMissingOverrideAnnotationProblem(problemId)) {
304
				ASTNode selectedNode= problem.getCoveringNode(compilationUnit);
311
				if (!isMissingOverrideAnnotationInterfaceProblem(problemId) || addOverrideInterfaceAnnotation) {
305
				if (selectedNode != null) {
312
					ASTNode selectedNode= problem.getCoveringNode(compilationUnit);
306
313
					if (selectedNode != null) {
307
					ASTNode declaringNode= getDeclaringNode(selectedNode);
314
	
308
					if (declaringNode instanceof BodyDeclaration) {
315
						ASTNode declaringNode= getDeclaringNode(selectedNode);
309
						BodyDeclaration declaration= (BodyDeclaration) declaringNode;
316
						if (declaringNode instanceof BodyDeclaration) {
310
						AnnotationRewriteOperation operation= new AnnotationRewriteOperation(declaration, OVERRIDE);
317
							BodyDeclaration declaration= (BodyDeclaration) declaringNode;
311
						result.add(operation);
318
							AnnotationRewriteOperation operation= new AnnotationRewriteOperation(declaration, OVERRIDE);
319
							result.add(operation);
320
						}
312
					}
321
					}
313
				}
322
				}
314
			}
323
			}
(-)ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties (+1 lines)
Lines 68-73 Link Here
68
MissingCodeTabPage_GroupName_PotentialProgrammingProblems=Potential programming problems
68
MissingCodeTabPage_GroupName_PotentialProgrammingProblems=Potential programming problems
69
MissingCodeTabPage_CheckboxName_AddMissingAnnotations=Add missing &Annotations
69
MissingCodeTabPage_CheckboxName_AddMissingAnnotations=Add missing &Annotations
70
MissingCodeTabPage_CheckboxName_AddMissingOverrideAnnotations='@Overr&ide'
70
MissingCodeTabPage_CheckboxName_AddMissingOverrideAnnotations='@Overr&ide'
71
MissingCodeTabPage_CheckboxName_AddMissingOverrideInterfaceAnnotations=Implemen&tations of interface methods (1.6 or higher)
71
MissingCodeTabPage_CheckboxName_AddMissingDeprecatedAnnotations='@&Deprecated'
72
MissingCodeTabPage_CheckboxName_AddMissingDeprecatedAnnotations='@&Deprecated'
72
MissingCodeTabPage_CheckboxName_AddMethods=Add u&nimplemented methods
73
MissingCodeTabPage_CheckboxName_AddMethods=Add u&nimplemented methods
73
MissingCodeTabPage_CheckboxName_AddSUID=Add &serial version ID
74
MissingCodeTabPage_CheckboxName_AddSUID=Add &serial version ID
(-)ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java (+2 lines)
Lines 83-88 Link Here
83
	public static String MissingCodeTabPage_CheckboxName_AddMissingAnnotations;
83
	public static String MissingCodeTabPage_CheckboxName_AddMissingAnnotations;
84
	public static String MissingCodeTabPage_CheckboxName_AddMissingDeprecatedAnnotations;
84
	public static String MissingCodeTabPage_CheckboxName_AddMissingDeprecatedAnnotations;
85
	public static String MissingCodeTabPage_CheckboxName_AddMissingOverrideAnnotations;
85
	public static String MissingCodeTabPage_CheckboxName_AddMissingOverrideAnnotations;
86
87
	public static String MissingCodeTabPage_CheckboxName_AddMissingOverrideInterfaceAnnotations;
86
	public static String MissingCodeTabPage_CheckboxName_AddMethods;
88
	public static String MissingCodeTabPage_CheckboxName_AddMethods;
87
	public static String MissingCodeTabPage_CheckboxName_AddSUID;
89
	public static String MissingCodeTabPage_CheckboxName_AddSUID;
88
	public static String MissingCodeTabPage_GroupName_Annotations;
90
	public static String MissingCodeTabPage_GroupName_Annotations;
(-)ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpTabPage.java (-1 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
(-)ui/org/eclipse/jdt/internal/ui/preferences/cleanup/MissingCodeTabPage.java (-3 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.ui.preferences.cleanup;
11
package org.eclipse.jdt.internal.ui.preferences.cleanup;
12
12
13
import java.util.Map;
13
import java.util.Map;
14
import java.util.Observable;
15
import java.util.Observer;
14
16
15
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Group;
18
import org.eclipse.swt.widgets.Group;
Lines 38-49 Link Here
38
40
39
    	Group annotationsGroup= createGroup(numColumns, composite, CleanUpMessages.MissingCodeTabPage_GroupName_Annotations);
41
    	Group annotationsGroup= createGroup(numColumns, composite, CleanUpMessages.MissingCodeTabPage_GroupName_Annotations);
40
42
41
    	final CheckboxPreference annotationsPref= createCheckboxPref(annotationsGroup, numColumns, CleanUpMessages.MissingCodeTabPage_CheckboxName_AddMissingAnnotations, CleanUpConstants.ADD_MISSING_ANNOTATIONS, CleanUpModifyDialog.FALSE_TRUE);
43
		final CheckboxPreference annotationsPref= createCheckboxPref(annotationsGroup, numColumns, CleanUpMessages.MissingCodeTabPage_CheckboxName_AddMissingAnnotations, CleanUpConstants.ADD_MISSING_ANNOTATIONS, CleanUpModifyDialog.FALSE_TRUE);
42
    	intent(annotationsGroup);
44
		
45
		intent(annotationsGroup);
43
		final CheckboxPreference overridePref= createCheckboxPref(annotationsGroup, numColumns - 1, CleanUpMessages.MissingCodeTabPage_CheckboxName_AddMissingOverrideAnnotations, CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpModifyDialog.FALSE_TRUE);
46
		final CheckboxPreference overridePref= createCheckboxPref(annotationsGroup, numColumns - 1, CleanUpMessages.MissingCodeTabPage_CheckboxName_AddMissingOverrideAnnotations, CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpModifyDialog.FALSE_TRUE);
44
		intent(annotationsGroup);
47
		intent(annotationsGroup);
48
		intent(annotationsGroup);
49
		final CheckboxPreference overrideInterfacePref= createCheckboxPref(annotationsGroup, numColumns - 2, CleanUpMessages.MissingCodeTabPage_CheckboxName_AddMissingOverrideInterfaceAnnotations, CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION, CleanUpModifyDialog.FALSE_TRUE);
50
		
51
		intent(annotationsGroup);
45
		final CheckboxPreference deprecatedPref= createCheckboxPref(annotationsGroup, numColumns - 1, CleanUpMessages.MissingCodeTabPage_CheckboxName_AddMissingDeprecatedAnnotations, CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED, CleanUpModifyDialog.FALSE_TRUE);
52
		final CheckboxPreference deprecatedPref= createCheckboxPref(annotationsGroup, numColumns - 1, CleanUpMessages.MissingCodeTabPage_CheckboxName_AddMissingDeprecatedAnnotations, CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED, CleanUpModifyDialog.FALSE_TRUE);
53
		
54
		/* This observable preferences framework is over-designed but under-performing.
55
		 * I didn't find an easy way to make it work for non-trivial (3-level) dependencies, so I just do it by hand for now...
56
		 */
57
		// Need to add observer before registering slaves below, since java.util.Observable notifies in wrong order!
58
		annotationsPref.addObserver(new Observer() {
59
			public void update(Observable o, Object arg) {
60
				boolean enabled= overridePref.getEnabled() && overridePref.getChecked();
61
				overrideInterfacePref.setEnabled(enabled);
62
			}
63
		});
64
		
46
		registerSlavePreference(annotationsPref, new CheckboxPreference[] {overridePref, deprecatedPref});
65
		registerSlavePreference(annotationsPref, new CheckboxPreference[] {overridePref, deprecatedPref});
66
		registerSlavePreference(overridePref, new CheckboxPreference[] {overrideInterfacePref});
67
		
68
		overrideInterfacePref.setEnabled(overridePref.getEnabled() && overridePref.getChecked());
47
69
48
		if (!isSaveAction()) {
70
		if (!isSaveAction()) {
49
			Group pppGroup= createGroup(numColumns, composite, CleanUpMessages.MissingCodeTabPage_GroupName_PotentialProgrammingProblems);
71
			Group pppGroup= createGroup(numColumns, composite, CleanUpMessages.MissingCodeTabPage_GroupName_PotentialProgrammingProblems);
(-)ui/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessor.java (+1 lines)
Lines 690-695 Link Here
690
			Map options= new Hashtable();
690
			Map options= new Hashtable();
691
			options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE);
691
			options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE);
692
			options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE);
692
			options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE);
693
			options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION, CleanUpOptions.TRUE);
693
			FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new Java50CleanUp(options), 15, image, context);
694
			FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new Java50CleanUp(options), 15, image, context);
694
			proposals.add(proposal);
695
			proposals.add(proposal);
695
		}
696
		}

Return to bug 235750