TargetElementUtil: only retrieve lookup when asked to (EA-35476,EA-38080)

This commit is contained in:
peter
2012-08-13 17:55:24 +02:00
parent 092aa296d0
commit 273baec3a8
@@ -156,12 +156,10 @@ public class TargetElementUtilBase {
Project project = editor.getProject();
if (project == null) return null;
Lookup activeLookup = LookupManager.getInstance(project).getActiveLookup();
if (activeLookup != null && (flags & LOOKUP_ITEM_ACCEPTED) != 0) {
LookupElement item = activeLookup.getCurrentItem();
final PsiElement psi = item == null ? null : CompletionUtil.getTargetElement(item);
if (psi != null && psi.isValid()) {
return psi;
if ((flags & LOOKUP_ITEM_ACCEPTED) != 0) {
PsiElement element = getTargetElementFromLookup(project);
if (element != null) {
return element;
}
}
@@ -197,6 +195,19 @@ public class TargetElementUtilBase {
return null;
}
@Nullable
private static PsiElement getTargetElementFromLookup(Project project) {
Lookup activeLookup = LookupManager.getInstance(project).getActiveLookup();
if (activeLookup != null) {
LookupElement item = activeLookup.getCurrentItem();
final PsiElement psi = item == null ? null : CompletionUtil.getTargetElement(item);
if (psi != null && psi.isValid()) {
return psi;
}
}
return null;
}
protected boolean isAcceptableReferencedElement(final PsiElement element, final PsiElement referenceOrReferencedElement) {
return referenceOrReferencedElement != null &&
referenceOrReferencedElement.isValid();