Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Jemerov
2012-05-02 13:59:23 +02:00
10 changed files with 61 additions and 22 deletions
@@ -17,10 +17,13 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.ExpectedTypeInfoImpl;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementWeigher;
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
import com.intellij.codeInsight.completion.impl.CompletionSorterImpl;
import com.intellij.codeInsight.completion.impl.LiftShorterItemsClassifier;
import com.intellij.codeInsight.lookup.*;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.patterns.PsiJavaPatterns;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
@@ -31,6 +34,7 @@ import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.ProcessingContext;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
@@ -75,6 +79,32 @@ public class JavaCompletionSorting {
CompletionSorter sorter = CompletionSorter.defaultSorter(parameters, result.getPrefixMatcher());
if (!smart && afterNew) {
sorter = sorter.weighBefore("liftShorter", new PreferExpected(true, expectedTypes));
} else {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(position.getProject()).getFileIndex();
sorter = ((CompletionSorterImpl)sorter).withClassifier("liftShorter", true, new ClassifierFactory<LookupElement>("liftShorterClasses") {
@Override
public Classifier<LookupElement> createClassifier(Classifier<LookupElement> next) {
return new LiftShorterItemsClassifier(next, new LiftShorterItemsClassifier.LiftingCondition() {
@Override
public boolean shouldLift(LookupElement shorterElement, LookupElement longerElement, ProcessingContext context) {
if (super.shouldLift(shorterElement, longerElement, context)) {
return true;
}
Object object = shorterElement.getObject();
if (object instanceof PsiClass) {
PsiFile file = ((PsiClass)object).getContainingFile();
if (file != null) {
VirtualFile vFile = file.getOriginalFile().getVirtualFile();
if (vFile != null && fileIndex.isInSource(vFile)) {
return true;
}
}
}
return false;
}
});
}
});
}
if (smart) {
sorter = sorter.weighBefore("negativeStats", new PreferDefaultTypeWeigher(expectedTypes, parameters));
@@ -101,7 +101,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
public void testDispreferImpls() throws Throwable {
myFixture.addClass("package foo; public class Xxx {}");
configureSecondCompletion();
assertPreferredItems(1, "Xxx", "XxxEx", "XxxImpl", "Xxy");
assertPreferredItems(0, "Xxx", "XxxEx", "XxxImpl", "Xxy");
}
public void testPreferOwnInnerClasses() throws Throwable {
@@ -128,7 +128,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
myFixture.addClass("package foo; public interface XaYa {}");
myFixture.addClass("package foo; public interface XyYa {}");
configureSecondCompletion();
assertPreferredItems(1, "XaYa", "XaYaEx", "XaYaImpl", "XyYa", "XyYaXa");
assertPreferredItems(0, "XaYa", "XaYaEx", "XaYaImpl", "XyYa", "XyYaXa");
}
public void testPreferLessParameters() throws Throwable {
@@ -219,7 +219,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
}
public void testPreferClassStaticMembers() {
checkPreferredItems(1, "Zoo", "Zoo.A", "Zoo.B", "Zoo.C", "Zoo.D", "Zoo.E", "Zoo.F", "Zoo.G", "Zoo.H");
checkPreferredItems(0, "Zoo", "Zoo.A", "Zoo.B", "Zoo.C", "Zoo.D", "Zoo.E", "Zoo.F", "Zoo.G", "Zoo.H");
}
public void testPreferFinallyToFinal() {
@@ -21,7 +21,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
}
public void testJComponentAdd() throws Throwable {
checkPreferredItems(0, "name", "b", "fooBean239", "this", "getName");
checkPreferredItems(0, "name", "b", "foo", "fooBean239", "this", "getName");
}
public void testJComponentAddNew() throws Throwable {
@@ -107,6 +107,7 @@ public class InspectionEP extends LanguageExtensionPoint {
public String level;
public HighlightDisplayLevel getDefaultLevel() {
if (level == null) return HighlightDisplayLevel.WARNING;
HighlightDisplayLevel displayLevel = HighlightDisplayLevel.find(level);
if (displayLevel == null) {
LOG.error("Can't find highlight display level: " + level);
@@ -292,7 +292,7 @@ public class CompletionServiceImpl extends CompletionService{
return sorter.withClassifier("priority", true, new ClassifierFactory<LookupElement>("liftShorter") {
@Override
public Classifier<LookupElement> createClassifier(final Classifier<LookupElement> next) {
return new LiftShorterItemsClassifier(next);
return new LiftShorterItemsClassifier(next, new LiftShorterItemsClassifier.LiftingCondition());
}
});
}
@@ -30,14 +30,16 @@ import java.util.*;
/**
* @author peter
*/
class LiftShorterItemsClassifier extends Classifier<LookupElement> {
public class LiftShorterItemsClassifier extends Classifier<LookupElement> {
private final TreeSet<String> mySortedStrings;
private final MultiMap<String, LookupElement> myElements;
private final MultiMap<String, String> myPrefixes;
private final Classifier<LookupElement> myNext;
private final LiftingCondition myCondition;
public LiftShorterItemsClassifier(Classifier<LookupElement> next) {
public LiftShorterItemsClassifier(Classifier<LookupElement> next, LiftingCondition condition) {
myNext = next;
myCondition = condition;
mySortedStrings = new TreeSet<String>();
myElements = new MultiMap<String, LookupElement>();
myPrefixes = new MultiMap<String, String>();
@@ -76,9 +78,6 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
@Override
public Iterable<LookupElement> classify(Iterable<LookupElement> source, ProcessingContext context) {
if (context.get(CompletionLookupArranger.PURE_RELEVANCE) == Boolean.TRUE) {
return myNext.classify(source, context);
}
return liftShorterElements(source, new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY), context);
}
@@ -99,7 +98,7 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
for (String prefix : prefixes) {
List<LookupElement> shorter = new SmartList<LookupElement>();
for (LookupElement shorterElement : myElements.get(prefix)) {
if (srcSet.contains(shorterElement) && processed.add(shorterElement)) {
if (srcSet.contains(shorterElement) && myCondition.shouldLift(shorterElement, element, context) && processed.add(shorterElement)) {
shorter.add(shorterElement);
}
}
@@ -134,4 +133,10 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
}
myNext.describeItems(map, context);
}
public static class LiftingCondition {
public boolean shouldLift(LookupElement shorterElement, LookupElement longerElement, ProcessingContext context) {
return context.get(CompletionLookupArranger.PURE_RELEVANCE) != Boolean.TRUE;
}
}
}
@@ -32,11 +32,9 @@ public class SmartTreeStructure extends AbstractTreeStructure {
public SmartTreeStructure(@NotNull Project project, @NotNull TreeModel model) {
myModel = model;
myProject = project;
}
public void commit() {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
}
@NotNull
@@ -54,7 +52,6 @@ public class SmartTreeStructure extends AbstractTreeStructure {
public Object getRootElement() {
if (myRootElementWrapper == null){
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
myRootElementWrapper = createTree();
}
return myRootElementWrapper;
@@ -77,7 +77,7 @@ public interface FileEditor extends UserDataHolder, Disposable {
void setState(@NotNull FileEditorState state);
/**
* @return whether the editor's content is modified in comparision with its file.
* @return whether the editor's content is modified in comparison with its file.
*/
boolean isModified();
@@ -300,7 +300,12 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
private final Alarm myUpdateEditorAlarm = new Alarm();
private void selectionChanged() {
myBackSlashPressed.clear();
updateEditorsFromProperties();
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
updateEditorsFromProperties();
}
});
}
private void updateEditorsFromProperties() {
@@ -210,10 +210,9 @@ public final class GuiEditor extends JPanel implements DataProvider {
* @param file file to be edited
* @throws java.lang.IllegalArgumentException
* if the <code>file</code>
* is <code>null</code> or <code>file</code> is not falid PsiFile
* is <code>null</code> or <code>file</code> is not valid PsiFile
*/
public GuiEditor(@NotNull final Module module, @NotNull final VirtualFile file) {
ApplicationManager.getApplication().assertIsDispatchThread();
LOG.assertTrue(file.isValid());
myModule = module;
@@ -474,7 +473,9 @@ public final class GuiEditor extends JPanel implements DataProvider {
}
// Standard Swing cut/copy/paste actions should work if user is editing something inside property inspector
final UIDesignerToolWindowManager manager = UIDesignerToolWindowManager.getInstance(getProject());
Project project = getProject();
if (project.isDisposed()) return null;
final UIDesignerToolWindowManager manager = UIDesignerToolWindowManager.getInstance(project);
final PropertyInspector inspector = manager.getPropertyInspector();
if (inspector != null && inspector.isEditing()) {
return null;