diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DefaultSourcePositionProvider.java b/java/debugger/impl/src/com/intellij/debugger/engine/DefaultSourcePositionProvider.java index 41e436ba6c8e..f75b1a27418a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DefaultSourcePositionProvider.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DefaultSourcePositionProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -87,7 +87,7 @@ public class DefaultSourcePositionProvider extends SourcePositionProvider { if (nearest) { return DebuggerContextUtil.findNearest(context, psiVariable, aClass.getContainingFile()); } - return SourcePosition.createFromOffset(psiVariable.getContainingFile(), psiVariable.getTextOffset()); + return SourcePosition.createFromElement(psiVariable); } else { final DebuggerSession session = context.getDebuggerSession(); @@ -115,13 +115,11 @@ public class DefaultSourcePositionProvider extends SourcePositionProvider { if (aClass != null) { PsiField field = aClass.findFieldByName(fieldName, false); - if (field != null) { - PsiElement element = field.getNavigationElement(); - if (nearest) { - return DebuggerContextUtil.findNearest(context, element, aClass.getContainingFile()); - } - return SourcePosition.createFromOffset(element.getContainingFile(), element.getTextOffset()); + if (field == null) return null; + if (nearest) { + return DebuggerContextUtil.findNearest(context, field.getNavigationElement(), aClass.getContainingFile()); } + return SourcePosition.createFromElement(field); } return null; } @@ -133,20 +131,16 @@ public class DefaultSourcePositionProvider extends SourcePositionProvider { @NotNull DebuggerContextImpl context, boolean nearest) { PsiElement place = PositionUtil.getContextElement(context); - if (place == null) { - return null; - } + if (place == null) return null; PsiVariable psiVariable = JavaPsiFacade.getInstance(project).getResolveHelper().resolveReferencedVariable(descriptor.getName(), place); - if (psiVariable == null) { - return null; - } + if (psiVariable == null) return null; PsiFile containingFile = psiVariable.getContainingFile(); if(containingFile == null) return null; if (nearest) { return DebuggerContextUtil.findNearest(context, psiVariable, containingFile); } - return SourcePosition.createFromOffset(containingFile, psiVariable.getTextOffset()); + return SourcePosition.createFromElement(psiVariable); } } \ No newline at end of file diff --git a/java/debugger/openapi/src/com/intellij/debugger/SourcePosition.java b/java/debugger/openapi/src/com/intellij/debugger/SourcePosition.java index 5e5ae9251384..831a5fc3c4ae 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/SourcePosition.java +++ b/java/debugger/openapi/src/com/intellij/debugger/SourcePosition.java @@ -274,7 +274,7 @@ public abstract class SourcePosition implements Navigatable{ } } - public static SourcePosition createFromLineComputable(final PsiFile file, final Computable line) { + public static SourcePosition createFromLineComputable(@NotNull final PsiFile file, final Computable line) { return new SourcePositionCache(file) { @Override protected int calcLine() { @@ -283,7 +283,7 @@ public abstract class SourcePosition implements Navigatable{ }; } - public static SourcePosition createFromLine(final PsiFile file, final int line) { + public static SourcePosition createFromLine(@NotNull final PsiFile file, final int line) { return new SourcePositionCache(file) { @Override protected int calcLine() { @@ -297,9 +297,8 @@ public abstract class SourcePosition implements Navigatable{ }; } - public static SourcePosition createFromOffset(final PsiFile file, final int offset) { + public static SourcePosition createFromOffset(@NotNull final PsiFile file, final int offset) { return new SourcePositionCache(file) { - @Override protected int calcOffset() { return offset; @@ -311,7 +310,8 @@ public abstract class SourcePosition implements Navigatable{ } }; } - + + @Nullable public static SourcePosition createFromElement(PsiElement element) { ApplicationManager.getApplication().assertReadAccessAllowed(); PsiElement navigationElement = element.getNavigationElement(); @@ -324,6 +324,7 @@ public abstract class SourcePosition implements Navigatable{ else { psiFile = navigationElement.getContainingFile(); } + if (psiFile == null) return null; return new SourcePositionCache(psiFile) { @Override protected PsiElement calcPsiElement() {