Exemple #1
0
 @Override
 protected void doPrepareSrcfile(
     final String srcfile, final String statetPath, final IProgressMonitor monitor)
     throws CoreException {
   final FunctionCall prepare = createFunctionCall("rj:::.statet.prepareSrcfile");
   prepare.addChar("filename", srcfile);
   prepare.addChar("path", statetPath);
   prepare.evalVoid(monitor);
 }
Exemple #2
0
  private void runApplyRepo(
      final ISelectedRepos repos, final RService r, final IProgressMonitor monitor)
      throws CoreException {
    monitor.subTask("Setting repository configuration...");
    try {
      if (repos.getBioCMirror() != null) {
        final FunctionCall call = r.createFunctionCall("options");
        call.addChar("BioC_mirror", repos.getBioCMirror().getURL());
        call.evalVoid(monitor);
      }
      {
        final List<RRepo> selectedRepos = (List<RRepo>) repos.getRepos();
        final String[] ids = new String[selectedRepos.size()];
        final String[] urls = new String[selectedRepos.size()];
        for (int i = 0; i < urls.length; i++) {
          final RRepo repo = selectedRepos.get(i);
          ids[i] = repo.getId();
          urls[i] = repo.getURL();
        }
        final RVector<RCharacterStore> data =
            new RVectorImpl<RCharacterStore>(
                new RCharacterDataImpl(urls), RObject.CLASSNAME_CHARACTER, ids);

        final FunctionCall call = r.createFunctionCall("options");
        call.add("repos", data);
        call.evalVoid(monitor);
      }
    } catch (final CoreException e) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              RCore.PLUGIN_ID,
              "An error occurred when setting repository configuration in R.",
              e));
    }
  }
Exemple #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);
  }
Exemple #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);
  }