コード例 #1
0
ファイル: StackTraceTool.java プロジェクト: NathanEEvans/api
    @Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

      // ### We should indicate the current thread independently of the
      // ### selection, e.g., with an icon, because the user may change
      // ### the selection graphically without affecting the current
      // ### thread.

      super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      if (value == null) {
        this.setText("<unavailable>");
      } else {
        StackFrame frame = (StackFrame) value;
        Location loc = frame.location();
        Method meth = loc.method();
        String methName = meth.declaringType().name() + '.' + meth.name();
        String position = "";
        if (meth.isNative()) {
          position = " (native method)";
        } else if (loc.lineNumber() != -1) {
          position = ":" + loc.lineNumber();
        } else {
          long pc = loc.codeIndex();
          if (pc != -1) {
            position = ", pc = " + pc;
          }
        }
        // Indices are presented to the user starting from 1, not 0.
        this.setText("[" + (index + 1) + "] " + methName + position);
      }
      return this;
    }
コード例 #2
0
 private void commandMethods(StringTokenizer t) throws NoSessionException {
   if (!t.hasMoreTokens()) {
     env.error("No class specified.");
     return;
   }
   String idClass = t.nextToken();
   ReferenceType cls = findClass(idClass);
   if (cls != null) {
     List<Method> methods = cls.allMethods();
     OutputSink out = env.getOutputSink();
     for (int i = 0; i < methods.size(); i++) {
       Method method = methods.get(i);
       out.print(method.declaringType().name() + " " + method.name() + "(");
       Iterator<String> it = method.argumentTypeNames().iterator();
       if (it.hasNext()) {
         while (true) {
           out.print(it.next());
           if (!it.hasNext()) {
             break;
           }
           out.print(", ");
         }
       }
       out.println(")");
     }
     out.show();
   } else {
     // ### Should validate class name syntax.
     env.failure("\"" + idClass + "\" is not a valid id or class name.");
   }
 }
コード例 #3
0
 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();
   }
 }
コード例 #4
0
  public Method concreteMethodByName(String name, String signature) {
    Method method = null;
    for (Method candidate : visibleMethods()) {
      if (candidate.name().equals(name)
          && candidate.signature().equals(signature)
          && !candidate.isAbstract()) {

        method = candidate;
        break;
      }
    }
    return method;
  }
コード例 #5
0
ファイル: DebuggerUtilsEx.java プロジェクト: jared2501/test
 @Override
 public int compare(Method m1, Method m2) {
   return LambdaMethodFilter.getLambdaOrdinal(m1.name())
       - LambdaMethodFilter.getLambdaOrdinal(m2.name());
 }
コード例 #6
0
ファイル: DebuggerUtilsEx.java プロジェクト: jared2501/test
 public static String methodName(final Method m) {
   return methodName(signatureToName(m.declaringType().signature()), m.name(), m.signature());
 }
コード例 #7
0
  /**
   * 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;
  }
コード例 #8
0
  public void startElement(String uri, String localName, String name, Attributes attributes)
      throws SAXException {
    if (collectText) {
      if (collectHTML) {
        text.append("<").append(localName);
        int nAttributes = attributes.getLength();
        for (int i = 0; i < nAttributes; i++) {
          String qname = attributes.getQName(i);
          String value = attributes.getValue(i);
          text.append(" ").append(qname).append("=\"").append(value).append("\"");
        }
      }
      pendingEndElement = true;
    } else {
      Integer stateObj = null;
      pushState();
      if (NAMESPACE_API.equals(uri)) {
        stateObj = (Integer) states.get(localName);
        if (stateObj != null) {
          int state = stateObj.intValue();
          switch (state) {
            case STATE_ABOUTME:
              {
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_ALIAS:
              {
                Alias alias = new Alias();
                this.currentObject = alias;
                addCollectionElement(TAG_ALIAS, alias);
                alias.name = attributes.getValue(ATTRIBUTE_ALAIS_NAME);
                alias.datatype = attributes.getValue(ATTRIBUTE_ALAIS_TYPE);

                break;
              }

            case STATE_ANCESTOR:
              {
                Ancestor ancestor = new Ancestor();
                this.currentObject = ancestor;
                addCollectionElement(TAG_ANCESTOR, ancestor);
                ancestor.dataType = attributes.getValue(ATTRIBUTE_ANCESTOR_DATATYPE);

                break;
              }

            case STATE_API:
              {
                this.apis.libraryVersion = attributes.getValue(ATTRIBUTE_API_VERSION);
                this.apis.language = attributes.getValue(ATTRIBUTE_API_LANGUAGE);
                this.apis.getterPattern = attributes.getValue(ATTRIBUTE_API_GETTERPATTERN);
                this.apis.setterPattern = attributes.getValue(ATTRIBUTE_API_SETTERPATTERN);
                this.apis.setterPattern = attributes.getValue(ATTRIBUTE_API_SETTERPATTERN);
                this.apis.spec = attributes.getValue(ATTRIBUTE_API_SPEC);
                this.collections = new HashMap();
                break;
              }

            case STATE_AUTHOR:
              {
                Author author = new Author();
                this.currentObject = author;

                author.email = attributes.getValue(ATTRIBUTE_AUTHOR_EMAIL);
                author.location = attributes.getValue(ATTRIBUTE_AUTHOR_LOCATION);
                author.name = attributes.getValue(ATTRIBUTE_AUTHOR_NAME);
                author.organization = attributes.getValue(ATTRIBUTE_AUTHOR_ORGANIZATION);
                author.photo = attributes.getValue(ATTRIBUTE_AUTHOR_PHOTO);
                author.type = attributes.getValue(ATTRIBUTE_AUTHOR_TYPE);
                author.website = attributes.getValue(ATTRIBUTE_AUTHOR_WEBSITE);

                addCollectionElement(TAG_AUTHOR, author);
                break;
              }

            case STATE_AVAILABLE:
              {
                DepreciatedOrAvailable available = new DepreciatedOrAvailable();
                if (this.currentObject instanceof VersionableElement)
                  ((VersionableElement) this.currentObject).available = available;
                available.version = attributes.getValue(ATTRIBUTE_AVAILABLE_VERSION);
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_CLASS:
            case STATE_INTERFACE:
              {
                ClassData clazz = new ClassData();
                this.currentObject = clazz;
                if (STATE_INTERFACE == state) {
                  clazz.isInterface = true;
                  addCollectionElement(TAG_INTERFACE, clazz);
                } else addCollectionElement(TAG_CLASS, clazz);
                clazz.name = attributes.getValue(ATTRIBUTE_CLASS_NAME);
                clazz.superclass = attributes.getValue(ATTRIBUTE_CLASS_SUPERCLASS);
                clazz.visibility = attributes.getValue(ATTRIBUTE_CLASS_VISIBILITY);
                clazz.getterPattern = attributes.getValue(ATTRIBUTE_CLASS_GETTERPATTERN);
                clazz.setterPattern = attributes.getValue(ATTRIBUTE_CLASS_SETTERPATTERN);

                this.collections = new HashMap();
                break;
              }

            case STATE_CONSTRUCTOR:
            case STATE_METHOD:
              {
                Method method = new Method();
                if (STATE_CONSTRUCTOR == state) {
                  method.isContructor = true;
                  addCollectionElement(TAG_CONSTRUCTOR, method);
                } else addCollectionElement(TAG_METHOD, method);
                this.currentObject = method;
                method.scope = attributes.getValue(ATTRIBUTE_CONSTRUCTOR_SCOPE);
                method.visibility = attributes.getValue(ATTRIBUTE_CONSTRUCTOR_VISIBILITY);
                method.name = attributes.getValue(ATTRIBUTE_METHOD_NAME);

                this.collections = new HashMap();
                break;
              }

            case STATE_DEPRECIATED:
              {
                DepreciatedOrAvailable depreciated = new DepreciatedOrAvailable();
                if (this.currentObject instanceof VersionableElement)
                  ((VersionableElement) this.currentObject).depreciated = depreciated;
                depreciated.isDepreciated = true;
                depreciated.version = attributes.getValue(ATTRIBUTE_DEPRECIATED_VERSION);
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_DESCRIPTION:
              {
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_ENUM:
              {
                Enum enumData = new Enum();
                this.currentObject = enumData;
                addCollectionElement(TAG_ENUM, enumData);
                enumData.name = attributes.getValue(ATTRIBUTE_ENUM_NAME);
                enumData.datatype = attributes.getValue(ATTRIBUTE_ENUM_DATATYPE);

                break;
              }

            case STATE_EVENT:
              {
                Event event = new Event();
                this.currentObject = event;
                addCollectionElement(TAG_EVENT, event);

                this.collections = new HashMap();
                break;
              }

            case STATE_EXCEPTION:
              {
                Exception exception = new Exception();
                this.currentObject = exception;
                addCollectionElement(TAG_EXCEPTION, exception);

                this.collections = new HashMap();
                break;
              }

            case STATE_FIELD:
            case STATE_PROPERTY:
              {
                Property property = new Property();
                this.currentObject = property;
                if (STATE_FIELD == state) {
                  property.isField = true;
                  addCollectionElement(TAG_FIELD, property);
                } else addCollectionElement(TAG_PROPERTY, property);
                property.name = attributes.getValue(ATTRIBUTE_FIELD_NAME);
                property.dataType = attributes.getValue(ATTRIBUTE_FIELD_DATATYPE);
                property.scope = attributes.getValue(ATTRIBUTE_FIELD_SCOPE);
                property.visibility = attributes.getValue(ATTRIBUTE_FIELD_VISIBILITY);

                this.collections = new HashMap();
                break;
              }

            case STATE_INCLUDE:
              {
                String src = attributes.getValue(ATTRIBUTE_INCLUDE_SRC);
                handleInclude(src);
                break;
              }

            case STATE_MIX:
              {
                Mix mix = new Mix();
                addCollectionElement(TAG_MIX, mix);
                this.currentObject = mix;
                mix.datatype = attributes.getValue(ATTRIBUTE_MIX_DATATYPE);
                mix.fromScope = attributes.getValue(ATTRIBUTE_MIX_FROMSCOPE);
                mix.toScope = attributes.getValue(ATTRIBUTE_MIX_TOSCOPE);

                break;
              }

            case STATE_MIXIN:
              {
                Mixin mixin = new Mixin();
                addCollectionElement(TAG_MIXIN, mixin);
                this.currentObject = mixin;
                mixin.name = attributes.getValue(ATTRIBUTE_MIXIN_NAME);
                mixin.scope = attributes.getValue(ATTRIBUTE_MIXIN_SCOPE);
                mixin.visibility = attributes.getValue(ATTRIBUTE_MIXIN_VISIBILITY);

                break;
              }

            case STATE_NAMESPACE:
              {
                Namespace namespace = new Namespace();
                addCollectionElement(TAG_NAMESPACE, namespace);
                this.currentObject = namespace;
                namespace.name = attributes.getValue(ATTRIBUTE_NAMESPACE_NAME);
                namespace.visibility = attributes.getValue(ATTRIBUTE_NAMESPACE_VISIBILITY);

                break;
              }

            case STATE_PARAMETER:
              {
                Parameter parameter = new Parameter();
                this.currentObject = parameter;
                addCollectionElement(TAG_PARAMETER, parameter);
                parameter.name = attributes.getValue(ATTRIBUTE_PARAMETER_NAME);
                parameter.dataType = attributes.getValue(ATTRIBUTE_PARAMETER_DATATYPE);
                parameter.usage = attributes.getValue(ATTRIBUTE_PARAMETER_USAGE);

                this.collections = new HashMap();
                break;
              }

            case STATE_QOUTE:
              {
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_RETURNS:
              {
                ReturnsData returnData = new ReturnsData();
                if (this.currentObject instanceof Method)
                  ((Method) this.currentObject).returns = returnData;
                else if (this.currentObject instanceof Event)
                  ((Event) this.currentObject).returns = returnData;
                else if (this.currentObject instanceof Exception)
                  ((Exception) this.currentObject).returns = returnData;
                this.currentObject = returnData;
                returnData.dataType = attributes.getValue(ATTRIBUTE_RETURNS_DATATYPE);
                break;
              }
          }
          this.currentState = state;
        }
      }
    }
  }