Search in sources :

Example 6 with JSImplicitElement

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

the class AngularJSTagDescriptor method getAttributesDescriptors.

@Override
public XmlAttributeDescriptor[] getAttributesDescriptors(@Nullable XmlTag context) {
    final JSImplicitElement declaration = getDeclaration();
    final String string = declaration.getTypeString();
    final String attributes = string.split(";", -1)[3];
    final String[] split = attributes.split(",");
    final XmlAttributeDescriptor[] result;
    if (context != null && AngularIndexUtil.hasAngularJS2(context.getProject())) {
        result = AngularAttributeDescriptor.getFieldBasedDescriptors(declaration);
    } else if (split.length == 1 && split[0].isEmpty()) {
        result = XmlAttributeDescriptor.EMPTY;
    } else {
        result = new XmlAttributeDescriptor[split.length];
        for (int i = 0; i < split.length; i++) {
            result[i] = new AnyXmlAttributeDescriptor(DirectiveUtil.getAttributeName(split[i]));
        }
    }
    final XmlAttributeDescriptor[] commonAttributes = HtmlNSDescriptorImpl.getCommonAttributeDescriptors(context);
    return ArrayUtil.mergeArrays(result, commonAttributes);
}
Also used : AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 7 with JSImplicitElement

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

the class DirectiveUtil method getDirective.

@Nullable
private static JSImplicitElement getDirective(@NotNull PsiElement element, final String name) {
    final String directiveName = getAttributeName(name);
    final JSImplicitElement directive = AngularIndexUtil.resolve(element.getProject(), AngularDirectivesIndex.KEY, directiveName);
    if (directive != null && directive.isEquivalentTo(element)) {
        return directive;
    }
    return null;
}
Also used : JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with JSImplicitElement

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

the class AngularAttributeDescriptor method getCompiledFieldBasedDescriptors.

@NotNull
private static XmlAttributeDescriptor[] getCompiledFieldBasedDescriptors(JSImplicitElement declaration, String decorator, NullableFunction<Pair<PsiElement, String>, XmlAttributeDescriptor> factory) {
    Project project = declaration.getProject();
    Collection<String> keys = StubIndex.getInstance().getAllKeys(AngularDecoratorsIndex.KEY, project);
    GlobalSearchScope scope = GlobalSearchScope.fileScope(declaration.getContainingFile());
    JSAssignmentExpression context = PsiTreeUtil.getContextOfType(declaration, JSAssignmentExpression.class);
    if (context == null)
        return EMPTY;
    final List<XmlAttributeDescriptor> result = new ArrayList<>();
    for (String key : keys) {
        StubIndex.getInstance().processElements(AngularDecoratorsIndex.KEY, key, project, scope, JSImplicitElementProvider.class, (provider) -> {
            JSElementIndexingData data = provider.getIndexingData();
            Collection<JSImplicitElement> elements = data != null ? data.getImplicitElements() : null;
            if (elements != null) {
                for (JSImplicitElement element : elements) {
                    if (key.equals(element.getName())) {
                        String type = element.getTypeString();
                        if (type != null && type.startsWith(decorator + ";") && inContext(context, element)) {
                            ContainerUtil.addIfNotNull(result, factory.fun(Pair.create(element, element.getName())));
                        }
                    }
                }
            }
            return true;
        });
    }
    return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
Also used : Project(com.intellij.openapi.project.Project) JSElementIndexingData(com.intellij.lang.javascript.psi.stubs.JSElementIndexingData) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) BasicXmlAttributeDescriptor(com.intellij.xml.impl.BasicXmlAttributeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) ArrayList(java.util.ArrayList) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with JSImplicitElement

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

the class AngularUiRouterDiagramBuilder method moduleDependenciesStep.

private void moduleDependenciesStep(String mainModule, NonCyclicQueue<VirtualFile> filesQueue, NonCyclicQueue<String> modulesQueue) {
    addContainingFile(filesQueue, mainModule);
    if (!StringUtil.isEmptyOrSpaces(mainModule)) {
        final JSImplicitElement element = AngularIndexUtil.resolve(myProject, AngularModuleIndex.KEY, mainModule);
        if (element != null) {
            final JSCallExpression callExpression = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
            if (callExpression == null)
                return;
            final List<String> dependenciesInModuleDeclaration = AngularModuleIndex.findDependenciesInModuleDeclaration(callExpression);
            if (dependenciesInModuleDeclaration != null) {
                for (String module : dependenciesInModuleDeclaration) {
                    modulesQueue.add(module);
                    addContainingFile(filesQueue, module);
                }
            }
        }
    }
}
Also used : JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 10 with JSImplicitElement

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

the class AngularRouterStateLoader method loadFreelyDefinedStates.

public List<JSObjectLiteralExpression> loadFreelyDefinedStates() {
    final List<JSObjectLiteralExpression> states = new ArrayList<>();
    final Collection<String> allKeys = AngularIndexUtil.getAllKeys(AngularUiRouterGenericStatesIndex.KEY, myProject);
    for (String key : allKeys) {
        final List<JSImplicitElement> list = new ArrayList<>();
        AngularIndexUtil.multiResolve(myProject, AngularUiRouterGenericStatesIndex.KEY, key, list::add);
        for (JSImplicitElement element : list) {
            final JSCallExpression callExpression = AngularUiRouterDiagramBuilder.findWrappingCallExpression(element);
            if (callExpression != null) {
                findPossibleReferences(callExpression, object -> {
                    final JSProperty name = object.findProperty("name");
                    if (name != null && name.getValue() instanceof JSLiteralExpression && ((JSLiteralExpression) name.getValue()).isQuotedLiteral()) {
                        for (String field : STATE_FIELDS) {
                            if (object.findProperty(field) != null && (myStateName == null || myStateName.endsWith(StringUtil.unquoteString(name.getValue().getText())))) {
                                states.add(object);
                                return true;
                            }
                        }
                    }
                    return false;
                });
                if (myStateName != null && !states.isEmpty())
                    return states;
            }
        }
    }
    return states;
}
Also used : 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