Examples of MethodDefRow


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

        CodeRow cr = (CodeRow) obj;
        RemoveInstructionAction ria = new RemoveInstructionAction(cr
            .getParentCode(), cr.getInstruction());
        ga.add(ria);
      } else if (obj instanceof MethodDefRow) {
        MethodDefRow mdr = (MethodDefRow) obj;
        RemoveMethodAction rma = new RemoveMethodAction(mdr
            .getClassFile(), mdr.getMethod());
        ga.add(rma);
      } else if (obj instanceof FieldDefRow) {
        FieldDefRow fdr = (FieldDefRow) obj;
        RemoveFieldAction rfa = new RemoveFieldAction(fdr
            .getClassFile(), fdr.getField());
View Full Code Here

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

              drawElementValue(sd, ev, ia);
            }
            sd.drawDefault(")");
          }
        } else if (er instanceof MethodDefRow) {
            MethodDefRow mdr = (MethodDefRow)er;
          sd.drawIndent();
          if (mdr.isClosing()) {
                sd.drawDefault("}");
            } else {
                Method m = mdr.getMethod();

                MethodSignature methodSig = null;
                boolean displayGenerics = SystemFacade.getInstance().getPreferences().isSettingTrue(Settings.DISPLAY_GENERICS);
                if (displayGenerics) {
                  SignatureAttribute signature = m.getAttributes().getSignatureAttribute();
                  if (signature != null) {
                    methodSig = Signatures.getMethodSignature(signature.getSignatureString());
                  }
                }

                String access = m.getAccessString();
                if (access.length() > 0) {
                    sd.drawKeyword(access + " ");
                }
               
                 if (methodSig != null) {
                   List<FormalTypeParameter> typeParams = methodSig.getFormalTypeParameters();
                     renderFormalTypeParameters(sd, ia, typeParams);
                   if (typeParams != null && typeParams.size() > 0) {
                     sd.drawKeyword(" ");
                   }
                }
               
                JavaType ret = m.getDescriptor().getReturn();
                if (methodSig == null) {
                  if (ret.isPrimitive()) {
                    sd.drawKeyword(ret.getType());
                  } else {
                    sd.drawDefault(ia.getShortName(ret.getType()));
                  }

                  sd.drawDefault(ret.getDimensions());
                } else {
                  renderGenericJavaType(sd, ia, methodSig.getReturnType());
                }
               
                sd.drawDefault(" ");

                if (m.isDeprecated()) {
                  sd.drawDefaultOverstrike(m.getName());
                } else {
                  sd.drawDefault(m.getName());
                }

                CodeAttribute ca = m.getAttributes().getCode();
                LocalVariableTableAttribute lvs = null;
                if (ca != null) {
                  lvs = ca.getAttributes().getLocalVariableTable();
                }

                int paramLVDefOffset = 0;
                if (!AccessFlags.isStatic(m.getAccessFlags())) {
                  paramLVDefOffset = 1;
                }

                sd.drawDefault("(");
                List<JavaType> params = m.getDescriptor().getParamList();
                List<GenericJavaType> genParams = null;
                if (methodSig != null) {
                  genParams = methodSig.getParameters();
                }
            boolean displayVarargs = SystemFacade.getInstance().getPreferences().isSettingTrue(Settings.DISPLAY_VARARGS);
            for (int i = 0; i < params.size(); i++) {
                    if (i > 0) {
                        sd.drawDefault(", ");
                    }
                    JavaType item = params.get(i);
                    // last time, method has varargs flag and type is a one dimensional array
                    boolean isLastItem = (i == params.size()-1);
                    if (displayVarargs
                     && isLastItem
                     && AccessFlags.isVarArgs(m.getAccessFlags())
                     && (item.getDimensionCount() > 0)) {
                      item.dropDimension();
                      if (methodSig == null) {
                        if (item.isPrimitive()) {
                          sd.drawKeyword(item.getType());
                        } else {
                          sd.drawDefault(ia.getShortName(item.getType()));
                        }
                        sd.drawDefault(item.getDimensions());
                      } else {
                        GenericJavaType genType = genParams.get(i);
                        genType.getBaseType().dropDimension();
                        renderGenericJavaType(sd, ia, genType);
                      }

                      sd.drawDefault(" ... ");
                      LocalVariable lv = null;
                      if (lvs != null) {
                        lv = lvs.getLocalVariable(paramLVDefOffset + i, 0);
                      }
                      if (lv != null) {
                        sd.drawDefault(lv.getName());
                      } else {
                        sd.drawDefault("p" + i);
                      }
                     
                    } else {
                      if (methodSig == null) {
                        if (item.isPrimitive()) {
                          sd.drawKeyword(item.getType());
                        } else {
                          sd.drawDefault(ia.getShortName(item.getType()));
                        }
                        sd.drawDefault(item.getDimensions());
                      } else {
                        renderGenericJavaType(sd, ia, genParams.get(i));
                      }
                      sd.drawDefault(" ");
                      LocalVariable lv = null;
                      if (lvs != null) {
                        lv = lvs.getLocalVariable(paramLVDefOffset + i, 0);
                      }
                      if (lv != null) {
                        sd.drawDefault(lv.getName());
                      } else {
                        sd.drawDefault("p" + i);
                      }
                    }
                }

                sd.drawDefault(")");
                List exc = m.getExceptions();
                for (int i = 0; i < exc.size(); i++) {
                    if (i == 0) {
                        sd.drawKeyword(" throws ");
                    } else {
                        sd.drawDefault(", ");
                    }
                    sd.drawDefault(ia.getShortName(((ExceptionDescriptor) exc.get(i)).getName()));
                }
                if (mdr.hasBody()) {
                  sd.drawDefault(" {");
                } else {
                  sd.drawDefault(";");
                }
            }
View Full Code Here

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

      CodeRow cr = (CodeRow) er;
      if (cr.isExecutionRow()) {
        return new Color(255, 190, 190);
      }
    } else if (er instanceof MethodDefRow) {
      MethodDefRow mdr = (MethodDefRow) er;
      if (mdr.isExecutionRow()) {
        return new Color(255, 190, 190);
      }
     
    }
    return Color.white;
View Full Code Here

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

    // TODO: Annotations and non-annotation deprecation
   
    // We matched these methods based on descriptor (=type & params) and name
    // but the thrown exceptions and access type may still be different
    // and if it is, we want that highlighted
    MethodDefRow mdrA = null;
    MethodDefRow mdrB = null;
    if (methodA.getAccessFlags() == methodB.getAccessFlags()
    && methodA.getExceptions().equals(methodB.getExceptions())) {
      // everything is equal, just add one line
      MethodDefRow mdr = new MethodDefRow(cfA, methodA, true, methodA.getAttributes().getCode() != null);
      mdrA = mdr;
      mdrB = mdr;
      this.rowsAll.add(mdr);
    } else {
      mdrA = new MethodDefRow(cfA, methodA, true, methodA.getAttributes().getCode() != null);
      rowsA.add(mdrA);
      mdrB = new MethodDefRow(cfB, methodB, true, methodB.getAttributes().getCode() != null);
      rowsB.add(mdrB);
      rowsAll.add(mdrA);
      rowsAll.add(mdrB);
    }

    Attributes attrA = methodA.getAttributes();
    Attributes attrB = methodB.getAttributes();
    CodeAttribute codeAttrA = attrA.getCode();
    CodeAttribute codeAttrB = attrB.getCode();

    LineNumberTableAttribute lnAttrA = null;
    LineNumberTableAttribute lnAttrB = null;
    LocalVariableTableAttribute lvsA = null;
    LocalVariableTableAttribute lvsB = null;
    if (codeAttrA != null && codeAttrB != null) {
      // TODO: deal with the case where only one is null
      // ie, one method has code, the other doesn't
     
      if (codeAttrA.getAttributes() != null) {
        lnAttrA = codeAttrA.getAttributes().getLineNumberTable();
        lvsA = codeAttrA.getAttributes().getLocalVariableTable();
      }
      if (codeAttrB.getAttributes() != null) {
        lnAttrB = codeAttrB.getAttributes().getLineNumberTable();
        lvsB = codeAttrB.getAttributes().getLocalVariableTable();
      }

      Code codeA = codeAttrA.getCode();
      Code codeB = codeAttrB.getCode();
     
      DecompilationContext dcA = codeA.createDecompilationContext();
      DecompilationContext dcB = codeB.createDecompilationContext();
     
      List<Instruction> instructionsA = codeA.getInstructions();
      List<Instruction> instructionsB = codeB.getInstructions();
      dcA.setPosition(0);
      dcB.setPosition(0);
     
      List<EditorRow> methodRowsA = getMethodRows(instructionsA, codeA, mdrA, lnAttrA, lvsA, dcA, cfA);
      List<EditorRow> methodRowsB = getMethodRows(instructionsB, codeB, mdrB, lnAttrB, lvsB, dcB, cfB);
     
      // find out the equal instructions at the beginning of the block
      int startEqCount = 0;
      while (true) {
        if (startEqCount == methodRowsA.size()) break;
        if (startEqCount == methodRowsB.size()) break;
       
        EditorRow erA = methodRowsA.get(startEqCount);
        EditorRow erB = methodRowsB.get(startEqCount);
        boolean equal = rowsAreEqual(erA, erB);
       
        if (!equal) break;
        startEqCount++;
      }
      for (int i=0; i < startEqCount; i++) {
        this.rowsAll.add(methodRowsA.get(0));
        methodRowsA.remove(0);
        methodRowsB.remove(0);
      }

      // find out the equal instructions at the end of each code block
      int endEqCount = 0;
      while (true) {
        if (endEqCount == methodRowsA.size()) break;
        if (endEqCount == methodRowsB.size()) break;
       
        EditorRow erA = methodRowsA.get((methodRowsA.size()-1)-endEqCount);
        EditorRow erB = methodRowsB.get((methodRowsB.size()-1)-endEqCount);
        boolean equal = rowsAreEqual(erA, erB);
       
        if (!equal) break;
        endEqCount++;
      }
      List<EditorRow> equalRowsAtTheEnd = new ArrayList<EditorRow>();
      for (int i=0; i < endEqCount; i++) {
        equalRowsAtTheEnd.add(methodRowsA.get(methodRowsA.size()-1));
        methodRowsA.remove(methodRowsA.size()-1);
        methodRowsB.remove(methodRowsB.size()-1);
      }
     
        int m = methodRowsA.size();
        int n = methodRowsB.size();
      int[][] C = new int[m+1][n+1];
        lcs(C, methodRowsA, methodRowsB);
       
        List<EditorRow> common = new ArrayList<EditorRow>();
        bt(C, methodRowsA, methodRowsB, m, n, common);

        for (EditorRow commonRow : common) {
          // rows from set A before the next common row
          while (!rowsAreEqual(methodRowsA.get(0), commonRow)) {
            this.rowsAll.add(methodRowsA.get(0));
            this.rowsA.add(methodRowsA.get(0));
            methodRowsA.remove(0);
          }

          // rows from set B before the next common row
          while (!rowsAreEqual(methodRowsB.get(0), commonRow)) {
            this.rowsAll.add(methodRowsB.get(0));
            this.rowsB.add(methodRowsB.get(0));
            methodRowsB.remove(0);
          }
         
          this.rowsAll.add(commonRow);
          methodRowsA.remove(0);
          methodRowsB.remove(0);
        }
       
        this.rowsA.addAll(methodRowsA);
        this.rowsAll.addAll(methodRowsA);
       
        this.rowsB.addAll(methodRowsB);
        this.rowsAll.addAll(methodRowsB);

      this.rowsAll.addAll(equalRowsAtTheEnd);
      this.rowsAll.add(new MethodDefRow(cfA, methodA, false, true));
    }

  }
View Full Code Here

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

        wrapper.setDisplay(cdr.getClassFile().getShortClassName());
      } else if (er instanceof FieldDefRow) {
        FieldDefRow fdr = (FieldDefRow)er;
        wrapper.setDisplay(fdr.getField().getName());
      } else if (er instanceof MethodDefRow) {
        MethodDefRow mdr = (MethodDefRow)er;
        wrapper.setDisplay(mdr.getMethod().getName());
      } else {
            throw new AssertionError("Invalid object type: " + er.getClass());
      }
    }
   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.