private void dumpStack(ThreadReference thread, boolean showPC) { // ### Check for these. // env.failure("Thread no longer exists."); // env.failure("Target VM must be in interrupted state."); // env.failure("Current thread isn't suspended."); // ### Should handle extremely long stack traces sensibly for user. List<StackFrame> stack = null; try { stack = thread.frames(); } catch (IncompatibleThreadStateException e) { env.failure("Thread is not suspended."); } // ### Fix this! // ### Previously mishandled cases where thread was not current. // ### Now, prints all of the stack regardless of current frame. int frameIndex = 0; // int frameIndex = context.getCurrentFrameIndex(); if (stack == null) { env.failure("Thread is not running (no stack)."); } else { OutputSink out = env.getOutputSink(); int nFrames = stack.size(); for (int i = frameIndex; i < nFrames; i++) { StackFrame frame = stack.get(i); Location loc = frame.location(); Method meth = loc.method(); out.print(" [" + (i + 1) + "] "); out.print(meth.declaringType().name()); out.print('.'); out.print(meth.name()); out.print(" ("); if (meth.isNative()) { out.print("native method"); } else if (loc.lineNumber() != -1) { try { out.print(loc.sourceName()); } catch (AbsentInformationException e) { out.print("<unknown>"); } out.print(':'); out.print(loc.lineNumber()); } out.print(')'); if (showPC) { long pc = loc.codeIndex(); if (pc != -1) { out.print(", pc = " + pc); } } out.println(); } out.show(); } }
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; }