1

I am currently developing a plugin in which I need a function to only execute when my cursor is within a javadoc comment partition.

I have tried to execute IDocument.computePartitioning() as well as IDocument.getContentType(). So far the only partition type that is returning is the default content type. I can see that, although the IDocument instance is correct, the getDocumentPartitioner() method returns null.

My question is, my IDocument clearly contains IJavaPartitions as it's a .java file. How can I access this partitioner in order to determine what partition my cursor is located within?

MJH
  • 2,301
  • 7
  • 18
  • 20
Bejal
  • 91
  • 7

2 Answers2

1

You can use the computePartitioning method of org.eclipse.jface.text.TextUtilities to get the region(s) for a range:

IDocument document = ... get document

String partitioning = IJavaPartitions.JAVA_PARTITIONING;

int start = ... start offset

int length = ... length of area

ITypedRegion[] regions = TextUtilities.computePartitioning(document, partitioning, start, length, false);

This will deal with any IDocumentExtension3

You can also get the partitioning name from the TextViewer / SourceViewer by calling the getDocumentPartitioning method.

greg-449
  • 109,219
  • 232
  • 102
  • 145
0

You need to look at, and use the methods on, IDocumentExtension3. A document can be partitioned in many different ways, by different partitioners. Each of these is considered a partitioning, with the computePartitioning being a case of a bad name choice sticking around for the sake of binary compatibility. In the case of Java documents, they exclusively use a partitioning value of their own. I think it is held as a constant in IJavaPartitions.JAVA_PARTITIONING.

nitind
  • 19,089
  • 4
  • 34
  • 43