use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.
the class AngularIndexUtil method multiResolveAngularNamedDefinitionIndex.
public static ResolveResult[] multiResolveAngularNamedDefinitionIndex(@NotNull final Project project, @NotNull final ID<String, AngularNamedItemDefinition> INDEX, @NotNull final String id, @NotNull final Condition<VirtualFile> filter, boolean dirtyResolve) {
final FileBasedIndex instance = FileBasedIndex.getInstance();
Collection<VirtualFile> files = instance.getContainingFiles(INDEX, id, GlobalSearchScope.allScope(project));
if (files.isEmpty())
return ResolveResult.EMPTY_ARRAY;
final List<VirtualFile> filtered = ContainerUtil.filter(files, filter);
if (filtered.isEmpty()) {
if (!dirtyResolve)
return ResolveResult.EMPTY_ARRAY;
} else {
files = filtered;
}
final List<JSImplicitElement> elements = new ArrayList<>();
for (VirtualFile file : files) {
final List<AngularNamedItemDefinition> values = instance.getValues(INDEX, id, GlobalSearchScope.fileScope(project, file));
for (AngularNamedItemDefinition value : values) {
JSQualifiedNameImpl qName = JSQualifiedNameImpl.fromQualifiedName(id);
JSImplicitElementImpl.Builder elementBuilder = new JSImplicitElementImpl.Builder(qName, null);
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile != null) {
elements.add(new JSOffsetBasedImplicitElement(elementBuilder, (int) value.getStartOffset(), psiFile));
}
}
}
final List<ResolveResult> list = ContainerUtil.map(elements, JS_IMPLICIT_TO_RESOLVE_RESULT);
return list.toArray(new ResolveResult[list.size()]);
}
use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.
the class AngularJSReferenceSearcher method processQuery.
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
final PsiElement element = queryParameters.getElementToSearch();
final JSImplicitElement directive = DirectiveUtil.getDirective(element);
if (directive == null)
return;
queryParameters.getOptimizer().searchWord(directive.getName(), queryParameters.getEffectiveSearchScope(), true, directive);
}
use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.
the class AngularAttributesRegistry method isJSONAttribute.
public static boolean isJSONAttribute(XmlAttribute parent) {
final String value = parent.getValue();
if (value == null || !value.startsWith("{"))
return false;
final String attributeName = DirectiveUtil.normalizeAttributeName(parent.getName());
final JSImplicitElement directive = AngularIndexUtil.resolve(parent.getProject(), AngularDirectivesDocIndex.KEY, attributeName);
if (directive != null) {
final String restrict = directive.getTypeString();
final String type = restrict != null ? restrict.split(";", -1)[2] : "";
return type.contains("object literal") || type.equals("mixed");
}
return false;
}
use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.
the class AngularBindingDescriptor method createOneTimeBinding.
@Nullable
private static AngularBindingDescriptor createOneTimeBinding(Pair<PsiElement, String> dom) {
PsiElement element = dom.first;
if (element instanceof JSImplicitElement) {
String type = ((JSImplicitElement) element).getTypeString();
if (type != null && (type.endsWith("String") || type.endsWith("Object"))) {
return new AngularBindingDescriptor(element, dom.second);
}
}
final JSType type = expandStringLiteralTypes(element instanceof JSFunction ? ((JSFunction) element).getReturnType() : element instanceof JSField ? ((JSField) element).getType() : null);
return type != null && type.isDirectlyAssignableType(STRING_TYPE, null) ? new AngularBindingDescriptor(element, dom.second) : null;
}
use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.
the class AngularModulesProvider method getDependencies.
@Override
public List<Link> getDependencies(@NotNull PsiFile file) {
final Project project = file.getProject();
if (!AngularIndexUtil.hasAngularJS(project))
return null;
if (!(file instanceof JSFile))
return null;
final SmartPointerManager spm = SmartPointerManager.getInstance(project);
final List<Link> result = new ArrayList<>();
final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<>();
final GlobalSearchScope fileScope = GlobalSearchScope.fileScope(file);
final int fileId = FileBasedIndex.getFileId(file.getVirtualFile());
StubIndex.getInstance().processAllKeys(AngularModuleIndex.KEY, processor, fileScope, new IdFilter() {
@Override
public boolean containsFileId(int id) {
return id == fileId;
}
});
for (String key : processor.getResults()) {
AngularIndexUtil.multiResolve(project, AngularModuleIndex.KEY, key, element -> {
if (!file.equals(element.getContainingFile()))
return true;
final JSCallExpression expression = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
if (expression != null) {
final List<String> dependencies = AngularModuleIndex.findDependenciesInModuleDeclaration(expression);
if (dependencies != null) {
for (String dependency : dependencies) {
final JSImplicitElement resolve = AngularIndexUtil.resolve(project, AngularModuleIndex.KEY, dependency);
if (resolve != null) {
result.add(new Link(spm.createSmartPsiElementPointer(element.getNavigationElement()), spm.createSmartPsiElementPointer(resolve.getNavigationElement()), key, resolve.getName(), AngularJSIcons.AngularJS));
}
}
}
}
return true;
});
}
return result;
}
Aggregations