use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class AddImportECMAScriptClassOrFunctionAction method getCandidates.
private Collection<JSQualifiedNamedElement> getCandidates(Editor editor, PsiFile file) {
final Collection<JSQualifiedNamedElement> candidates;
if (myReference instanceof JSReferenceExpression && ((JSReferenceExpression) myReference).getQualifier() == null) {
Collection<JSQualifiedNamedElement> c = getCandidates(editor, file, myReference.getCanonicalText());
filterCandidates(c);
candidates = new THashSet<>(c, JSPsiImplUtils.QUALIFIED_NAME_HASHING_STRATEGY);
} else {
JSQualifiedNamedElement invalidResult = null;
for (ResolveResult r : myReference.multiResolve(false)) {
PsiElement element = r.getElement();
if (element instanceof JSQualifiedNamedElement) {
invalidResult = (JSQualifiedNamedElement) element;
}
}
if (invalidResult != null) {
if (myReference.getElement().getParent() instanceof JSNewExpression && invalidResult instanceof JSFunction && ((JSFunction) invalidResult).isConstructor()) {
invalidResult = (JSClass) invalidResult.getParent();
}
candidates = new SmartList<>();
candidates.add(invalidResult);
} else {
candidates = Collections.emptyList();
}
}
return candidates;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexSchemaHandler method getAvailableNamespaces.
@NotNull
@Override
public Set<String> getAvailableNamespaces(@NotNull XmlFile _file, @Nullable @NonNls final String tagName) {
// tagName == null => tag name completion
// tagName != null => guess namespace of unresolved tag
PsiFile originalFile = _file.getOriginalFile();
if (originalFile instanceof XmlFile)
_file = (XmlFile) originalFile;
final XmlFile file = _file;
final Project project = file.getProject();
final Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(file.getVirtualFile());
final Collection<String> illegalNamespaces = getIllegalNamespaces(file);
final Set<String> result = new THashSet<>();
final Set<String> componentsThatHaveNotPackageBackedNamespace = new THashSet<>();
for (final String namespace : CodeContextHolder.getInstance(project).getNamespaces(module)) {
if (!CodeContext.isPackageBackedNamespace(namespace) && !illegalNamespaces.contains(namespace)) {
// package backed namespaces will be added later from JSPackageIndex
if (tagName == null) {
result.add(namespace);
} else {
final XmlElementDescriptor descriptor = CodeContext.getContext(namespace, module).getElementDescriptor(tagName, (XmlTag) null);
if (descriptor != null) {
result.add(namespace);
componentsThatHaveNotPackageBackedNamespace.add(descriptor.getQualifiedName());
}
}
}
}
if (tagName == null && !illegalNamespaces.contains(JavaScriptSupportLoader.MXML_URI)) {
result.add(JavaScriptSupportLoader.MXML_URI);
}
if (XmlBackedJSClassImpl.SCRIPT_TAG_NAME.equals(tagName) || "Style".equals(tagName))
return result;
if (DumbService.isDumb(project))
return result;
if (tagName == null) {
FileBasedIndex.getInstance().processAllKeys(JSPackageIndex.INDEX_ID, packageName -> {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
return true;
}, project);
} else {
final GlobalSearchScope scopeWithLibs = module != null ? GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) : GlobalSearchScope.allScope(project);
for (JSQualifiedNamedElement element : JSResolveUtil.findElementsByName(tagName, project, scopeWithLibs, false)) {
if (element instanceof JSClass && CodeContext.hasDefaultConstructor((JSClass) element)) {
final String packageName = StringUtil.getPackageName(element.getQualifiedName());
if (!componentsThatHaveNotPackageBackedNamespace.contains(StringUtil.getQualifiedName(packageName, tagName))) {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
}
}
}
}
final GlobalSearchScope scopeWithoutLibs = module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.allScope(project);
// packages that contain *.mxml files and do not contain *.as are not retrieved from JSPackageIndex
FlexResolveHelper.processAllMxmlAndFxgFiles(scopeWithoutLibs, project, new FlexResolveHelper.MxmlAndFxgFilesProcessor() {
public void addDependency(final PsiDirectory directory) {
}
public boolean processFile(final VirtualFile file, final VirtualFile root) {
if (tagName == null || tagName.equals(file.getNameWithoutExtension())) {
final String packageName = VfsUtilCore.getRelativePath(file.getParent(), root, '.');
if (packageName != null && (tagName == null || !componentsThatHaveNotPackageBackedNamespace.contains(StringUtil.getQualifiedName(packageName, tagName)))) {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
}
}
return true;
}
}, tagName);
return result;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexCssPropertyDescriptor method getDeclarations.
@NotNull
@Override
public PsiElement[] getDeclarations(@NotNull PsiElement context) {
Map<PsiElement, PairInfo> navElement2pairInfo = new HashMap<>();
final Project project = context.getProject();
GlobalSearchScope scope = FlexCssUtil.getResolveScope(context);
Set<JSClass> visited = ContainerUtil.newLinkedHashSet();
for (String className : myClassNames) {
Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, className.hashCode(), project, scope, JSQualifiedNamedElement.class);
findStyleAttributes(candidates, visited, navElement2pairInfo);
// search in MXML files
PsiElement jsClass = ActionScriptClassResolver.findClassByQNameStatic(className, scope);
if (jsClass instanceof JSClass) {
findStyleAttributesInClassOrSuper((JSClass) jsClass, visited, navElement2pairInfo);
}
}
Set<JSFile> visitedFiles = ContainerUtil.newLinkedHashSet();
for (String fileName : myFileNames) {
Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, fileName, scope);
for (final VirtualFile file : files) {
PsiFile psiFile = ReadAction.compute(() -> PsiManager.getInstance(project).findFile(file));
if (psiFile instanceof JSFile) {
findStyleAttributesInFile((JSFile) psiFile, visitedFiles, navElement2pairInfo);
}
}
}
Set<PsiElement> navPairs = navElement2pairInfo.keySet();
Map<String, PsiElement> qName2ResultElement = new HashMap<>();
for (PsiElement navPair : navPairs) {
PairInfo pairInfo = navElement2pairInfo.get(navPair);
String jsClassQName = pairInfo.myJsClassQName;
PsiElement navPairInOtherClassWithSameQName = jsClassQName != null ? qName2ResultElement.get(jsClassQName) : null;
if (navPairInOtherClassWithSameQName == null || navPairInOtherClassWithSameQName == navElement2pairInfo.get(navPairInOtherClassWithSameQName) && pairInfo.myPair != navPair) {
qName2ResultElement.put(jsClassQName, navPair);
}
}
Collection<PsiElement> result = qName2ResultElement.values();
return PsiUtilCore.toPsiElementArray(result);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement 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);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexUnitTestFinder method findClassesForTest.
@NotNull
public Collection<PsiElement> findClassesForTest(@NotNull final PsiElement element) {
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;
if (className == null || module == null || flexUnitSupport == null) {
return Collections.emptyList();
}
final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesScope(module).intersectWith(GlobalSearchScopes.projectProductionScope(module.getProject()));
final List<Pair<? extends PsiNamedElement, Integer>> classesWithWeights = new ArrayList<>();
for (Pair<String, Integer> nameWithWeight : TestFinderHelper.collectPossibleClassNamesWithWeights(className)) {
for (final JSQualifiedNamedElement jsElement : JSResolveUtil.findElementsByName(nameWithWeight.first, module.getProject(), scope)) {
if (jsElement instanceof JSClass && jsElement != jsClass && !((JSClass) jsElement).isInterface() && !flexUnitSupport.isTestClass((JSClass) jsElement, true)) {
classesWithWeights.add(Pair.create(jsElement, nameWithWeight.second));
}
}
}
return TestFinderHelper.getSortedElements(classesWithWeights, false);
}
Aggregations