]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/text/correction/SerialVersionSubProcessor.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / text / correction / SerialVersionSubProcessor.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.text.correction;
12
13 import java.util.Collection;
14 import java.util.Hashtable;
15 import java.util.Map;
16
17 import org.eclipse.core.runtime.Assert;
18 import org.eclipse.core.runtime.IProgressMonitor;
19
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;
23
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;
29
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;
33
34 /**
35  * Subprocessor for serial version quickfix proposals.
36  *
37  * @since 3.1
38  */
39 public final class SerialVersionSubProcessor {
40
41         public static final class SerialVersionProposal extends FixCorrectionProposal {
42                 private boolean fIsDefaultProposal;
43
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;
47                 }
48
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);
52                         if (isDefault) {
53                                 options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_DEFAULT, CleanUpOptions.TRUE);
54                         } else {
55                                 options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_GENERATED, CleanUpOptions.TRUE);
56                         }
57                         return new PotentialProgrammingProblemsCleanUp(options);
58                 }
59
60                 public boolean isDefaultProposal() {
61                         return fIsDefaultProposal;
62                 }
63
64                 /**
65                  * {@inheritDoc}
66                  */
67                 @Override
68                 public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
69                         if (fIsDefaultProposal) {
70                                 return CorrectionMessages.SerialVersionDefaultProposal_message_default_info;
71                         } else {
72                                 return CorrectionMessages.SerialVersionHashProposal_message_generated_info;
73                         }
74                 }
75         }
76
77
78         /**
79          * Determines the serial version quickfix proposals.
80          *
81          * @param context
82          *        the invocation context
83          * @param location
84          *        the problem location
85          * @param proposals
86          *        the proposal collection to extend
87          */
88         public static final void getSerialVersionProposals(final IInvocationContext context, final IProblemLocation location, final Collection<ICommandAccess> proposals) {
89
90                 Assert.isNotNull(context);
91                 Assert.isNotNull(location);
92                 Assert.isNotNull(proposals);
93
94                 IProposableFix[] fixes= PotentialProgrammingProblemsFix.createMissingSerialVersionFixes(context.getASTRoot(), location);
95                 if (fixes != null) {
96                         proposals.add(new SerialVersionProposal(fixes[0], 9, context, true));
97                         proposals.add(new SerialVersionProposal(fixes[1], 9, context, false));
98                 }
99         }
100 }