@Override
 public IRegion getSubject(final ITextViewer textViewer, final int offset) {
   if (fScanner == null) {
     fScanner =
         (RHeuristicTokenScanner)
             LTK.getModelAdapter(getEditor().getModelTypeId(), RHeuristicTokenScanner.class);
   }
   try {
     final IDocument document = getEditor().getViewer().getDocument();
     fScanner.configure(document);
     final IRegion word = fScanner.findRWord(offset, false, true);
     if (word != null) {
       final ITypedRegion partition = fScanner.getPartition(word.getOffset());
       if (fScanner
               .getPartitioningConfig()
               .getDefaultPartitionConstraint()
               .matches(partition.getType())
           || partition.getType() == IRDocumentPartitions.R_STRING
           || partition.getType() == IRDocumentPartitions.R_QUOTED_SYMBOL) {
         return word;
       }
     }
   } catch (final Exception e) {
   }
   return new Region(offset, 0);
 }
Ejemplo n.º 2
0
 @Override
 protected String getInitialFileContent(final IFile newFileHandle, final SubMonitor m) {
   final String lineDelimiter = TextUtil.getLineDelimiter(newFileHandle.getProject());
   final IRSourceUnit su =
       (IRSourceUnit)
           LTK.getSourceUnitManager()
               .getSourceUnit(
                   LTK.PERSISTENCE_CONTEXT,
                   newFileHandle,
                   getContentType(newFileHandle),
                   true,
                   m);
   try {
     final EvaluatedTemplate data = CodeGeneration.getNewRFileContent(su, lineDelimiter);
     if (data != null) {
       fInitialSelection = data.getRegionToSelect();
       return data.getContent();
     }
   } catch (final CoreException e) {
     RUIPlugin.logError(
         ICommonStatusConstants.INTERNAL_TEMPLATE,
         "An error occured when applying template to new R script file.",
         e); //$NON-NLS-1$
   } finally {
     if (su != null) {
       su.disconnect(m);
     }
   }
   return null;
 }
Ejemplo n.º 3
0
 public RContentAssistProcessor(
     final ContentAssist assistant,
     final String partition,
     final ContentAssistComputerRegistry registry,
     final ISourceEditor editor) {
   super(assistant, partition, registry, editor);
   fScanner =
       (RHeuristicTokenScanner)
           LTK.getModelAdapter(editor.getModelTypeId(), RHeuristicTokenScanner.class);
 }