Package net.sf.rej.java.constantpool

Examples of net.sf.rej.java.constantpool.ConstantPoolInfo


  @Override
  public void processInstruction(IterationContext sc, Instruction instruction) {
    Parameters params = instruction.getParameters();
    for (int i = 0; i < params.getCount(); i++) {
      if (params.getType(i) == ParameterType.TYPE_CONSTANT_POOL_FIELD_REF) {
        ConstantPoolInfo cpi = sc.getDc().getConstantPool().get(
            params.getInt(i));
        RefInfo ri = (RefInfo) cpi;
        boolean classNamesMatch = ri.getClassName().equals(className);

        if (classNamesMatch) {
          String instructionLine = instruction.getMnemonic() + " "
              + instruction.getParameters().getString(sc.getDc());
          Link link = new Link();
          link.setText("Field Ref : " + sc.getCf().getFullClassName() + "." + sc.getMethod().getName() + " / " + instructionLine);
          link.setAnchor(Link.ANCHOR_METHOD_CODE);
          link.setProject(sc.getProject());
          link.setFile(sc.getFilename());
          link.setTab(Tab.EDITOR);
          link.setMethod(sc.getMethod());
          link.setPosition(sc.getDc().getPosition());

          MainWindow.getInstance().getSearchTab().addResult(link);
          this.resultCount++;
        }

      } else if (params.getType(i) == ParameterType.TYPE_CONSTANT_POOL_METHOD_REF) {
        ConstantPoolInfo cpi = sc.getDc().getConstantPool().get(
            params.getInt(i));
        RefInfo ri = (RefInfo) cpi;
        boolean classNamesMatch = ri.getClassName().equals(className);

        if (classNamesMatch) {
          String instructionLine = instruction.getMnemonic() + " "
              + instruction.getParameters().getString(sc.getDc());
          Link link = new Link();
          link.setText("Method Call : " + sc.getCf().getFullClassName() + "."  + sc.getMethod().getName() + " / " + instructionLine);
          link.setAnchor(Link.ANCHOR_METHOD_CODE);
          link.setProject(sc.getProject());
          link.setFile(sc.getFilename());
          link.setTab(Tab.EDITOR);
          link.setMethod(sc.getMethod());
          link.setPosition(sc.getDc().getPosition());
          MainWindow.getInstance().getSearchTab().addResult(link);
          this.resultCount++;
        }

      } else if (params.getType(i) == ParameterType.TYPE_CONSTANT_POOL_CLASS) {
        ConstantPoolInfo cpi = sc.getDc().getConstantPool().get(
            params.getInt(i));
        ClassInfo ci = (ClassInfo) cpi;
        boolean classNamesMatch = ci.getName().equals(className);

        if (classNamesMatch) {
View Full Code Here


  public String toString() {
    return this.index + " - " + this.getName();
  }

  public String getName() {
    ConstantPoolInfo cpi = this.pool.get(this.nameIndex);
    return cpi.getValue();
  }
View Full Code Here

        ConstantPool pool = new ConstantPool();
        pool.init(contantPoolCount);
        cf.setPool(pool);

        for (int i = 1; i < contantPoolCount; i++) {
            ConstantPoolInfo cpi = ConstantPoolInfo.getCPI(parser, pool);
            pool.set(i, cpi);

            // 8byte types take up two indices
            if (cpi.getType() == ConstantPoolInfo.LONG
                    || cpi.getType() == ConstantPoolInfo.DOUBLE)
                i++;
        }

        cf.setAccessFlags(parser.getShortAsInt());
        cf.setThisClass(parser.getShortAsInt());
View Full Code Here

  public int getNameIndex() {
    return this.nameIndex;
  }

  public String getName() {
    ConstantPoolInfo cpi = this.cp.get(this.nameIndex);

    return cpi.getValue();
  }
View Full Code Here

     * example <code>"net.sf.rej.java.ClassFile"</code>.
     * @return the full name of this class.
     */
    public String getFullClassName() {
        ConstantPool cp = this.pool;
        ConstantPoolInfo cpi = cp.get(this.getThisClass());
        return cpi.getValue();
    }
View Full Code Here

     * @return the full name of the super class of this class.
     */
    public String getSuperClassName() {
      if (this.getSuperClass() == 0) return null;
     
        ConstantPoolInfo cpi = this.pool.get(this.getSuperClass());
        return cpi.getValue();
    }
View Full Code Here

    public void setConstantPool(ConstantPool pool) {
        this.cp = pool;

        List<Wrapper<ConstantPoolInfo>> al = new ArrayList<Wrapper<ConstantPoolInfo>>();
        for (int i = 0; i < this.cp.size(); i++) {
            ConstantPoolInfo cpi = this.cp.get(i);
            if (cpi != null) {
                switch(cpi.getType()) {
                  case ConstantPoolInfo.DOUBLE:
                  case ConstantPoolInfo.FLOAT:
                  case ConstantPoolInfo.INTEGER:
                  case ConstantPoolInfo.LONG:
                  case ConstantPoolInfo.STRING:
View Full Code Here

        int value = 0;
        if (o instanceof String) {
            // parse into ClassInfo, RefInfo NameAndTypeInfo etc
            throw new RuntimeException("Editing not implemented.");
        } else {
            ConstantPoolInfo cpi = (ConstantPoolInfo) ( (Wrapper) o).getContent();
            value = this.cp.indexOf(cpi);
        }

        return Integer.valueOf(value);
    }
View Full Code Here

            }
           
          sd.drawDefault(" ");

            sd.drawField(f.getName());
            ConstantPoolInfo constant = f.getConstant();
            if (constant != null) {
              sd.drawDefault(" = ");
              drawConstant(sd, constant);
            }
            sd.drawDefault(";");
        } else if (er instanceof DeprecatedAnnotationDefRow) {
          sd.drawIndent();
          sd.drawAnnotation("@Deprecated");
        } else if (er instanceof ClassAnnotationDefRow || er instanceof MethodAnnotationDefRow || er instanceof FieldAnnotationDefRow) {
          Annotation ann = null;
          if (er instanceof ClassAnnotationDefRow) {
            ann = ((ClassAnnotationDefRow)er).getAnnotation();
          } else if (er instanceof MethodAnnotationDefRow) {
            sd.drawIndent();
            ann = ((MethodAnnotationDefRow)er).getAnnotation();
          } else {
            sd.drawIndent();
            ann = ((FieldAnnotationDefRow)er).getAnnotation();
          }
         
          sd.drawAnnotation("@" + ia.getShortName(ann.getName()));
          if (ann.getElementValueCount() > 0) {
            sd.drawDefault("(");
            Map<String, ElementValue> elementValues = ann.getElementValues();
            boolean first = true;
            for (Entry<String, ElementValue> entry : elementValues.entrySet()) {
              if (!first) {
                sd.drawDefault(", ");
              } else {
                first = false;
              }
              if (entry.getKey().equals("value") && elementValues.size() == 1) {
                // only one element, named "value", don't show the display name, just show the value
              } else {
                sd.drawDefault(entry.getKey() + "=");
              }
              ElementValue ev = entry.getValue();
              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(";");
                }
            }
        } else if (er instanceof LocalVariableDefRow) {
            LocalVariableDefRow lvdr = (LocalVariableDefRow)er;
            LocalVariable lv = lvdr.getLocalVariable();
            JavaType ret = lv.getDescriptor().getReturn();
          sd.drawIndent();
          sd.drawIndent();

            if (ret.isPrimitive()) {
                sd.drawKeyword(ret.getType());
            } else {
                sd.drawDefault(ia.getShortName(ret.getType()));
            }
            sd.drawDefault(ret.getDimensions() + " " + lv.getName() + " (#" + lv.getIndex() + " " + lv.getStartPc() + " - " + lv.getEndPc() + ")");
        } else if (er instanceof LabelRow) {
            LabelRow lr = (LabelRow)er;
          sd.drawIndent();
          sd.drawIndent();
            sd.drawDefault(lr.getLabel().getId() + ":");
        } else if (er instanceof CodeRow) {
            CodeRow cr = (CodeRow)er;
           
            // execution row
            if (cr.isExecutionRow()) {
              sd.setExecutionBackground();
            }
            // breakpoint
            if (cr.getBreakpoint() != null) {
              sd.drawBreakpoint();
            }
           
            // line identifier
            LineIdentifierMode mode = EditorFacade.getInstance().getLineIdentifierMode();
            switch (mode.getMode()) {
                case LineIdentifierMode.MODE_OFF:
                    break;
                case LineIdentifierMode.MODE_PC:
                    sd.drawSmall(String.valueOf(cr.getPosition()), 15);
                    break;
                case LineIdentifierMode.MODE_SOURCELINE:
                    if (cr.hasLineNumber()) {
                        sd.drawSmall(String.valueOf(cr.getLineNumber()), 0);
                    }
                    break;
            }

            sd.setOffset(0);

            Instruction inst = cr.getInstruction();
            DecompilationContext dc = cr.getDecompilationContext();
            LocalVariableTableAttribute lvs = dc.getLocalVariableTable();
            ConstantPool pool = dc.getConstantPool();
          sd.drawIndent();
          sd.drawIndent();
            sd.drawInstruction(inst.getMnemonic());
            Parameters params = inst.getParameters();
            for (int i = 0; i < params.getCount(); i++) {
                try {
                    switch (params.getType(i)) {
                        case TYPE_LOCAL_VARIABLE:
                        case TYPE_LOCAL_VARIABLE_WIDE:
                        case TYPE_LOCAL_VARIABLE_READONLY:
                            if (lvs == null) {
                                sd.drawDefault(" " + params.getInt(i));
                            } else {
                                LocalVariable lv = lvs.getLocalVariable(params.getInt(i), cr.getPosition());
                                if (lv == null) {
                                    sd.drawDefault(" " + params.getInt(i));
                                } else {
                                    sd.drawDefault(" " + lv.getName());
                                }
                            }
                            break;
                        case TYPE_CONSTANT_POOL_METHOD_REF: {
                          int index = params.getInt(i);
                            ConstantPoolInfo cpi = pool.get(index);
                            renderMethodRef(sd, ia, (RefInfo) cpi, index);
                            break;
                        }
                        case TYPE_CONSTANT_POOL_FIELD_REF: {
                          int index = params.getInt(i);
                            ConstantPoolInfo cpi = pool.get(index);
                            renderFieldRef(sd, ia, (RefInfo) cpi, index);
                            break;
                        }
                        case TYPE_CONSTANT_POOL_CLASS: {
                          int index = params.getInt(i);
                            ConstantPoolInfo cpi = pool.get(index);
                            renderClassRef(sd, ia, (ClassInfo) cpi, index);
                            break;
                        }
                        case TYPE_CONSTANT_POOL_CONSTANT: {
                           int index = params.getInt(i);
                           ConstantPoolInfo cpi = pool.get(index);
                           renderConstant(sd, cpi, index);
                           break;
                        }
                        case TYPE_LABEL: {
                            Label label = (Label) params.getObject(i);
View Full Code Here

 
  public Map<String, ElementValue> getElementValues() {
    Map<String, ElementValue> result = new HashMap<String, ElementValue>();
    for (Entry<Integer, ElementValue> entry: this.elementValues.entrySet()) {
      int key = entry.getKey();
      ConstantPoolInfo nameInfo = this.pool.get(key);
      String name = nameInfo.getValue();
      result.put(name, entry.getValue());
    }
   
    return result;
  }
View Full Code Here

TOP

Related Classes of net.sf.rej.java.constantpool.ConstantPoolInfo

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.