1 /*******************************************************************************
2 * Copyright (c) 2000, 2012 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.text.correction;
13 import java.util.Collection;
14 import java.util.Hashtable;
17 import org.eclipse.core.runtime.Assert;
18 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
21 import org.eclipse.jdt.internal.corext.fix.IProposableFix;
22 import org.eclipse.jdt.internal.corext.fix.PotentialProgrammingProblemsFix;
24 import org.eclipse.jdt.ui.cleanup.CleanUpOptions;
25 import org.eclipse.jdt.ui.cleanup.ICleanUp;
26 import org.eclipse.jdt.ui.text.java.IInvocationContext;
27 import org.eclipse.jdt.ui.text.java.IProblemLocation;
28 import org.eclipse.jdt.ui.text.java.correction.ICommandAccess;
30 import org.eclipse.jdt.internal.ui.JavaPluginImages;
31 import org.eclipse.jdt.internal.ui.fix.PotentialProgrammingProblemsCleanUp;
32 import org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal;
35 * Subprocessor for serial version quickfix proposals.
39 public final class SerialVersionSubProcessor {
41 public static final class SerialVersionProposal extends FixCorrectionProposal {
42 private boolean fIsDefaultProposal;
44 public SerialVersionProposal(IProposableFix fix, int relevance, IInvocationContext context, boolean isDefault) {
45 super(fix, createCleanUp(isDefault), relevance, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD), context);
46 fIsDefaultProposal= isDefault;
49 private static ICleanUp createCleanUp(boolean isDefault) {
50 Map<String, String> options= new Hashtable<String, String>();
51 options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID, CleanUpOptions.TRUE);
53 options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_DEFAULT, CleanUpOptions.TRUE);
55 options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_GENERATED, CleanUpOptions.TRUE);
57 return new PotentialProgrammingProblemsCleanUp(options);
60 public boolean isDefaultProposal() {
61 return fIsDefaultProposal;
68 public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
69 if (fIsDefaultProposal) {
70 return CorrectionMessages.SerialVersionDefaultProposal_message_default_info;
72 return CorrectionMessages.SerialVersionHashProposal_message_generated_info;
79 * Determines the serial version quickfix proposals.
82 * the invocation context
84 * the problem location
86 * the proposal collection to extend
88 public static final void getSerialVersionProposals(final IInvocationContext context, final IProblemLocation location, final Collection<ICommandAccess> proposals) {
90 Assert.isNotNull(context);
91 Assert.isNotNull(location);
92 Assert.isNotNull(proposals);
94 IProposableFix[] fixes= PotentialProgrammingProblemsFix.createMissingSerialVersionFixes(context.getASTRoot(), location);
96 proposals.add(new SerialVersionProposal(fixes[0], 9, context, true));
97 proposals.add(new SerialVersionProposal(fixes[1], 9, context, false));