Search in sources :

Example 26 with ProcessingContext

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

the class GrLanguageReferenceProvider method registerReferenceProviders.

@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    final Configuration configuration = Configuration.getInstance();
    registrar.registerReferenceProvider(GroovyPatterns.groovyLiteralExpression().annotationParam(StandardPatterns.string().with(isLanguageAnnotation(configuration)), "value").and(GroovyPatterns.groovyLiteralExpression().with(isStringLiteral())), new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            return new PsiReference[] { new LanguageReference((PsiLiteral) element) };
        }
    });
}
Also used : LanguageReference(org.intellij.plugins.intelliLang.inject.java.LanguageReference) ProcessingContext(com.intellij.util.ProcessingContext) Configuration(org.intellij.plugins.intelliLang.Configuration) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with ProcessingContext

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

the class JavaFxEventHandlerReferenceProvider method getReferencesByElement.

@Override
protected PsiReference[] getReferencesByElement(@NotNull PsiClass controllerClass, XmlAttributeValue xmlAttributeValue, ProcessingContext context) {
    final String attValueString = xmlAttributeValue.getValue();
    LOG.assertTrue(attValueString.startsWith("#"));
    final XmlAttribute attribute = (XmlAttribute) xmlAttributeValue.getParent();
    if (attribute == null || !JavaFxPsiUtil.isEventHandlerProperty(attribute))
        return PsiReference.EMPTY_ARRAY;
    final String eventHandlerName = attValueString.substring(1);
    final PsiMethod[] methods = controllerClass.findMethodsByName(eventHandlerName, true);
    final PsiReference[] references = Arrays.stream(methods).filter(psiMethod -> JavaFxEventHandlerReference.isHandlerMethodSignature(psiMethod, controllerClass)).map(psiMethod -> new JavaFxEventHandlerReference(xmlAttributeValue, psiMethod, controllerClass)).toArray(PsiReference.ARRAY_FACTORY::create);
    if (references.length == 1) {
        return references;
    }
    if (references.length > 1) {
        return new PsiReference[] { new PsiMultiReference(references, xmlAttributeValue) };
    }
    if (references.length == 0) {
        final XmlTag rootTag = ((XmlFile) xmlAttributeValue.getContainingFile()).getRootTag();
        if (rootTag == null || FxmlConstants.FX_ROOT.equals(rootTag.getName())) {
            return PsiReference.EMPTY_ARRAY;
        }
    }
    return new PsiReference[] { new JavaFxEventHandlerReference(xmlAttributeValue, null, controllerClass) };
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) Arrays(java.util.Arrays) PsiMultiReference(com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference) PsiMethod(com.intellij.psi.PsiMethod) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) PsiReference(com.intellij.psi.PsiReference) JavaFxPsiUtil(org.jetbrains.plugins.javaFX.fxml.JavaFxPsiUtil) PsiClass(com.intellij.psi.PsiClass) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) FxmlConstants(org.jetbrains.plugins.javaFX.fxml.FxmlConstants) XmlTag(com.intellij.psi.xml.XmlTag) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) PsiMethod(com.intellij.psi.PsiMethod) PsiReference(com.intellij.psi.PsiReference) PsiMultiReference(com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference) XmlTag(com.intellij.psi.xml.XmlTag)

Example 28 with ProcessingContext

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

the class PyReferenceImpl method getTypeCompletionVariants.

protected static Object[] getTypeCompletionVariants(PyExpression pyExpression, PyType type) {
    ProcessingContext context = new ProcessingContext();
    context.put(PyType.CTX_NAMES, new HashSet<>());
    return type.getCompletionVariants(pyExpression.getName(), pyExpression, context);
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext)

Example 29 with ProcessingContext

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

the class XmlEnumeratedValueReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (XmlSchemaTagsProcessor.PROCESSING_FLAG.get() != null || context.get(SUPPRESS) != null) {
        return PsiReference.EMPTY_ARRAY;
    }
    @SuppressWarnings("unchecked") PsiElement host = getHost((T) element);
    if (host instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost) host)) {
        return PsiReference.EMPTY_ARRAY;
    }
    if (XmlHighlightVisitor.skipValidation(element)) {
        return PsiReference.EMPTY_ARRAY;
    }
    String unquotedValue = ElementManipulators.getValueText(element);
    if (!XmlUtil.isSimpleValue(unquotedValue, element)) {
        return PsiReference.EMPTY_ARRAY;
    }
    @SuppressWarnings("unchecked") final Object descriptor = getDescriptor((T) element);
    if (descriptor instanceof XmlEnumerationDescriptor) {
        XmlEnumerationDescriptor enumerationDescriptor = (XmlEnumerationDescriptor) descriptor;
        if (enumerationDescriptor.isFixed() || enumerationDescriptor.isEnumerated((XmlElement) element)) {
            //noinspection unchecked
            return enumerationDescriptor.getValueReferences((XmlElement) element, unquotedValue);
        } else if (unquotedValue.equals(enumerationDescriptor.getDefaultValue())) {
            // todo case insensitive
            return ContainerUtil.map2Array(enumerationDescriptor.getValueReferences((XmlElement) element, unquotedValue), PsiReference.class, reference -> PsiDelegateReference.createSoft(reference, true));
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) ArrayUtil(com.intellij.util.ArrayUtil) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Key(com.intellij.openapi.util.Key) ContainerUtil(com.intellij.util.containers.ContainerUtil) XmlHighlightVisitor(com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor) PsiDelegateReference(com.intellij.psi.impl.source.resolve.reference.impl.PsiDelegateReference) XmlSchemaTagsProcessor(com.intellij.xml.impl.schema.XmlSchemaTagsProcessor) XmlText(com.intellij.psi.xml.XmlText) XmlEnumerationDescriptor(com.intellij.xml.impl.XmlEnumerationDescriptor) XmlElement(com.intellij.psi.xml.XmlElement) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) XmlTag(com.intellij.psi.xml.XmlTag) XmlEnumerationDescriptor(com.intellij.xml.impl.XmlEnumerationDescriptor) XmlElement(com.intellij.psi.xml.XmlElement) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with ProcessingContext

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

the class XmlReferenceContributor method registerReferenceProviders.

@Override
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {
    final IdReferenceProvider idReferenceProvider = new IdReferenceProvider();
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, idReferenceProvider.getIdForAttributeNames(), idReferenceProvider.getIdForFilter(), true, idReferenceProvider, PsiReferenceRegistrar.DEFAULT_PRIORITY);
    final DtdReferencesProvider dtdReferencesProvider = new DtdReferencesProvider();
    //registerReferenceProvider(null, XmlEntityDecl.class,dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlEntityRef.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlDoctype.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementDecl.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlAttlistDecl.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementContentSpec.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlToken.class), dtdReferencesProvider);
    registrar.registerReferenceProvider(xmlAttributeValue(), new ArbitraryPlaceUrlReferenceProvider(), PsiReferenceRegistrar.LOWER_PRIORITY);
    URIReferenceProvider uriProvider = new URIReferenceProvider();
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, dtdReferencesProvider.getSystemReferenceFilter(), uriProvider);
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] { "href" }, new ScopeFilter(new ParentElementFilter(new AndFilter(new AndFilter(XmlTagFilter.INSTANCE, new XmlTextFilter("include")), new NamespaceFilter(XmlUtil.XINCLUDE_URI)), 2)), true, new XmlBaseReferenceProvider(true));
    registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("base").withNamespace(XmlUtil.XML_NAMESPACE_URI), new XmlBaseReferenceProvider(false));
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] { MicrodataUtil.ITEM_TYPE }, null, new MicrodataReferenceProvider());
    final SchemaReferencesProvider schemaReferencesProvider = new SchemaReferencesProvider();
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, schemaReferencesProvider.getCandidateAttributeNamesForSchemaReferences(), new ScopeFilter(new ParentElementFilter(new NamespaceFilter(XmlUtil.SCHEMA_URIS), 2)), schemaReferencesProvider);
    registrar.registerReferenceProvider(xmlAttributeValue(xmlAttribute().withNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI)).withLocalName("type"), schemaReferencesProvider);
    registrar.registerReferenceProvider(xmlAttributeValue(xmlAttribute().withNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI)).withLocalName("noNamespaceSchemaLocation", "schemaLocation"), uriProvider);
    registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("schemaLocation", "namespace").withSuperParent(2, xmlTag().withNamespace(XmlUtil.SCHEMA_URIS).withLocalName("import", "include", "redefine")), uriProvider);
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, URIReferenceProvider.ELEMENT_FILTER, true, uriProvider);
    XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] { "encoding" }, new ScopeFilter(new ParentElementFilter(new ClassFilter(XmlProcessingInstruction.class))), true, new XmlEncodingReferenceProvider());
    registrar.registerReferenceProvider(xmlAttributeValue(), new XmlPrefixReferenceProvider());
    registrar.registerReferenceProvider(xmlAttributeValue(), new XmlEnumeratedValueReferenceProvider(), PsiReferenceRegistrar.LOWER_PRIORITY);
    registrar.registerReferenceProvider(xmlTag(), XmlEnumeratedValueReferenceProvider.forTags(), PsiReferenceRegistrar.LOWER_PRIORITY);
    registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("source").withSuperParent(2, xmlTag().withLocalName("documentation").withNamespace(XmlUtil.SCHEMA_URIS)), new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
            return new PsiReference[] { new WebReference(element) };
        }
    });
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) ArbitraryPlaceUrlReferenceProvider(com.intellij.psi.impl.source.resolve.reference.ArbitraryPlaceUrlReferenceProvider) MicrodataReferenceProvider(com.intellij.html.impl.providers.MicrodataReferenceProvider) NotNull(org.jetbrains.annotations.NotNull) ParentElementFilter(com.intellij.psi.filters.position.ParentElementFilter) WebReference(com.intellij.openapi.paths.WebReference) NamespaceFilter(com.intellij.psi.filters.position.NamespaceFilter) XmlEncodingReferenceProvider(com.intellij.codeInsight.daemon.impl.analysis.encoding.XmlEncodingReferenceProvider)

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