2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.internal;
19 import com.intellij.codeInsight.lookup.LookupElement;
20 import com.intellij.codeInsight.lookup.LookupManager;
21 import com.intellij.codeInsight.lookup.impl.LookupImpl;
22 import com.intellij.openapi.actionSystem.AnAction;
23 import com.intellij.openapi.actionSystem.AnActionEvent;
24 import com.intellij.openapi.actionSystem.PlatformDataKeys;
25 import com.intellij.openapi.actionSystem.Presentation;
26 import com.intellij.openapi.diagnostic.Logger;
27 import com.intellij.openapi.editor.Editor;
28 import com.intellij.openapi.project.DumbAware;
30 import java.util.LinkedHashMap;
31 import java.util.List;
36 public class DumpLookupElementWeights extends AnAction implements DumbAware {
37 private static final Logger LOG = Logger.getInstance("#com.intellij.internal.DumpLookupElementWeights");
40 public void actionPerformed(final AnActionEvent e) {
41 final Editor editor = e.getData(PlatformDataKeys.EDITOR);
42 dumpLookupElementWeights((LookupImpl)LookupManager.getActiveLookup(editor));
46 public void update(final AnActionEvent e) {
47 final Presentation presentation = e.getPresentation();
48 final Editor editor = e.getData(PlatformDataKeys.EDITOR);
49 presentation.setEnabled(editor != null && LookupManager.getActiveLookup(editor) != null);
52 public static void dumpLookupElementWeights(final LookupImpl lookup) {
53 final LinkedHashMap<LookupElement,StringBuilder> strings = lookup.getRelevanceStrings();
55 final List<LookupElement> items = lookup.getItems();
56 final int count = lookup.getPreferredItemsCount();
58 for (int i = 0; i < items.size(); i++) {
59 LookupElement item = items.get(i);
60 String weight = strings.get(item).toString();
61 final String s = item.getLookupString() + (lookup.isFrozen(item) ? "\t_first_\t" : "\t") + weight;
62 System.out.println(s);
65 final String separator = "------------";
66 System.out.println(separator);