public void addMethod(JMethod jMethod) throws IllegalArgumentException { if (jMethod == null) { throw new IllegalArgumentException("Class methods cannot be null"); } // -- check method name and signatures *add later* // -- keep method list sorted for esthetics when printing // -- START SORT :-) boolean added = false; short modifierVal = 0; JModifiers modifiers = jMethod.getModifiers(); for (int i = 0; i < methods.size(); i++) { JMethod tmp = (JMethod) methods.elementAt(i); // -- first compare modifiers if (tmp.getModifiers().isPrivate()) { if (!modifiers.isPrivate()) { methods.insertElementAt(jMethod, i); added = true; break; } } // -- compare names if (jMethod.getName().compareTo(tmp.getName()) < 0) { methods.insertElementAt(jMethod, i); added = true; break; } } // -- END SORT if (!added) methods.addElement(jMethod); // -- check parameter packages to make sure we have them // -- in our import list String[] pkgNames = jMethod.getParameterClassNames(); for (int i = 0; i < pkgNames.length; i++) { addImport(pkgNames[i]); } // -- check return type to make sure it's included in the // -- import list JType jType = jMethod.getReturnType(); if (jType != null) { while (jType.isArray()) jType = jType.getComponentType(); if (!jType.isPrimitive()) addImport(((JClass) jType).getName()); } // -- check exceptions JClass[] exceptions = jMethod.getExceptions(); for (int i = 0; i < exceptions.length; i++) { addImport(exceptions[i].getName()); } } // -- addMethod
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