How to use jdt java model to get the line number of a field in a java class

StackOverflow https://stackoverflow.com/questions/19017835

  •  29-06-2022
  •  | 
  •  

Вопрос

org.eclipse.jdt.core.IField

IField field = IType.createField(contents, null, true, null);

How to get the line number of field?

Это было полезно?

Решение

You can get the line number of an ASTNode using the below code

ASTNode node = compilationUnit.findDeclaringNode(field.getKey());

int lineNumber = compilationUnit.getLineNumber(node.getStartPosition()) - 1;

Note that this will work only if the bindings are resolved.

Refer the below links for more details:

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top