Search in sources :

Example 1 with WebReference

use of com.intellij.openapi.paths.WebReference in project intellij-community by JetBrains.

the class JavadocHighlightingTest method testIssueLinksInJavaDoc.

public void testIssueLinksInJavaDoc() {
    IssueNavigationConfiguration navigationConfiguration = IssueNavigationConfiguration.getInstance(getProject());
    List<IssueNavigationLink> oldLinks = navigationConfiguration.getLinks();
    try {
        navigationConfiguration.setLinks(ContainerUtil.newArrayList(new IssueNavigationLink("ABC-\\d+", "http://example.com/$0"), new IssueNavigationLink("INVALID-\\d+", "http://example.com/$0/$1")));
        configureByFile(getTestName(false) + ".java");
        List<String> expected = ContainerUtil.newArrayList("http://example.com/ABC-1123", "http://example.com/ABC-2", "http://example.com/ABC-22", "http://example.com/ABC-11");
        List<WebReference> refs = PlatformTestUtil.collectWebReferences(myFile);
        assertTrue(refs.stream().allMatch(PsiReferenceBase::isSoft));
        assertEquals(expected, refs.stream().map(WebReference::getUrl).collect(Collectors.toList()));
    } finally {
        navigationConfiguration.setLinks(oldLinks);
    }
}
Also used : WebReference(com.intellij.openapi.paths.WebReference) IssueNavigationLink(com.intellij.openapi.vcs.IssueNavigationLink) IssueNavigationConfiguration(com.intellij.openapi.vcs.IssueNavigationConfiguration)

Example 2 with WebReference

use of com.intellij.openapi.paths.WebReference in project intellij-community by JetBrains.

the class PlatformTestUtil method collectWebReferences.

@NotNull
public static List<WebReference> collectWebReferences(@NotNull PsiElement element) {
    List<WebReference> refs = new ArrayList<>();
    element.accept(new PsiRecursiveElementWalkingVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            for (PsiReference ref : element.getReferences()) {
                if (ref instanceof WebReference) {
                    refs.add((WebReference) ref);
                }
            }
            super.visitElement(element);
        }
    });
    return refs;
}
Also used : WebReference(com.intellij.openapi.paths.WebReference) PsiRecursiveElementWalkingVisitor(com.intellij.psi.PsiRecursiveElementWalkingVisitor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 3 with WebReference

use of com.intellij.openapi.paths.WebReference 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

WebReference (com.intellij.openapi.paths.WebReference)3 XmlEncodingReferenceProvider (com.intellij.codeInsight.daemon.impl.analysis.encoding.XmlEncodingReferenceProvider)1 MicrodataReferenceProvider (com.intellij.html.impl.providers.MicrodataReferenceProvider)1 IssueNavigationConfiguration (com.intellij.openapi.vcs.IssueNavigationConfiguration)1 IssueNavigationLink (com.intellij.openapi.vcs.IssueNavigationLink)1 PsiElement (com.intellij.psi.PsiElement)1 PsiRecursiveElementWalkingVisitor (com.intellij.psi.PsiRecursiveElementWalkingVisitor)1 PsiReference (com.intellij.psi.PsiReference)1 NamespaceFilter (com.intellij.psi.filters.position.NamespaceFilter)1 ParentElementFilter (com.intellij.psi.filters.position.ParentElementFilter)1 ArbitraryPlaceUrlReferenceProvider (com.intellij.psi.impl.source.resolve.reference.ArbitraryPlaceUrlReferenceProvider)1 ProcessingContext (com.intellij.util.ProcessingContext)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1