diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java index 32c1716645b4..44701a3ab0de 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java @@ -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("liftShorterClasses") { + @Override + public Classifier createClassifier(Classifier 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)); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy index 4148143c9fce..a3c6273a587a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy @@ -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() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy index e8002a8be6c4..cddb71d9e6bc 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy @@ -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 { diff --git a/platform/lang-api/src/com/intellij/codeInspection/InspectionEP.java b/platform/lang-api/src/com/intellij/codeInspection/InspectionEP.java index 1e121ba7e1ff..1169bf53bc02 100644 --- a/platform/lang-api/src/com/intellij/codeInspection/InspectionEP.java +++ b/platform/lang-api/src/com/intellij/codeInspection/InspectionEP.java @@ -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); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java index aa3a9510ae46..4854888bfc60 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java @@ -292,7 +292,7 @@ public class CompletionServiceImpl extends CompletionService{ return sorter.withClassifier("priority", true, new ClassifierFactory("liftShorter") { @Override public Classifier createClassifier(final Classifier next) { - return new LiftShorterItemsClassifier(next); + return new LiftShorterItemsClassifier(next, new LiftShorterItemsClassifier.LiftingCondition()); } }); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java index 4a05b7758acf..65391ce8e046 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java @@ -30,14 +30,16 @@ import java.util.*; /** * @author peter */ -class LiftShorterItemsClassifier extends Classifier { +public class LiftShorterItemsClassifier extends Classifier { private final TreeSet mySortedStrings; private final MultiMap myElements; private final MultiMap myPrefixes; private final Classifier myNext; + private final LiftingCondition myCondition; - public LiftShorterItemsClassifier(Classifier next) { + public LiftShorterItemsClassifier(Classifier next, LiftingCondition condition) { myNext = next; + myCondition = condition; mySortedStrings = new TreeSet(); myElements = new MultiMap(); myPrefixes = new MultiMap(); @@ -76,9 +78,6 @@ class LiftShorterItemsClassifier extends Classifier { @Override public Iterable classify(Iterable source, ProcessingContext context) { - if (context.get(CompletionLookupArranger.PURE_RELEVANCE) == Boolean.TRUE) { - return myNext.classify(source, context); - } return liftShorterElements(source, new THashSet(TObjectHashingStrategy.IDENTITY), context); } @@ -99,7 +98,7 @@ class LiftShorterItemsClassifier extends Classifier { for (String prefix : prefixes) { List shorter = new SmartList(); 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 { } 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; + } + } } diff --git a/platform/lang-impl/src/com/intellij/ide/util/treeView/smartTree/SmartTreeStructure.java b/platform/lang-impl/src/com/intellij/ide/util/treeView/smartTree/SmartTreeStructure.java index c8bde1879bce..7db150821b82 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/treeView/smartTree/SmartTreeStructure.java +++ b/platform/lang-impl/src/com/intellij/ide/util/treeView/smartTree/SmartTreeStructure.java @@ -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; diff --git a/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditor.java b/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditor.java index 9d4b1f4c4315..f22010baa31a 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditor.java +++ b/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditor.java @@ -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(); diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java index 78b8859f0af9..7ddb4d84ba25 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java @@ -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() { diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java index b19d46b823ac..e829de30dae4 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java @@ -210,10 +210,9 @@ public final class GuiEditor extends JPanel implements DataProvider { * @param file file to be edited * @throws java.lang.IllegalArgumentException * if the file - * is null or file is not falid PsiFile + * is null or file 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;