cannot add annotation on local variable

Jeri Lockhart <[email protected]> Mon, 28 Mar 2005 18:10:54 -0800
Newsgroups gmane.comp.java.netbeans.modules.mdr.devel
Message-ID <[email protected]>
Can anyone tell me what's wrong with the code below?

I'm trying to programmatically add a marker annotation to a local 
variable declaration, to look like this:

@MyAnnotation
 MyXyz fn1=new MyXyz ();

But the annotation is not being added.  Only the local variable 
declaration is being created.  This is a snippet of the code I'm using. 

        TypeReference fn1TypeRef = 
jmp.getMultipartId().createMultipartId(fn1name, null, null);   
        TypeReference fn1TypeRef_decl = 
jmp.getMultipartId().createMultipartId(fn1name, null, null);
       
        NewClassExpression fn1InitialValue = 
jmp.getNewClassExpression().createNewClassExpression(
                        null,                                   // 
String name
                        Collections.EMPTY_LIST,                 // List 
parameters,
                        null,                                   // 
PrimaryExpression enclosingClass,
                        jmp.getMultipartId().createMultipartId(
                            fn1name,
                            null,
                            Collections.EMPTY_LIST),            // 
MultipartId className,
                        null);                                  // 
ClassDefinition classDefinition)
      
        MultipartId fn1mpid = 
jmp.getMultipartId().createMultipartId("MyAnnotation", null, null);
        Annotation fn1Annot = 
jmp.getAnnotation().createAnnotation(fn1mpid, null);
       
        LocalVariable fn1Var = jmp.getLocalVariable().createLocalVariable(
                                         
"fn1",                                 // String name,
                                         
Collections.singletonList(fn1Annot),   // List annotations,
                                         
false,                                 // boolean isFinal
                                         
fn1TypeRef,                            // TypeReference typeName
                                         
0,                                     // int dimCount
                                         
fn1InitialValue,                       // InitialValue initialValue
                                         
null);                                 // String initialValueText)
       
                                          
        LocalVarDeclaration fn1Lvd = 
jmp.getLocalVarDeclaration().createLocalVarDeclaration(
                                         
false,                                 //  boolean isFinal,
                                         
fn1TypeRef,                            //  TypeReference typeName,
                                         
Collections.singletonList(fn1Var));    // List variables
               
        tryBody.getStatements().add(fn1Lvd);

--Jeri