Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JDT - Check Instances of RuntimeException class(To check if a Exception class is subclass of RuntimeException using the QualifiedName string)
JDT - Check Instances of RuntimeException class [message #1754877] Thu, 23 February 2017 12:37 Go to next message
Suresh P is currently offline Suresh PFriend
Messages: 27
Registered: May 2013
Junior Member
hi

By using JDT (AST), I need to check using the Exception class's QualifiedName (string format) is an subclass of RuntimeException class?

Im using the below code:
IMethodBinding methodbinding = ((MethodDeclaration)node).resolveBinding().getMethodDeclaration();
ITypeBinding[] exceptiontypes = methodbinding.getExceptionTypes();




Thanks
Re: JDT - Check Instances of RuntimeException class [message #1754996 is a reply to message #1754877] Sat, 25 February 2017 15:57 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
3 steps:
- ask the IJavaProject for the IType for j.l.RuntimeException
- https://wiki.eclipse.org/JDT/FAQ#From_an_IJavaElement_to_an_IBinding
- ask the current exception type e.isSubTypeCompatible(runtimeExceptionBinding)
Re: JDT - Check Instances of RuntimeException class [message #1755232 is a reply to message #1754996] Wed, 01 March 2017 11:11 Go to previous messageGo to next message
Suresh P is currently offline Suresh PFriend
Messages: 27
Registered: May 2013
Junior Member
Thanks for the response. I followed the three steps you have mentioned, but not clear about how to get the "runtimeExceptionBinding" object.
Can you let me know what I'm doing wrong here?


   IType runtimeExcepType = cu.getJavaElement().getJavaProject().findType("java.lang.RuntimeException");
					String key = runtimeExcepType.getKey();
					ASTNode node1 = cu.findDeclaringNode(key);
					exceptionTypeBinding.isSubTypeCompatible(  ???   );
Re: JDT - Check Instances of RuntimeException class [message #1755261 is a reply to message #1755232] Wed, 01 March 2017 18:05 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Suresh P wrote on Wed, 01 March 2017 12:11
Thanks for the response. I followed the three steps you have mentioned, but not clear about how to get the "runtimeExceptionBinding" object.
Can you let me know what I'm doing wrong here?


Your attempt stops one yard before the finish line.

You could inspect the node and get it's resolved binding, but its certainly easier to follow the other road using ASTParser.createBindings(..).

(I see that there's room for improving the FAQ in this item).
Previous Topic:Unable to use Google Play Services Vision API in Eclipse
Next Topic:IMarkerResolution2 - Display HTML content
Goto Forum:
  


Current Time: Fri Apr 19 18:10:32 GMT 2024

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

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

Back to the top