Package net.sf.rej.java

Examples of net.sf.rej.java.Method


      MethodNode mNode = (MethodNode) node;
      return this.offsets.get(mNode.getMethod());
    } else if (node instanceof MethodAccessFlagsNode) {
      Range parentRange = getRange((StructureNode)node.getParent());
      MethodAccessFlagsNode mafNode = (MethodAccessFlagsNode) node;
      Method method = mafNode.getMethod();
      Range afRange = method.getOffsetMap().get(Method.OffsetTag.ACCESS_FLAGS);
      return afRange.offsetBy(parentRange.getOffset());
    } else if (node instanceof MethodNameNode) {
      Range parentRange = getRange((StructureNode)node.getParent());
      MethodNameNode mafNode = (MethodNameNode) node;
      Method method = mafNode.getMethod();
      Range afRange = method.getOffsetMap().get(Method.OffsetTag.METHOD_NAME);
      return afRange.offsetBy(parentRange.getOffset());
    } else if (node instanceof MethodDescriptorNode) {     
      Range parentRange = getRange((StructureNode)node.getParent());
      MethodDescriptorNode mafNode = (MethodDescriptorNode) node;
      Method method = mafNode.getMethod();
      Range afRange = method.getOffsetMap().get(Method.OffsetTag.METHOD_DESCRIPTOR);
      return afRange.offsetBy(parentRange.getOffset());
    } else if (node instanceof AttributeNode) {
      AttributeNode aNode = (AttributeNode) node;
      AttributesNode an = (AttributesNode) aNode.getParent();
      Range range = getRange(an);
View Full Code Here


  public void refresh() {
    this.methods = new ArrayList<MethodNode>();
    List list = this.cf.getMethods();
    for (int i = 0; i < list.size(); i++) {
      Method method = (Method) list.get(i);
      MethodNode methodNode = new MethodNode(this.cf, method);
      methodNode.setParent(this);
      this.methods.add(methodNode);
    }
  }
View Full Code Here

        MethodDefRow mdr = (MethodDefRow) er;
        Range offset = this.offsets.get(mdr.getMethod());
        this.hexEditor.getHexEditor().getSelectionModel().setSelectedInverval(offset.getOffset(), offset.getOffset() + offset.getSize());         
      } else if (er instanceof CodeRow) {
        CodeRow cr = (CodeRow) er;
        Method m = cr.getEnclosingMethodDef().getMethod();
        CodeAttribute ca = m.getAttributes().getCode();
        // "cache" method offset maps
        Map<Object, Range> methodOffsetMap = this.methodOffsets.get(m);
        if (methodOffsetMap == null) {
          methodOffsetMap = m.getOffsetMap();
          this.methodOffsets.put(m, methodOffsetMap);
        }
        Range range = methodOffsetMap.get(ca);
        int offset = this.offsets.get(m).getOffset() +  range.getOffset() + 14 + cr.getPosition();
        DecompilationContext dc = ca.getCode().createDecompilationContext();
View Full Code Here

            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(", ");
View Full Code Here

    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
View Full Code Here

            // cf will be null if referenced class is not in project classpath
            if (cf != null) {
                List methods = cf.getMethods();
                for (int i = 0; i < methods.size(); i++) {
                    Method method = (Method) methods.get(i);
                    Wrapper<Method> wrapper = new Wrapper<Method>();
                    wrapper.setContent(method);
                    wrapper.setDisplay(method.getSignatureLine());
                    this.methodModel.addElement(wrapper);
                }
            }

        } catch (Exception e) {
View Full Code Here

      ClassIndex ci = SystemFacade.getInstance().getClassIndex();
      ClassLocator cl = ci.getLocator(className);
      if (cl != null && cl.getFileSet().equals(this.openProject.getFileSet())) {
        ClassFile cf = SystemFacade.getInstance().getClassFile(cl);
        List methods = cf.getMethods();
        Method method = null;
        for (int i = 0; i < methods.size(); i++) {
          Method m = (Method) methods.get(i);
          if (m.getName().equals(methodName)
              && m.getDescriptor().equals(desc)) {
            method = m;
            break;
          }
        }
View Full Code Here

    }

    // 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);
            }
View Full Code Here

      CodeRow cr = (CodeRow) o;
      modifyInstruction(cr.getPosition(), cr.getInstruction(), cr.getDecompilationContext().getLocalVariableTable());
      this.list.repaint();
    } else if (o instanceof MethodDefRow) {
      MethodDefRow mdr = (MethodDefRow) o;
      Method method = mdr.getMethod();
      CodeAttribute code = method.getAttributes().getCode();
      int flags = method.getAccessFlags();
      if (!AccessFlags.isNative(flags) && !AccessFlags.isAbstract(flags)) {
        this.methodEditor.invoke(method.getName(), method
            .getDescriptor(), method.getAccessFlags(), Integer.valueOf(
            code.getMaxStackSize()), Integer.valueOf(code
            .getMaxLocals()), method.getExceptions());
      } else {
        this.methodEditor.invoke(method.getName(), method
            .getDescriptor(), method.getAccessFlags(), null, null,
            method.getExceptions());
      }

      if (!this.methodEditor.wasCancelled()) {
        AccessFlags af = this.methodEditor.getAccessFlags();
        String name = this.methodEditor.getMethodName();
View Full Code Here

    for (int row : rows) {
      Object obj = this.model.elementAt(row);
      if (obj instanceof MethodDefRow) {
        MethodDefRow mdr = (MethodDefRow) obj;
        if (!mdr.isClosing()) {
          Method method = mdr.getMethod();
          List<String> exceptionNames = new ArrayList<String>();
          for (ExceptionDescriptor ex : method
              .getExceptions()) {
            exceptionNames.add(ex.getName());
          }
          // TODO: Attributes are not being copied

          TransferrableMethod transferrable = new TransferrableMethod();
          transferrable.setMethodName(method.getName());
          transferrable.setDescriptor(method.getDescriptor());
          transferrable.setAccessFlags(method.getAccessFlags());
          CodeAttribute ca = method.getAttributes().getCode();
          if (ca != null) {
            transferrable.setMaxStack(ca.getMaxStackSize());
            transferrable.setMaxLocals(ca.getMaxLocals());
            List<Instruction> list = new ArrayList<Instruction>();
            for (EditorRow er : mdr.getCodeRows()) {
View Full Code Here

TOP

Related Classes of net.sf.rej.java.Method

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.