/**
* The version number of this release.
*/
- public static final String version = "3.12.0.GA";
+ public static final String version = "3.13.0.GA";
/**
* Prints the version number and the copyright notice.
* may be a private field declared in a super class or interface.
*/
public CtField getField(String name) throws NotFoundException {
+ return getField(name, null);
+ }
+
+ /**
+ * Returns the field with the specified name and type. The returned field
+ * may be a private field declared in a super class or interface.
+ * Unlike Java, the JVM allows a class to have
+ * multiple fields with the same name but different types.
+ *
+ * @param name the field name.
+ * @param desc the type descriptor of the field. It is available by
+ * {@link CtField#getSignature()}.
+ * @see CtField#getSignature()
+ */
+ public CtField getField(String name, String desc) throws NotFoundException {
throw new NotFoundException(name);
}
/**
* @return null if the specified field is not found.
*/
- CtField getField2(String name) { return null; }
+ CtField getField2(String name, String desc) { return null; }
/**
* Gets all the fields declared in the class. The inherited fields
* Retrieves the field with the specified name among the fields
* declared in the class.
*
- * <p>Note: this method does not search the superclasses.
+ * <p>Note: this method does not search the super classes.
*/
public CtField getDeclaredField(String name) throws NotFoundException {
throw new NotFoundException(name);
}
+ /**
+ * Retrieves the field with the specified name and type among the fields
+ * declared in the class. Unlike Java, the JVM allows a class to have
+ * multiple fields with the same name but different types.
+ *
+ * <p>Note: this method does not search the super classes.
+ *
+ * @param name the field name.
+ * @param desc the type descriptor of the field. It is available by
+ * {@link CtField#getSignature()}.
+ * @see CtField#getSignature()
+ */
+ public CtField getDeclaredField(String name, String desc) throws NotFoundException {
+ throw new NotFoundException(name);
+ }
+
/**
* Gets all the constructors and methods declared in the class.
*/
}
}
- public CtField getField(String name) throws NotFoundException {
- CtField f = getField2(name);
- if (f == null)
- throw new NotFoundException("field: " + name + " in " + getName());
+ public CtField getField(String name, String desc) throws NotFoundException {
+ CtField f = getField2(name, desc);
+ return checkGetField(f, name, desc);
+ }
+
+ private CtField checkGetField(CtField f, String name, String desc)
+ throws NotFoundException
+ {
+ if (f == null) {
+ String msg = "field: " + name;
+ if (desc != null)
+ msg += " type " + desc;
+
+ throw new NotFoundException(msg + " in " + getName());
+ }
else
return f;
}
- CtField getField2(String name) {
- CtField df = getDeclaredField2(name);
+ CtField getField2(String name, String desc) {
+ CtField df = getDeclaredField2(name, desc);
if (df != null)
return df;
CtClass[] ifs = getInterfaces();
int num = ifs.length;
for (int i = 0; i < num; ++i) {
- CtField f = ifs[i].getField2(name);
+ CtField f = ifs[i].getField2(name, desc);
if (f != null)
return f;
}
CtClass s = getSuperclass();
if (s != null)
- return s.getField2(name);
+ return s.getField2(name, desc);
}
catch (NotFoundException e) {}
return null;
}
public CtField getDeclaredField(String name) throws NotFoundException {
- CtField f = getDeclaredField2(name);
- if (f == null)
- throw new NotFoundException("field: " + name + " in " + getName());
- else
- return f;
+ return getDeclaredField(name, null);
+ }
+
+ public CtField getDeclaredField(String name, String desc) throws NotFoundException {
+ CtField f = getDeclaredField2(name, desc);
+ return checkGetField(f, name, desc);
}
- private CtField getDeclaredField2(String name) {
+ private CtField getDeclaredField2(String name, String desc) {
CtMember.Cache memCache = getMembers();
CtMember field = memCache.fieldHead();
CtMember tail = memCache.lastField();
while (field != tail) {
field = field.next();
- if (field.getName().equals(name))
+ if (field.getName().equals(name)
+ && (desc == null || desc.equals(field.getSignature())))
return (CtField)field;
}
/**
* Returns the character string representing the type of the field.
+ * The field signature is represented by a character string
+ * called a field descriptor, which is defined in the JVM specification.
* If two fields have the same type,
* <code>getSignature()</code> returns the same string.
*