Title: [681] trunk/qdox/src/test/com/thoughtworks/qdox: Fix QDOX-193: ArrayIndexOutOfBoundsException FieldRefAnnotation
Revision
681
Author
rfscholte
Date
2009-11-25 17:03:20 -0600 (Wed, 25 Nov 2009)

Log Message

Fix QDOX-193: ArrayIndexOutOfBoundsException FieldRefAnnotation

Modified Paths

Diff

Modified: trunk/qdox/src/java/com/thoughtworks/qdox/model/annotation/AnnotationFieldRef.java (680 => 681)

--- trunk/qdox/src/java/com/thoughtworks/qdox/model/annotation/AnnotationFieldRef.java	2009-11-25 22:55:51 UTC (rev 680)
+++ trunk/qdox/src/java/com/thoughtworks/qdox/model/annotation/AnnotationFieldRef.java	2009-11-25 23:03:20 UTC (rev 681)
@@ -1,5 +1,9 @@
 package com.thoughtworks.qdox.model.annotation;
 
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.StringTokenizer;
 
 import com.thoughtworks.qdox.model.AbstractBaseJavaEntity;
@@ -10,6 +14,7 @@
 
 public class AnnotationFieldRef implements AnnotationValue {
 
+    String[] myArray = new String[]{"unchecked"};
     private final int[] parts;
 
     private final String name;
@@ -108,19 +113,19 @@
 
     public JavaField getField() {
         if( fieldIndex < 0 ) {
-            if( context.getParent() instanceof JavaClass ) {
-                JavaClass javaClass = (JavaClass) context.getParent();
-                field = resolveField( javaClass, 0, parts.length );
+            if( context.getParentClass() != null ) {
+                JavaClass javaClass = context.getParentClass();
+                field = resolveField( javaClass, 0, parts.length -1 );
                 fieldIndex = 0;
             }
 
             if( field == null ) {
                 for( int i = 0; i < parts.length - 1; ++i ) {
                     String className = getNamePrefix( i );
-                    String typeName = context.getParent().resolveType( className );
+                    String typeName = context.getParentClass().resolveType( className );
 
                     if( typeName != null ) {
-                        Type type = Type.createUnresolved( typeName, 0, context.getParent() );
+                        Type type = Type.createUnresolved( typeName, 0, context.getParentClass() );
                         JavaClass javaClass = type.getJavaClass();
 
                         if( javaClass != null ) {

Modified: trunk/qdox/src/test/com/thoughtworks/qdox/AnnotationsTest.java (680 => 681)

--- trunk/qdox/src/test/com/thoughtworks/qdox/AnnotationsTest.java	2009-11-25 22:55:51 UTC (rev 680)
+++ trunk/qdox/src/test/com/thoughtworks/qdox/AnnotationsTest.java	2009-11-25 23:03:20 UTC (rev 681)
@@ -8,6 +8,7 @@
 import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaMethod;
 import com.thoughtworks.qdox.model.Type;
+import com.thoughtworks.qdox.model.annotation.AnnotationFieldRef;
 
 public class AnnotationsTest extends TestCase {
 
@@ -242,4 +243,16 @@
         assertEquals( "ParamInfo", annotation.getType().getValue() );
         assertEquals( "ParamInfo.Direction.OUT", annotation.getProperty( "direction" ).getParameterValue() );
     }
+    
+    public void testFieldRefAnnotation() throws Exception {
+        String source = "public class Foo {\n" +
+        		"  final String s = \"unchecked\";\n" + 
+        		"  @SuppressWarnings( s )\n" +
+        		"  public void testNothing() { }\n " +
+        		"}";
+        builder.addSource( new StringReader( source ) );
+        JavaMethod method = builder.getClasses()[0].getMethods()[0];
+        AnnotationFieldRef suppressWarnings = (AnnotationFieldRef) method.getAnnotations()[0].getProperty( "value" );
+        assertEquals( builder.getClasses()[0].getFields()[0], suppressWarnings.getField());
+    }
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to