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
/** * Adds the given JMethodSignature to this JClass * * @param jMethodSig the JMethodSignature to add. * @throws java.lang.IllegalArgumentException when the given JMethodSignature conflicts with an * existing method signature. */ public void addMethod(JMethodSignature jMethodSig) throws IllegalArgumentException { if (jMethodSig == null) { String err = "The JMethodSignature cannot be null."; throw new IllegalArgumentException(err); } // -- 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 = jMethodSig.getModifiers(); for (int i = 0; i < methods.size(); i++) { JMethodSignature tmp = (JMethodSignature) methods.elementAt(i); // -- first compare modifiers if (tmp.getModifiers().isProtected()) { if (!modifiers.isProtected()) { methods.insertElementAt(jMethodSig, i); added = true; break; } } // -- compare names if (jMethodSig.getName().compareTo(tmp.getName()) < 0) { methods.insertElementAt(jMethodSig, i); added = true; break; } } // -- END SORT if (!added) methods.addElement(jMethodSig); // -- check return type to make sure it's included in the // -- import list JType jType = jMethodSig.getReturnType(); if (jType != null) { while (jType.isArray()) jType = jType.getComponentType(); if (!jType.isPrimitive()) addImport(jType.getName()); } // -- check exceptions JClass[] exceptions = jMethodSig.getExceptions(); for (JClass exception : exceptions) { addImport(exception.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