use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexStyleIndex method getIndexer.
@NotNull
@Override
public DataIndexer<String, Set<FlexStyleIndexInfo>, FileContent> getIndexer() {
return new DataIndexer<String, Set<FlexStyleIndexInfo>, FileContent>() {
@Override
@NotNull
public Map<String, Set<FlexStyleIndexInfo>> map(@NotNull FileContent inputData) {
final THashMap<String, Set<FlexStyleIndexInfo>> map = new THashMap<>();
if (JavaScriptSupportLoader.isFlexMxmFile(inputData.getFileName())) {
PsiFile file = inputData.getPsiFile();
VirtualFile virtualFile = inputData.getFile();
if (file instanceof XmlFile) {
indexMxmlFile((XmlFile) file, virtualFile, map);
}
} else {
StubTree tree = JSPackageIndex.getStubTree(inputData);
if (tree != null) {
for (StubElement e : tree.getPlainList()) {
if (e instanceof JSClassStub) {
final PsiElement psiElement = e.getPsi();
if (psiElement instanceof JSClass) {
final String qName = ((JSClass) psiElement).getQualifiedName();
indexAttributes(psiElement, qName, true, map);
}
} else if (e instanceof PsiFileStub) {
PsiElement psiElement = e.getPsi();
if (psiElement instanceof JSFile) {
String name = ((JSFile) psiElement).getName();
indexAttributes(psiElement, name, false, map);
}
}
}
}
}
return map;
}
};
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method getPropertyDescriptorsDynamically.
@NotNull
private static Collection<? extends CssPropertyDescriptor> getPropertyDescriptorsDynamically(@NotNull List<CssSimpleSelector> selectors, @NotNull Module module) {
FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false);
Set<JSClass> visited = ContainerUtil.newLinkedHashSet();
Set<CssPropertyDescriptor> result = ContainerUtil.newLinkedHashSet();
Project project = module.getProject();
for (CssSimpleSelector selector : selectors) {
final JSClass jsClass = getClassFromMxmlDescriptor(selector, module);
if (jsClass != null) {
fillPropertyDescriptorsDynamically(jsClass, visited, result);
continue;
}
final String shortClassName = selector.getElementName();
Collection<JSQualifiedNamedElement> candidates = JSResolveUtil.findElementsByName(shortClassName, project, scope);
for (JSQualifiedNamedElement candidate : candidates) {
if (candidate instanceof JSClass) {
fillPropertyDescriptorsDynamically((JSClass) candidate, visited, result);
}
}
}
for (Iterator<CssPropertyDescriptor> iterator = result.iterator(); iterator.hasNext(); ) {
CssPropertyDescriptor propertyDescriptor = iterator.next();
List<Set<FlexStyleIndexInfo>> values = fileBasedIndex.getValues(FlexStyleIndex.INDEX_ID, propertyDescriptor.getPropertyName(), scope);
if (values.size() == 0) {
iterator.remove();
}
}
return result;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method getClassFromMxmlDescriptor.
@Nullable
private static JSClass getClassFromMxmlDescriptor(@NotNull CssSimpleSelector selector, @NotNull Module module) {
final XmlElementDescriptor xmlElementDescriptor = getTypeSelectorDescriptor(selector, module);
if (xmlElementDescriptor == null) {
return null;
}
final PsiElement declaration = xmlElementDescriptor.getDeclaration();
return declaration instanceof JSClass ? (JSClass) declaration : null;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method generateDocForSelector.
public String generateDocForSelector(@NotNull String selectorName, @Nullable PsiElement context) {
PsiElement[] declarations = getDeclarationsForSimpleSelector(selectorName, context);
JSClass[] classes = new JSClass[declarations.length];
for (int i = 0; i < declarations.length; i++) {
PsiElement declaration = declarations[i];
assert declaration instanceof JSClass;
classes[i] = (JSClass) declaration;
}
Arrays.sort(classes, (c1, c2) -> Comparing.compare(c1.getQualifiedName(), c2.getQualifiedName()));
StringBuilder builder = new StringBuilder();
for (int i = 0, n = classes.length; i < n; i++) {
JSClass jsClass = classes[i];
PsiFile file = jsClass.getContainingFile();
if (file != null) {
DocumentationProvider provider = DocumentationManager.getProviderFromElement(jsClass);
String docForDeclaration = provider.generateDoc(jsClass, jsClass);
if (docForDeclaration != null) {
builder.append(docForDeclaration);
if (i != n - 1) {
builder.append("<br><br>\n\n");
}
}
}
}
return builder.toString();
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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;
}
Aggregations