Search in sources :

Example 1 with JSLiteralImplicitElementProvider

use of com.intellij.lang.javascript.psi.literal.JSLiteralImplicitElementProvider in project intellij-plugins by JetBrains.

the class AngularJSIndexingHandler method createLiteralImplicitElementProvider.

@Override
public JSLiteralImplicitElementProvider createLiteralImplicitElementProvider(@NotNull final String command) {
    return new JSLiteralImplicitElementProvider() {

        @Override
        public void fillIndexingData(@NotNull JSLiteralExpression argument, @NotNull JSCallExpression callExpression, @NotNull JSElementIndexingData outIndexingData) {
            JSExpression[] arguments = callExpression.getArguments();
            if (arguments.length == 0 || arguments[0] != argument)
                return;
            final JSExpression methodExpression = callExpression.getMethodExpression();
            if (!(methodExpression instanceof JSReferenceExpression))
                return;
            JSExpression qualifier = ((JSReferenceExpression) methodExpression).getQualifier();
            if (qualifier == null)
                return;
            final StubIndexKey<String, JSImplicitElementProvider> index = INDEXERS.get(command);
            if (index != null) {
                if (argument.isQuotedLiteral()) {
                    final Processor<JSArgumentList> argumentListProcessor = ARGUMENT_LIST_CHECKERS.get(command);
                    if (argumentListProcessor != null && !argumentListProcessor.process(callExpression.getArgumentList()))
                        return;
                    final Function<PsiElement, String> calculator = DATA_CALCULATORS.get(command);
                    final String data = calculator != null ? calculator.fun(argument) : null;
                    final String argumentText = unquote(argument);
                    addImplicitElements(argument, command, index, argumentText, data, outIndexingData);
                }
            } else if (INJECTABLE_METHODS.contains(command)) {
                // INTERESTING_METHODS are contained in INJECTABLE_METHODS
                if (argument.isQuotedLiteral()) {
                    generateNamespace(argument, outIndexingData);
                }
            }
            if (START_SYMBOL.equals(command) || END_SYMBOL.equals(command)) {
                while (qualifier != null) {
                    if (qualifier instanceof JSReferenceExpression) {
                        if ("$interpolateProvider".equals(((JSReferenceExpression) qualifier).getReferenceName())) {
                            if (argument.isQuotedLiteral()) {
                                String interpolation = unquote(argument);
                                // '//' interpolations are usually dragged from examples folder and not supposed to be used by real users
                                if ("//".equals(interpolation))
                                    return;
                                FileViewProvider provider = qualifier.getContainingFile().getOriginalFile().getViewProvider();
                                VirtualFile virtualFile = provider.getVirtualFile();
                                virtualFile = virtualFile instanceof LightVirtualFile ? ((LightVirtualFile) virtualFile).getOriginalFile() : virtualFile;
                                if (JSLibraryUtil.isProbableLibraryFile(virtualFile))
                                    return;
                                addImplicitElements(argument, null, AngularInjectionDelimiterIndex.KEY, command, interpolation, outIndexingData);
                            }
                        }
                        qualifier = ((JSReferenceExpression) qualifier).getQualifier();
                    } else {
                        qualifier = qualifier instanceof JSCallExpression ? ((JSCallExpression) qualifier).getMethodExpression() : null;
                    }
                }
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) JSLiteralImplicitElementProvider(com.intellij.lang.javascript.psi.literal.JSLiteralImplicitElementProvider) NotNull(org.jetbrains.annotations.NotNull) JSElementIndexingData(com.intellij.lang.javascript.psi.stubs.JSElementIndexingData) FileViewProvider(com.intellij.psi.FileViewProvider) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSLiteralImplicitElementProvider (com.intellij.lang.javascript.psi.literal.JSLiteralImplicitElementProvider)1 JSElementIndexingData (com.intellij.lang.javascript.psi.stubs.JSElementIndexingData)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FileViewProvider (com.intellij.psi.FileViewProvider)1 PsiElement (com.intellij.psi.PsiElement)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 NotNull (org.jetbrains.annotations.NotNull)1