public boolean canMoveTo(SourcePosition position) {
   if (!super.canMoveTo(position)) {
     return false;
   }
   final Document document =
       PsiDocumentManager.getInstance(getProject()).getDocument(position.getFile());
   return canAddLineBreakpoint(myProject, document, position.getLine());
 }
 @Override
 public List<ReferenceType> getAllClasses(final SourcePosition source) throws NoDataException {
   PsiFile _file = source.getFile();
   Language _language = _file.getLanguage();
   boolean _notEquals = (!Objects.equal(_language, this.language));
   if (_notEquals) {
     throw NoDataException.INSTANCE;
   }
   final Map<URI, AbstractTraceRegion> traces =
       this._debugProcessExtensions.getTracesForSource(this.process, source);
   final ArrayList<ReferenceType> allClasses = CollectionLiterals.<ReferenceType>newArrayList();
   final int line = source.getLine();
   Set<Map.Entry<URI, AbstractTraceRegion>> _entrySet = traces.entrySet();
   for (final Map.Entry<URI, AbstractTraceRegion> uri2trace : _entrySet) {
     {
       AbstractTraceRegion _value = uri2trace.getValue();
       TreeIterator<AbstractTraceRegion> _treeIterator = _value.treeIterator();
       final Function1<AbstractTraceRegion, Boolean> _function =
           new Function1<AbstractTraceRegion, Boolean>() {
             @Override
             public Boolean apply(final AbstractTraceRegion it) {
               List<ILocationData> _associatedLocations = it.getAssociatedLocations();
               ILocationData _head =
                   IterableExtensions.<ILocationData>head(_associatedLocations);
               int _lineNumber = 0;
               if (_head != null) {
                 _lineNumber = _head.getLineNumber();
               }
               return Boolean.valueOf((_lineNumber == line));
             }
           };
       final AbstractTraceRegion region =
           IteratorExtensions.<AbstractTraceRegion>findFirst(_treeIterator, _function);
       boolean _notEquals_1 = (!Objects.equal(region, null));
       if (_notEquals_1) {
         URI _key = uri2trace.getKey();
         final PsiFile psiFile = this._debugProcessExtensions.getPsiFile(this.process, _key);
         PositionManagerImpl _javaPositionManger =
             this._debugProcessExtensions.getJavaPositionManger(this.process);
         int _myLineNumber = region.getMyLineNumber();
         int _plus = (_myLineNumber + 1);
         SourcePosition _createFromLine = SourcePosition.createFromLine(psiFile, _plus);
         final List<ReferenceType> classes = _javaPositionManger.getAllClasses(_createFromLine);
         allClasses.addAll(classes);
       }
     }
   }
   return allClasses;
 }
Exemple #3
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;
  }
  private void update(@NotNull List<BreakpointWithHighlighter> breakpoints) {
    final TIntHashSet intHash = new TIntHashSet();
    for (BreakpointWithHighlighter breakpoint : breakpoints) {
      SourcePosition sourcePosition = breakpoint.getSourcePosition();
      breakpoint.reload();

      if (breakpoint.isValid()) {
        if (sourcePosition == null
            || breakpoint.getSourcePosition().getLine() != sourcePosition.getLine()) {
          fireBreakpointChanged(breakpoint);
        }

        if (intHash.contains(breakpoint.getLineIndex())) {
          remove(breakpoint);
        } else {
          intHash.add(breakpoint.getLineIndex());
        }
      } else {
        remove(breakpoint);
      }
    }
  }
  public boolean moveTo(@NotNull SourcePosition position) {
    if (!canMoveTo(position)) {
      return false;
    }
    final PsiFile psiFile = position.getFile();
    final PsiFile oldFile = getSourcePosition().getFile();
    final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);
    final Document oldDocument = PsiDocumentManager.getInstance(getProject()).getDocument(oldFile);
    if (document == null || oldDocument == null) {
      return false;
    }
    final RangeHighlighter newHighlighter =
        createHighlighter(myProject, document, position.getLine());
    if (newHighlighter == null) {
      return false;
    }
    final RangeHighlighter oldHighlighter = myHighlighter;
    myHighlighter = newHighlighter;

    reload();

    if (!isValid()) {
      myHighlighter.dispose();
      myHighlighter = oldHighlighter;
      reload();
      return false;
    }

    if (oldHighlighter != null) {
      oldHighlighter.dispose();
    }

    DebuggerManagerEx.getInstanceEx(getProject())
        .getBreakpointManager()
        .fireBreakpointChanged(this);
    updateUI();

    return true;
  }
Exemple #6
0
  @Nullable
  public static String getSourcePositionClassDisplayName(
      DebugProcessImpl debugProcess, @Nullable SourcePosition position) {
    if (position == null) {
      return null;
    }
    final PsiFile positionFile = position.getFile();
    if (positionFile instanceof JspFile) {
      return positionFile.getName();
    }

    final PsiClass psiClass = getClassAt(position);

    if (psiClass != null) {
      final String qName = psiClass.getQualifiedName();
      if (qName != null) {
        return qName;
      }
    }

    if (debugProcess != null && debugProcess.isAttached()) {
      List<ReferenceType> allClasses = debugProcess.getPositionManager().getAllClasses(position);
      if (!allClasses.isEmpty()) {
        return allClasses.get(0).name();
      }
    }
    if (psiClass == null) {
      if (positionFile instanceof PsiClassOwner) {
        return positionFile.getName();
      }

      return DebuggerBundle.message(
          "string.file.line.position", positionFile.getName(), position.getLine());
    }
    return calcClassDisplayName(psiClass);
  }
Exemple #7
0
 @Override
 public int getLine() {
   return mySourcePosition.getLine();
 }
 public int getLineIndex() {
   final SourcePosition sourcePosition = getSourcePosition();
   return sourcePosition != null ? sourcePosition.getLine() : -1;
 }
  private static Pair<Set<String>, Set<TextWithImports>> findReferencedVars(
      Set<String> visibleVars, SourcePosition position) {
    final int line = position.getLine();
    if (line < 0) {
      return Pair.create(Collections.<String>emptySet(), Collections.<TextWithImports>emptySet());
    }
    final PsiFile positionFile = position.getFile();
    if (!positionFile.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
      return Pair.create(visibleVars, Collections.<TextWithImports>emptySet());
    }

    final VirtualFile vFile = positionFile.getVirtualFile();
    final Document doc =
        vFile != null ? FileDocumentManager.getInstance().getDocument(vFile) : null;
    if (doc == null || doc.getLineCount() == 0 || line > (doc.getLineCount() - 1)) {
      return Pair.create(Collections.<String>emptySet(), Collections.<TextWithImports>emptySet());
    }

    final TextRange limit = calculateLimitRange(positionFile, doc, line);

    int startLine = Math.max(limit.getStartOffset(), line - 1);
    startLine = Math.min(startLine, limit.getEndOffset());
    while (startLine > limit.getStartOffset() && shouldSkipLine(positionFile, doc, startLine)) {
      startLine--;
    }
    final int startOffset = doc.getLineStartOffset(startLine);

    int endLine = Math.min(line + 2, limit.getEndOffset());
    while (endLine < limit.getEndOffset() && shouldSkipLine(positionFile, doc, endLine)) {
      endLine++;
    }
    final int endOffset = doc.getLineEndOffset(endLine);

    final TextRange lineRange = new TextRange(startOffset, endOffset);
    if (!lineRange.isEmpty()) {
      final int offset =
          CharArrayUtil.shiftForward(doc.getCharsSequence(), doc.getLineStartOffset(line), " \t");
      PsiElement element = positionFile.findElementAt(offset);
      if (element != null) {
        PsiMethod method = PsiTreeUtil.getNonStrictParentOfType(element, PsiMethod.class);
        if (method != null) {
          element = method;
        } else {
          PsiField field = PsiTreeUtil.getNonStrictParentOfType(element, PsiField.class);
          if (field != null) {
            element = field;
          } else {
            final PsiClassInitializer initializer =
                PsiTreeUtil.getNonStrictParentOfType(element, PsiClassInitializer.class);
            if (initializer != null) {
              element = initializer;
            }
          }
        }

        //noinspection unchecked
        if (element instanceof PsiCompiledElement) {
          return Pair.create(visibleVars, Collections.<TextWithImports>emptySet());
        } else {
          VariablesCollector collector =
              new VariablesCollector(visibleVars, adjustRange(element, lineRange));
          element.accept(collector);
          return Pair.create(collector.getVars(), collector.getExpressions());
        }
      }
    }
    return Pair.create(Collections.<String>emptySet(), Collections.<TextWithImports>emptySet());
  }