EA-69221 - IAE: SourcePosition$SourcePositionCache.<init>

This commit is contained in:
Egor.Ushakov
2015-06-10 16:24:22 +03:00
parent 7851ebc18e
commit da13f24051
2 changed files with 15 additions and 20 deletions
@@ -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);
}
}
@@ -274,7 +274,7 @@ public abstract class SourcePosition implements Navigatable{
}
}
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() {
@@ -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() {