This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[ecj] Patch: FYI: more annotations fixes
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 18 Oct 2006 13:40:56 -0600
- Subject: [ecj] Patch: FYI: more annotations fixes
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcj-eclipse branch.
This fixes a few buglets.
* PR 28203 -- annotation inheritance is wrong. I'll push this patch
upstream to Classpath at some point.
* defineclass incorrectly masks off some modifier bits we need later
Also, we incorrectly re-use a modifier bit.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
PR classpath/28203:
* java/lang/Class.java (getAnnotations): Rewrote.
* java/lang/reflect/Method.java (METHOD_MODIFIERS): Now
package-private.
* java/lang/reflect/Field.java (FIELD_MODIFIERS): Now
package-private.
* gcj/field.h (_Jv_FIELD_CONSTANT_VALUE): Removed.
* defineclass.cc (handleConstantValueAttribute): Added found_value
argument. Don't use _Jv_FIELD_CONSTANT_VALUE.
(read_one_field_attribute): Updated.
(read_fields): Likewise.
(handleField): Mask with FIELD_MODIFIERS, not ALL_FLAGS.
(handleMethod): Mask with METHOD_MODIFIERS, not ALL_FLAGS.
Index: gcj/field.h
===================================================================
--- gcj/field.h (revision 117705)
+++ gcj/field.h (working copy)
@@ -1,6 +1,6 @@
// field.h - Header file for fieldID instances. -*- c++ -*-
-/* Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation
This file is part of libgcj.
@@ -17,7 +17,6 @@
#include <gnu/gcj/RawData.h>
#define _Jv_FIELD_UNRESOLVED_FLAG 0x8000
-#define _Jv_FIELD_CONSTANT_VALUE 0x4000
struct _Jv_Field
{
Index: java/lang/reflect/Field.java
===================================================================
--- java/lang/reflect/Field.java (revision 117838)
+++ java/lang/reflect/Field.java (working copy)
@@ -89,7 +89,7 @@
// The Class (or primitive TYPE) of this field.
private Class type;
- private static final int FIELD_MODIFIERS
+ static final int FIELD_MODIFIERS
= Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED
| Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT
| Modifier.VOLATILE;
Index: java/lang/reflect/Method.java
===================================================================
--- java/lang/reflect/Method.java (revision 117838)
+++ java/lang/reflect/Method.java (working copy)
@@ -51,7 +51,7 @@
public final class Method
extends AccessibleObject implements Member, GenericDeclaration
{
- private static final int METHOD_MODIFIERS
+ static final int METHOD_MODIFIERS
= Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE
| Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC
| Modifier.STATIC | Modifier.STRICT | Modifier.SYNCHRONIZED;
Index: java/lang/Class.java
===================================================================
--- java/lang/Class.java (revision 117705)
+++ java/lang/Class.java (working copy)
@@ -54,8 +54,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Collection;
import java.lang.reflect.AnnotatedElement;
import java.lang.annotation.Annotation;
+import java.lang.annotation.Inherited;
/**
* A Class represents a Java type. There will never be multiple Class
@@ -1283,15 +1286,22 @@
*/
public Annotation[] getAnnotations()
{
- HashSet<Annotation> set = new HashSet<Annotation>();
- set.addAll(Arrays.asList(getDeclaredAnnotations()));
- Class[] interfaces = getInterfaces();
- for (int i = 0; i < interfaces.length; i++)
- set.addAll(Arrays.asList(interfaces[i].getAnnotations()));
- Class<? super T> superClass = getSuperclass();
- if (superClass != null)
- set.addAll(Arrays.asList(superClass.getAnnotations()));
- return set.toArray(new Annotation[set.size()]);
+ HashMap<Class, Annotation> map = new HashMap<Class, Annotation>();
+ for (Annotation a : getDeclaredAnnotations())
+ map.put((Class) a.annotationType(), a);
+ for (Class<? super T> s = getSuperclass();
+ s != null;
+ s = s.getSuperclass())
+ {
+ for (Annotation a : s.getAnnotations())
+ {
+ Class k = (Class) a.annotationType();
+ if (! map.containsKey(k) && k.isAnnotationPresent(Inherited.class))
+ map.put(k, a);
+ }
+ }
+ Collection<Annotation> v = map.values();
+ return v.toArray(new Annotation[v.size()]);
}
/**
Index: defineclass.cc
===================================================================
--- defineclass.cc (revision 117838)
+++ defineclass.cc (working copy)
@@ -39,6 +39,8 @@
#include <java/lang/ClassCircularityError.h>
#include <java/lang/IncompatibleClassChangeError.h>
#include <java/lang/reflect/Modifier.h>
+#include <java/lang/reflect/Field.h>
+#include <java/lang/reflect/Method.h>
#include <java/security/ProtectionDomain.h>
#include <java/io/DataOutputStream.h>
#include <java/io/ByteArrayOutputStream.h>
@@ -281,7 +283,7 @@
void read_one_class_attribute ();
void read_one_method_attribute (int method);
void read_one_code_attribute (int method);
- void read_one_field_attribute (int field);
+ void read_one_field_attribute (int field, bool *);
void throw_class_format_error (const char *msg);
void handleEnclosingMethod(int);
@@ -305,7 +307,7 @@
void handleFieldsBegin (int);
void handleField (int, int, int, int);
void handleFieldsEnd ();
- void handleConstantValueAttribute (int,int);
+ void handleConstantValueAttribute (int, int, bool *);
void handleMethodsBegin (int);
void handleMethod (int, int, int, int);
void handleMethodsEnd ();
@@ -722,9 +724,10 @@
handleField (i, access_flags, name_index, descriptor_index);
+ bool found_value = false;
for (int j = 0; j < attributes_count; j++)
{
- read_one_field_attribute (i);
+ read_one_field_attribute (i, &found_value);
}
}
@@ -742,7 +745,8 @@
return !memcmp (bytes+offsets[index]+2, name, len);
}
-void _Jv_ClassReader::read_one_field_attribute (int field_index)
+void _Jv_ClassReader::read_one_field_attribute (int field_index,
+ bool *found_value)
{
int name = read2u ();
int length = read4 ();
@@ -759,7 +763,7 @@
|| tags[cv] == JV_CONSTANT_Double
|| tags[cv] == JV_CONSTANT_String))
{
- handleConstantValueAttribute (field_index, cv);
+ handleConstantValueAttribute (field_index, cv, found_value);
}
else
{
@@ -1420,7 +1424,9 @@
field->name = field_name;
// Ignore flags we don't know about.
- field->flags = flags & Modifier::ALL_FLAGS;
+ field->flags = flags & (Field::FIELD_MODIFIERS
+ | Modifier::SYNTHETIC
+ | Modifier::ENUM);
_Jv_Utf8Const* sig = pool_data[desc].utf8;
@@ -1461,7 +1467,8 @@
void _Jv_ClassReader::handleConstantValueAttribute (int field_index,
- int value)
+ int value,
+ bool *found_value)
{
using namespace java::lang::reflect;
@@ -1476,10 +1483,10 @@
}
// do not allow multiple constant fields!
- if (field->flags & _Jv_FIELD_CONSTANT_VALUE)
+ if (*found_value)
throw_class_format_error ("field has multiple ConstantValue attributes");
- field->flags |= _Jv_FIELD_CONSTANT_VALUE;
+ *found_value = true;
def_interp->field_initializers[field_index] = value;
/* type check the initializer */
@@ -1573,7 +1580,10 @@
method->signature = pool_data[desc].utf8;
// ignore unknown flags
- method->accflags = accflags & Modifier::ALL_FLAGS;
+ method->accflags = accflags & (Method::METHOD_MODIFIERS
+ | Modifier::BRIDGE
+ | Modifier::SYNTHETIC
+ | Modifier::VARARGS);
// Initialize...
method->ncode = 0;