/** * Adds the given JField to this JStructure. * * <p>This method is implemented by subclasses and should only accept the proper fields for the * subclass otherwise an IllegalArgumentException will be thrown. For example a JInterface will * only accept static fields. * * <p> * * @param jField, the JField to add * @exception java.lang.IllegalArgumentException when the given JField has a name of an existing * JField */ public void addField(JField jField) throws IllegalArgumentException { if (jField == null) { throw new IllegalArgumentException("argument 'jField' cannot be null"); } String name = jField.getName(); // -- check for duplicate field name if ((fields != null) && (fields.get(name) != null)) { String err = "duplicate name found: " + name; throw new IllegalArgumentException(err); } // -- check for proper modifiers JModifiers modifiers = jField.getModifiers(); if (!modifiers.isStatic()) { throw new IllegalArgumentException("Fields added to a JInterface must be static."); } if (modifiers.isPrivate()) { throw new IllegalArgumentException("Fields added to a JInterface must not be private."); } // -- only initialize fields if we need it, many interfaces // -- don't contain any fields, no need to waste space if (fields == null) { fields = new JNamedMap(3); } fields.put(name, jField); }
public void addMember(JMember jMember) throws IllegalArgumentException { if (jMember == null) { throw new IllegalArgumentException("Class members cannot be null"); } if (members.get(jMember.getName()) != null) { String err = "duplicate name found: " + jMember.getName(); throw new IllegalArgumentException(err); } members.put(jMember.getName(), jMember); // if member is of a type not imported by this class // then add import JType type = jMember.getType(); while (type.isArray()) type = type.getComponentType(); if (!type.isPrimitive()) { addImport(((JClass) type).getName()); } } // -- addMember