From 52e0a7b07ad882ca5e660fa1c6b9349368f009c4 Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Mon, 24 Aug 2015 15:26:11 +0300 Subject: [PATCH] Allow to specify custom url for WebReference --- .../paths/GlobalPathReferenceProvider.java | 6 +++--- .../intellij/openapi/paths/WebReference.java | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/paths/GlobalPathReferenceProvider.java b/platform/lang-impl/src/com/intellij/openapi/paths/GlobalPathReferenceProvider.java index 63841da51015..ba38d3ec31a7 100644 --- a/platform/lang-impl/src/com/intellij/openapi/paths/GlobalPathReferenceProvider.java +++ b/platform/lang-impl/src/com/intellij/openapi/paths/GlobalPathReferenceProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ package com.intellij.openapi.paths; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.util.io.URLUtil; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NonNls; import java.util.List; @@ -61,7 +61,7 @@ public class GlobalPathReferenceProvider implements PathReferenceProvider { String url, TextRange rangeInElement, @NotNull List references) { if (isWebReferenceUrl(url)) { - references.add(new WebReference(psiElement, rangeInElement)); + references.add(new WebReference(psiElement, rangeInElement, url)); return true; } else if (url.contains("://") || url.startsWith("//") || startsWithAllowedPrefix(url)) { diff --git a/platform/lang-impl/src/com/intellij/openapi/paths/WebReference.java b/platform/lang-impl/src/com/intellij/openapi/paths/WebReference.java index 77b076938efc..49033af5564a 100644 --- a/platform/lang-impl/src/com/intellij/openapi/paths/WebReference.java +++ b/platform/lang-impl/src/com/intellij/openapi/paths/WebReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,17 +21,30 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReferenceBase; import com.intellij.psi.impl.FakePsiElement; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Eugene.Kudelevsky */ public class WebReference extends PsiReferenceBase { + @Nullable private final String myUrl; + public WebReference(@NotNull PsiElement element) { + this(element, (String)null); + } + + public WebReference(@NotNull PsiElement element, @Nullable String url) { super(element, true); + myUrl = url; } public WebReference(@NotNull PsiElement element, @NotNull TextRange textRange) { + this(element, textRange, null); + } + + public WebReference(@NotNull PsiElement element, TextRange textRange, @Nullable String url) { super(element, textRange, true); + myUrl = url; } @Override @@ -40,7 +53,7 @@ public class WebReference extends PsiReferenceBase { } protected String getUrl() { - return getValue(); + return myUrl != null ? myUrl : getValue(); } @NotNull