Package net.sf.rej.java

Examples of net.sf.rej.java.JavaType


  @Override
  public List<StackElement> getPoppedElements(DecompilationContext dc) {
    List<StackElement> elements = new ArrayList<StackElement>();
    RefInfo ri = (RefInfo) dc.getConstantPool().get(this.index);
    Descriptor desc = ri.getDescriptor();
    JavaType jt = desc.getReturn();
    if (jt.getDimensionCount() > 0 || (!jt.isPrimitive())) {
      // array or primitive are both refs
      elements.add(new StackElement("value", StackElementType.REF));
    } else {
      // primitive non-array
      if (jt.getType().equals("long")) {
        elements.add(new StackElement("value", StackElementType.LONG));       
      } else if (jt.getType().equals("float")) {
        elements.add(new StackElement("value", StackElementType.FLOAT));
      } else if (jt.getType().equals("double")) {
        elements.add(new StackElement("value", StackElementType.DOUBLE));
      } else {
        // boolean, byte, short, char and int are all of type int
        elements.add(new StackElement("value", StackElementType.INT));
      }
View Full Code Here


  @Override
  public List<StackElement> getPushedElements(DecompilationContext dc) {
    List<StackElement> elements = new ArrayList<StackElement>();
    RefInfo ri = (RefInfo) dc.getConstantPool().get(this.index);
    Descriptor desc = ri.getDescriptor();
    JavaType jt = desc.getReturn();
    if (jt.getDimensionCount() > 0 || (!jt.isPrimitive())) {
      // array or primitive are both refs
      elements.add(new StackElement("result", StackElementType.REF));
    } else {
      // primitive non-array
      if (jt.getType().equals("long")) {
        elements.add(new StackElement("result", StackElementType.LONG));       
      } else if (jt.getType().equals("float")) {
        elements.add(new StackElement("result", StackElementType.FLOAT));
      } else if (jt.getType().equals("double")) {
        elements.add(new StackElement("result", StackElementType.DOUBLE));
      } else {
        // boolean, byte, short, char and int are all of type int
        elements.add(new StackElement("result", StackElementType.INT));
      }
View Full Code Here

            sd.drawIndent();
            String access = f.getAccessString();
            if (access.length() > 0) {
                sd.drawKeyword(access + " ");
            }
            JavaType ret = f.getDescriptor().getReturn();
            if (fieldSig == null) {
              if (ret.isPrimitive()) {
                sd.drawKeyword(ret.getType());
              } else {
                sd.drawDefault(ia.getShortName(ret.getType()));
              }
              sd.drawDefault(ret.getDimensions());
            } else {
              renderGenericJavaType(sd, ia, fieldSig.getType());
            }
           
          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() + ":");
View Full Code Here

    if (moveDownButton == null) {
      moveDownButton = new JButton();
      moveDownButton.setText("Move Down");
      moveDownButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          JavaType jt = (JavaType)ExceptionChooseDialog.this.paramList.getSelectedValue();
          if (jt != null) {
            int index = ExceptionChooseDialog.this.paramList.getSelectedIndex();
            if (index < (ExceptionChooseDialog.this.model.size()-1)) {
              ExceptionChooseDialog.this.model.remove(index);
              ExceptionChooseDialog.this.model.add(index+1, jt);
View Full Code Here

    if (moveUpButton == null) {
      moveUpButton = new JButton();
      moveUpButton.setText("Move Up");
      moveUpButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          JavaType jt = (JavaType)ExceptionChooseDialog.this.paramList.getSelectedValue();
          if (jt != null) {
            int index = ExceptionChooseDialog.this.paramList.getSelectedIndex();
            if (index > 0) {
              ExceptionChooseDialog.this.model.remove(index);
              ExceptionChooseDialog.this.model.add(index-1, jt);
View Full Code Here

      sd.drawDefault(">");
    }
  }

  private void renderGenericJavaType(JavaBytecodeSyntaxDrawer sd, Imports ia, GenericJavaType gjt) {
    JavaType baseType = gjt.getBaseType();
        if (baseType.isPrimitive()) {
            sd.drawKeyword(baseType.getType());
        } else {
            sd.drawDefault(ia.getShortName(baseType.getType()));
        }
            
        List<TypeArgument> typeArgs = gjt.getTypeArguments();
        if (typeArgs.size() > 0) {
          sd.drawDefault("<");
          boolean isFirstTypeArg = true;
          for (TypeArgument typeArg : typeArgs) {
            if (isFirstTypeArg) {
              isFirstTypeArg = false;
            } else {
              sd.drawDefault(", ");
            }
            if (typeArg instanceof GenericJavaType) {
              renderGenericJavaType(sd, ia, (GenericJavaType) typeArg);
            } else if (typeArg instanceof BoundTypeArgument) {
              BoundTypeArgument bta = (BoundTypeArgument) typeArg;
              sd.drawDefault("? ");
              sd.drawKeyword(bta.getBoundString());
              sd.drawDefault(" ");
              renderGenericJavaType(sd, ia, bta.getBound());
            } else if (typeArg instanceof Any) {
              sd.drawDefault("?");
            } else {
              throw new AssertionError("Invalid TypeArgument : " + typeArg.getClass().getName());
            }
          }
          sd.drawDefault(">");
        }
        sd.drawDefault(baseType.getDimensions());   
  }
View Full Code Here

    if (mode == ConstantPoolTranslationMode.HYBRID) {
      sd.drawComment(" //");
    }
   
    if (mode == ConstantPoolTranslationMode.TRANSLATION || mode == ConstantPoolTranslationMode.HYBRID) {
      JavaType jt = new JavaType(ci.getName());
      sd.drawDefault(ia.getShortName(jt.getType()) + jt.getDimensions());
    }
  }
View Full Code Here

      sd.drawComment(" //");
    }
   
    if (mode == ConstantPoolTranslationMode.TRANSLATION || mode == ConstantPoolTranslationMode.HYBRID) {
      Descriptor desc = ri.getDescriptor();
      JavaType ret = desc.getReturn();
      if (ret.isPrimitive()) {
        sd.drawKeyword(ret.getType());
      } else {
        sd.drawDefault(ia.getShortName(ret.getType()));
      }
      sd.drawDefault(ret.getDimensions() + " " + ia.getShortName(ri.getClassName()) + ".");
      sd.drawField(ri.getTargetName());
    }
  }
View Full Code Here

      sd.drawComment(" //");
    }
   
    if (mode == ConstantPoolTranslationMode.TRANSLATION || mode == ConstantPoolTranslationMode.HYBRID) {
      Descriptor desc = ri.getDescriptor();
      JavaType ret = desc.getReturn();
      if (ret.isPrimitive()) {
        sd.drawKeyword(ret.getType());
      } else {
        sd.drawDefault(ia.getShortName(ret.getType()));
      }
      sd.drawDefault(ret.getDimensions() + " " +
                   ia.getShortName(ri.getClassName()) + "." +
                   ri.getTargetName());
      sd.drawDefault("(");
      List al = desc.getParamList();
      for (int j = 0; j < al.size(); j++) {
        JavaType item = (JavaType) al.get(j);
        if (j > 0) {
          sd.drawDefault(", ");
        }
        if (item.isPrimitive()) {
          sd.drawKeyword(item.getType());
        } else {
          sd.drawDefault(ia.getShortName(item.getType()));
        }
        sd.drawDefault(item.getDimensions());
      }
      sd.drawDefault(")");
    }
  }
View Full Code Here

    if ("None".equals(arrayString)) {
      dimensions = 0;
    } else {
      dimensions = Integer.parseInt(arrayString);
    }
    return new JavaType(name, dimensions);
  }
View Full Code Here

TOP

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

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.