/*
 * 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.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.psi.impl.source.resolve.reference;

import com.intellij.openapi.paths.GlobalPathReferenceProvider;
import com.intellij.openapi.paths.PathReferenceManager;
import com.intellij.openapi.util.UserDataCache;
import com.intellij.openapi.vcs.IssueNavigationConfiguration;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceProvider;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.util.ProcessingContext;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

public class ArbitraryPlaceUrlReferenceProvider extends PsiReferenceProvider {
  private static final UserDataCache<CachedValue<PsiReference[]>, PsiElement, Object> ourRefsCache = new UserDataCache<CachedValue<PsiReference[]>, PsiElement, Object>("psielement.url.refs") {
      private final AtomicReference<GlobalPathReferenceProvider> myReferenceProvider = new AtomicReference<GlobalPathReferenceProvider>();

      @Override
      protected CachedValue<PsiReference[]> compute(final PsiElement element, Object p) {
        return CachedValuesManager.getManager(element.getProject()).createCachedValue(new CachedValueProvider<PsiReference[]>() {
          public Result<PsiReference[]> compute() {
            IssueNavigationConfiguration navigationConfiguration = IssueNavigationConfiguration.getInstance(element.getProject());
            if (navigationConfiguration == null) {
              return Result.create(PsiReference.EMPTY_ARRAY, element);
            }
            
            List<PsiReference> refs = null;
            GlobalPathReferenceProvider provider = myReferenceProvider.get();
            for (IssueNavigationConfiguration.LinkMatch link : navigationConfiguration.findIssueLinks(element.getText())) {
              if (refs == null) refs = new SmartList<PsiReference>();
              if (provider == null) {
                provider = (GlobalPathReferenceProvider)PathReferenceManager.getInstance().getGlobalWebPathReferenceProvider();
                myReferenceProvider.lazySet(provider);
              }
              provider.createUrlReference(element, link.getTargetUrl(), link.getRange(), refs);
            }
            PsiReference[] references = refs != null ? refs.toArray(new PsiReference[refs.size()]) : PsiReference.EMPTY_ARRAY;
            return new Result<PsiReference[]>(references, element, navigationConfiguration);
          }
        }, false);
      }
    };

  @NotNull
  @Override
  public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull ProcessingContext context) {
    return ourRefsCache.get(element, null).getValue();
  }
}

@@ -818,16 +818,66 @@
 aCache;%0A
+import com.intellij.openapi.util.text.StringUtil;%0A
 import c
@@ -2489,24 +2489,121 @@
 ider.get();%0A
+            CharSequence commentText = StringUtil.newBombedCharSequence(element.getText(), 500);%0A
             
@@ -2692,33 +2692,27 @@
 ueLinks(
-ele
+com
 ment
-.get
 Text
-()
 )) %7B%0A   

Use bombed charsequence while calculating issue references in comment