Search in sources :

Example 1 with CssPropertyValueReference

use of com.intellij.javascript.flex.css.CssPropertyValueReference in project intellij-plugins by JetBrains.

the class ActionScriptReferenceContributor method registerReferenceProviders.

@Override
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {

        public boolean isAcceptable(Object element, PsiElement context) {
            PsiElement parent = ((JSLiteralExpression) element).getParent();
            if (parent instanceof JSArgumentList) {
                JSExpression[] arguments = ((JSArgumentList) parent).getArguments();
                if (arguments.length > 0 && arguments[0] == element) {
                    parent = parent.getParent();
                    if (parent instanceof JSCallExpression) {
                        JSExpression invokedMethod = ((JSCallExpression) parent).getMethodExpression();
                        if (invokedMethod instanceof JSReferenceExpression) {
                            String methodName = ((JSReferenceExpression) invokedMethod).getReferencedName();
                            if (SET_STYLE_METHOD_NAME.equals(methodName)) {
                                Module module = findModuleForPsiElement(parent);
                                return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
                            }
                        }
                    }
                }
            }
            return false;
        }

        public boolean isClassAcceptable(Class hintClass) {
            return true;
        }
    })), new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
            String value = element.getText();
            if (FlexCssUtil.inQuotes(value)) {
                return new PsiReference[] { new CssPropertyValueReference(element) };
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
    registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {

        public boolean isAcceptable(Object element, PsiElement context) {
            PsiElement parent = ((JSLiteralExpression) element).getParent();
            if (parent instanceof JSAssignmentExpression) {
                PsiElement assignee = parent.getChildren()[0];
                if (assignee instanceof JSDefinitionExpression) {
                    JSExpression expression = ((JSDefinitionExpression) assignee).getExpression();
                    if (expression instanceof JSReferenceExpression) {
                        String refName = ((JSReferenceExpression) expression).getReferencedName();
                        if (refName != null && FlexCssUtil.isStyleNameProperty(refName)) {
                            Module module = findModuleForPsiElement(parent);
                            return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
                        }
                    }
                }
            }
            return false;
        }

        public boolean isClassAcceptable(Class hintClass) {
            return true;
        }
    })), new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
            String value = element.getText();
            if (FlexCssUtil.inQuotes(value)) {
                return new PsiReference[] { new CssClassValueReference(element) };
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
    registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {

        public boolean isAcceptable(Object element, PsiElement context) {
            PsiElement parent = ((JSLiteralExpression) element).getParent();
            if (parent instanceof JSArgumentList) {
                final JSExpression[] arguments = ((JSArgumentList) parent).getArguments();
                if (arguments.length > 0 && arguments[0] == element) {
                    parent = parent.getParent();
                    if (parent instanceof JSCallExpression) {
                        final JSExpression invokedMethod = ((JSCallExpression) parent).getMethodExpression();
                        if (invokedMethod instanceof JSReferenceExpression) {
                            final String methodName = ((JSReferenceExpression) invokedMethod).getReferencedName();
                            if (methodName != null && FlexCssUtil.isStyleNameMethod(methodName)) {
                                Module module = findModuleForPsiElement(parent);
                                return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
                            }
                        }
                    }
                }
            }
            return false;
        }

        public boolean isClassAcceptable(Class hintClass) {
            return true;
        }
    })), new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
            String value = element.getText();
            if (FlexCssUtil.inQuotes(value)) {
                return new PsiReference[] { new CssClassValueReference(element) };
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
    registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class), new FlexPropertyReferenceProvider());
    registrar.registerReferenceProvider(psiElement(JSAttributeNameValuePair.class), new FlexAttributeReferenceProvider());
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) CssClassValueReference(com.intellij.javascript.flex.css.CssClassValueReference) NotNull(org.jetbrains.annotations.NotNull) FilterPattern(com.intellij.psi.filters.position.FilterPattern) CssPropertyValueReference(com.intellij.javascript.flex.css.CssPropertyValueReference) ElementFilter(com.intellij.psi.filters.ElementFilter) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) Module(com.intellij.openapi.module.Module) ModuleUtilCore.findModuleForPsiElement(com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement)

Aggregations

CssClassValueReference (com.intellij.javascript.flex.css.CssClassValueReference)1 CssPropertyValueReference (com.intellij.javascript.flex.css.CssPropertyValueReference)1 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)1 Module (com.intellij.openapi.module.Module)1 ModuleUtilCore.findModuleForPsiElement (com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement)1 ElementFilter (com.intellij.psi.filters.ElementFilter)1 FilterPattern (com.intellij.psi.filters.position.FilterPattern)1 ProcessingContext (com.intellij.util.ProcessingContext)1 NotNull (org.jetbrains.annotations.NotNull)1