/*
 * Copyright 2000-2014 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.ide.browsers;

import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.util.Url;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

public abstract class WebBrowserUrlProvider {
  public static final ExtensionPointName<WebBrowserUrlProvider> EP_NAME = ExtensionPointName.create("com.intellij.webBrowserUrlProvider");

  /**
   * Browser exceptions are printed in Error Dialog when user presses any browser button
   */
  public static class BrowserException extends Exception {
    public BrowserException(final String message) {
      super(message);
    }
  }

  public boolean canHandleElement(@NotNull OpenInBrowserRequest request) {
    try {
      Collection<Url> urls = getUrls(request);
      if (!urls.isEmpty()) {
        request.setResult(urls);
        return true;
      }
    }
    catch (BrowserException ignored) {
    }

    return false;
  }

  @Nullable
  protected Url getUrl(@NotNull OpenInBrowserRequest request, @NotNull VirtualFile file) throws BrowserException {
    return null;
  }

  @NotNull
  public Collection<Url> getUrls(@NotNull OpenInBrowserRequest request) throws BrowserException {
    return ContainerUtil.createMaybeSingletonList(getUrl(request, request.getVirtualFile()));
  }

  @SuppressWarnings({"UnusedParameters", "unused"})
  @Nullable
  @Deprecated
  public String getOpenInBrowserActionDescription(@NotNull PsiFile file) {
    return null;
  }
}
@@ -627,17 +627,16 @@
 browsers
-;
 %0A%0Aimport
@@ -686,17 +686,16 @@
 ointName
-;
 %0Aimport 
@@ -734,247 +734,39 @@
 File
-;%0Aimport com.intellij.psi.PsiFile;%0Aimport com.intellij.util.Url;%0Aimport com.intellij.util.containers.ContainerUtil;%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.annotations.Nullable;%0A%0Aimport java.util.Collection;%0A%0Apublic 
+%0Aimport com.intellij.util.Url%0A%0A
 abst
@@ -806,27 +806,44 @@
 %7B%0A  
-public static final
+companion object %7B%0A    val EP_NAME =
  Ext
@@ -857,16 +857,23 @@
 ointName
+.create
 %3CWebBrow
@@ -891,44 +891,8 @@
 der%3E
- EP_NAME = ExtensionPointName.create
 (%22co
@@ -925,17 +925,20 @@
 ovider%22)
-;
+%0A  %7D
 %0A%0A  /**%0A
@@ -1038,22 +1038,8 @@
 /%0A  
-public static 
 clas
@@ -1060,78 +1060,46 @@
 tion
- extends Exception %7B%0A    public BrowserException(final String 
+(message: String) : Exception(
 message)
  %7B%0A 
@@ -1098,59 +1098,19 @@
 age)
- %7B%0A      super(message);%0A    %7D%0A  %7D%0A%0A  public boolea
+%0A%0A  open fu
 n ca
@@ -1124,24 +1124,24 @@
 Element(
-@NotNull
+request:
  OpenInB
@@ -1157,79 +1157,137 @@
 uest
- request) %7B%0A    try %7B%0A      Collection%3CUrl%3E urls = getUrls(request);%0A  
+): Boolean %7B%0A    val urls = try %7B%0A      getUrls(request)%0A    %7D%0A    catch (ignored: BrowserException) %7B%0A      return false%0A    %7D%0A%0A
     
@@ -1319,18 +1319,16 @@
     
-  
 request.
 setR
@@ -1327,27 +1327,22 @@
 est.
-setR
+r
 esult
-(
+ = 
 urls
-);%0A  
+%0A
     
@@ -1354,20 +1354,17 @@
 urn true
-;%0A  
+%0A
     %7D%0A  
@@ -1369,203 +1369,144 @@
     
-%7D%0A    catch (BrowserException ignored) %7B%0A    %7D%0A%0A    return false;%0A  %7D%0A%0A  @Nullable%0A  protected Url getUrl(@NotNull OpenInBrowserRequest request, @NotNull VirtualFile file) throws BrowserException
+return false%0A  %7D%0A%0A  @Throws(BrowserException::class)%0A  protected open fun getUrl(request: OpenInBrowserRequest, file: VirtualFile): Url?
  %7B%0A 
@@ -1515,25 +1515,24 @@
  return null
-;
 %0A  %7D%0A%0A  @Not
@@ -1532,40 +1532,50 @@
 %0A  @
-NotNull%0A  public Collection%3CUrl%3E
+Throws(BrowserException::class)%0A  open fun
  get
@@ -1579,24 +1579,24 @@
 getUrls(
-@NotNull
+request:
  OpenInB
@@ -1612,314 +1612,90 @@
 uest
- request) throws BrowserException %7B%0A    return ContainerUtil.createMaybeSingletonList(getUrl(request, request.getVirtualFile()));%0A  %7D%0A%0A  @SuppressWarnings(%7B%22UnusedParameters%22, %22unused%22%7D)%0A  @Nullable%0A  @Deprecated%0A  public String getOpenInBrowserActionDescription(@NotNull PsiFile file) %7B%0A    return null;%0A  %7D
+): Collection%3CUrl%3E = listOfNotNull(request.virtualFile?.let %7B getUrl(request, it) %7D)
 %0A%7D

convert WebBrowserUrlProvider to kotlin