Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » IllegalArgumentException on ast.newSimpleName
IllegalArgumentException on ast.newSimpleName [message #1707510] Sun, 06 September 2015 06:49 Go to next message
Eclipse UserFriend
Trying to create annotation with AST

String value = "mypackage.MyClass.class";
TypeLiteral typeLiteral = ast.newTypeLiteral();
typeLiteral.setType(ast.newSimpleType(ast.newSimpleName(value)));


I am getting IllegalArgumentException, on
ast.newSimpleName(value)

Should I use newQualifiedName?

But how would it work if my package contains 10 names??

[Updated on: Sun, 06 September 2015 07:42] by Moderator

Re: IllegalArgumentException on ast.newSimpleName [message #1707581 is a reply to message #1707510] Mon, 07 September 2015 10:31 Go to previous messageGo to next message
Eclipse UserFriend
It's just a guess, but I would guess that the value shouldn't include
the ".class"...

On 06/09/2015 12:49 PM, yev xxxxx wrote:
> Trying to create annotation with AST
>
> String value = "mypackage.MyClass.class";
> TypeLiteral typeLiteral = ast.newTypeLiteral();
> typeLiteral.setType(ast.newSimpleType(ast.newSimpleName(value)));
>
> I am getting IllegalArgumentException, on ast.newSimpleName(value)
Re: IllegalArgumentException on ast.newSimpleName [message #1707671 is a reply to message #1707581] Tue, 08 September 2015 08:55 Go to previous messageGo to next message
Eclipse UserFriend
Correct, Ed. Plus, you can't have dots (".") in a SimpleName. If you want a qualified name (i.e. with dots) you need to construct a QualifiedName.

Say your value is "aaa.bbb.ccc.MyClass" (as Ed notes, don't include the ".class" for a TypeLiteral, that's implied by being a TypeLiteral).

SimpleName a = ast.newSimpleName("aaa");
SimpleName b = ast.newSimpleName("bbb");
QualifiedName ab = ast.newQualifiedName(a, b);
SimpleName c = ast.newSimpleName("ccc");
QualifiedName abc = ast.newQualifiedName(ab, c);
SimpleName d = ast.newSimpleName("ddd");
QualifedName abcd = ast.newQualifiedName(abc, d);
etc.
Re: IllegalArgumentException on ast.newSimpleName [message #1707718 is a reply to message #1707671] Tue, 08 September 2015 13:47 Go to previous message
Eclipse UserFriend
Yes, that worked.
I created a recursive method to create nested names to support any number if names in package.

Thanks
Previous Topic:Unable to start eclipse
Next Topic:cvs required password each time restart
Goto Forum:
  


Current Time: Mon Apr 28 01:16:04 EDT 2025

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

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

Back to the top