Package com.sun.jdi

Examples of com.sun.jdi.ClassType


import com.sun.jdi.request.StepRequest;

public class JDWPInjector {

  public static ClassType inject(VirtualMachine vm, byte[][] classes, String embeddedArgs, boolean disableSecurityManager, PrintStream consoleOut) throws Exception {
    ClassType result = null;
    consoleOut.println("== Preparing...");
    if (vm.eventRequestManager().stepRequests().size() > 0) {
      throw new RuntimeException("Some threads are currently stepping");
    }
    for (int i = 0; i < vm.allThreads().size(); i++) {
      final ThreadReference tr = (ThreadReference) vm.allThreads().get(i);
      vm.eventRequestManager().createStepRequest(tr, StepRequest.STEP_MIN, StepRequest.STEP_INTO).enable();
    }
    final com.sun.jdi.event.EventQueue q = vm.eventQueue();
    boolean done = false;
    consoleOut.println("== Handling events...");
    vm.resume();
    while (true) {
      final EventSet es;
      if (!done) {
        es = q.remove();
      } else {
        es = q.remove(1000);
        if (es == null) {
          break;
        }
      }
      for (final EventIterator ei = es.eventIterator(); ei.hasNext();) {
        final Event e = ei.nextEvent();
        consoleOut.println("== Event received: " + e.toString());
        if (!done && e instanceof StepEvent) {
          final StepEvent se = (StepEvent) e;
          final ThreadReference tr = se.thread();
          vm.eventRequestManager().deleteEventRequest(se.request());
          final List stepRequests = new ArrayList(vm.eventRequestManager().stepRequests());
          for (int i = 0; i < stepRequests.size(); i++) {
            ((StepRequest) stepRequests.get(i)).disable();
          }
          if (disableSecurityManager) {
            consoleOut.println("== Disabling security manager...");
            ClassType _System = (ClassType) vm.classesByName("java.lang.System").get(0);
            _System.setValue(_System.fieldByName("security"), null);
          }
          consoleOut.println("== Trying to inject...");
          try {
            final JDWPClassInjector ci = new JDWPClassInjector(tr);
            for (int i = 0; i < classes.length; i++) {
              ClassType ct = ci.inject(classes[i], i == classes.length - 1 ? embeddedArgs : null);
              if (i==0) result = ct;
            }
            consoleOut.println("== done.");
            done = true;
            for (int i = 0; i < stepRequests.size(); i++) {
View Full Code Here


      classBytes[i] = out.toByteArray();
      if (classBytes[i] == null) {
        throw new RuntimeException();
      }
    }
    ClassType firstInjectedClass = inject(vm, classBytes, embeddedArgs.toString(), disableSecurityManager, loader.stageHandler.consoleOut);

    if (isJDWPTunnelStager) {
      loader.handleAfter(loader.stageHandler.consoleErr, firstInjectedClass);
    } else {
      vm.dispose();
View Full Code Here

  }

  public boolean isEnum() {
    if (virtualMachineImpl().isJdwpVersionGreaterOrEqual(1, 5)) {
      // there is no modifier for this ... :(
      ClassType superClass = superclass();
      return superClass != null
          && "<E:Ljava/lang/Enum<TE;>;>Ljava/lang/Object;Ljava/lang/Comparable<TE;>;Ljava/io/Serializable;".equals(superClass.genericSignature()); //$NON-NLS-1$
    }
    // jdwp 1.5 only option
    return false;
  }
View Full Code Here

      try {
        if (entry) {
          if (classFilter instanceof ClassType && getMethodName() != null
              && getMethodSignature() != null) {
            // use a line breakpoint if possible for better performance
            ClassType clazz = (ClassType) classFilter;
            if (clazz.name().equals(getTypeName())) {
              // only use line breakpoint when there is an exact match
              Method method = clazz.concreteMethodByName(
                  getMethodName(), getMethodSignature());
              if (method != null && !method.isNative()) {
                Location location = method.location();
                if (location != null && location.codeIndex() != -1) {
                  request = manager
View Full Code Here

    String typeName = referenceType.name();

    boolean isAnonymousType = isAnonymousTypeName(typeName);

    if (isAnonymousType) {
      ClassType classType = (ClassType) referenceType;

      List<InterfaceType> interfaceList = classType.interfaces();
      String superClassName = classType.superclass().name();
      if (hasEnclosingInstance) {
        source.append("void "); //$NON-NLS-1$
        source.append(getUniqueMethodName(EVAL_METHOD_NAME,
            referenceType));
        source.append("() {\nnew "); //$NON-NLS-1$
        if (interfaceList.size() != 0) {
          source.append(getDotName(interfaceList
              .get(0).name()));
        } else {
          source.append(getDotName(superClassName));
        }
        source.append("()"); //$NON-NLS-1$
      } else {
        source.append("public class ").append(ANONYMOUS_CLASS_NAME).append(" "); //$NON-NLS-1$ //$NON-NLS-2$
        if (interfaceList.size() != 0) {
          source.append(" implements ").append(getDotName(interfaceList.get(0).name())); //$NON-NLS-1$
        } else {
          source.append(" extends ").append(getDotName(superClassName)); //$NON-NLS-1$
        }
      }

    } else {
      if (referenceType.isFinal()) {
        source.append("final "); //$NON-NLS-1$
      }

      if (referenceType.isStatic()) {
        source.append("static "); //$NON-NLS-1$
      }

      if (referenceType instanceof ClassType) {
        ClassType classType = (ClassType) referenceType;

        if (classType.isAbstract()) {
          source.append("abstract "); //$NON-NLS-1$
        }

        source.append("class "); //$NON-NLS-1$

        source.append(getSimpleName(typeName)).append(' ');

        String genericSignature = referenceType.genericSignature();
        if (genericSignature != null
            && isSourceLevelGreaterOrEqual(1, 5)) {
          String[] typeParameters = Signature
              .getTypeParameters(genericSignature);
          if (typeParameters.length > 0) {
            source.append('<');
            source.append(Signature
                .getTypeVariable(typeParameters[0]));
            String[] typeParameterBounds = Signature
                .getTypeParameterBounds(typeParameters[0]);
            source.append(" extends ").append(Signature.toString(typeParameterBounds[0]).replace('/', '.')); //$NON-NLS-1$
            for (int i = 1; i < typeParameterBounds.length; i++) {
              source.append(" & ").append(Signature.toString(typeParameterBounds[i]).replace('/', '.')); //$NON-NLS-1$
            }
            for (int j = 1; j < typeParameters.length; j++) {
              source.append(',')
                  .append(Signature
                      .getTypeVariable(typeParameters[j]));
              typeParameterBounds = Signature
                  .getTypeParameterBounds(typeParameters[j]);
              source.append(" extends ").append(Signature.toString(typeParameterBounds[0]).replace('/', '.')); //$NON-NLS-1$
              for (int i = 1; i < typeParameterBounds.length; i++) {
                source.append(" & ").append(Signature.toString(typeParameterBounds[i]).replace('/', '.')); //$NON-NLS-1$
              }
            }
            source.append("> "); //$NON-NLS-1$
          }
          String[] superClassInterfaces = SignatureExt
              .getTypeSuperClassInterfaces(genericSignature);
          int length = superClassInterfaces.length;
          if (length > 0) {
            source.append("extends ").append(Signature.toString(superClassInterfaces[0]).replace('/', '.')); //$NON-NLS-1$
            if (length > 1) {
              source.append(" implements ").append(Signature.toString(superClassInterfaces[1]).replace('/', '.')); //$NON-NLS-1$
              for (int i = 2; i < length; i++) {
                source.append(',')
                    .append(Signature
                        .toString(superClassInterfaces[1]));
              }
            }
          }
        } else {

          ClassType superClass = classType.superclass();
          if (superClass != null) {
            source.append("extends ").append(getDotName(superClass.name())).append(' '); //$NON-NLS-1$
          }

          List<InterfaceType> interfaces;
          try {
            interfaces = classType.interfaces();
View Full Code Here

      List<ClassType> implementorList = ((InterfaceType) getUnderlyingType())
          .implementors();
      List<JDIType> javaClassTypeList = new ArrayList<JDIType>(implementorList.size());
      Iterator<ClassType> iterator = implementorList.iterator();
      while (iterator.hasNext()) {
        ClassType classType = iterator.next();
        if (classType != null) {
          javaClassTypeList.add(JDIType.createType(
              getJavaDebugTarget(), classType));
        }
      }
View Full Code Here

  @Override
  protected EventRequest[] newRequests(JDIDebugTarget target,
      ReferenceType type) throws CoreException {
    try {
      if (type instanceof ClassType) {
        ClassType clazz = (ClassType) type;
        Method method = clazz.concreteMethodByName(getMethodName(),
            getMethodSignature());
        if (method == null) {
          return null;
        }
        Location location = method.location();
View Full Code Here

        }
      }
    } else {
      if (type instanceof ClassType) {
        if (valueType instanceof ClassType) {
          ClassType superClass = (ClassType) valueType;
          while (superClass != null) {
            if (superClass.equals(type)) {
              return;
            }
            superClass = superClass.superclass();
          }
        } else if (valueType instanceof InterfaceType) {
          // an interface can be assigned to an object
          if (type.signature().equals("Ljava/lang/Object;")) { //$NON-NLS-1$
            return;
View Full Code Here

      allInterfacesSet.addAll(((InterfaceTypeImpl)inter).allInterfaces());
    }

    // If it is a class, all interfaces of it's superclass.
    if (this instanceof ClassType) {
      ClassType superclass = ((ClassType) this).superclass();
      if (superclass != null) {
        allInterfacesSet.addAll(superclass.allInterfaces());
      }
    }

    fAllInterfaces = new ArrayList<InterfaceType>(allInterfacesSet);
    return fAllInterfaces;
View Full Code Here

          visibleMethods);
    }

    // If it is a class, all methods of it's superclass.
    if (this instanceof ClassType) {
      ClassType superclass = ((ClassType) this).superclass();
      if (superclass != null)
        addVisibleMethods(superclass.visibleMethods(),
            namesAndSignatures, visibleMethods);
    }

    fVisibleMethods = visibleMethods;
    return fVisibleMethods;
View Full Code Here

TOP

Related Classes of com.sun.jdi.ClassType

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.