Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
org.eclipse.jdt.core.IField IField field = IType.createField(contents, null, true, null);
如何获取字段的行号?
您可以使用以下代码获取 ASTNode 的行号
ASTNode node = compilationUnit.findDeclaringNode(field.getKey()); int lineNumber = compilationUnit.getLineNumber(node.getStartPosition()) - 1;
请注意,这仅在绑定已解决时才有效。
有关详细信息,请参阅以下链接:
eclipse ASTNode 到源代码行号
FieldDeclaration 到 IField - 从 FieldDeclaration 获取 IBinding