KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > code > ScriptableRefactoring


1 /*******************************************************************************
2  * Copyright (c) 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.refactoring.code;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.ltk.core.refactoring.Refactoring;
16 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
17
18 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
19 import org.eclipse.jdt.internal.corext.refactoring.tagging.ICommentProvider;
20 import org.eclipse.jdt.internal.corext.refactoring.tagging.IScriptableRefactoring;
21 import org.eclipse.jdt.internal.corext.util.Messages;
22
23 import org.eclipse.jdt.ui.JavaElementLabels;
24
25 /**
26  * Partial implementation of a scriptable refactoring which provides a comment
27  * for the history.
28  *
29  * @since 3.2
30  */

31 public abstract class ScriptableRefactoring extends Refactoring implements IScriptableRefactoring, ICommentProvider {
32
33     /**
34      * Creates a fatal error status telling that the input element does not
35      * exist.
36      *
37      * @param element
38      * the input element, or <code>null</code>
39      * @param name
40      * the name of the refactoring
41      * @param id
42      * the id of the refactoring
43      * @return the refactoring status
44      */

45     public static RefactoringStatus createInputFatalStatus(final Object JavaDoc element, final String JavaDoc name, final String JavaDoc id) {
46         Assert.isNotNull(name);
47         Assert.isNotNull(id);
48         if (element != null)
49             return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_input_not_exists, new String JavaDoc[] { JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED), name, id}));
50         else
51             return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist, new String JavaDoc[] { name, id}));
52     }
53
54     /**
55      * Creates a warning status telling that the input element does not exist.
56      *
57      * @param element
58      * the input element, or <code>null</code>
59      * @param name
60      * the name of the refactoring
61      * @param id
62      * the id of the refactoring
63      * @return the refactoring status
64      */

65     public static RefactoringStatus createInputWarningStatus(final Object JavaDoc element, final String JavaDoc name, final String JavaDoc id) {
66         Assert.isNotNull(name);
67         Assert.isNotNull(id);
68         if (element != null)
69             return RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_input_not_exists, new String JavaDoc[] { JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED), name, id}));
70         else
71             return RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist, new String JavaDoc[] { name, id}));
72     }
73
74     /** The comment */
75     private String JavaDoc fComment;
76
77     /**
78      * {@inheritDoc}
79      */

80     public boolean canEnableComment() {
81         return true;
82     }
83
84     /**
85      * Creates a fatal error status telling that the input element does not
86      * exist.
87      *
88      * @param element
89      * the input element, or <code>null</code>
90      * @param id
91      * the id of the refactoring
92      * @return the refactoring status
93      */

94     public final RefactoringStatus createInputFatalStatus(final Object JavaDoc element, final String JavaDoc id) {
95         return createInputFatalStatus(element, getName(), id);
96     }
97
98     /**
99      * Creates a warning status telling that the input element does not exist.
100      *
101      * @param element
102      * the input element, or <code>null</code>
103      * @param id
104      * the id of the refactoring
105      * @return the refactoring status
106      */

107     public final RefactoringStatus createInputWarningStatus(final Object JavaDoc element, final String JavaDoc id) {
108         return createInputWarningStatus(element, getName(), id);
109     }
110
111     /**
112      * {@inheritDoc}
113      */

114     public String JavaDoc getComment() {
115         return fComment;
116     }
117
118     /**
119      * {@inheritDoc}
120      */

121     public void setComment(String JavaDoc comment) {
122         fComment= comment;
123     }
124 }
Popular Tags