001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring.code;
011:
012: import org.eclipse.core.runtime.Assert;
013:
014: import org.eclipse.ltk.core.refactoring.Refactoring;
015: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
016:
017: import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
018: import org.eclipse.jdt.internal.corext.refactoring.tagging.ICommentProvider;
019: import org.eclipse.jdt.internal.corext.refactoring.tagging.IScriptableRefactoring;
020: import org.eclipse.jdt.internal.corext.util.Messages;
021:
022: import org.eclipse.jdt.ui.JavaElementLabels;
023:
024: /**
025: * Partial implementation of a scriptable refactoring which provides a comment
026: * for the history.
027: *
028: * @since 3.2
029: */
030: public abstract class ScriptableRefactoring extends Refactoring
031: implements IScriptableRefactoring, ICommentProvider {
032:
033: /**
034: * Creates a fatal error status telling that the input element does not
035: * exist.
036: *
037: * @param element
038: * the input element, or <code>null</code>
039: * @param name
040: * the name of the refactoring
041: * @param id
042: * the id of the refactoring
043: * @return the refactoring status
044: */
045: public static RefactoringStatus createInputFatalStatus(
046: final Object element, final String name, final String id) {
047: Assert.isNotNull(name);
048: Assert.isNotNull(id);
049: if (element != null)
050: return RefactoringStatus
051: .createFatalErrorStatus(Messages
052: .format(
053: RefactoringCoreMessages.InitializableRefactoring_input_not_exists,
054: new String[] {
055: JavaElementLabels
056: .getTextLabel(
057: element,
058: JavaElementLabels.ALL_FULLY_QUALIFIED),
059: name, id }));
060: else
061: return RefactoringStatus
062: .createFatalErrorStatus(Messages
063: .format(
064: RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist,
065: new String[] { name, id }));
066: }
067:
068: /**
069: * Creates a warning status telling that the input element does not exist.
070: *
071: * @param element
072: * the input element, or <code>null</code>
073: * @param name
074: * the name of the refactoring
075: * @param id
076: * the id of the refactoring
077: * @return the refactoring status
078: */
079: public static RefactoringStatus createInputWarningStatus(
080: final Object element, final String name, final String id) {
081: Assert.isNotNull(name);
082: Assert.isNotNull(id);
083: if (element != null)
084: return RefactoringStatus
085: .createWarningStatus(Messages
086: .format(
087: RefactoringCoreMessages.InitializableRefactoring_input_not_exists,
088: new String[] {
089: JavaElementLabels
090: .getTextLabel(
091: element,
092: JavaElementLabels.ALL_FULLY_QUALIFIED),
093: name, id }));
094: else
095: return RefactoringStatus
096: .createWarningStatus(Messages
097: .format(
098: RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist,
099: new String[] { name, id }));
100: }
101:
102: /** The comment */
103: private String fComment;
104:
105: /**
106: * {@inheritDoc}
107: */
108: public boolean canEnableComment() {
109: return true;
110: }
111:
112: /**
113: * Creates a fatal error status telling that the input element does not
114: * exist.
115: *
116: * @param element
117: * the input element, or <code>null</code>
118: * @param id
119: * the id of the refactoring
120: * @return the refactoring status
121: */
122: public final RefactoringStatus createInputFatalStatus(
123: final Object element, final String id) {
124: return createInputFatalStatus(element, getName(), id);
125: }
126:
127: /**
128: * Creates a warning status telling that the input element does not exist.
129: *
130: * @param element
131: * the input element, or <code>null</code>
132: * @param id
133: * the id of the refactoring
134: * @return the refactoring status
135: */
136: public final RefactoringStatus createInputWarningStatus(
137: final Object element, final String id) {
138: return createInputWarningStatus(element, getName(), id);
139: }
140:
141: /**
142: * {@inheritDoc}
143: */
144: public String getComment() {
145: return fComment;
146: }
147:
148: /**
149: * {@inheritDoc}
150: */
151: public void setComment(String comment) {
152: fComment = comment;
153: }
154: }
|