com.intellij.codeInsight.highlighting.HighlightImportedElementsHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-impl Show documentation
Show all versions of java-impl Show documentation
A packaging of the IntelliJ Community Edition java-impl library.
This is release number 1 of trunk branch 142.
The newest version!
/*
* Copyright 2000-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.highlighting;
import com.intellij.codeInsight.CodeInsightBundle;
import com.intellij.ide.util.NavigationItemListCellRenderer;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.ui.components.JBList;
import com.intellij.util.Consumer;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.*;
/**
* @author Bas Leijdekkers
*/
public class HighlightImportedElementsHandler extends HighlightUsagesHandlerBase {
private final PsiElement myTarget;
private final PsiImportStatementBase myImportStatement;
private final boolean myImportStatic;
private Map> myClassReferenceListMap = null;
public HighlightImportedElementsHandler(Editor editor, PsiFile file, PsiElement target, PsiImportStatementBase importStatement) {
super(editor, file);
myTarget = target;
myImportStatement = importStatement;
myImportStatic = myImportStatement instanceof PsiImportStaticStatement;
}
@Override
public List getTargets() {
final PsiJavaCodeReferenceElement importReference = myImportStatement.getImportReference();
if (importReference == null) {
return Collections.emptyList();
}
final PsiJavaFile javaFile = PsiTreeUtil.getParentOfType(importReference, PsiJavaFile.class);
if (javaFile == null) {
return Collections.emptyList();
}
final JavaResolveResult[] resolveResults = importReference.multiResolve(false);
if (resolveResults.length == 0) {
return Collections.emptyList();
}
final PsiElement[] importedElements = new PsiElement[resolveResults.length];
for (int i = 0; i < resolveResults.length; i++) {
final JavaResolveResult resolveResult = resolveResults[i];
importedElements[i] = resolveResult.getElement();
}
final ReferenceCollector collector = new ReferenceCollector(importedElements, myImportStatement.isOnDemand(), myImportStatic);
javaFile.accept(collector);
myClassReferenceListMap = collector.getClassReferenceListMap();
if (myClassReferenceListMap.isEmpty()) {
return Collections.emptyList();
}
return new ArrayList(myClassReferenceListMap.keySet());
}
@Override
protected void selectTargets(final List targets, final Consumer> selectionConsumer) {
if (targets.isEmpty()) {
selectionConsumer.consume(Collections.emptyList());
return;
}
if (targets.size() == 1) {
selectionConsumer.consume(Collections.singletonList(targets.get(0)));
return;
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
selectionConsumer.consume(targets);
return;
}
Collections.sort(targets, new PsiMemberComparator());
final List