public RefactoringStatus initialize(final RefactoringArguments arguments) {
   if (arguments instanceof JavaRefactoringArguments) {
     final JavaRefactoringArguments extended = (JavaRefactoringArguments) arguments;
     final String selection = extended.getAttribute(JDTRefactoringDescriptor.ATTRIBUTE_SELECTION);
     if (selection != null) {
       int offset = -1;
       int length = -1;
       final StringTokenizer tokenizer = new StringTokenizer(selection);
       if (tokenizer.hasMoreTokens()) offset = Integer.valueOf(tokenizer.nextToken()).intValue();
       if (tokenizer.hasMoreTokens()) length = Integer.valueOf(tokenizer.nextToken()).intValue();
       if (offset >= 0 && length >= 0) {
         fSelectionStart = offset;
         fSelectionLength = length;
       } else
         return RefactoringStatus.createFatalErrorStatus(
             Messages.format(
                 RefactoringCoreMessages.InitializableRefactoring_illegal_argument,
                 new Object[] {selection, JDTRefactoringDescriptor.ATTRIBUTE_SELECTION}));
     } else
       return RefactoringStatus.createFatalErrorStatus(
           Messages.format(
               RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
               JDTRefactoringDescriptor.ATTRIBUTE_SELECTION));
     final String handle = extended.getAttribute(JDTRefactoringDescriptor.ATTRIBUTE_INPUT);
     if (handle != null) {
       final IJavaScriptElement element =
           JDTRefactoringDescriptor.handleToElement(extended.getProject(), handle, false);
       if (element == null
           || !element.exists()
           || element.getElementType() != IJavaScriptElement.JAVASCRIPT_UNIT)
         return createInputFatalStatus(element, IJavaScriptRefactorings.EXTRACT_CONSTANT);
       else fCu = (IJavaScriptUnit) element;
     } else
       return RefactoringStatus.createFatalErrorStatus(
           Messages.format(
               RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
               JDTRefactoringDescriptor.ATTRIBUTE_INPUT));
     final String visibility = extended.getAttribute(ATTRIBUTE_VISIBILITY);
     if (visibility != null && !"".equals(visibility)) { // $NON-NLS-1$
       int flag = 0;
       try {
         flag = Integer.parseInt(visibility);
       } catch (NumberFormatException exception) {
         return RefactoringStatus.createFatalErrorStatus(
             Messages.format(
                 RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
                 ATTRIBUTE_VISIBILITY));
       }
       fVisibility = JdtFlags.getVisibilityString(flag);
     }
     final String name = extended.getAttribute(JDTRefactoringDescriptor.ATTRIBUTE_NAME);
     if (name != null && !"".equals(name)) // $NON-NLS-1$
     fConstantName = name;
     else
       return RefactoringStatus.createFatalErrorStatus(
           Messages.format(
               RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
               JDTRefactoringDescriptor.ATTRIBUTE_NAME));
     final String replace = extended.getAttribute(ATTRIBUTE_REPLACE);
     if (replace != null) {
       fReplaceAllOccurrences = Boolean.valueOf(replace).booleanValue();
     } else
       return RefactoringStatus.createFatalErrorStatus(
           Messages.format(
               RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
               ATTRIBUTE_REPLACE));
     final String declareFinal = extended.getAttribute(ATTRIBUTE_QUALIFY);
     if (declareFinal != null) {
       fQualifyReferencesWithDeclaringClassName = Boolean.valueOf(declareFinal).booleanValue();
     } else
       return RefactoringStatus.createFatalErrorStatus(
           Messages.format(
               RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
               ATTRIBUTE_QUALIFY));
   } else
     return RefactoringStatus.createFatalErrorStatus(
         RefactoringCoreMessages.InitializableRefactoring_inacceptable_arguments);
   return new RefactoringStatus();
 }
 public Change createChange(IProgressMonitor monitor) throws CoreException {
   final Map arguments = new HashMap();
   String project = null;
   IJavaScriptProject javaProject = fCu.getJavaScriptProject();
   if (javaProject != null) project = javaProject.getElementName();
   int flags =
       JavaScriptRefactoringDescriptor.JAR_REFACTORING
           | JavaScriptRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
   if (JdtFlags.getVisibilityCode(fVisibility) != Modifier.PRIVATE)
     flags |= RefactoringDescriptor.STRUCTURAL_CHANGE;
   String pattern = ""; // $NON-NLS-1$
   try {
     pattern =
         BindingLabelProvider.getBindingLabel(
                 getContainingTypeBinding(), JavaScriptElementLabels.ALL_FULLY_QUALIFIED)
             + "."; //$NON-NLS-1$
   } catch (JavaScriptModelException exception) {
     JavaScriptPlugin.log(exception);
   }
   final String expression = ASTNodes.asString(fSelectedExpression.getAssociatedExpression());
   final String description =
       Messages.format(
           RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description_short,
           fConstantName);
   final String header =
       Messages.format(
           RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description,
           new String[] {pattern + fConstantName, expression});
   final JDTRefactoringDescriptorComment comment =
       new JDTRefactoringDescriptorComment(project, this, header);
   comment.addSetting(
       Messages.format(
           RefactoringCoreMessages.ExtractConstantRefactoring_constant_name_pattern,
           fConstantName));
   comment.addSetting(
       Messages.format(
           RefactoringCoreMessages.ExtractConstantRefactoring_constant_expression_pattern,
           expression));
   String visibility = fVisibility;
   if ("".equals(visibility)) // $NON-NLS-1$
   visibility = RefactoringCoreMessages.ExtractConstantRefactoring_default_visibility;
   comment.addSetting(
       Messages.format(
           RefactoringCoreMessages.ExtractConstantRefactoring_visibility_pattern, visibility));
   if (fReplaceAllOccurrences)
     comment.addSetting(RefactoringCoreMessages.ExtractConstantRefactoring_replace_occurrences);
   if (fQualifyReferencesWithDeclaringClassName)
     comment.addSetting(RefactoringCoreMessages.ExtractConstantRefactoring_qualify_references);
   final JDTRefactoringDescriptor descriptor =
       new JDTRefactoringDescriptor(
           IJavaScriptRefactorings.EXTRACT_CONSTANT,
           project,
           description,
           comment.asString(),
           arguments,
           flags);
   arguments.put(JDTRefactoringDescriptor.ATTRIBUTE_INPUT, descriptor.elementToHandle(fCu));
   arguments.put(JDTRefactoringDescriptor.ATTRIBUTE_NAME, fConstantName);
   arguments.put(
       JDTRefactoringDescriptor.ATTRIBUTE_SELECTION,
       new Integer(fSelectionStart).toString()
           + " "
           + new Integer(fSelectionLength).toString()); // $NON-NLS-1$
   arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllOccurrences).toString());
   arguments.put(
       ATTRIBUTE_QUALIFY, Boolean.valueOf(fQualifyReferencesWithDeclaringClassName).toString());
   arguments.put(
       ATTRIBUTE_VISIBILITY, new Integer(JdtFlags.getVisibilityCode(fVisibility)).toString());
   return new RefactoringDescriptorChange(
       descriptor,
       RefactoringCoreMessages.ExtractConstantRefactoring_name,
       new Change[] {fChange});
 }