Search in sources :

Example 16 with JSImplicitElement

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

the class AngularUiRouterDiagramBuilder method addStatesFromIndex.

private void addStatesFromIndex() {
    final Collection<String> stateIds = AngularIndexUtil.getAllKeys(AngularUiRouterStatesIndex.KEY, myProject);
    for (String id : stateIds) {
        if (id.startsWith("."))
            continue;
        final CommonProcessors.CollectProcessor<JSImplicitElement> processor = new CommonProcessors.CollectProcessor<>();
        AngularIndexUtil.multiResolve(myProject, AngularUiRouterStatesIndex.KEY, id, processor);
        for (JSImplicitElement element : processor.getResults()) {
            final UiRouterState state = new UiRouterState(id, element.getContainingFile().getVirtualFile());
            if (!element.getContainingFile().getLanguage().isKindOf(JavascriptLanguage.INSTANCE) && PsiTreeUtil.getParentOfType(element, JSEmbeddedContent.class) != null) {
                createRootTemplatesForEmbedded(element.getContainingFile());
            }
            final JSCallExpression call = findWrappingCallExpression(element);
            if (call != null) {
                final JSReferenceExpression methodExpression = ObjectUtils.tryCast(call.getMethodExpression(), JSReferenceExpression.class);
                if (methodExpression != null && methodExpression.getQualifier() != null && "state".equals(methodExpression.getReferenceName())) {
                    final JSExpression[] arguments = call.getArguments();
                    if (arguments.length > 0 && PsiTreeUtil.isAncestor(arguments[0], element.getNavigationElement(), false)) {
                        state.setPointer(mySmartPointerManager.createSmartPsiElementPointer(arguments[0]));
                        if (arguments.length > 1 && arguments[1] instanceof JSObjectLiteralExpression) {
                            final JSObjectLiteralExpression object = (JSObjectLiteralExpression) arguments[1];
                            fillStateParameters(state, object);
                        } else if (arguments[0] instanceof JSObjectLiteralExpression) {
                            final JSObjectLiteralExpression object = (JSObjectLiteralExpression) arguments[0];
                            final JSProperty name = object.findProperty("name");
                            if (name != null && PsiTreeUtil.isAncestor(name, element.getNavigationElement(), false)) {
                                fillStateParameters(state, object);
                            }
                        }
                    }
                }
            }
            myStates.add(state);
        }
    }
}
Also used : CommonProcessors(com.intellij.util.CommonProcessors) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 17 with JSImplicitElement

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

the class AngularJSProcessor method scopeMatches.

private static boolean scopeMatches(PsiElement element, PsiElement declaration) {
    final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(element.getProject());
    if (declaration instanceof JSImplicitElement) {
        if ($EVENT.equals(((JSImplicitElement) declaration).getName())) {
            return eventScopeMatches(injector, element, declaration.getParent());
        }
        declaration = declaration.getParent();
    }
    final PsiLanguageInjectionHost elementContainer = injector.getInjectionHost(element);
    final XmlTagChild elementTag = PsiTreeUtil.getNonStrictParentOfType(elementContainer, XmlTag.class, XmlText.class);
    final PsiLanguageInjectionHost declarationContainer = injector.getInjectionHost(declaration);
    final XmlTagChild declarationTag = PsiTreeUtil.getNonStrictParentOfType(declarationContainer, XmlTag.class, XmlText.class);
    if (declarationContainer != null && elementContainer != null && elementTag != null && declarationTag != null) {
        return PsiTreeUtil.isAncestor(declarationTag, elementTag, true) || (PsiTreeUtil.isAncestor(declarationTag, elementTag, false) && declarationContainer.getTextOffset() < elementContainer.getTextOffset()) || isInRepeatStartEnd(declarationTag, declarationContainer, elementContainer);
    }
    return true;
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 18 with JSImplicitElement

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

the class DirectiveUtil method getTagDirective.

private static JSImplicitElement getTagDirective(Project project, String directiveName, final StubIndexKey<String, JSImplicitElementProvider> index) {
    final JSImplicitElement directive = AngularIndexUtil.resolve(project, index, directiveName);
    final String restrictions = directive != null ? directive.getTypeString() : null;
    if (restrictions != null) {
        final String[] split = restrictions.split(";", -1);
        final String restrict = AngularIndexUtil.convertRestrictions(project, split[0]);
        if (!StringUtil.isEmpty(restrict) && StringUtil.containsIgnoreCase(restrict, "E")) {
            return directive;
        }
    }
    return null;
}
Also used : JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 19 with JSImplicitElement

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

the class DirectiveUtil method processTagDirectives.

public static boolean processTagDirectives(final Project project, Processor<JSImplicitElement> processor) {
    final Collection<String> docDirectives = AngularIndexUtil.getAllKeys(AngularDirectivesDocIndex.KEY, project);
    for (String directiveName : docDirectives) {
        final JSImplicitElement directive = getTagDirective(project, directiveName, AngularDirectivesDocIndex.KEY);
        if (directive != null) {
            if (!processor.process(directive)) {
                return false;
            }
        }
    }
    final Collection<String> directives = AngularIndexUtil.getAllKeys(AngularDirectivesIndex.KEY, project);
    for (String directiveName : directives) {
        if (!docDirectives.contains(directiveName)) {
            final JSImplicitElement directive = getTagDirective(project, directiveName, AngularDirectivesIndex.KEY);
            if (directive != null) {
                if (!processor.process(directive)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 20 with JSImplicitElement

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

the class AngularAttributesRegistry method isAngularExpressionAttribute.

public static boolean isAngularExpressionAttribute(XmlAttribute parent) {
    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 param = restrict != null ? restrict.split(";", -1)[2] : "";
        return param.endsWith("expression") || param.startsWith("string");
    }
    return false;
}
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