Package com.subhajit.diagrams.codeanalysis

Examples of com.subhajit.diagrams.codeanalysis.ClassInfo


          sourceMethod);
      if (method == null) {
        System.err.println("Could not locate method.");
        return;
      }
      ctx.setClassInfo(new ClassInfo(className, classLoader));
      ctx.setFilters(SequenceDiagramAction.getPackageListInteractively()
          .toArray(IConstants.ZERO_LENGTH_STRING_ARRAY));
      ctx.setFollowInvokedMethods(true);

      MethodInfo methodInfo = MethodInfo.createMethodInfo(method);
View Full Code Here


        SequenceDiagramGenerator gen = new SequenceDiagramGenerator(
            classLoader);

        SequenceDiagramContext ctx = new SequenceDiagramContext();
        ctx
            .setClassInfo(new ClassInfo(className, gen
                .getClassLoader()));
        ctx.setFilters(packagesList
            .toArray(IConstants.ZERO_LENGTH_STRING_ARRAY));
        ctx.setFollowInvokedMethods(false);

        // Show source code lines.
        ctx.setShowSourceLines(true);
        // Find all relevant source code locations.
        EclipseProject eclipseProject = new EclipseProject(ProjectUtils
            .getProjectFile((IJavaProject) inputs.get("project")));
        ctx.setSourceCodeManager(new SourceCodeManager(eclipseProject
            .getSourcePaths()));
        ctx.setShowInstructions(false);

        ClassInfo classInfo = new ClassInfo(className, gen
            .getClassLoader());
        final List<MethodInfo> methods = classInfo.getMethods();
        progress.setRange(0, methods.size() + 1);
        for (MethodInfo method : methods) {
          progress.increment(1, "Processing "
              + method.getMethodName());
          ctx.setMethodInfo(method);
View Full Code Here

    new TaskRunner(new ISwingRunnableWithProgress() {
      public void run(IProgress progress) throws Throwable {
        progress.setMessage("Computing sequence diagram...");
        SequenceDiagramGenerator gen = new SequenceDiagramGenerator(
            classLoader);
        ClassInfo classInfo = new ClassInfo(className, gen
            .getClassLoader());
        final List<MethodInfo> methods = classInfo.getMethods();
        progress.setRange(0, methods.size() + 1);
        for (MethodInfo method : methods) {
          progress.increment(1, "Processing "
              + method.getMethodName());
          diagrams.put(method, SequenceDiagramUtils
View Full Code Here

    }

    final SequenceDiagramContext ctx = new SequenceDiagramContext();
    final SequenceDiagramGenerator gen = new SequenceDiagramGenerator(
        classLoader);
    ctx.setClassInfo(new ClassInfo(className, gen.getClassLoader()));
    ctx.setFilters(packagesList
        .toArray(IConstants.ZERO_LENGTH_STRING_ARRAY));
    ctx.setFollowInvokedMethods(false);
    // Show source code lines.
    ctx.setShowSourceLines(true);

    // Find all relevant source code locations.
    // Actually, ask the user to provide these (if any).
    // ctx.setSourceCodeManager(sourceCodeManager)
    ctx.setShowInstructions(false);

    ClassInfo classInfo = new ClassInfo(className, gen.getClassLoader());
    final List<MethodInfo> methods = classInfo.getMethods();
    final Map<MethodInfo, byte[]> diagrams = new HashMap<MethodInfo, byte[]>();

    // Create the sequence diagram.
    new TaskRunner(new ISwingRunnableWithProgress() {
      public void run(IProgress progress) throws Throwable {
View Full Code Here

//    final File[] jarFiles = new File[scl.getURLs().length];
//    for (int i = 0; i < scl.getURLs().length; i++) {
//      jarFiles[i] = new File(scl.getURLs()[i].getFile());
//    }
//
    ClassInfo classInfo = new ClassInfo(className, scl);
    Map<MethodInfo, List<MethodInfo>> map = classInfo.getCalledMethodInfo();

    // Trim the map
    Map<MethodInfo, List<MethodInfo>> trimmedMap = new HashMap<MethodInfo, List<MethodInfo>>();
    for (Map.Entry<MethodInfo, List<MethodInfo>> entry : map.entrySet()) {
      final MethodInfo method = entry.getKey();
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

          .findAllClassNames(zipFileOrJarFileOrDirectory);
      sLog.info("Processing - " + classNames.size() + " classes in - "
          + zipFileOrJarFileOrDirectory.getCanonicalPath());
      for (String className : classNames) {
        try {
          ClassInfo classInfo = new ClassInfo(className, classLoader);
          Map<MethodInfo, List<MethodInfo>> invocationInfo = classInfo
              .getCalledMethodInfo();
          File saveFile = new File(dir, className.replace('.', '/')
              + ".ser");
          if (!saveFile.getParentFile().exists()) {
            if (!saveFile.getParentFile().mkdirs()) {
View Full Code Here

            + className);
        SequenceDiagramGenerator sequenceDiagramGenerator = new SequenceDiagramGenerator(
            classpaths);

        SequenceDiagramContext ctx = new SequenceDiagramContext();
        ctx.setClassInfo(new ClassInfo(className,
            sequenceDiagramGenerator.getClassLoader()));
        ctx.setFilters(StrUtils.parse(packageNames, COMMA));
        System.out.println("recurse = " + recurse);
        ctx.setFollowInvokedMethods(recurse);
        ctx.setShowInstructions(showInstructions);
View Full Code Here

    if (Thread.currentThread().isInterrupted()) {
      return classInfoMap;
    }
    for (Map.Entry<String, ClassInfo> entry : classInfoMap.entrySet()) {
      final String className = entry.getKey();
      ClassInfo classInfo = classInfoMap.get(className);
      Set<String> usedClasses = classInfo.getUsedClasses();
      Set<String> interestingClasses = new HashSet<String>();
      for (String usedClass : usedClasses) {
        interestingClasses.add(usedClass);
      }
      usedClasses.clear();
View Full Code Here

    }
    if (!inputFilter.isClassOfInterest(className)) {
      return;
    }
    sLog.info("Creating ClassInfo for class - " + className);
    ClassInfo classInfo = new ClassInfo(className, classLoader, repository);
    map.put(className, classInfo);
    for (String usedClass : classInfo.getUsedClasses()) {
      if (Thread.currentThread().isInterrupted()) {
        return;
      }
      if (inputFilter.isClassOfInterest(usedClass)) {
        update(map, usedClass, classLoader, repository, inputFilter);
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.