use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method filter.
private static List<FlexStyleIndexInfo> filter(Collection<? extends Collection<FlexStyleIndexInfo>> collections, List<CssSimpleSelector> selectors, @NotNull GlobalSearchScope scope, @Nullable Module module) {
Set<String> allNames = ContainerUtil.newLinkedHashSet();
for (Collection<FlexStyleIndexInfo> collection : collections) {
for (FlexStyleIndexInfo info : collection) {
allNames.add(info.getClassOrFileName());
}
}
Set<String> namesFromSelectors = null;
if (selectors.size() > 0 && !containsGlobalSelectors(selectors)) {
namesFromSelectors = ContainerUtil.newLinkedHashSet();
for (CssSimpleSelector selector : selectors) {
if (module != null) {
final JSClass jsClass = getClassFromMxmlDescriptor(selector, module);
if (jsClass != null) {
String classOrFileName = findJsClassOrFile(jsClass, ContainerUtil.newLinkedHashSet(), allNames);
if (classOrFileName != null) {
namesFromSelectors.add(classOrFileName);
}
continue;
}
}
final String selectorName = selector.getElementName();
Collection<JSQualifiedNamedElement> elements = JSResolveUtil.findElementsByName(selectorName, scope.getProject(), scope);
for (PsiElement element : elements) {
if (element instanceof JSClass) {
String classOrFileName = findJsClassOrFile((JSClass) element, ContainerUtil.newLinkedHashSet(), allNames);
if (classOrFileName != null) {
namesFromSelectors.add(classOrFileName);
}
}
}
}
}
List<FlexStyleIndexInfo> result = new ArrayList<>();
for (Collection<FlexStyleIndexInfo> collection : collections) {
for (FlexStyleIndexInfo info : collection) {
if (namesFromSelectors == null || namesFromSelectors.contains(info.getClassOrFileName())) {
result.add(info);
}
}
}
return result;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method isPossibleSelector.
public boolean isPossibleSelector(@NotNull String selector, @NotNull PsiElement context) {
if (selector.equals("global"))
return true;
GlobalSearchScope scope = FlexCssUtil.getResolveScope(context);
Collection<JSQualifiedNamedElement> classes = JSResolveUtil.findElementsByName(selector, context.getProject(), scope);
for (JSQualifiedNamedElement c : classes) {
if (c instanceof JSClass) {
return true;
}
}
return false;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method getDeclarationsForSimpleSelector.
@NotNull
private static PsiElement[] getDeclarationsForSimpleSelector(@NotNull String className, @Nullable PsiElement context) {
Collection<JSQualifiedNamedElement> elements = getClasses(className, context);
if (elements != null && elements.size() > 0) {
List<PsiElement> result = new ArrayList<>();
Set<String> qNames = ContainerUtil.newLinkedHashSet();
for (JSQualifiedNamedElement c : elements) {
if (c instanceof JSClass) {
// do not add classes with same qualified names
String qName = c.getQualifiedName();
if (qNames.add(qName)) {
result.add(getReferencedElement(c));
}
}
}
return toPsiElementArray(result);
}
return PsiElement.EMPTY_ARRAY;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlexMoveInnerClassTest method performAction.
private void performAction(VirtualFile rootDir, String fromFilePath, String className, final String targetPackage, boolean searchInStringsAndComments, boolean searchTextOccurences, String[] conflicts) {
PsiFile sourceFile = myPsiManager.findFile(rootDir.findFileByRelativePath(fromFilePath));
final EditorInfo editorInfo = new EditorInfo(sourceFile.getText());
assertEquals("Wrong number of carets", 1, editorInfo.caretState.carets.size());
assertNotNull("No caret specified", editorInfo.caretState.carets.get(0).position);
final Document doc = PsiDocumentManager.getInstance(myProject).getDocument(sourceFile);
final PsiDirectory targetDirectory = WriteAction.compute(() -> {
doc.setText(editorInfo.getNewFileText());
PsiDocumentManager.getInstance(myProject).commitDocument(doc);
final VirtualFile srcRootFile = ModuleRootManager.getInstance(myModule).getSourceRoots()[0];
final VirtualFile file = VfsUtilCore.findRelativeFile(targetPackage.replace('.', File.separatorChar), srcRootFile);
if (file != null) {
return myPsiManager.findDirectory(file);
} else {
PsiDirectory srcRoot = myPsiManager.findDirectory(srcRootFile);
return DirectoryUtil.createSubdirectories(targetPackage, srcRoot, ".");
}
});
PsiElement element = sourceFile.findElementAt(editorInfo.caretState.carets.get(0).getCaretOffset(doc));
while (true) {
assertFalse("inner element to move not found", element instanceof JSFile);
final JSQualifiedNamedElement adjusted = FlexMoveFileRefactoringHandler.adjustForMove(element);
if (adjusted != null) {
element = adjusted;
break;
}
element = element.getParent();
}
try {
new FlexMoveInnerClassProcessor((JSQualifiedNamedElement) element, targetDirectory, className, targetPackage, searchInStringsAndComments, searchTextOccurences, null).run();
assertEquals("Conflicts expected:\n" + StringUtil.join(conflicts, "\n"), 0, conflicts.length);
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
assertTrue("Conflicts not expected but found:" + e.getMessage(), conflicts.length > 0);
assertSameElements(e.getMessages(), conflicts);
myDoCompare = false;
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement in project intellij-plugins by JetBrains.
the class FlashUmlVfsResolver method getQualifiedNameStatic.
@Nullable
public static String getQualifiedNameStatic(Object element) {
if (element == null) {
return null;
}
if (element instanceof PsiElement) {
if (((PsiElement) element).getProject().isDisposed()) {
return null;
}
if (element instanceof JSQualifiedNamedElement) {
JSQualifiedNamedElement qualifiedNamedElement = (JSQualifiedNamedElement) element;
String qName = qualifiedNamedElement.getQualifiedName();
if (qName == null)
return null;
return combineWithModuleName(qualifiedNamedElement, fixVectorTypeName(qName));
} else if (element instanceof JSFile) {
return getQualifiedNameStatic(JSPsiImplUtils.findQualifiedElement((JSFile) element));
} else if (element instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) element)) {
//noinspection ConstantConditions
return getQualifiedNameStatic(XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element));
} else if (element instanceof PsiDirectory) {
PsiDirectory directory = (PsiDirectory) element;
return JSResolveUtil.getExpectedPackageNameFromFile(directory.getVirtualFile(), directory.getProject());
}
} else if (element instanceof String) {
return (String) element;
}
LOG.error("can't get qualified name of " + element);
return null;
}
Aggregations