]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.corext.fix; | |
12 | ||
13 | import org.eclipse.core.runtime.Assert; | |
14 | ||
15 | import org.eclipse.jdt.core.ICompilationUnit; | |
16 | import org.eclipse.jdt.core.dom.ASTNode; | |
17 | import org.eclipse.jdt.core.dom.Expression; | |
18 | import org.eclipse.jdt.core.dom.VariableDeclarationFragment; | |
19 | import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; | |
20 | ||
21 | ||
22 | /** | |
23 | * Proposal for a default serial version id. | |
24 | * | |
25 | * @since 3.1 | |
26 | */ | |
27 | public final class SerialVersionDefaultOperation extends AbstractSerialVersionOperation { | |
28 | ||
29 | /** The initializer linked position group id */ | |
30 | private static final String GROUP_INITIALIZER= "initializer"; //$NON-NLS-1$ | |
31 | ||
32 | /** | |
33 | * Creates a new serial version default proposal. | |
34 | * | |
35 | * @param unit | |
36 | * the compilation unit | |
37 | * @param nodes | |
38 | * the originally selected nodes | |
39 | */ | |
40 | public SerialVersionDefaultOperation(ICompilationUnit unit, ASTNode[] nodes) { | |
41 | super(unit, nodes); | |
42 | } | |
43 | ||
44 | ||
45 | /** | |
46 | * {@inheritDoc} | |
47 | */ | |
48 | @Override | |
49 | protected boolean addInitializer(final VariableDeclarationFragment fragment, final ASTNode declarationNode) { | |
50 | Assert.isNotNull(fragment); | |
51 | ||
52 | final Expression expression= fragment.getAST().newNumberLiteral(DEFAULT_EXPRESSION); | |
53 | if (expression != null) | |
54 | fragment.setInitializer(expression); | |
55 | return true; | |
56 | } | |
57 | ||
58 | /** | |
59 | * {@inheritDoc} | |
60 | */ | |
61 | @Override | |
62 | protected void addLinkedPositions(final ASTRewrite rewrite, final VariableDeclarationFragment fragment, final LinkedProposalModel positionGroups) { | |
63 | ||
64 | Assert.isNotNull(rewrite); | |
65 | Assert.isNotNull(fragment); | |
66 | ||
67 | final Expression initializer= fragment.getInitializer(); | |
68 | if (initializer != null) { | |
69 | LinkedProposalPositionGroup group= new LinkedProposalPositionGroup(GROUP_INITIALIZER); | |
70 | group.generated_2390643363755428768(rewrite, positionGroups, initializer); | |
71 | } | |
72 | } | |
73 | ||
74 | } |