use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class FileReferenceCompletionImpl method getFileReferenceCompletionVariants.
@NotNull
@Override
public Object[] getFileReferenceCompletionVariants(final FileReference reference) {
final String s = reference.getText();
if (s != null && s.equals("/")) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final CommonProcessors.CollectUniquesProcessor<PsiFileSystemItem> collector = new CommonProcessors.CollectUniquesProcessor<>();
final PsiElementProcessor<PsiFileSystemItem> processor = new PsiElementProcessor<PsiFileSystemItem>() {
@Override
public boolean execute(@NotNull PsiFileSystemItem fileSystemItem) {
return new FilteringProcessor<>(reference.getFileReferenceSet().getReferenceCompletionFilter(), collector).process(FileReference.getOriginalFile(fileSystemItem));
}
};
List<Object> additionalItems = ContainerUtil.newArrayList();
for (PsiFileSystemItem context : reference.getContexts()) {
for (final PsiElement child : context.getChildren()) {
if (child instanceof PsiFileSystemItem) {
processor.execute((PsiFileSystemItem) child);
}
}
if (context instanceof FileReferenceResolver) {
additionalItems.addAll(((FileReferenceResolver) context).getVariants(reference));
}
}
final FileType[] types = reference.getFileReferenceSet().getSuitableFileTypes();
final THashSet<PsiElement> set = new THashSet<>(collector.getResults(), VARIANTS_HASHING_STRATEGY);
final PsiElement[] candidates = PsiUtilCore.toPsiElementArray(set);
final Object[] variants = new Object[candidates.length + additionalItems.size()];
for (int i = 0; i < candidates.length; i++) {
PsiElement candidate = candidates[i];
Object item = reference.createLookupItem(candidate);
if (item == null) {
item = FileInfoManager.getFileLookupItem(candidate);
}
if (candidate instanceof PsiFile && item instanceof LookupElement && types.length > 0 && ArrayUtil.contains(((PsiFile) candidate).getFileType(), types)) {
item = PrioritizedLookupElement.withPriority((LookupElement) item, Double.MAX_VALUE);
}
variants[i] = item;
}
for (int i = 0; i < additionalItems.size(); i++) {
variants[i + candidates.length] = additionalItems.get(i);
}
if (!reference.getFileReferenceSet().isUrlEncoded()) {
return variants;
}
List<Object> encodedVariants = new ArrayList<>(variants.length + additionalItems.size());
for (int i = 0; i < candidates.length; i++) {
final PsiElement element = candidates[i];
if (element instanceof PsiNamedElement) {
final PsiNamedElement psiElement = (PsiNamedElement) element;
String name = psiElement.getName();
final String encoded = reference.encode(name, psiElement);
if (encoded == null)
continue;
if (!encoded.equals(name)) {
final Icon icon = psiElement.getIcon(Iconable.ICON_FLAG_READ_STATUS | Iconable.ICON_FLAG_VISIBILITY);
LookupElementBuilder item = FileInfoManager.getFileLookupItem(candidates[i], encoded, icon);
encodedVariants.add(item.withTailText(" (" + name + ")"));
} else {
encodedVariants.add(variants[i]);
}
}
}
encodedVariants.addAll(additionalItems);
return ArrayUtil.toObjectArray(encodedVariants);
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class JavaTestFinder method findTestsForClass.
@NotNull
public Collection<PsiElement> findTestsForClass(@NotNull PsiElement element) {
PsiClass klass = findSourceElement(element);
if (klass == null)
return Collections.emptySet();
List<Pair<? extends PsiNamedElement, Integer>> classesWithProximities = new ArrayList<>();
Processor<Pair<? extends PsiNamedElement, Integer>> processor = Processors.cancelableCollectProcessor(classesWithProximities);
collectTests(klass, processor);
return TestFinderHelper.getSortedElements(classesWithProximities, true);
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class AddMethodQualifierTest method doTest.
private void doTest(final String... candidatesNames) {
myFixture.configureByFile(getTestName(false) + ".java");
final AddMethodQualifierFix addMethodQualifierFix = getQuickFix();
if (candidatesNames.length == 0) {
assertNull(addMethodQualifierFix);
return;
}
assertNotNull(addMethodQualifierFix);
final Set<String> actualCandidatesNames = new TreeSet<>(ContainerUtil.map(addMethodQualifierFix.getCandidates(), new Function<PsiNamedElement, String>() {
@Override
public String fun(final PsiNamedElement psiNamedElement) {
final String name = psiNamedElement.getName();
assertNotNull(name);
return name;
}
}));
final Set<String> expectedCandidatesNames = new TreeSet<>(ContainerUtil.list(candidatesNames));
assertEquals(expectedCandidatesNames, actualCandidatesNames);
}
use of com.intellij.psi.PsiNamedElement in project intellij-plugins by JetBrains.
the class GherkinInplaceRenamer method finish.
@Override
public void finish(boolean success) {
super.finish(success);
if (success) {
final PsiNamedElement newVariable = getVariable();
if (newVariable != null) {
final GherkinScenarioOutline scenario = PsiTreeUtil.getParentOfType(newVariable, GherkinScenarioOutline.class);
if (scenario != null) {
final CodeStyleManager csManager = CodeStyleManager.getInstance(newVariable.getProject());
csManager.reformat(scenario);
}
}
}
}
use of com.intellij.psi.PsiNamedElement in project intellij-plugins by JetBrains.
the class FlexUnitTestFinder method findTestsForClass.
@NotNull
public Collection<PsiElement> findTestsForClass(@NotNull final PsiElement element) {
final VirtualFile file = element.getContainingFile().getVirtualFile();
final JSClass jsClass = findSourceElement(element);
final String className = jsClass == null ? null : jsClass.getName();
final Pair<Module, FlexUnitSupport> moduleAndSupport = FlexUnitSupport.getModuleAndSupport(element);
final Module module = moduleAndSupport == null ? null : moduleAndSupport.first;
final FlexUnitSupport flexUnitSupport = moduleAndSupport == null ? null : moduleAndSupport.second;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
if (className == null || module == null || flexUnitSupport == null || (file != null && fileIndex.isInTestSourceContent(file))) {
return Collections.emptyList();
}
final Collection<String> allNames = StubIndex.getInstance().getAllKeys(JSNameIndex.KEY, element.getProject());
final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependentsScope(module);
final List<Pair<? extends PsiNamedElement, Integer>> classesWithProximity = new ArrayList<>();
for (final String possibleTestName : allNames) {
if (possibleTestName.contains(className)) {
for (final JSQualifiedNamedElement jsElement : JSResolveUtil.findElementsByName(possibleTestName, element.getProject(), scope)) {
final VirtualFile f = jsElement.getContainingFile().getVirtualFile();
final boolean inTestSource = f != null && fileIndex.isInTestSourceContent(f);
if (jsElement instanceof JSClass && jsElement != jsClass && ((inTestSource && possibleTestName.contains("Test")) || flexUnitSupport.isTestClass((JSClass) jsElement, true))) {
classesWithProximity.add(Pair.create(jsElement, TestFinderHelper.calcTestNameProximity(className, jsElement.getName())));
}
}
}
}
return TestFinderHelper.getSortedElements(classesWithProximity, true);
}
Aggregations