Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to get ASTNode of constant which is returned by Expression.resolveConstantExpressionValue()?
How to get ASTNode of constant which is returned by Expression.resolveConstantExpressionValue()? [message #1799411] Thu, 06 December 2018 05:50 Go to next message
Eclipse UserFriend
Hi,
I have a declaration like
public static final String VALUE = "some value";

and it's used somewhere like
String v = DeclaringClass.VALUE;

In this case if I call QualifiedName.resolveConstantExpressionValue() it returns "some value". But how to get StringLiteral which is returned by FieldDeclaration.fragments().get(0).getInitializer()? Thanks
Re: How to get ASTNode of constant which is returned by Expression.resolveConstantExpressionValue()? [message #1799430 is a reply to message #1799411] Thu, 06 December 2018 12:03 Go to previous messageGo to next message
Eclipse UserFriend
Here's an example:
assertTrue("not a string literal", expression.getNodeType() == ASTNode.STRING_LITERAL); 
StringLiteral stringLiteral = (StringLiteral) expression;
assertEquals("wrong value", "some string", stringLiteral.getLiteralValue());

Re: How to get ASTNode of constant which is returned by Expression.resolveConstantExpressionValue()? [message #1799475 is a reply to message #1799430] Fri, 07 December 2018 07:57 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jay,
Thanks for you message. But I wanted to ask different thing. Let's assume that we have only QualifiedName (DeclaringClass.VALUE), for knowing only that to get that StringLiteral?
Re: How to get ASTNode of constant which is returned by Expression.resolveConstantExpressionValue()? [message #1799836 is a reply to message #1799475] Fri, 14 December 2018 09:03 Go to previous messageGo to next message
Eclipse UserFriend
@Jay, I think it should be similar to the solution of finding usages of DeclaringClass.VALUE. Or I have a declaration variable binding of DeclaringClass.VALUE, so how to get appropriate AST node?
Re: How to get ASTNode of constant which is returned by Expression.resolveConstantExpressionValue()? [message #1804154 is a reply to message #1799836] Tue, 19 March 2019 09:52 Go to previous messageGo to next message
Eclipse UserFriend
Really need any kind of suggestions :/
Re: How to get ASTNode of constant which is returned by Expression.resolveConstantExpressionValue()? [message #1807386 is a reply to message #1804154] Wed, 29 May 2019 01:21 Go to previous message
Eclipse UserFriend
Sorry, looks like I forgot to subscribe to the thread. Hope it's not too late.
I see it works in my case. Can you confirm that you have enabled the resolve binding flag when you request for AST Conversion?
Previous Topic:generate complex method annotations
Next Topic:More intelligent auto completion
Goto Forum:
  


Current Time: Sat Jul 12 12:39:52 EDT 2025

Powered by FUDForum. Page generated in 1.45229 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top