Search in sources :

Example 1 with JSImplicitElement

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()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSQualifiedNameImpl(com.intellij.lang.javascript.psi.JSQualifiedNameImpl) JSImplicitElementImpl(com.intellij.lang.javascript.psi.stubs.impl.JSImplicitElementImpl) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) JSOffsetBasedImplicitElement(com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) ResolveResult(com.intellij.psi.ResolveResult) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex)

Example 2 with JSImplicitElement

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);
}
Also used : JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) PsiElement(com.intellij.psi.PsiElement)

Example 3 with JSImplicitElement

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;
}
Also used : JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 4 with JSImplicitElement

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;
}
Also used : JSType(com.intellij.lang.javascript.psi.JSType) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSField(com.intellij.lang.javascript.psi.JSField) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with JSImplicitElement

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;
}
Also used : IdFilter(com.intellij.util.indexing.IdFilter) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) SmartPointerManager(com.intellij.psi.SmartPointerManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSFile(com.intellij.lang.javascript.psi.JSFile) CommonProcessors(com.intellij.util.CommonProcessors) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Aggregations

JSImplicitElement (com.intellij.lang.javascript.psi.stubs.JSImplicitElement)20 Project (com.intellij.openapi.project.Project)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 CommonProcessors (com.intellij.util.CommonProcessors)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 JSElementIndexingData (com.intellij.lang.javascript.psi.stubs.JSElementIndexingData)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSField (com.intellij.lang.javascript.psi.JSField)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 JSFunction (com.intellij.lang.javascript.psi.JSFunction)1 JSQualifiedNameImpl (com.intellij.lang.javascript.psi.JSQualifiedNameImpl)1 JSType (com.intellij.lang.javascript.psi.JSType)1 JSOffsetBasedImplicitElement (com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement)1 JSDocComment (com.intellij.lang.javascript.psi.jsdoc.JSDocComment)1 JSDocTag (com.intellij.lang.javascript.psi.jsdoc.JSDocTag)1