• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.adt.internal.refactorings.extractstring;
18 
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.ltk.core.refactoring.Refactoring;
21 import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
22 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
23 
24 import java.util.Map;
25 
26 /**
27  * A descriptor that allows an {@link ExtractStringRefactoring} to be created from
28  * a previous instance of itself.
29  */
30 public class ExtractStringDescriptor extends RefactoringDescriptor {
31 
32     public static final String ID =
33         "com.android.ide.eclipse.adt.refactoring.extract.string";  //$NON-NLS-1$
34 
35     private final Map<String, String> mArguments;
36 
ExtractStringDescriptor(String project, String description, String comment, Map<String, String> arguments)37     public ExtractStringDescriptor(String project, String description, String comment,
38             Map<String, String> arguments) {
39         super(ID, project, description, comment,
40                 RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE //flags
41         );
42         mArguments = arguments;
43     }
44 
getArguments()45     public Map<String, String> getArguments() {
46         return mArguments;
47     }
48 
49     /**
50      * Creates a new refactoring instance for this refactoring descriptor based on
51      * an argument map. The argument map is created by the refactoring itself in
52      * {@link ExtractStringRefactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)}
53      * <p/>
54      * This is apparently used to replay a refactoring.
55      *
56      * {@inheritDoc}
57      *
58      * @throws CoreException
59      */
60     @Override
createRefactoring(RefactoringStatus status)61     public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
62         try {
63             ExtractStringRefactoring ref = new ExtractStringRefactoring(mArguments);
64             return ref;
65         } catch (NullPointerException e) {
66             status.addFatalError("Failed to recreate ExtractStringRefactoring from descriptor");
67             return null;
68         }
69     }
70 
71 }
72