Package net.sf.rej.gui.editor.row

Examples of net.sf.rej.gui.editor.row.BlankRow


      this.rowsB.add(pdrB);
      this.rowsAll.add(pdrA);
      this.rowsAll.add(pdrB);
    }
   
    this.rowsAll.add(new BlankRow());

    // Imports
    Imports importsA = EditorFacade.getInstance().getImports(cfA);
    Imports importsB = EditorFacade.getInstance().getImports(cfB);
    this.renderer.setImports(importsA, importsB);
   
    Set<String> tsA = importsA.getImports();
    Set<String> tsB = importsB.getImports();
    Set<String> allOrdered = new TreeSet<String>();
    allOrdered.addAll(tsA);
    allOrdered.addAll(tsB);
    for (String imp : allOrdered) {
      ImportDefRow idr = new ImportDefRow(imp);
      this.rowsAll.add(idr);
      if (!tsA.contains(imp)) {
        this.rowsB.add(idr);
      }
      if (!tsB.contains(imp)) {
        this.rowsA.add(idr);
      }
    }

    if (allOrdered.size() > 0) {
      this.rowsAll.add(new BlankRow());
      /* empty space between imports and class def */
    }
   
    // Add some useful information as comments

    // Source file name
    SourceFileAttribute sfA = cfA.getAttributes().getSourceFileAttribute();
    SourceFileAttribute sfB = cfB.getAttributes().getSourceFileAttribute();
    if (sfA == null && sfB == null) {
      // Add nothing, neither has a source file attribute
    } else if (sfA == null || sfB == null) {
      // Only one has a source file attribute
      if (sfA != null) {
        ClassCommentRow sfComment = new ClassCommentRow("SourceFile = " + sfA.getSourceFile());
        this.rowsA.add(sfComment);
        this.rowsAll.add(sfComment);
      }
     
      if (sfB != null) {
        ClassCommentRow sfComment = new ClassCommentRow("SourceFile = " + sfB.getSourceFile());
        this.rowsB.add(sfComment);
        this.rowsAll.add(sfComment);       
      }
     
    } else {
      // Both have source file attributes
      if (sfA.getSourceFile().equals(sfB.getSourceFile())) {
        ClassCommentRow sfComment = new ClassCommentRow("SourceFile = " + sfA.getSourceFile());
        this.rowsAll.add(sfComment);
      } else {
        ClassCommentRow sfCommentA = new ClassCommentRow("SourceFile = " + sfA.getSourceFile());
        this.rowsA.add(sfCommentA);
        this.rowsAll.add(sfCommentA);

        ClassCommentRow sfCommentB = new ClassCommentRow("SourceFile = " + sfB.getSourceFile());
        this.rowsB.add(sfCommentB);
        this.rowsAll.add(sfCommentB);
      }
    }
   
    // Class version
    if (cfA.getMajorVersion() == cfB.getMajorVersion()
     && cfA.getMinorVersion() == cfB.getMinorVersion()) {
        ClassCommentRow versionComment = new ClassCommentRow("Class Version: " + cfA.getMajorVersion() + "." + cfA.getMinorVersion());
        this.rowsAll.add(versionComment);
    } else {
      ClassCommentRow versionCommentA = new ClassCommentRow("Class Version: " + cfA.getMajorVersion() + "." + cfA.getMinorVersion());
      this.rowsA.add(versionCommentA);
      ClassCommentRow versionCommentB = new ClassCommentRow("Class Version: " + cfB.getMajorVersion() + "." + cfB.getMinorVersion());
      this.rowsB.add(versionCommentB);
      this.rowsAll.add(versionCommentA);
      this.rowsAll.add(versionCommentB);
    }

    // Class annotations
    /* TODO:
    RuntimeInvisibleAnnotationsAttribute annInvisible = cf.getAttributes()
        .getRuntimeInvisibleAnnotationsAttribute();
    RuntimeVisibleAnnotationsAttribute annVisible = cf.getAttributes()
        .getRuntimeVisibleAnnotationsAttribute();
    List<Annotation> classAnnotations = new ArrayList<Annotation>();
    if (annInvisible != null) {
      classAnnotations.addAll(annInvisible.getAnnotations());
    }
    if (annVisible != null) {
      classAnnotations.addAll(annVisible.getAnnotations());
    }
    for (Annotation annotation : classAnnotations) {
      ClassAnnotationDefRow adr = new ClassAnnotationDefRow(annotation);
      this.rows.add(adr);
    }
     */
   
    List<Interface> interfacesA = cfA.getInterfaces();
    List<Interface> interfacesB = cfB.getInterfaces();
    boolean interfacesAreEqual = interfacesA.equals(interfacesB);

    // Class
    if (cfA.getShortClassName().equals(cfB.getShortClassName())
     && cfA.getAccessFlags() == cfB.getAccessFlags()
     && cfA.getSuperClassName().equals(cfB.getSuperClassName())
     && interfacesAreEqual) {
      this.rowsAll.add(new ClassDefRow(cfA, true));
    } else {
      ClassDefRow cdrA = new ClassDefRow(cfA, true);
      ClassDefRow cdrB = new ClassDefRow(cfB, true);
      this.rowsA.add(cdrA);
      this.rowsB.add(cdrB);
      this.rowsAll.add(cdrA);
      this.rowsAll.add(cdrB);
    }
   
    this.rowsAll.add(new BlankRow());

    // Fields
    // TODO: Constant value compare
    Map<String, Field> fieldsA = new HashMap<String, Field>();
    for (Field field : cfA.getFields()) {
      fieldsA.put(field.getSignatureLine(), field);
    }
    Map<String, Field> fieldsB = new HashMap<String, Field>();
    for (Field field : cfB.getFields()) {
      fieldsB.put(field.getSignatureLine(), field);
    }
    Set<String> allFields = new TreeSet<String>();
    allFields.addAll(fieldsA.keySet());
    allFields.addAll(fieldsB.keySet());
    for (String fieldSignature : allFields) {
      // Field annotations
      /* TODO
      RuntimeInvisibleAnnotationsAttribute fieldAnnInvisible = field
          .getAttributes().getRuntimeInvisibleAnnotationsAttribute();
      RuntimeVisibleAnnotationsAttribute fieldAnnVisible = field
          .getAttributes().getRuntimeVisibleAnnotationsAttribute();
      List<Annotation> fieldAnnotations = new ArrayList<Annotation>();
      if (fieldAnnInvisible != null) {
        fieldAnnotations.addAll(fieldAnnInvisible.getAnnotations());
      }
      if (fieldAnnVisible != null) {
        fieldAnnotations.addAll(fieldAnnVisible.getAnnotations());
      }
      for (Annotation annotation : fieldAnnotations) {
        FieldAnnotationDefRow fadr = new FieldAnnotationDefRow(
            annotation);
        this.rows.add(fadr);
      }
       */

      FieldDefRow fdr = null;
      Field field = fieldsA.get(fieldSignature);
      if (field == null) {
        field = fieldsB.get(fieldSignature);
        fdr = new FieldDefRow(cfB, field);
        this.rowsB.add(fdr);
      } else {
        fdr = new FieldDefRow(cfA, field);
        if (!fieldsB.keySet().contains(fieldSignature)) {
          this.rowsA.add(fdr);
        }
      }
     
      this.rowsAll.add(fdr);
    }

    if (allFields.size() > 0) {
      this.rowsAll.add(new BlankRow());
    }

    // Methods
    Map<String, Method> methodsA = new HashMap<String, Method>();
    for (Method method : cfA.getMethods()) {
      Descriptor desc = method.getDescriptor();
      methodsA.put(desc.getReturn() + method.getName() + " " + desc.getParams(), method);
    }
    Map<String, Method> methodsB = new HashMap<String, Method>();
    for (Method method : cfB.getMethods()) {
      Descriptor desc = method.getDescriptor();
      methodsB.put(desc.getReturn() + method.getName() + " " + desc.getParams(), method);
    }

    Set<String> allMethods = new TreeSet<String>();
    allMethods.addAll(methodsA.keySet());
    allMethods.addAll(methodsB.keySet());
    for (String methodTypeNameParams : allMethods) {
      Method methodA = methodsA.get(methodTypeNameParams);
      Method methodB = methodsB.get(methodTypeNameParams);
      if (methodA == null) {
        List<EditorRow> methodRows = getMethodRows(cfB, methodB);
        this.rowsB.addAll(methodRows);
        this.rowsAll.addAll(methodRows);
        // method only exists in B
      } else if (methodB == null) {
        List<EditorRow> methodRows = getMethodRows(cfA, methodA);
        this.rowsA.addAll(methodRows);
        this.rowsAll.addAll(methodRows);
        // method only exists in A
      } else {
        // method exists in both
        addMethodRows(cfA, cfB, methodA, methodB);
      }

      this.rowsAll.add(new BlankRow());
    }

    this.rowsAll.add(new ClassDefRow(cfA, false));
   
    this.renderer.setRedSet(this.rowsA);
View Full Code Here


    this.rows = new ArrayList<EditorRow>();

    // Package
    this.packageDef = new PackageDefRow(cf);
    this.rows.add(this.packageDef);
    this.rows.add(new BlankRow());

    // Imports
    Imports imports = EditorFacade.getInstance().getImports(cf);
    this.renderer.setImports(imports);
    Set<String> ts = imports.getImports();
    this.importDefs = new ArrayList<ImportDefRow>(ts.size());
    for (String imp : ts) {
      ImportDefRow idr = new ImportDefRow(imp);
      this.rows.add(idr);
      this.importDefs.add(idr);
    }

    if (ts.size() > 0) {
      this.rows.add(new BlankRow());
      /* empty space between imports and class def */
    }
   
    // Add some useful information as comments

    // Source file name
    SourceFileAttribute sf = cf.getAttributes().getSourceFileAttribute();
    if (sf != null) {
      ClassCommentRow sfComment = new ClassCommentRow("SourceFile = " + sf.getSourceFile());
      this.rows.add(sfComment);
    }
   
    // Class version
      ClassCommentRow versionComment = new ClassCommentRow("Class Version: " + cf.getMajorVersion() + "." + cf.getMinorVersion());
      this.rows.add(versionComment);

    // Class annotations
    RuntimeInvisibleAnnotationsAttribute annInvisible = cf.getAttributes()
        .getRuntimeInvisibleAnnotationsAttribute();
    RuntimeVisibleAnnotationsAttribute annVisible = cf.getAttributes()
        .getRuntimeVisibleAnnotationsAttribute();
    List<Annotation> classAnnotations = new ArrayList<Annotation>();
    if (annInvisible != null) {
      classAnnotations.addAll(annInvisible.getAnnotations());
    }
    if (annVisible != null) {
      classAnnotations.addAll(annVisible.getAnnotations());
    }
    for (Annotation annotation : classAnnotations) {
      ClassAnnotationDefRow adr = new ClassAnnotationDefRow(annotation);
      this.rows.add(adr);
    }

    // Class
    this.classDef = new ClassDefRow(cf, true);
    this.rows.add(this.classDef);
    this.rows.add(new BlankRow());

    // Fields
    java.util.List fields = cf.getFields();
    for (int i = 0; i < fields.size(); i++) {
      Field field = (Field) fields.get(i);

      // Field annotations
      RuntimeInvisibleAnnotationsAttribute fieldAnnInvisible = field
          .getAttributes().getRuntimeInvisibleAnnotationsAttribute();
      RuntimeVisibleAnnotationsAttribute fieldAnnVisible = field
          .getAttributes().getRuntimeVisibleAnnotationsAttribute();
      List<Annotation> fieldAnnotations = new ArrayList<Annotation>();
      if (fieldAnnInvisible != null) {
        fieldAnnotations.addAll(fieldAnnInvisible.getAnnotations());
      }
      if (fieldAnnVisible != null) {
        fieldAnnotations.addAll(fieldAnnVisible.getAnnotations());
      }
      for (Annotation annotation : fieldAnnotations) {
        FieldAnnotationDefRow fadr = new FieldAnnotationDefRow(
            annotation);
        this.rows.add(fadr);
      }

      FieldDefRow fdr = new FieldDefRow(cf, field);
      this.rows.add(fdr);
      this.classDef.addField(fdr);
    }

    if (fields.size() > 0) {
      this.rows.add(new BlankRow());
    }

    // Methods
    java.util.List methods = cf.getMethods();
    for (int i = 0; i < methods.size(); i++) {
      Method method = (Method) methods.get(i);

      // Method annotations
      boolean deprecatedAnnotationAdded = false;
      RuntimeInvisibleAnnotationsAttribute methodAnnInvisible = method
          .getAttributes().getRuntimeInvisibleAnnotationsAttribute();
      RuntimeVisibleAnnotationsAttribute methodAnnVisible = method
          .getAttributes().getRuntimeVisibleAnnotationsAttribute();
      List<Annotation> methodAnnotations = new ArrayList<Annotation>();
      if (methodAnnInvisible != null) {
        methodAnnotations.addAll(methodAnnInvisible.getAnnotations());
      }
      if (methodAnnVisible != null) {
        methodAnnotations.addAll(methodAnnVisible.getAnnotations());
      }
      for (Annotation annotation : methodAnnotations) {
        MethodAnnotationDefRow madr = new MethodAnnotationDefRow(
            annotation);
        this.rows.add(madr);
        if ("java.lang.Deprecated".equals(annotation.getName())) {
          deprecatedAnnotationAdded = true;
          // store this information so that
          // the Deprecated attribute isn't used to
          // create another deprecation EditorRow
        }
      }

      Attributes attr = method.getAttributes();
      CodeAttribute codeAttr = attr.getCode();
      MethodDefRow mdr = new MethodDefRow(cf, method, true,
          codeAttr != null);
      if (!deprecatedAnnotationAdded && method.isDeprecated()) {
        DeprecatedAnnotationDefRow ddr = new DeprecatedAnnotationDefRow();
        this.rows.add(ddr);
      }
      this.rows.add(mdr);
      this.classDef.addMethod(mdr);
      LineNumberTableAttribute lnAttr = null;
      LocalVariableTableAttribute lvs = null;
      if (codeAttr != null) {
        if (codeAttr.getAttributes() != null) {
          lnAttr = codeAttr.getAttributes().getLineNumberTable();
          lvs = codeAttr.getAttributes().getLocalVariableTable();
        }
        Code code = codeAttr.getCode();
        DecompilationContext dc = code.createDecompilationContext();
        dc.setPosition(0);
        for (Instruction instruction : code.getInstructions()) {

          if (instruction instanceof Label) {
            LabelRow lr = new LabelRow((Label) instruction, mdr);
            lr.setParentCode(code);
            this.rows.add(lr);
            mdr.addCodeRow(lr);
          } else {
            int lineNumber = -1;

            if (lnAttr != null) {
              lineNumber = lnAttr.getLineNumber(dc.getPosition());
            }
            if (lvs != null) {
              List locals = lvs
                  .getLocalVariable(dc.getPosition());
              for (int k = 0; k < locals.size(); k++) {
                LocalVariable lv = (LocalVariable) locals
                    .get(k);
                LocalVariableDefRow lvdr = new LocalVariableDefRow(
                    lv, mdr);
                this.rows.add(lvdr);
                mdr.addLocalVariable(lvdr);
              }
            }

            CodeRow cd = new CodeRow(cf, mdr, instruction);
            cd.setPosition(dc.getPosition());
            cd.setDecompilationContext(dc);
            cd.setParentCode(code);
            cd.setBreakpoint(EditorFacade.getInstance()
                .getBreakpoint(cf.getFullClassName(),
                    method.getName(),
                    method.getDescriptor(),
                    dc.getPosition()));

            if (lineNumber != -1) {
              cd.setLineNumber(lineNumber);
            }

            this.rows.add(cd);
            mdr.addCodeRow(cd);

            dc.incrementPosition(instruction);
          }

        }

        this.rows.add(new MethodDefRow(cf, method, false, true));
      }
      this.rows.add(new BlankRow());
    }

    this.rows.add(new ClassDefRow(cf, false));

    this.label.setText("Bytecode Editor: " + cf.getFullClassName());
View Full Code Here

TOP

Related Classes of net.sf.rej.gui.editor.row.BlankRow

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.