Search in sources :

Example 31 with ProcessingContext

use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.

the class DomHighlightingHelperImpl method checkResolveProblems.

@Override
@NotNull
public List<DomElementProblemDescriptor> checkResolveProblems(GenericDomValue element, final DomElementAnnotationHolder holder) {
    if (StringUtil.isEmpty(element.getStringValue())) {
        final Required required = element.getAnnotation(Required.class);
        if (required != null && !required.nonEmpty())
            return Collections.emptyList();
    }
    final XmlElement valueElement = DomUtil.getValueElement(element);
    if (valueElement != null && !isSoftReference(element)) {
        final SmartList<DomElementProblemDescriptor> list = new SmartList<>();
        final PsiReference[] psiReferences = myProvider.getReferencesByElement(valueElement, new ProcessingContext());
        GenericDomValueReference domReference = ContainerUtil.findInstance(psiReferences, GenericDomValueReference.class);
        final Converter converter = WrappingConverter.getDeepestConverter(element.getConverter(), element);
        boolean hasBadResolve = false;
        if (domReference == null || !isDomResolveOK(element, domReference, converter)) {
            for (final PsiReference reference : psiReferences) {
                if (reference != domReference && hasBadResolve(reference)) {
                    hasBadResolve = true;
                    list.add(holder.createResolveProblem(element, reference));
                }
            }
            final boolean isResolvingConverter = converter instanceof ResolvingConverter;
            //noinspection unchecked
            if (!hasBadResolve && (domReference != null || isResolvingConverter && hasBadResolve(domReference = new GenericDomValueReference(element)))) {
                hasBadResolve = true;
                final String errorMessage = converter.getErrorMessage(element.getStringValue(), ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element)));
                if (errorMessage != null) {
                    list.add(holder.createResolveProblem(element, domReference));
                }
            }
        }
        if (!hasBadResolve && psiReferences.length == 0 && element.getValue() == null && !PsiTreeUtil.hasErrorElements(valueElement)) {
            final String errorMessage = converter.getErrorMessage(element.getStringValue(), ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element)));
            if (errorMessage != null) {
                list.add(holder.createProblem(element, errorMessage));
            }
        }
        return list;
    }
    return Collections.emptyList();
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) PsiReference(com.intellij.psi.PsiReference) XmlElement(com.intellij.psi.xml.XmlElement) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with ProcessingContext

use of com.intellij.util.ProcessingContext 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)

Example 33 with ProcessingContext

use of com.intellij.util.ProcessingContext in project intellij-plugins by JetBrains.

the class PhoneGapEventLiteralsCompletionContributor method getProvider.

private static CompletionProvider<CompletionParameters> getProvider() {
    return new CompletionProvider<CompletionParameters>() {

        @Override
        protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
            Project project = completionParameters.getEditor().getProject();
            if (null == project || !PhoneGapUtil.isPhoneGapProject(project)) {
                return;
            }
            completionResultSet.addElement(LookupElementBuilder.create("deviceready"));
            completionResultSet.addElement(LookupElementBuilder.create("pause"));
            completionResultSet.addElement(LookupElementBuilder.create("resume"));
            completionResultSet.addElement(LookupElementBuilder.create("online"));
            completionResultSet.addElement(LookupElementBuilder.create("offline"));
            completionResultSet.addElement(LookupElementBuilder.create("backbutton"));
            completionResultSet.addElement(LookupElementBuilder.create("menubutton"));
            completionResultSet.addElement(LookupElementBuilder.create("searchbutton"));
            completionResultSet.addElement(LookupElementBuilder.create("startcallbutton"));
            completionResultSet.addElement(LookupElementBuilder.create("endcallbutton"));
            completionResultSet.addElement(LookupElementBuilder.create("volumedownbutton"));
            completionResultSet.addElement(LookupElementBuilder.create("volumeupbutton"));
        }
    };
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProcessingContext (com.intellij.util.ProcessingContext)33 NotNull (org.jetbrains.annotations.NotNull)20 XmlAttribute (com.intellij.psi.xml.XmlAttribute)4 CompletionSorterImpl (com.intellij.codeInsight.completion.impl.CompletionSorterImpl)3 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 Collection (java.util.Collection)3 LiveTemplateLookupElement (com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)2 CssClassValueReference (com.intellij.javascript.flex.css.CssClassValueReference)2 Logger (com.intellij.openapi.diagnostic.Logger)2 ModuleUtilCore.findModuleForPsiElement (com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 PsiReference (com.intellij.psi.PsiReference)2 JavaClassReferenceProvider (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider)2 XmlElement (com.intellij.psi.xml.XmlElement)2 XmlTag (com.intellij.psi.xml.XmlTag)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Configuration (org.intellij.plugins.intelliLang.Configuration)2