You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by Sarvesh Kesharwani <sa...@oracle.com> on 2019/02/20 11:49:45 UTC

Calculating Caret Positions in Test files

Hi Folks,

I had a question regarding calculating caret positions. I was writing 
some test cases for java.completion module, to make sure that invoking 
code completion results as the desired output. But in order to do that, 
I needed the caret position of where code completion needs to be 
invoked. (as can be seen in JavaCompletionTask18FeaturesTest.java 
<https://github.com/apache/incubator-netbeans/blob/master/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask18FeaturesTest.java>)

So, my question is how can I calculate the caret position of a 
particular position in a java file in NetBeans? I apologize for the 
naivety of the question. Any pointers are appreciated.

Thanks,
Sarvesh


Re: Calculating Caret Positions in Test files

Posted by Jan Lahoda <la...@gmail.com>.
Hi Sarvesh,

I believe there are a few ways to do that in NetBeans, besides resorting to
using an external editor. One is to use this command line option:
-J-Dorg.netbeans.editor.caret.offset.level=FINE

Which will add absolute character position of the caret in the file to the
line:column info in bottom right corner. It may then look like:
56:1 <2316>
where 2316 is the character position of the caret.

Alternatively, without the command line option, select the text from the
beginning of the file to the place you are interested in. The bottom right
info may then look like:
25:1/25:1213

The first 25:1 is the line:column of the caret. The second 25:1213 is the
size of the selection in lines and in characters. So when starting the
selection at the beginning of the file, the last number is the character
position of the caret in the file.

Jan


On Wed, Feb 20, 2019 at 12:50 PM Sarvesh Kesharwani <
sarvesh.k.kesharwani@oracle.com> wrote:

> Hi Folks,
>
> I had a question regarding calculating caret positions. I was writing
> some test cases for java.completion module, to make sure that invoking
> code completion results as the desired output. But in order to do that,
> I needed the caret position of where code completion needs to be
> invoked. (as can be seen in JavaCompletionTask18FeaturesTest.java
> <
> https://github.com/apache/incubator-netbeans/blob/master/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask18FeaturesTest.java
> >)
>
> So, my question is how can I calculate the caret position of a
> particular position in a java file in NetBeans? I apologize for the
> naivety of the question. Any pointers are appreciated.
>
> Thanks,
> Sarvesh
>
>