Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 10:50 Go to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
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 17:03 Go to previous messageGo to next message
Jay Arthanareeswaran is currently offline Jay ArthanareeswaranFriend
Messages: 128
Registered: July 2009
Senior Member
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 12:57 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
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 14:03 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
@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 13:52 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
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 05:21 Go to previous message
Jay Arthanareeswaran is currently offline Jay ArthanareeswaranFriend
Messages: 128
Registered: July 2009
Senior Member
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: Thu Apr 25 10:09:38 GMT 2024

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

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

Back to the top