Package com.subhajit.diagrams.codeanalysis

Examples of com.subhajit.diagrams.codeanalysis.ClassInfo


      SequenceDiagramGenerator sequenceDiagramGenerator,
      URLClassLoader scl, final String className, MethodInfo methodSpec,
      String[] filters, boolean followInvokedClasses) throws IOException,
      NoSuchMethodException, ClassNotFoundException, InterruptedException {
    SequenceDiagramContext ctx = new SequenceDiagramContext();
    ctx.setClassInfo(new ClassInfo(className, scl));
    ctx.setFilters(filters);
    ctx.setFollowInvokedMethods(followInvokedClasses);
    ctx.setMethodInfo(methodSpec);
    return DrawImage.drawImage(sequenceDiagramGenerator
        .generateSequenceDiagramSpec(ctx), DrawImage.OutputFormat.PNG);
View Full Code Here


      boolean followInvokedClasses) throws IOException,
      ClassNotFoundException, NoSuchMethodException, InterruptedException {
    SequenceDiagramGenerator sequenceDiagramGenerator = new SequenceDiagramGenerator(
        scl);
    SequenceDiagramContext ctx = new SequenceDiagramContext();
    ctx.setClassInfo(new ClassInfo(className, scl));
    ctx.setFilters(filters);
    ctx.setFollowInvokedMethods(followInvokedClasses);
    ctx.setMethodInfo(methodSpec);
    return new String(DrawImage.drawImage(sequenceDiagramGenerator
        .generateSequenceDiagramSpec(ctx), OutputFormat.SVG), "UTF-8");
View Full Code Here

      SequenceDiagramGenerator sequenceDiagramGenerator,
      final String className, MethodInfo methodSpec, String[] packages,
      boolean followInvokedMethods) throws IOException,
      ClassNotFoundException, NoSuchMethodException, InterruptedException {
    SequenceDiagramContext ctx = new SequenceDiagramContext();
    ctx.setClassInfo(new ClassInfo(className, sequenceDiagramGenerator
        .getClassLoader()));
    ctx.setFilters(packages);
    ctx.setFollowInvokedMethods(followInvokedMethods);
    ctx.setMethodInfo(methodSpec);
    ctx.setShowSourceLines(true);
View Full Code Here

      SequenceDiagramGenerator sequenceDiagramGenerator,
      final String className, String[] packages,
      boolean followInvokedMethods) throws IOException,
      ClassNotFoundException, NoSuchMethodException, InterruptedException {
    final Map<MethodInfo, byte[]> ret = new HashMap<MethodInfo, byte[]>();
    final ClassInfo classInfo = new ClassInfo(className,
        sequenceDiagramGenerator.getClassLoader());
    final List<MethodInfo> methods = classInfo.getMethods();
    for (MethodInfo method : methods) {
      ret.put(method, generateSequenceDiagramForMethod(
          sequenceDiagramGenerator, className, method, packages,
          followInvokedMethods));
    }
View Full Code Here

      ClassNotFoundException, NoSuchMethodException {
    ZipOutputStream zOut = null;
    try {
      zOut = new ZipOutputStream(new BufferedOutputStream(
          new FileOutputStream(zipFile)));
      final ClassInfo classInfo = new ClassInfo(className,
          sequenceDiagramGenerator.getClassLoader());
      final List<MethodInfo> methods = classInfo.getMethods();

      SequenceDiagramContext ctx = new SequenceDiagramContext();
      ctx.setClassInfo(classInfo);
      ctx.setFilters(packages);
      ctx.setFollowInvokedMethods(recurseInvocations);
View Full Code Here

      ClassNotFoundException, NoSuchMethodException, InterruptedException {
    ZipOutputStream zOut = null;
    try {
      zOut = new ZipOutputStream(new BufferedOutputStream(
          new FileOutputStream(zipFile)));
      final ClassInfo classInfo = ctx.getClassInfo();
      final List<MethodInfo> methods = classInfo.getMethods();
      for (MethodInfo method : methods) {
        ctx.setMethodInfo(method);
        final byte[] bytes = DrawImage.drawImage(
            sequenceDiagramGenerator
                .generateSequenceDiagramSpec(ctx),
View Full Code Here

      ClassNotFoundException, NoSuchMethodException, InterruptedException {
    ZipOutputStream zOut = null;
    try {
      zOut = new ZipOutputStream(new BufferedOutputStream(
          new FileOutputStream(file)));
      final ClassInfo classInfo = new ClassInfo(className,
          sequenceDiagramGenerator.getClassLoader());
      final List<MethodInfo> methods = classInfo.getMethods();

      SequenceDiagramContext ctx = new SequenceDiagramContext();
      ctx.setClassInfo(classInfo);
      ctx.setFilters(packages);
      ctx.setFollowInvokedMethods(recurseInvocations);
View Full Code Here

  private SequenceDiagramModel generateSequenceDiagramModel(
      SequenceDiagramContext ctx, Set<MethodInfo> methodStack)
      throws NoSuchMethodException, ClassNotFoundException, IOException {
    final MethodInfo method = ctx.getMethodInfo();
    final ClassInfo classInfo = ctx.getClassInfo();
    final String[] filters = ctx.getFilters();
    final boolean followMethodCalls = ctx.getFollowInvokedMethods();

    // Set used to keep track of which source lines have been shown.
    final Set<Integer> sourceLinesShown = new HashSet<Integer>();

    sLog.fine("generateSequenceDiagramModel invoked for - "
        + method.toString());
    if (methodStack.contains(method)) {
      sLog.fine("methodStack contains method. Returning.");
      return null;
    }
    methodStack.add(method);
    SequenceDiagramModel model = new SequenceDiagramModel();
    model.setTitle(method.toString());

    ImmutableActor srcActor = new ImmutableActor(method.getClassName()
        .replace('.', '_'), CommonUtils.getClassNameSansPackage(method
        .getClassName())
        + "." + method.getMethodName());

    model.addActor(srcActor);

    List<Instruction> code = classInfo.getMethodCode(method);
    LineNumberTable lineNumberTable = classInfo.getLineNumberTable(method);
    LineNumber[] lineNumbers = null;
    if (lineNumberTable != null) {
      lineNumbers = lineNumberTable.getLineNumberTable();
    }

    for (Instruction line : code) {
      if (line instanceof InvokeInstruction) {
        sLog.fine("InvokeInstruction - " + line.toString());
        InvokeInstruction destInvokeInstruction = (InvokeInstruction) line;
        final String invokedClassName = destInvokeInstruction
            .getInvokedClass();

        // Check if this is a class of interest.
        if (filters != null) {
          if (!checkPackageMatch(filters, invokedClassName)) {
            sLog
                .fine("Returning, since this class is not interesting.");
            continue;
          }
        }

        final ImmutableActor destActor = new ImmutableActor(
            generateSequenceDiagramActorRef(destInvokeInstruction),
            CommonUtils
                .getClassNameSansPackage(destInvokeInstruction
                    .getInvokedClass())
                + "."
                + destInvokeInstruction.getInvokedMethod());
        model.addMessage(new ImmutableMessage(srcActor, destActor,
            generateSequenceDiagramMessage(destInvokeInstruction),
            destInvokeInstruction.getInvokedMethodReturnType()));

        // Experimentally, at this point, add a sequence diagram model
        // for the destActor's invoked method.
        if (followMethodCalls) {
          sLog.fine(" method calls");
          try {
            MethodInfo destMethod = new MethodInfo(
                invokedClassName, destInvokeInstruction
                    .getInvokedMethod(),
                Utility.methodSignatureArgumentTypes(
                    destInvokeInstruction
                        .getInvokedMethodSignature(),
                    false),
                Utility.methodSignatureReturnType(
                    destInvokeInstruction
                        .getInvokedMethodSignature(),
                    false), null);

            if (!methodStack.contains(destMethod)) {
              // methodStack.add(destMethod);

              sLog.info("Following - "
                  + destMethod.getClassName() + "."
                  + destMethod.getMethodName());

              SequenceDiagramContext ctx2 = new SequenceDiagramContext();
              ctx2.setClassInfo(new ClassInfo(invokedClassName,
                  getClassLoader()));
              ctx2.setFilters(ctx.getFilters());
              ctx2.setFollowInvokedMethods(ctx
                  .getFollowInvokedMethods());
              ctx2.setMethodInfo(destMethod);
              ctx2.setShowInstructions(ctx.getShowInstructions());
              ctx2.setShowSourceLines(ctx.getShowSourceLines());
              ctx2.setSourceCodeManager(ctx
                  .getSourceCodeManager());
              SequenceDiagramModel destActorInvocationModel = generateSequenceDiagramModel(
                  ctx2, methodStack);
              if (destActorInvocationModel != null) {
                model.merge(destActorInvocationModel);
              }
            }
          } catch (NoSuchMethodException exc) {
            sLog.warning(exc.getMessage());
          }
        } else {
          sLog.fine("Not following method calls");
        }
      } else if (line instanceof PutfieldInstruction) {
        if (showPutFieldInstructions) {
          sLog.fine("PutfieldInstruction - " + line.toString());
          PutfieldInstruction putFieldInstruction = (PutfieldInstruction) line;
          final String invokedClassName = putFieldInstruction
              .getInvokedClass();

          // Check if this is a class of interest.
          if (filters != null) {
            if (!checkPackageMatch(filters, invokedClassName)) {
              sLog
                  .fine("Returning, since this class is not interesting.");
              continue;
            }
          }

          final ImmutableActor destActor = srcActor;
          model
              .addMessage(new ImmutableMessage(
                  srcActor,
                  destActor,
                  generateSequenceDiagramMessage(putFieldInstruction)));
        }
      } else if (line instanceof GetfieldInstruction) {
        if (showGetFieldInstructions) {
          sLog.fine("GetfieldInstruction - " + line.toString());
          GetfieldInstruction getFieldInstruction = (GetfieldInstruction) line;
          final String invokedClassName = getFieldInstruction
              .getInvokedClass();

          // Check if this is a class of interest.
          if (filters != null) {
            if (!checkPackageMatch(filters, invokedClassName)) {
              sLog
                  .fine("Returning, since this class is not interesting.");
              continue;
            }
          }

          final ImmutableActor destActor = srcActor;
          model
              .addMessage(new ImmutableMessage(
                  srcActor,
                  destActor,
                  generateSequenceDiagramMessage(getFieldInstruction)));
        }
      } else {
        // This instruction is not a method call.
        sLog.fine("Non-method call - " + line.toString());

        if (ctx.getShowInstructions() && ctx.getShowSourceLines()) {
          if (lineNumbers != null
              && ctx.getSourceCodeManager() != null) {
            showSourceLine(sourceLinesShown, model, srcActor,
                lineNumbers, line, classInfo.getJavaClass(),
                ctx.getSourceCodeManager());
          } else {
            model.addMessage(new ImmutableMessage(srcActor,
                srcActor, line.toString().replace(':', '_')));
          }
        } else if (ctx.getShowInstructions()
            && !ctx.getShowSourceLines()) {
          model.addMessage(new ImmutableMessage(srcActor, srcActor,
              line.toString().replace(':', '_')));
        } else if (!ctx.getShowInstructions()
            && ctx.getShowSourceLines()) {
          if (lineNumbers != null
              && ctx.getSourceCodeManager() != null) {
            showSourceLine(sourceLinesShown, model, srcActor,
                lineNumbers, line, classInfo.getJavaClass(),
                ctx.getSourceCodeManager());
          }
        } else if (!ctx.getShowInstructions()
            && !ctx.getShowSourceLines()) {
          sLog
View Full Code Here

TOP

Related Classes of com.subhajit.diagrams.codeanalysis.ClassInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.