本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}