Skip to main content



      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 07:37 Go to next message
Eclipse UserFriend
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 10:57 Go to previous messageGo to next message
Eclipse UserFriend
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 06:11 Go to previous messageGo to next message
Eclipse UserFriend
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 13:05 Go to previous message
Eclipse UserFriend
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: Sat Nov 08 05:13:07 EST 2025

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

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

Back to the top