Allow to specify custom url for WebReference

This commit is contained in:
Alexander Zolotov
2015-08-25 16:46:25 +03:00
parent c75c96aac1
commit 52e0a7b07a
2 changed files with 18 additions and 5 deletions
@@ -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<PsiReference> 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)) {
@@ -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<PsiElement> {
@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<PsiElement> {
}
protected String getUrl() {
return getValue();
return myUrl != null ? myUrl : getValue();
}
@NotNull