private void importMethod(DbJVClass dbClaz, Method method) throws DbException { if (dbClaz == null) { return; } String methodName = method.getName(); boolean isConstructor = "<init>".equals(methodName); boolean isInitBlock = "<clinit>".equals(methodName); DbOOAbstractMethod oper = null; if (isInitBlock) { new DbJVInitBlock(dbClaz); } else if (isConstructor) { DbJVConstructor constr = new DbJVConstructor(dbClaz); importExceptions(constr, method); oper = constr; } else { // create method and return type DbJVMethod meth = new DbJVMethod(dbClaz); Type type = method.getReturnType(); meth.setReturnType(toAdt(type)); meth.setTypeUse(toTypeUse(type)); // set method modifiers meth.setAbstract(method.isAbstract()); meth.setFinal(method.isFinal()); meth.setNative(method.isNative()); meth.setStatic(method.isStatic()); meth.setStrictfp(method.isStrictfp()); meth.setSynchronized(method.isSynchronized()); // method.isTransient() // method.isVolatile() importExceptions(meth, method); oper = meth; } // set name and visibility if (oper != null) { oper.setName(methodName); oper.setVisibility(toVisibility(method)); // create parameters Type[] args = method.getArgumentTypes(); for (Type arg : args) { DbJVParameter param = new DbJVParameter(oper); param.setType(toAdt(arg)); param.setTypeUse(toTypeUse(arg)); } // end for } // end if } // end importMethod()
/** * Parses a method type definition * * @param docMethod * @return */ protected static Method ParseMethod(MethodDoc docMethod) { assert (docMethod != null); Method xmlMethod = new Method(); xmlMethod.name = docMethod.name(); xmlMethod.hash = computeHash(docMethod.qualifiedName(), docMethod.signature()); xmlMethod.qualifiedName = docMethod.qualifiedName(); xmlMethod.comment = docMethod.commentText(); xmlMethod.signature = docMethod.signature(); xmlMethod.isNative = docMethod.isNative(); xmlMethod.isVarArgs = docMethod.isVarArgs(); xmlMethod.isSynchronized = docMethod.isSynchronized(); xmlMethod.isFinal = docMethod.isFinal(); xmlMethod.isAbstract = docMethod.isAbstract(); xmlMethod.isStatic = docMethod.isStatic(); xmlMethod.scope = DetermineScope(docMethod); // Parse parameters of the method Parameter[] parameters = docMethod.parameters(); if (parameters != null && parameters.length > 0) { ParamTag[] paramComments = docMethod.paramTags(); ArrayList<Param> paramList = new ArrayList<Param>(); for (Parameter parameter : parameters) { ParamTag paramComment = null; // look to see if this parameter has comments // if so, paramComment will be set for (ParamTag testParam : paramComments) { String testParamName = testParam.parameterName(); if (testParamName != null) { if (testParamName.compareTo(parameter.name()) == 0) { paramComment = testParam; break; } } } paramList.add(ParseParameter(parameter, paramComment)); } xmlMethod.parameters = paramList.toArray(new Param[] {}); } else { log.debug("No parameters for method: " + docMethod.name()); } // Parse result data Result returnInfo = new Result(); Tag[] returnTags = docMethod.tags("@return"); if (returnTags != null && returnTags.length > 0) { // there should be only one return tag. but heck, // if they specify two, so what... StringBuilder builder = new StringBuilder(); for (Tag returnTag : returnTags) { String returnTagText = returnTag.text(); if (returnTagText != null) { builder.append(returnTagText); builder.append("\n"); } } returnInfo.comment = builder.substring(0, builder.length() - 1); } returnInfo.type = ParseType(docMethod.returnType()); xmlMethod.result = returnInfo; // Parse exceptions of the method Type[] types = docMethod.thrownExceptionTypes(); ThrowsTag[] exceptionComments = docMethod.throwsTags(); if (types != null && types.length > 0) { ArrayList<ExceptionInstance> exceptionList = new ArrayList<ExceptionInstance>(); for (Type exceptionType : types) { ExceptionInstance exception = new ExceptionInstance(); exception.type = ParseType(exceptionType); for (ThrowsTag exceptionComment : exceptionComments) { if (exceptionType == exceptionComment.exceptionType()) { exception.comment = exceptionComment.exceptionComment(); ClassDoc exceptionDetails = exceptionComment.exception(); // not yet parsing Exceptions defined within the supplied code set exception.type = ParseType(exceptionComment.exceptionType()); break; } } exceptionList.add(exception); } xmlMethod.exceptions = exceptionList.toArray(new ExceptionInstance[] {}); } // parse annotations from the method xmlMethod.annotationInstances = ParseAnnotationInstances(docMethod.annotations(), docMethod.qualifiedName()); return xmlMethod; }