1
org.eclipse.jdt.core.IField
IField field = IType.createField(contents, null, true, null);

How to get the line number of field?

Mark
8,47115 gold badges52 silver badges81 bronze badges
asked Sep 26, 2013 at 1:26

1 Answer 1

2

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:

answered Sep 26, 2013 at 9:41
Sign up to request clarification or add additional context in comments.

2 Comments

org.eclipse.jdt.core.dom.rewrite.ListRewrite.insertLast(node, null), how to get the line number of node?
couldn't understand your comment, can u explain a bit more?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.