KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > fix > SerialVersionDefaultOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 JavaDoc 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     protected boolean addInitializer(final VariableDeclarationFragment fragment, final ASTNode declarationNode) {
49         Assert.isNotNull(fragment);
50
51         final Expression expression= fragment.getAST().newNumberLiteral(DEFAULT_EXPRESSION);
52         if (expression != null)
53             fragment.setInitializer(expression);
54         return true;
55     }
56
57     /**
58      * {@inheritDoc}
59      */

60     protected void addLinkedPositions(final ASTRewrite rewrite, final VariableDeclarationFragment fragment, final LinkedProposalModel positionGroups) {
61
62         Assert.isNotNull(rewrite);
63         Assert.isNotNull(fragment);
64
65         final Expression initializer= fragment.getInitializer();
66         if (initializer != null) {
67             LinkedProposalPositionGroup group= new LinkedProposalPositionGroup(GROUP_INITIALIZER);
68             group.addPosition(rewrite.track(initializer), true);
69             positionGroups.addPositionGroup(group);
70         }
71     }
72
73 }
74
Popular Tags