Esempio n. 1
0
  void compareAllVariables(String className, String methodName) throws Exception {
    println("compareAllVariables for method: " + className + "." + methodName);
    Method method = getMethod(className, methodName);
    List localVars;
    try {
      localVars = method.variables();
      println("\n Success: got a list of all method variables: " + methodName);
    } catch (com.sun.jdi.AbsentInformationException ex) {
      failure("\n AbsentInformationException has been thrown");
      return;
    }

    // We consider N*N combinations for set of N variables
    int index1 = 0;
    for (Iterator it1 = localVars.iterator(); it1.hasNext(); index1++) {
      LocalVariable lv1 = (LocalVariable) it1.next();

      int index2 = 0;
      for (Iterator it2 = localVars.iterator(); it2.hasNext(); index2++) {
        LocalVariable lv2 = (LocalVariable) it2.next();

        println("\n Two variables:");
        printVariable(lv1, index1);
        printVariable(lv2, index2);
        println("");
        if (index1 == index2) {
          compareTwoEqualVars(lv1, lv2);
        } else {
          compareTwoDifferentVars(lv1, lv2);
        }
      }
    }
    println("");
    return;
  }
Esempio n. 2
0
 static void addExcludes(MethodExitRequest request) {
   Iterator iter = excludes().iterator();
   while (iter.hasNext()) {
     String pattern = (String) iter.next();
     request.addClassExclusionFilter(pattern);
   }
 }
Esempio n. 3
0
 private void commandMethods(StringTokenizer t) throws NoSessionException {
   if (!t.hasMoreTokens()) {
     env.error("No class specified.");
     return;
   }
   String idClass = t.nextToken();
   ReferenceType cls = findClass(idClass);
   if (cls != null) {
     List<Method> methods = cls.allMethods();
     OutputSink out = env.getOutputSink();
     for (int i = 0; i < methods.size(); i++) {
       Method method = methods.get(i);
       out.print(method.declaringType().name() + " " + method.name() + "(");
       Iterator<String> it = method.argumentTypeNames().iterator();
       if (it.hasNext()) {
         while (true) {
           out.print(it.next());
           if (!it.hasNext()) {
             break;
           }
           out.print(", ");
         }
       }
       out.println(")");
     }
     out.show();
   } else {
     // ### Should validate class name syntax.
     env.failure("\"" + idClass + "\" is not a valid id or class name.");
   }
 }
Esempio n. 4
0
 static ReferenceType getReferenceTypeFromToken(String idToken) {
   ReferenceType cls = null;
   if (Character.isDigit(idToken.charAt(0))) {
     cls = null;
   } else if (idToken.startsWith("*.")) {
     // This notation saves typing by letting the user omit leading
     // package names. The first
     // loaded class whose name matches this limited regular
     // expression is selected.
     idToken = idToken.substring(1);
     List classes = Env.vm().allClasses();
     Iterator iter = classes.iterator();
     while (iter.hasNext()) {
       ReferenceType type = ((ReferenceType) iter.next());
       if (type.name().endsWith(idToken)) {
         cls = type;
         break;
       }
     }
   } else {
     // It's a class name
     List classes = Env.vm().classesByName(idToken);
     if (classes.size() > 0) {
       // TO DO: handle multiples
       cls = (ReferenceType) classes.get(0);
     }
   }
   return cls;
 }
Esempio n. 5
0
  static synchronized String sourceLine(Location location, int lineNumber) throws IOException {
    if (lineNumber == -1) {
      throw new IllegalArgumentException();
    }

    try {
      String fileName = location.sourceName();

      Iterator<SourceCode> iter = sourceCache.iterator();
      SourceCode code = null;
      while (iter.hasNext()) {
        SourceCode candidate = iter.next();
        if (candidate.fileName().equals(fileName)) {
          code = candidate;
          iter.remove();
          break;
        }
      }
      if (code == null) {
        BufferedReader reader = sourceReader(location);
        if (reader == null) {
          throw new FileNotFoundException(fileName);
        }
        code = new SourceCode(fileName, reader);
        if (sourceCache.size() == SOURCE_CACHE_SIZE) {
          sourceCache.remove(sourceCache.size() - 1);
        }
      }
      sourceCache.add(0, code);
      return code.sourceLine(lineNumber);
    } catch (AbsentInformationException e) {
      throw new IllegalArgumentException();
    }
  }
  private static boolean elementListsEqual(List<Element> l1, List<Element> l2) {
    if (l1 == null) return l2 == null;
    if (l2 == null) return false;

    if (l1.size() != l2.size()) return false;

    Iterator<Element> i1 = l1.iterator();
    Iterator<Element> i2 = l2.iterator();

    while (i2.hasNext()) {
      Element elem1 = i1.next();
      Element elem2 = i2.next();

      if (!elementsEqual(elem1, elem2)) return false;
    }
    return true;
  }
 public void deleteEventRequests(List eventRequests) {
   // validateMirrors(eventRequests);
   // copy the eventRequests to avoid ConcurrentModificationException
   Iterator iter = (new ArrayList(eventRequests)).iterator();
   while (iter.hasNext()) {
     ((EventRequestImpl) iter.next()).delete();
   }
 }
Esempio n. 8
0
 static String excludesString() {
   Iterator iter = excludes().iterator();
   StringBuffer buffer = new StringBuffer();
   while (iter.hasNext()) {
     String pattern = (String) iter.next();
     buffer.append(pattern);
     buffer.append(",");
   }
   return buffer.toString();
 }
Esempio n. 9
0
 /*
  * Find Connector by name
  */
 private static Connector findConnector(String name) {
   List connectors = Bootstrap.virtualMachineManager().allConnectors();
   Iterator iter = connectors.iterator();
   while (iter.hasNext()) {
     Connector connector = (Connector) iter.next();
     if (connector.name().equals(name)) {
       return connector;
     }
   }
   return null;
 }
  private static boolean attributeListsEqual(List<Attribute> l1, List<Attribute> l2) {
    if (l1 == null) return l2 == null;
    if (l2 == null) return false;

    if (l1.size() != l2.size()) return false;

    Iterator<Attribute> i1 = l1.iterator();
    Iterator<Attribute> i2 = l2.iterator();

    while (i2.hasNext()) {
      Attribute attr1 = i1.next();
      Attribute attr2 = i2.next();

      if (!Comparing.equal(attr1.getName(), attr2.getName())
          || !Comparing.equal(attr1.getValue(), attr2.getValue())) {
        return false;
      }
    }
    return true;
  }
 public static ClassFilter[] readFilters(List children) throws InvalidDataException {
   if (children == null || children.size() == 0) {
     return ClassFilter.EMPTY_ARRAY;
   }
   List<ClassFilter> classFiltersList = new ArrayList<ClassFilter>(children.size());
   for (Iterator i = children.iterator(); i.hasNext(); ) {
     final ClassFilter classFilter = new ClassFilter();
     classFilter.readExternal((Element) i.next());
     classFiltersList.add(classFilter);
   }
   return classFiltersList.toArray(new ClassFilter[classFiltersList.size()]);
 }
  protected void runTests() throws Exception {
    /*
     * Get to the top of main()
     * to determine targetClass and mainThread
     */
    BreakpointEvent bpe = startToMain("GetLocalVariables2Targ");
    targetClass = bpe.location().declaringType();
    mainThread = bpe.thread();
    EventRequestManager erm = vm().eventRequestManager();

    bpe = resumeTo("GetLocalVariables2Targ", "bar", "(I)Z");

    /*
     * Inspect the stack frame for main(), not bar()...
     */
    StackFrame frame = bpe.thread().frame(1);
    List localVars = frame.visibleVariables();
    System.out.println("    Visible variables at this point are: ");
    for (Iterator it = localVars.iterator(); it.hasNext(); ) {
      LocalVariable lv = (LocalVariable) it.next();
      System.out.print(lv.name());
      System.out.print(" typeName: ");
      System.out.print(lv.typeName());
      System.out.print(" signature: ");
      System.out.print(lv.type().signature());
      System.out.print(" primitive type: ");
      System.out.println(lv.type().name());

      if ("command".equals(lv.name())) {
        failure("Failure: LocalVariable \"command\" should not be visible at this point.");
        if (lv.isVisible(frame)) {
          System.out.println("Failure: \"command.isvisible(frame)\" returned true.");
        }
      }
    }

    /*
     * resume the target listening for events
     */
    listenUntilVMDisconnect();

    /*
     * deal with results of test
     * if anything has called failure("foo") testFailed will be true
     */
    if (!testFailed) {
      println("GetLocalVariables2Test: passed");
    } else {
      throw new Exception("GetLocalVariables2Test: failed");
    }
  }
  public static ReferenceType getSuperClass(
      final String baseQualifiedName, ReferenceType checkedType) {
    if (baseQualifiedName.equals(checkedType.name())) {
      return checkedType;
    }

    if (checkedType instanceof ClassType) {
      ClassType classType = (ClassType) checkedType;
      ClassType superClassType = classType.superclass();
      if (superClassType != null) {
        ReferenceType superClass = getSuperClass(baseQualifiedName, superClassType);
        if (superClass != null) {
          return superClass;
        }
      }
      List<InterfaceType> ifaces = classType.allInterfaces();
      for (Iterator<InterfaceType> it = ifaces.iterator(); it.hasNext(); ) {
        InterfaceType iface = it.next();
        ReferenceType superClass = getSuperClass(baseQualifiedName, iface);
        if (superClass != null) {
          return superClass;
        }
      }
    }

    if (checkedType instanceof InterfaceType) {
      List<InterfaceType> list = ((InterfaceType) checkedType).superinterfaces();
      for (Iterator<InterfaceType> it = list.iterator(); it.hasNext(); ) {
        InterfaceType superInterface = it.next();
        ReferenceType superClass = getSuperClass(baseQualifiedName, superInterface);
        if (superClass != null) {
          return superClass;
        }
      }
    }
    return null;
  }
Esempio n. 14
0
  private static boolean elementListsEqual(List<Element> l1, List<Element> l2) {
    if (l1 == null) return l2 == null;
    if (l2 == null) return false;

    if (l1.size() != l2.size()) return false;

    Iterator<Element> i1 = l1.iterator();

    for (Element aL2 : l2) {
      Element elem1 = i1.next();

      if (!elementsEqual(elem1, aL2)) return false;
    }
    return true;
  }
Esempio n. 15
0
  void addInterfaces(List<InterfaceType> list) {
    List<InterfaceType> immediate = interfaces();
    list.addAll(interfaces());

    Iterator iter = immediate.iterator();
    while (iter.hasNext()) {
      InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
      interfaze.addSuperinterfaces(list);
    }

    ClassTypeImpl superclass = (ClassTypeImpl) superclass();
    if (superclass != null) {
      superclass.addInterfaces(list);
    }
  }
    StepRequestImpl(ThreadReference thread, int size, int depth) {
      this.thread = (ThreadReferenceImpl) thread;
      this.size = size;
      this.depth = depth;

      /*
       * Make sure this isn't a duplicate
       */
      List requests = stepRequests();
      Iterator iter = requests.iterator();
      while (iter.hasNext()) {
        StepRequest request = (StepRequest) iter.next();
        if ((request != this) && request.isEnabled() && request.thread().equals(thread)) {
          throw new DuplicateRequestException("Only one step request allowed per thread");
        }
      }
    }
Esempio n. 17
0
 boolean isAssignableTo(ReferenceType type) {
   ClassTypeImpl superclazz = (ClassTypeImpl) superclass();
   if (this.equals(type)) {
     return true;
   } else if ((superclazz != null) && superclazz.isAssignableTo(type)) {
     return true;
   } else {
     List<InterfaceType> interfaces = interfaces();
     Iterator iter = interfaces.iterator();
     while (iter.hasNext()) {
       InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
       if (interfaze.isAssignableTo(type)) {
         return true;
       }
     }
     return false;
   }
 }
Esempio n. 18
0
  void addVisibleMethods(Map<String, Method> methodMap) {
    /*
     * Add methods from
     * parent types first, so that the methods in this class will
     * overwrite them in the hash table
     */

    Iterator iter = interfaces().iterator();
    while (iter.hasNext()) {
      InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
      interfaze.addVisibleMethods(methodMap);
    }

    ClassTypeImpl clazz = (ClassTypeImpl) superclass();
    if (clazz != null) {
      clazz.addVisibleMethods(methodMap);
    }

    addToMethodMap(methodMap, methods());
  }
Esempio n. 19
0
 // ### Use hash table for this?
 public SourceModel sourceForFile(File path) {
   Iterator<SourceModel> iter = sourceList.iterator();
   SourceModel sm = null;
   while (iter.hasNext()) {
     SourceModel candidate = iter.next();
     if (candidate.fileName().equals(path)) {
       sm = candidate;
       iter.remove(); // Will move to start of list.
       break;
     }
   }
   if (sm == null && path.exists()) {
     sm = new SourceModel(env, path);
   }
   if (sm != null) {
     // At start of list for faster access
     sourceList.add(0, sm);
   }
   return sm;
 }
    private void refresh(int index) {
      GridBagConstraints c = new GridBagConstraints();

      // No connector ................
      if (acs.size() == 0) {
        add(new JLabel(bundle.getString("CTL_No_Connector")), c);
        return;
      }

      // Connector switch ................
      if (acs.size() > 1) {
        c.insets = new Insets(0, 0, 3, 3);
        add(new JLabel(bundle.getString("CTL_Connector")), c);

        cbConnectors = new JComboBox();
        int i, k = acs.size();
        for (i = 0; i < k; i++) {
          AttachingConnector ac = (AttachingConnector) acs.get(i);
          int jj = ac.name().lastIndexOf('.');
          String s = (jj < 0) ? ac.name() : ac.name().substring(jj + 1);
          cbConnectors.addItem(s + " (" + ac.description() + ")");
        }
        c = new GridBagConstraints();
        c.insets = new Insets(0, 3, 3, 0);
        c.weightx = 1.0;
        c.fill = java.awt.GridBagConstraints.HORIZONTAL;
        c.gridwidth = 0;
        cbConnectors.setSelectedIndex(index);
        cbConnectors.setActionCommand("SwitchMe!");
        cbConnectors.addActionListener(this);
        add(cbConnectors, c);
      }

      ac = (AttachingConnector) acs.get(index);

      // Transport ................
      c = new GridBagConstraints();
      c.insets = new Insets(3, 0, 0, 3);
      add(new JLabel(bundle.getString("CTL_Transport")), c);

      JTextField tfTransport = new JTextField(ac.transport().name());
      tfTransport.setEnabled(false);
      c = new GridBagConstraints();
      c.gridwidth = 0;
      c.insets = new Insets(3, 3, 0, 0);
      c.fill = java.awt.GridBagConstraints.HORIZONTAL;
      c.weightx = 1.0;
      add(tfTransport, c);

      // Other params ................
      args = ac.defaultArguments();
      tfParams = new JTextField[args.size()];
      Iterator it = args.keySet().iterator();
      int i = 0;
      while (it.hasNext()) {
        String name = (String) it.next();
        Argument a = (Argument) args.get(name);

        c = new GridBagConstraints();
        c.insets = new Insets(6, 0, 0, 3);
        c.anchor = GridBagConstraints.WEST;
        add(new JLabel(a.label() + ": "), c);

        JTextField tfParam = new JTextField(a.value());
        tfParams[i++] = tfParam;
        tfParam.setName(name);
        c = new GridBagConstraints();
        c.gridwidth = 0;
        c.insets = new Insets(6, 3, 0, 0);
        c.fill = java.awt.GridBagConstraints.HORIZONTAL;
        c.weightx = 1.0;
        add(tfParam, c);
      }

      c = new GridBagConstraints();
      c.weighty = 1.0;
      JPanel p = new JPanel();
      p.setPreferredSize(new Dimension(1, 1));
      add(p, c);
    }