private void checkFunction(final RefactoringStatus result) {
    if ((fFunction.getElementType() & IRElement.MASK_C2) != IRElement.R_COMMON_FUNCTION
        && (fFunction.getElementType() & IRElement.MASK_C2) != IRElement.R_COMMON_FUNCTION) {
      result.merge(
          RefactoringStatus.createFatalErrorStatus(
              Messages.FunctionToS4Method_error_SelectionAlreadyS4_message));
      return;
    }
    final RAstNode node = (RAstNode) fFunction.getAdapter(IAstNode.class);
    if (RAst.hasErrors(node)) {
      result.merge(
          RefactoringStatus.createWarningStatus(
              Messages.FunctionToS4Method_warning_SelectionSyntaxError_message));
    }
    //		if (fSelectionRegion != null
    //				&& (fSelectionRegion.getOffset() != fOperationRegion.getOffset() ||
    // fSelectionRegion.getLength() != fOperationRegion.getLength())) {
    //			result.merge(RefactoringStatus.createWarningStatus("The selected code does not equal
    // exactly the found expression(s)."));
    //		}

    RElementName elementName = fFunction.getElementName();
    while (elementName.getNextSegment() != null) {
      elementName = elementName.getNamespace();
    }
    fFunctionName = elementName.getDisplayName();

    final ArgsDefinition argsDef = fFunction.getArgsDefinition();
    final int count = (argsDef != null) ? argsDef.size() : 0;
    fVariablesList = new ArrayList(count);
    boolean dots = false;
    for (int i = 0; i < count; i++) {
      final Arg arg = argsDef.get(i);
      final Variable variable = new Variable(arg);
      if (variable.getName().equals(RTerminal.S_ELLIPSIS)) {
        dots = true;
        variable.init(true);
      } else {
        variable.init(!dots);
      }
      fVariablesList.add(variable);
    }
  }
  private void createSubChanges(
      final Variable parent, final TextFileChange change, final List<String> names) {
    final String parentMsgName =
        RUtil.formatVarName(RRefactoringAdapter.getUnquotedIdentifier(parent.fName));
    for (final Variable variable : parent.fSubVariables.values()) {
      if (variable.fNewName != null) {
        final String oldName = RRefactoringAdapter.getUnquotedIdentifier(variable.fName);
        final String oldMsgName = RUtil.formatVarName(oldName);
        final boolean isQuoted = (variable.fNewName.charAt(0) == '`');
        final GroupCategorySet set =
            new GroupCategorySet(
                new GroupCategory(
                    ((IRFrameInSource) parent.getParent()).getFrameId() + '$' + parent.fName,
                    NLS.bind(Messages.RenameInRegion_Changes_VariableGroup_name, parentMsgName),
                    "")); //$NON-NLS-1$
        final String message =
            NLS.bind(
                Messages.RenameInRegion_Changes_ReplaceOccurrenceOf_name,
                oldMsgName,
                parentMsgName);

        for (final RElementAccess access : variable.fAccessList) {
          final RAstNode nameNode = access.getNameNode();
          if (nameNode == null) {
            continue;
          }
          final String text =
              (isQuoted
                      && nameNode.getNodeType() == NodeType.SYMBOL
                      && nameNode.getOperator(0) == RTerminal.SYMBOL)
                  ? variable.fNewName
                  : RRefactoringAdapter.getUnquotedIdentifier(variable.fNewName);
          final IRegion nameRegion = RAst.getElementNameRegion(nameNode);
          TextChangeCompatibility.addTextEdit(
              change,
              message,
              new ReplaceEdit(nameRegion.getOffset(), nameRegion.getLength(), text),
              set);
        }
        names.add(oldName);
      }
    }
  }
Beispiel #3
0
  @Override
  protected void doSubmitCommandL(
      final String[] lines,
      final SrcfileData srcfile,
      final IRSrcref srcref,
      final IProgressMonitor monitor)
      throws CoreException {
    if ((fCurrentPrompt.meta
            & (IRBasicAdapter.META_PROMPT_DEFAULT | IRBasicAdapter.META_PROMPT_SUSPENDED))
        == 0) {
      super.doSubmitCommandL(lines, srcfile, srcref, monitor);
      return;
    }

    final FunctionCall prepare = createFunctionCall("rj:::.statet.prepareCommand");
    prepare.add("lines", fRObjectFactory.createVector(fRObjectFactory.createCharData(lines)));

    if (srcfile != null && srcref != null) {
      final List<String> attributeNames = new ArrayList<String>();
      final List<RObject> attributeValues = new ArrayList<RObject>();

      if (srcfile.getName() != null) {
        prepare.addChar("filename", srcfile.getName());
      }
      //			if (srcfile.workspacePath != null) {
      //				attributeNames.add("statet.Path");
      //				attributeValues.add(fRObjectFactory.createVector(fRObjectFactory.createCharData(
      //						new String[] { srcfile.workspacePath } )));
      //			}
      if (srcfile.getTimestamp() != 0) {
        attributeNames.add("timestamp");
        attributeValues.add(
            fRObjectFactory.createVector(
                fRObjectFactory.createNumData(new double[] {srcfile.getTimestamp()})));
      }
      final int[] rjSrcref = RDbg.createRJSrcref(srcref);
      if (rjSrcref != null) {
        attributeNames.add("linesSrcref");
        attributeValues.add(fRObjectFactory.createVector(fRObjectFactory.createIntData(rjSrcref)));
      }

      if (attributeNames.size() > 0) {
        prepare.add(
            "srcfileAttributes",
            fRObjectFactory.createList(
                attributeValues.toArray(new RObject[attributeValues.size()]),
                attributeNames.toArray(new String[attributeNames.size()])));
      }

      if (srcref instanceof IRModelSrcref) {
        // Move to abstract controller or breakpoint adapter?
        final IRModelSrcref modelSrcref = (IRModelSrcref) srcref;
        final List<IRLangSourceElement> elements = modelSrcref.getElements();
        if (elements.size() > 0) {
          final List<String> elementIds = new ArrayList<String>(elements.size());
          final List<RObject> elementIndexes = new ArrayList<RObject>(elements.size());
          for (final IRLangSourceElement element : elements) {
            if (TAG_ELEMENT_FILTER.include(element)) {
              final FDef fdef = (FDef) element.getAdapter(FDef.class);
              if (fdef != null) {
                final String elementId = RDbg.getElementId(element);
                final RAstNode cont = fdef.getContChild();
                final int[] path =
                    RAst.computeRExpressionIndex(cont, RAst.getRRootNode(cont, modelSrcref));
                if (elementId != null && path != null) {
                  final int[] fullPath = new int[path.length + 1];
                  fullPath[0] = 1;
                  System.arraycopy(path, 0, fullPath, 1, path.length);
                  elementIds.add(elementId);
                  elementIndexes.add(
                      fRObjectFactory.createVector(fRObjectFactory.createIntData(fullPath)));
                }
              }
            }
          }
          if (elementIds.size() > 0) {
            prepare.add(
                "elementIds",
                fRObjectFactory.createList(
                    elementIndexes.toArray(new RObject[elementIndexes.size()]),
                    elementIds.toArray(new String[elementIds.size()])));
          }
        }
      }
    }

    prepare.evalVoid(monitor);

    final boolean addToHistory = (fCurrentPrompt.meta & IRBasicAdapter.META_HISTORY_DONTADD) == 0;
    fCurrentInput = lines[0];
    doBeforeSubmitL();
    for (int i = 1; i < lines.length; i++) {
      setCurrentPromptL(fContinuePromptText, addToHistory);
      fCurrentInput = lines[i];
      doBeforeSubmitL();
    }
    fCurrentInput = "rj:::.statet.evalCommand()";
    doSubmitL(monitor);
  }
Beispiel #4
0
  @Override
  public void doSubmitFileCommandToConsole(
      final String[] lines,
      final SrcfileData srcfile,
      final ISourceUnit su,
      final IProgressMonitor monitor)
      throws CoreException {
    if (srcfile != null
        && su instanceof IRWorkspaceSourceUnit
        && su.getModelTypeId() == RModel.TYPE_ID) {
      try {
        final IRModelInfo modelInfo =
            (IRModelInfo) su.getModelInfo(RModel.TYPE_ID, IRModelManager.MODEL_FILE, monitor);
        if (modelInfo != null) {
          final IRLangSourceElement fileElement = modelInfo.getSourceElement();
          final RAstNode rootNode = (RAstNode) fileElement.getAdapter(IAstNode.class);
          final List<? extends IRLangSourceElement> elements =
              modelInfo.getSourceElement().getSourceChildren(TAG_ELEMENT_FILTER);

          final List<String> elementIds = new ArrayList<String>(elements.size());
          final List<RObject> elementIndexes = new ArrayList<RObject>(elements.size());

          for (final IRLangSourceElement element : elements) {
            final FDef fdef = (FDef) element.getAdapter(FDef.class);
            if (fdef != null) {
              final String elementId = RDbg.getElementId(element);
              final RAstNode cont = fdef.getContChild();
              final int[] path = RAst.computeRExpressionIndex(cont, rootNode);
              if (elementId != null && path != null) {
                elementIds.add(elementId);
                elementIndexes.add(
                    fRObjectFactory.createVector(fRObjectFactory.createIntData(path)));
              }
            }
          }

          final FunctionCall prepare =
              createFunctionCall("rj:::.statet.prepareSource"); // $NON-NLS-1$
          prepare.add(
              fRObjectFactory.createList(
                  new RObject[] {
                    fRObjectFactory.createVector(
                        fRObjectFactory.createCharData(new String[] {srcfile.getPath()})),
                    fRObjectFactory.createVector(
                        fRObjectFactory.createNumData(new double[] {srcfile.getTimestamp()})),
                    fRObjectFactory.createVector(
                        fRObjectFactory.createIntData(new int[] {rootNode.getChildCount()})),
                    fRObjectFactory.createList(
                        elementIndexes.toArray(new RObject[elementIndexes.size()]),
                        elementIds.toArray(new String[elementIds.size()])),
                  },
                  new String[] {
                    "path", "timestamp", "exprsLength", "elementIds"
                  })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
          prepare.evalVoid(monitor);
        }
      } catch (final CoreException e) {
        RConsoleCorePlugin.log(
            new Status(
                IStatus.ERROR,
                RConsoleCorePlugin.PLUGIN_ID,
                -1,
                NLS.bind(
                    "An error occurred when preparing element tagging for file ''{0}''.",
                    srcfile.getPath()),
                e));
      }
    }
    super.doSubmitFileCommandToConsole(lines, srcfile, su, monitor);
  }