Search in sources :

Example 11 with JSImplicitElement

use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.

the class AngularJSDocumentationProvider method getUrlFor.

@Override
public List<String> getUrlFor(PsiElement element, PsiElement originalElement) {
    if (element instanceof JSImplicitElement)
        element = element.getParent();
    if (element instanceof JSDocComment) {
        JSDocTag ngdocTag = null;
        JSDocTag nameTag = null;
        for (JSDocTag tag : ((JSDocComment) element).getTags()) {
            if ("ngdoc".equals(tag.getName()))
                ngdocTag = tag;
            else if ("name".equals(tag.getName()))
                nameTag = tag;
        }
        if (ngdocTag != null && nameTag != null) {
            final JSDocTagValue nameValue = nameTag.getValue();
            String name = nameValue != null ? nameValue.getText() : null;
            if (name != null)
                name = name.substring(name.indexOf(':') + 1);
            if (name != null && AngularIndexUtil.resolve(element.getProject(), AngularDirectivesDocIndex.KEY, DirectiveUtil.getAttributeName(name)) != null) {
                final String directiveName = DirectiveUtil.attributeToDirective(null, name);
                return Collections.singletonList("http://docs.angularjs.org/api/ng/directive/" + directiveName);
            }
        }
    }
    return null;
}
Also used : JSDocComment(com.intellij.lang.javascript.psi.jsdoc.JSDocComment) JSDocTagValue(com.intellij.lang.javascript.psi.jsdoc.JSDocTagValue) JSDocTag(com.intellij.lang.javascript.psi.jsdoc.JSDocTag) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 12 with JSImplicitElement

use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.

the class AngularJSTagDescriptorsProvider method getDescriptor.

@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
    final Project project = xmlTag.getProject();
    if (!(xmlTag instanceof HtmlTag && AngularIndexUtil.hasAngularJS(project)))
        return null;
    final String tagName = xmlTag.getName();
    final String directiveName = DirectiveUtil.normalizeAttributeName(tagName);
    final XmlNSDescriptor nsDescriptor = xmlTag.getNSDescriptor(xmlTag.getNamespace(), false);
    final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(xmlTag) : null;
    if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
        return null;
    }
    if ((NG_CONTAINER.equals(directiveName) || NG_CONTENT.equals(directiveName) || NG_TEMPLATE.equals(directiveName)) && AngularIndexUtil.hasAngularJS2(project)) {
        return new AngularJSTagDescriptor(directiveName, createDirective(xmlTag, directiveName));
    }
    JSImplicitElement directive = DirectiveUtil.getTagDirective(directiveName, project);
    if (DirectiveUtil.isAngular2Directive(directive) && !directive.getName().equals(tagName)) {
        // we've found directive via normalized name for Angular, it should not work
        directive = null;
    }
    if (directive == null && !tagName.equals(directiveName) && AngularIndexUtil.hasAngularJS2(project)) {
        directive = DirectiveUtil.getTagDirective(tagName, project);
        if (!DirectiveUtil.isAngular2Directive(directive))
            directive = null;
    }
    return directive != null ? new AngularJSTagDescriptor(directiveName, directive) : null;
}
Also used : Project(com.intellij.openapi.project.Project) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) HtmlTag(com.intellij.psi.html.HtmlTag) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with JSImplicitElement

use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.

the class AngularJSBracesUtil method getInjectionDelimiter.

private static String getInjectionDelimiter(Project project, final Key<CachedValue<String>> key, final String defaultDelimiter) {
    return CachedValuesManager.getManager(project).getCachedValue(project, key, () -> {
        String id = key.toString();
        final JSImplicitElement delimiter = AngularIndexUtil.resolve(project, AngularInjectionDelimiterIndex.KEY, id.substring(id.lastIndexOf(".") + 1));
        if (delimiter != null) {
            return CachedValueProvider.Result.create(delimiter.getTypeString(), delimiter);
        }
        return CachedValueProvider.Result.create(defaultDelimiter, PsiModificationTracker.MODIFICATION_COUNT);
    }, false);
}
Also used : JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 14 with JSImplicitElement

use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.

the class AngularIndexUtil method multiResolve.

public static void multiResolve(Project project, final StubIndexKey<String, JSImplicitElementProvider> index, final String lookupKey, final Processor<JSImplicitElement> processor) {
    final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
    StubIndex.getInstance().processElements(index, lookupKey, project, scope, JSImplicitElementProvider.class, provider -> {
        final JSElementIndexingData indexingData = provider.getIndexingData();
        if (indexingData != null) {
            final Collection<JSImplicitElement> elements = indexingData.getImplicitElements();
            if (elements != null) {
                for (JSImplicitElement element : elements) {
                    if (element.getName().equals(lookupKey) && ((index != AngularDirectivesIndex.KEY && index != AngularDirectivesDocIndex.KEY) || AngularJSIndexingHandler.isAngularRestrictions(element.getTypeString()))) {
                        if (!processor.process(element))
                            return false;
                    }
                }
            }
        }
        return true;
    });
}
Also used : JSElementIndexingData(com.intellij.lang.javascript.psi.stubs.JSElementIndexingData) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 15 with JSImplicitElement

use of com.intellij.lang.javascript.psi.stubs.JSImplicitElement in project intellij-plugins by JetBrains.

the class AngularUiRouterDiagramBuilder method addContainingFile.

private void addContainingFile(@NotNull final NonCyclicQueue<VirtualFile> filesQueue, @NotNull final String module) {
    final CommonProcessors.CollectProcessor<JSImplicitElement> collectProcessor = new CommonProcessors.CollectProcessor<>();
    AngularIndexUtil.multiResolve(myProject, AngularModuleIndex.KEY, module, collectProcessor);
    if (collectProcessor.getResults().size() != 1)
        return;
    for (JSImplicitElement element : collectProcessor.getResults()) {
        if (element != null && element.getNavigationElement() != null && element.getNavigationElement().getContainingFile() != null) {
            final VirtualFile file = element.getNavigationElement().getContainingFile().getVirtualFile();
            // prefer library resolves
            if (NodeModuleUtil.isFromNodeModules(myProject, file))
                return;
        }
    }
    final JSImplicitElement element = collectProcessor.getResults().iterator().next();
    if (element != null && element.getNavigationElement() != null && element.getNavigationElement().getContainingFile() != null) {
        filesQueue.add(element.getNavigationElement().getContainingFile().getVirtualFile());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) 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