/*
- * 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.
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();
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;
}
@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
}
}
- public static SourcePosition createFromLineComputable(final PsiFile file, final Computable<Integer> line) {
+ public static SourcePosition createFromLineComputable(@NotNull final PsiFile file, final Computable<Integer> line) {
return new SourcePositionCache(file) {
@Override
protected int calcLine() {
};
}
- 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() {
};
}
- 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;
}
};
}
-
+
+ @Nullable
public static SourcePosition createFromElement(PsiElement element) {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiElement navigationElement = element.getNavigationElement();
else {
psiFile = navigationElement.getContainingFile();
}
+ if (psiFile == null) return null;
return new SourcePositionCache(psiFile) {
@Override
protected PsiElement calcPsiElement() {