Package org.eclipse.dltk.internal.corext.refactoring

Examples of org.eclipse.dltk.internal.corext.refactoring.ScriptRefactoringArguments


  @Override
  public RefactoringStatus initialize(RefactoringArguments arguments) {
    if (!(arguments instanceof ScriptRefactoringArguments))
      return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InitializableRefactoring_inacceptable_arguments);
    final ScriptRefactoringArguments extended = (ScriptRefactoringArguments) arguments;
    final String handle = extended.getAttribute(ScriptRefactoringDescriptor.ATTRIBUTE_INPUT);
    if (handle != null) {
      final IModelElement element = ScriptRefactoringDescriptor.handleToElement(extended.getProject(), handle, false);
      if (element != null && element.exists()) {
        if (element.getElementType() == IModelElement.SOURCE_MODULE) {
          cu = (ISourceModule) element;
        } else if (element.getElementType() == IModelElement.LOCAL_VARIABLE) {
          modelElement = (ILocalVariable) element;
          cu = (ISourceModule) modelElement.getAncestor(IModelElement.SOURCE_MODULE);
          if (cu == null)
            return ScriptableRefactoring.createInputFatalStatus(element, getProcessorName(), IPHPRefactorings.RENAME_LOCAL_VARIABLE);
        } else
          return ScriptableRefactoring.createInputFatalStatus(element, getProcessorName(), IPHPRefactorings.RENAME_LOCAL_VARIABLE);
      } else
        return ScriptableRefactoring.createInputFatalStatus(element, getProcessorName(), IPHPRefactorings.RENAME_LOCAL_VARIABLE);
    } else {
      return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ScriptRefactoringDescriptor.ATTRIBUTE_INPUT));
    }
    final String name = extended.getAttribute(ScriptRefactoringDescriptor.ATTRIBUTE_NAME);
    if (name != null && !"".equals(name)) //$NON-NLS-1$
      setNewElementName(name);
    else
      return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ScriptRefactoringDescriptor.ATTRIBUTE_NAME));
    if (cu != null && modelElement == null) {
      final String selection = extended.getAttribute(ScriptRefactoringDescriptor.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) {
          try {
            final IModelElement[] elements = cu.codeSelect(offset, length);
            if (elements != null) {
              for (int index = 0; index < elements.length; index++) {
                final IModelElement element = elements[index];
                if (element instanceof ILocalVariable)
                  modelElement = (ILocalVariable) element;
              }
            }
            if (modelElement == null)
              return ScriptableRefactoring.createInputFatalStatus(null, getProcessorName(), IPHPRefactorings.RENAME_LOCAL_VARIABLE);
          } catch (ModelException exception) {
            PEXUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, PEXUIPlugin.PLUGIN_ID, exception.getMessage(), exception));
          }
        } else
          return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { selection,
              ScriptRefactoringDescriptor.ATTRIBUTE_SELECTION }));
      } else
        return RefactoringStatus
            .createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ScriptRefactoringDescriptor.ATTRIBUTE_SELECTION));
    }
    final String references= extended.getAttribute(ScriptRefactoringDescriptor.ATTRIBUTE_REFERENCES);
    if (references != null) {
      updateReferences= Boolean.valueOf(references).booleanValue();
    } else
      return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ScriptRefactoringDescriptor.ATTRIBUTE_REFERENCES));
    return new RefactoringStatus();
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.internal.corext.refactoring.ScriptRefactoringArguments

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.