예제 #1
0
  @Override
  public List<IWatchable> getVisibleWatchables() {
    try {
      StackFrame stackFrame = getStackFrame();
      List<IWatchable> result = new ArrayList<IWatchable>();

      if (stackFrame != null) {
        for (LocalVariable variable : stackFrame.visibleVariables()) {
          result.add(new JavaLocalVariable(variable, this, myClassFqName, myThreadReference));
        }

        ObjectReference thisObject = stackFrame.thisObject();
        if (thisObject != null) {
          result.add(new JavaThisObject(thisObject, this, myClassFqName, myThreadReference));
        } else {
          result.add(
              new JavaStaticContext(
                  getStackFrame().location().declaringType(), myClassFqName, myThreadReference));
        }
      }

      return result;
    } catch (InvalidStackFrameException ex) {
      LOG.warning(
          "InvalidStackFrameException",
          ex); // TODO something should be done here. See, for instance, how idea deals with those
               // exceptions
      return Collections.emptyList();
    } catch (AbsentInformationException ex) {
      // doing nothing, variables are just not available for us
      return Collections.emptyList();
    }
  }
예제 #2
0
 List<ReferenceType> inheritedTypes() {
   List<ReferenceType> inherited = new ArrayList<ReferenceType>();
   if (superclass() != null) {
     inherited.add(0, (ReferenceType) superclass()); /* insert at front */
   }
   for (ReferenceType rt : interfaces()) {
     inherited.add(rt);
   }
   return inherited;
 }
예제 #3
0
파일: Env.java 프로젝트: NathanEEvans/api
  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();
    }
  }
예제 #4
0
  private void commandClear(StringTokenizer t) throws NoSessionException {
    if (!t.hasMoreTokens()) {
      // Print set breakpoints
      listEventRequests();
      return;
    }
    // ### need 'clear all'
    BreakpointSpec bpSpec = parseBreakpointSpec(t.nextToken());
    if (bpSpec != null) {
      List<EventRequestSpec> specs = runtime.eventRequestSpecs();

      if (specs.isEmpty()) {
        env.notice("No breakpoints set.");
      } else {
        List<EventRequestSpec> toDelete = new ArrayList<EventRequestSpec>();
        for (EventRequestSpec spec : specs) {
          if (spec.equals(bpSpec)) {
            toDelete.add(spec);
          }
        }
        // The request used for matching should be found
        if (toDelete.size() <= 1) {
          env.notice("No matching breakpoint set.");
        }
        for (EventRequestSpec spec : toDelete) {
          runtime.delete(spec);
        }
      }
    } else {
      env.error("Ill-formed breakpoint specification.");
    }
  }
예제 #5
0
 /**
  * @param context
  * @return all CodeFragmentFactoryProviders that provide code fragment factories suitable in the
  *     context given
  */
 public static List<CodeFragmentFactory> getCodeFragmentFactories(@Nullable PsiElement context) {
   final DefaultCodeFragmentFactory defaultFactory = DefaultCodeFragmentFactory.getInstance();
   final CodeFragmentFactory[] providers =
       ApplicationManager.getApplication().getExtensions(CodeFragmentFactory.EXTENSION_POINT_NAME);
   final List<CodeFragmentFactory> suitableFactories =
       new ArrayList<CodeFragmentFactory>(providers.length);
   if (providers.length > 0) {
     for (CodeFragmentFactory factory : providers) {
       if (factory != defaultFactory && factory.isContextAccepted(context)) {
         suitableFactories.add(factory);
       }
     }
   }
   suitableFactories.add(defaultFactory); // let default factory be the last one
   return suitableFactories;
 }
예제 #6
0
파일: Env.java 프로젝트: NathanEEvans/api
 static void setExcludes(String excludeString) {
   StringTokenizer t = new StringTokenizer(excludeString, " ,;");
   List<String> list = new ArrayList<String>();
   while (t.hasMoreTokens()) {
     list.add(t.nextToken());
   }
   excludes = list;
 }
예제 #7
0
 private ThreadReference[] threads() throws NoSessionException {
   if (threads == null) {
     ThreadIterator ti = new ThreadIterator(getDefaultThreadGroup());
     List<ThreadReference> tlist = new ArrayList<ThreadReference>();
     while (ti.hasNext()) {
       tlist.add(ti.nextThread());
     }
     threads = tlist.toArray(new ThreadReference[tlist.size()]);
   }
   return threads;
 }
예제 #8
0
  /** @return a list of threadGroupProxies */
  public List<ThreadGroupReferenceProxyImpl> topLevelThreadGroups() {
    List<ThreadGroupReference> list = getVirtualMachine().topLevelThreadGroups();

    List<ThreadGroupReferenceProxyImpl> result = new ArrayList<>(list.size());

    for (ThreadGroupReference threadGroup : list) {
      result.add(getThreadGroupReferenceProxy(threadGroup));
    }

    return result;
  }
예제 #9
0
파일: Env.java 프로젝트: NathanEEvans/api
 SourceCode(String fileName, BufferedReader reader) throws IOException {
   this.fileName = fileName;
   try {
     String line = reader.readLine();
     while (line != null) {
       sourceLines.add(line);
       line = reader.readLine();
     }
   } finally {
     reader.close();
   }
 }
 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()]);
 }
예제 #11
0
  public List<ClassType> subclasses() {
    List<ClassType> subs = new ArrayList<ClassType>();
    for (ReferenceType refType : vm.allClasses()) {
      if (refType instanceof ClassType) {
        ClassType clazz = (ClassType) refType;
        ClassType superclass = clazz.superclass();
        if ((superclass != null) && superclass.equals(this)) {
          subs.add((ClassType) refType);
        }
      }
    }

    return subs;
  }
예제 #12
0
  public static List<PsiLambdaExpression> collectLambdas(
      @NotNull SourcePosition position, final boolean onlyOnTheLine) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    PsiFile file = position.getFile();
    final int line = position.getLine();
    final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if (document == null || line >= document.getLineCount()) {
      return Collections.emptyList();
    }
    PsiElement element = position.getElementAt();
    final TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
    do {
      PsiElement parent = element.getParent();
      if (parent == null || (parent.getTextOffset() < lineRange.getStartOffset())) {
        break;
      }
      element = parent;
    } while (true);

    final List<PsiLambdaExpression> lambdas = new ArrayList<PsiLambdaExpression>(3);
    final PsiElementVisitor lambdaCollector =
        new JavaRecursiveElementVisitor() {
          @Override
          public void visitLambdaExpression(PsiLambdaExpression expression) {
            super.visitLambdaExpression(expression);
            if (!onlyOnTheLine || getFirstElementOnTheLine(expression, document, line) != null) {
              lambdas.add(expression);
            }
          }
        };
    element.accept(lambdaCollector);
    // add initial lambda if we're inside already
    PsiElement method = getContainingMethod(element);
    if (method instanceof PsiLambdaExpression) {
      lambdas.add((PsiLambdaExpression) method);
    }
    for (PsiElement sibling = getNextElement(element);
        sibling != null;
        sibling = getNextElement(sibling)) {
      if (!intersects(lineRange, sibling)) {
        break;
      }
      sibling.accept(lambdaCollector);
    }
    return lambdas;
  }
예제 #13
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;
 }
예제 #14
0
 private BreakpointSpec parseBreakpointSpec(String bptSpec) {
   StringTokenizer t = new StringTokenizer(bptSpec);
   BreakpointSpec bpSpec = null;
   //        try {
   String token = t.nextToken("@:( \t\n\r");
   // We can't use hasMoreTokens here because it will cause any leading
   // paren to be lost.
   String rest;
   try {
     rest = t.nextToken("").trim();
   } catch (NoSuchElementException e) {
     rest = null;
   }
   if ((rest != null) && rest.startsWith("@")) {
     t = new StringTokenizer(rest.substring(1));
     String sourceName = token;
     String lineToken = t.nextToken();
     int lineNumber = Integer.valueOf(lineToken).intValue();
     if (t.hasMoreTokens()) {
       return null;
     }
     bpSpec = runtime.createSourceLineBreakpoint(sourceName, lineNumber);
   } else if ((rest != null) && rest.startsWith(":")) {
     t = new StringTokenizer(rest.substring(1));
     String classId = token;
     String lineToken = t.nextToken();
     int lineNumber = Integer.valueOf(lineToken).intValue();
     if (t.hasMoreTokens()) {
       return null;
     }
     bpSpec = runtime.createClassLineBreakpoint(classId, lineNumber);
   } else {
     // Try stripping method from class.method token.
     int idot = token.lastIndexOf(".");
     if ((idot <= 0) || /* No dot or dot in first char */ (idot >= token.length() - 1)) {
       /* dot in last char */
       return null;
     }
     String methodName = token.substring(idot + 1);
     String classId = token.substring(0, idot);
     List<String> argumentList = null;
     if (rest != null) {
       if (!rest.startsWith("(") || !rest.endsWith(")")) {
         // ### Should throw exception with error message
         // out.println("Invalid method specification: "
         //            + methodName + rest);
         return null;
       }
       // Trim the parens
       // ### What about spaces in arglist?
       rest = rest.substring(1, rest.length() - 1);
       argumentList = new ArrayList<String>();
       t = new StringTokenizer(rest, ",");
       while (t.hasMoreTokens()) {
         argumentList.add(t.nextToken());
       }
     }
     bpSpec = runtime.createMethodBreakpoint(classId, methodName, argumentList);
   }
   //        } catch (Exception e) {
   //            env.error("Exception attempting to create breakpoint: " + e);
   //            return null;
   //        }
   return bpSpec;
 }
예제 #15
0
파일: VMConnection.java 프로젝트: 9r3y/c47
  private static List<String> splitStringAtNonEnclosedWhiteSpace(String value)
      throws IllegalArgumentException {
    List<String> al = new ArrayList<String>();
    char[] arr;
    int startPosition = 0;
    int endPosition = 0;
    final char SPACE = ' ';
    final char DOUBLEQ = '"';
    final char SINGLEQ = '\'';

    /*
     * An "open" or "active" enclosing state is where
     * the first valid start quote qualifier is found,
     * and there is a search in progress for the
     * relevant end matching quote
     *
     * enclosingTargetChar set to SPACE
     * is used to signal a non open enclosing state
     */
    char enclosingTargetChar = SPACE;

    if (value == null) {
      throw new IllegalArgumentException(MessageOutput.format("value string is null"));
    }

    // split parameter string into individual chars
    arr = value.toCharArray();

    for (int i = 0; i < arr.length; i++) {
      switch (arr[i]) {
        case SPACE:
          {
            // do nothing for spaces
            // unless last in array
            if (isLastChar(arr, i)) {
              endPosition = i;
              // break for substring creation
              break;
            }
            continue;
          }
        case DOUBLEQ:
        case SINGLEQ:
          {
            if (enclosingTargetChar == arr[i]) {
              // potential match to close open enclosing
              if (isNextCharWhitespace(arr, i)) {
                // if peek next is whitespace
                // then enclosing is a valid substring
                endPosition = i;
                // reset enclosing target char
                enclosingTargetChar = SPACE;
                // break for substring creation
                break;
              }
            }
            if (enclosingTargetChar == SPACE) {
              // no open enclosing state
              // handle as normal char
              if (isPreviousCharWhitespace(arr, i)) {
                startPosition = i;
                // peek forward for end candidates
                if (value.indexOf(arr[i], i + 1) >= 0) {
                  // set open enclosing state by
                  // setting up the target char
                  enclosingTargetChar = arr[i];
                } else {
                  // no more target chars left to match
                  // end enclosing, handle as normal char
                  if (isNextCharWhitespace(arr, i)) {
                    endPosition = i;
                    // break for substring creation
                    break;
                  }
                }
              }
            }
            continue;
          }
        default:
          {
            // normal non-space, non-" and non-' chars
            if (enclosingTargetChar == SPACE) {
              // no open enclosing state
              if (isPreviousCharWhitespace(arr, i)) {
                // start of space delim substring
                startPosition = i;
              }
              if (isNextCharWhitespace(arr, i)) {
                // end of space delim substring
                endPosition = i;
                // break for substring creation
                break;
              }
            }
            continue;
          }
      }

      // break's end up here
      if (startPosition > endPosition) {
        throw new IllegalArgumentException(MessageOutput.format("Illegal option values"));
      }

      // extract substring and add to List<String>
      al.add(value.substring(startPosition, ++endPosition));

      // set new start position
      i = startPosition = endPosition;
    } // for loop

    return al;
  }