/*
 * Copyright 2006 Sascha Weinreuter
 *
 * 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 org.intellij.plugins.intelliLang.inject.java;

import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementFactory;
import com.intellij.codeInsight.lookup.LookupElementFactoryImpl;
import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.EmptyIcon;
import org.intellij.plugins.intelliLang.util.StringLiteralReference;
import org.intellij.plugins.intelliLang.inject.InjectedLanguage;
import org.jetbrains.annotations.Nullable;

/**
 * Provides completion for available Language-IDs in
 * <pre>@Language("[ctrl-space]")</pre>
 */
final class LanguageReference extends StringLiteralReference {

  public LanguageReference(PsiLiteralExpression value) {
    super(value);
  }

  @Nullable
  public PsiElement resolve() {
    return InjectedLanguage.findLanguageById(getValue()) != null ? myValue : null;
  }

  public boolean isSoft() {
    return false;
  }

  public Object[] getVariants() {
    final String[] ids = InjectedLanguage.getAvailableLanguageIDs();
    return ContainerUtil.map2Array(ids, LookupElement.class, new Function<String, LookupElement>() {
      public LookupElement fun(String s) {
        final Language l = InjectedLanguage.findLanguageById(s);
        assert l != null;

        final FileType ft = l.getAssociatedFileType();
        if (ft != null) {
          return LookupElementFactoryImpl.getInstance().createLookupElement(s).setIcon(ft.getIcon()).setTypeText(ft.getDescription());
//                } else if (l == StdLanguages.EL) {
//                    // IDEA-10012
//                    return new LanguageLookupValue(s, StdFileTypes.JSP.getIcon(), "Expression Language");
        }
        return LookupElementFactory.getInstance().createLookupElement(s).setIcon(new EmptyIcon(16));
      }
    });
  }

}

@@ -768,73 +768,8 @@
 ry;%0A
-import com.intellij.codeInsight.lookup.LookupElementFactoryImpl;%0A
 impo
@@ -1098,34 +1098,30 @@
 ang.
-util.StringLiteralReferenc
+inject.InjectedLanguag
 e;%0Ai
@@ -1159,38 +1159,42 @@
 lliLang.
-inject.InjectedLanguag
+util.StringLiteralReferenc
 e;%0Aimpor
@@ -2121,46 +2121,16 @@
 tory
-Impl.getInstance().createLookupElement
+.builder
 (s).
@@ -2183,16 +2183,38 @@
 ption())
+.createLookupElement()
 ;%0A//    
@@ -2454,41 +2454,15 @@
 ory.
-getInstance().createLookupElement
+builder
 (s).
@@ -2487,16 +2487,38 @@
 con(16))
+.createLookupElement()
 ;%0A      

rename LookupElementBuilder methods and start using it