当前位置: 首页>>代码示例>>Java>>正文


Java SourcePosition.createFromOffset方法代码示例

本文整理汇总了Java中com.intellij.debugger.SourcePosition.createFromOffset方法的典型用法代码示例。如果您正苦于以下问题:Java SourcePosition.createFromOffset方法的具体用法?Java SourcePosition.createFromOffset怎么用?Java SourcePosition.createFromOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.debugger.SourcePosition的用法示例。


在下文中一共展示了SourcePosition.createFromOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: LambdaMethodFilter

import com.intellij.debugger.SourcePosition; //导入方法依赖的package包/类
public LambdaMethodFilter(PsiLambdaExpression lambda, int expressionOrdinal, Range<Integer> callingExpressionLines) {
  myLambdaOrdinal = expressionOrdinal;
  myCallingExpressionLines = callingExpressionLines;

  SourcePosition firstStatementPosition = null;
  SourcePosition lastStatementPosition = null;
  final PsiElement body = lambda.getBody();
  if (body instanceof PsiCodeBlock) {
    final PsiStatement[] statements = ((PsiCodeBlock)body).getStatements();
    if (statements.length > 0) {
      firstStatementPosition = SourcePosition.createFromElement(statements[0]);
      if (firstStatementPosition != null) {
        final PsiStatement lastStatement = statements[statements.length - 1];
        lastStatementPosition =
          SourcePosition.createFromOffset(firstStatementPosition.getFile(), lastStatement.getTextRange().getEndOffset());
      }
    }
  }
  else if (body != null) {
    firstStatementPosition = SourcePosition.createFromElement(body);
  }
  myFirstStatementPosition = firstStatementPosition;
  myLastStatementLine = lastStatementPosition != null ? lastStatementPosition.getLine() : -1;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LambdaMethodFilter.java

示例2: AnonymousClassMethodFilter

import com.intellij.debugger.SourcePosition; //导入方法依赖的package包/类
public AnonymousClassMethodFilter(PsiMethod psiMethod, Range<Integer> lines) {
  super(psiMethod, lines);
  SourcePosition firstStatementPosition = null;
  SourcePosition lastStatementPosition = null;
  final PsiCodeBlock body = psiMethod.getBody();
  if (body != null) {
    final PsiStatement[] statements = body.getStatements();
    if (statements.length > 0) {
      firstStatementPosition = SourcePosition.createFromElement(statements[0]);
      if (firstStatementPosition != null) {
        final PsiStatement lastStatement = statements[statements.length - 1];
        lastStatementPosition = SourcePosition.createFromOffset(firstStatementPosition.getFile(), lastStatement.getTextRange().getEndOffset());
      }
    }
  }
  myBreakpointPosition = firstStatementPosition;
  myLastStatementLine = lastStatementPosition != null? lastStatementPosition.getLine() : -1;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AnonymousClassMethodFilter.java

示例3: create

import com.intellij.debugger.SourcePosition; //导入方法依赖的package包/类
@Nullable
protected static RunToCursorBreakpoint create(@NotNull Project project, @NotNull XSourcePosition position, boolean restoreBreakpoints) {
  PsiFile psiFile = PsiManager.getInstance(project).findFile(position.getFile());
  return new RunToCursorBreakpoint(project, SourcePosition.createFromOffset(psiFile, position.getOffset()), restoreBreakpoints);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:RunToCursorBreakpoint.java

示例4: findNearest

import com.intellij.debugger.SourcePosition; //导入方法依赖的package包/类
public static SourcePosition findNearest(@NotNull DebuggerContextImpl context, @NotNull PsiElement psi, @NotNull PsiFile file) {
  final DebuggerSession session = context.getDebuggerSession();
  if (session != null) {
    try {
      final XDebugSession debugSession = session.getXDebugSession();
      if (debugSession != null) {
        final XSourcePosition position = debugSession.getCurrentPosition();
        Editor editor = ((FileEditorManagerImpl)FileEditorManager.getInstance(file.getProject())).getSelectedTextEditor(true);

        //final Editor editor = fileEditor instanceof TextEditorImpl ? ((TextEditorImpl)fileEditor).getEditor() : null;
        if (editor != null && position != null && file.getVirtualFile().equals(position.getFile())) {
          PsiMethod method = PsiTreeUtil.getParentOfType(PositionUtil.getContextElement(context), PsiMethod.class, false);
          final Couple<Collection<TextRange>> usages =
            IdentifierHighlighterPass.getHighlightUsages(psi, method != null ? method : file, false);
          final List<TextRange> ranges = new ArrayList<TextRange>();
          ranges.addAll(usages.first);
          ranges.addAll(usages.second);
          final int breakPointLine = position.getLine();
          int bestLine = -1;
          int bestOffset = -1;
          for (TextRange range : ranges) {
            final int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
            if (line > bestLine && line < breakPointLine) {
              bestLine = line;
              bestOffset = range.getStartOffset();
            } else if (line == breakPointLine) {
              bestOffset = range.getStartOffset();
              break;
            }
          }
          if (bestOffset > -1) {
            return SourcePosition.createFromOffset(file, bestOffset);
          }
        }
      }
    }
    catch (Exception ignore) {
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:42,代码来源:DebuggerContextUtil.java


注:本文中的com.intellij.debugger.SourcePosition.createFromOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。