Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Kirill Kalishev
2011-03-10 20:48:27 +03:00
31 changed files with 313 additions and 156 deletions
@@ -1047,20 +1047,11 @@ public class CompileDriver {
final boolean hasUnprocessedTraverseRoots = context.getDependencyCache().hasUnprocessedTraverseRoots();
if (!isRebuild && (compiledSomethingForThisChunk || hasUnprocessedTraverseRoots)) {
final Set<VirtualFile> compiledWithSuccess;
final Set<VirtualFile> compiledWithErrors = CacheUtils.getFilesCompiledWithErrors(context);
if (compiledWithErrors.isEmpty()) {
compiledWithSuccess = sink.getCompiledSources();
}
else {
compiledWithSuccess = new HashSet<VirtualFile>();
compiledWithSuccess.addAll(sink.getCompiledSources());
compiledWithSuccess.removeAll(compiledWithErrors);
}
filesToRecompile.removeAll(compiledWithSuccess);
filesToRecompile.removeAll(sink.getCompiledSources());
filesToRecompile.addAll(compiledWithErrors);
dependentFiles = CacheUtils.findDependentFiles(context, compiledWithSuccess, dependencyFilter);
dependentFiles = CacheUtils.findDependentFiles(context, compiledWithErrors, dependencyFilter);
if (!processedModules.isEmpty()) {
for (Iterator<VirtualFile> it = dependentFiles.iterator(); it.hasNext();) {
final VirtualFile next = it.next();
@@ -130,7 +130,7 @@ public class CacheUtils {
public static Collection<VirtualFile> findDependentFiles(
final CompileContextEx context,
final Set<VirtualFile> succesfullyCompiledJavaFiles,
final Set<VirtualFile> compiledWithErrors,
final @Nullable Function<Pair<int[], Set<VirtualFile>>, Pair<int[], Set<VirtualFile>>> filter) throws CacheCorruptedException {
if (!CompilerConfiguration.MAKE_ENABLED) {
@@ -141,7 +141,7 @@ public class CacheUtils {
final DependencyCache dependencyCache = context.getDependencyCache();
final Pair<int[], Set<VirtualFile>> deps =
dependencyCache.findDependentClasses(context, context.getProject(), succesfullyCompiledJavaFiles);
dependencyCache.findDependentClasses(context, context.getProject(), compiledWithErrors);
final Pair<int[], Set<VirtualFile>> filteredDeps = filter != null? filter.fun(deps) : deps;
final Set<VirtualFile> dependentFiles = new HashSet<VirtualFile>();
@@ -390,14 +390,14 @@ public class DependencyCache {
/**
* @return qualified names of the classes that should be additionally recompiled
*/
public Pair<int[], Set<VirtualFile>> findDependentClasses(CompileContext context, Project project, Set<VirtualFile> successfullyCompiled)
public Pair<int[], Set<VirtualFile>> findDependentClasses(CompileContext context, Project project, Set<VirtualFile> compiledWithErrors)
throws CacheCorruptedException {
markDependencies(context, project, successfullyCompiled);
markDependencies(context, project, compiledWithErrors);
return new Pair<int[], Set<VirtualFile>>(myMarkedInfos.toArray(), Collections.unmodifiableSet(myMarkedFiles));
}
private void markDependencies(CompileContext context, Project project, final Set<VirtualFile> successfullyCompiled) throws CacheCorruptedException {
private void markDependencies(CompileContext context, Project project, final Set<VirtualFile> compiledWithErrors) throws CacheCorruptedException {
try {
if (LOG.isDebugEnabled()) {
LOG.debug("====================Marking dependent files=====================");
@@ -441,7 +441,7 @@ public class DependencyCache {
final boolean markAsRemovedSource = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
public Boolean compute() {
VirtualFile sourceFile = sourceFileFinder.findSourceFile(qualifiedName, sourceFileName);
return sourceFile == null || successfullyCompiled.contains(sourceFile) ? Boolean.TRUE : Boolean.FALSE;
return sourceFile == null || !compiledWithErrors.contains(sourceFile) ? Boolean.TRUE : Boolean.FALSE;
}
}).booleanValue();
if (markAsRemovedSource) {
@@ -67,7 +67,6 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
});
}
});
}
public static void addAllClasses(CompletionParameters parameters, final CompletionResultSet result, @NotNull final Consumer<LookupElement> consumer) {
@@ -76,10 +75,12 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
final ElementFilter filter =
or(JavaSmartCompletionContributor.AFTER_THROW_NEW,
JavaCompletionContributor.INSIDE_METHOD_THROWS_CLAUSE,
JavaCompletionContributor.IN_CATCH_TYPE).accepts(insertedElement) ? new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE) :
IN_TYPE_PARAMETER.accepts(insertedElement) ? new ExcludeDeclaredFilter(new ClassFilter(PsiTypeParameter.class)) :
TrueFilter.INSTANCE;
JavaCompletionContributor.IN_CATCH_TYPE,
JavaCompletionContributor.IN_MULTI_CATCH_TYPE).accepts(insertedElement)
? new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE)
: IN_TYPE_PARAMETER.accepts(insertedElement)
? new ExcludeDeclaredFilter(new ClassFilter(PsiTypeParameter.class))
: TrueFilter.INSTANCE;
final boolean inJavaContext = parameters.getPosition() instanceof PsiIdentifier;
if (AFTER_NEW.accepts(insertedElement)) {
@@ -90,6 +90,9 @@ public class JavaCompletionContributor extends CompletionContributor {
psiElement().withParent(psiElement(PsiJavaCodeReferenceElement.class).withParent(PsiImportStatementBase.class));
static final PsiJavaElementPattern.Capture<PsiElement> IN_CATCH_TYPE =
psiElement().afterLeaf(psiElement().withText("(").withParent(PsiCatchSection.class));
static final ElementPattern<PsiElement> IN_MULTI_CATCH_TYPE =
or(psiElement().afterLeaf(psiElement().withText("|").withParent(PsiTypeElement.class).withSuperParent(2, PsiCatchSection.class)),
psiElement().afterLeaf(psiElement().withText("|").withParent(PsiTypeElement.class).withSuperParent(2, PsiParameter.class).withSuperParent(3, PsiCatchSection.class)));
static final PsiJavaElementPattern.Capture<PsiElement> INSIDE_METHOD_THROWS_CLAUSE = psiElement().afterLeaf(PsiKeyword.THROWS, ",").inside(
PsiMethod.class).andNot(psiElement().inside(PsiCodeBlock.class)).andNot(psiElement().inside(PsiParameterList.class));
@@ -128,7 +131,7 @@ public class JavaCompletionContributor extends CompletionContributor {
return ElementClassFilter.VARIABLE;
}
if (IN_CATCH_TYPE.accepts(position)) {
if (IN_CATCH_TYPE.accepts(position) || IN_MULTI_CATCH_TYPE.accepts(position)) {
return new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE);
}
@@ -2,7 +2,7 @@
String name();
}
@Column(<caret>)
@Column<caret>
@interface Annotation {
}
@@ -0,0 +1,7 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (MyException<caret>) { }
}
}
@@ -0,0 +1,7 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (My<caret>) { }
}
}
@@ -0,0 +1,7 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (MyException<caret> e) { }
}
}
@@ -0,0 +1,7 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (My<caret> e) { }
}
}
@@ -0,0 +1,7 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (RuntimeException | MyException<caret>) { }
}
}
@@ -0,0 +1,7 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (RuntimeException | My<caret>) { }
}
}
@@ -0,0 +1,7 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (RuntimeException | MyException<caret> e) { }
}
}
@@ -0,0 +1,7 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (RuntimeException | My<caret> e) { }
}
}
@@ -9,6 +9,8 @@ import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.module.JavaModuleType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.TestDataPath;
@@ -62,29 +64,29 @@ public class ClassNameCompletionTest extends CompletionTestCase {
checkResultByFile(path + "/after2.java");
}
public void testExcessParensAfterNew() throws Throwable { doTest(); }
public void testExcessParensAfterNew() throws Exception { doTest(); }
public void testReuseParensAfterNew() throws Throwable { doTest(); }
public void testReuseParensAfterNew() throws Exception { doTest(); }
public void testBracesAfterNew() throws Throwable { doTest(); }
public void testBracesAfterNew() throws Exception { doTest(); }
public void testInPlainTextFile() throws Throwable {
public void testInPlainTextFile() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".txt");
checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt");
checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt");
}
public void testDoubleStringBuffer() throws Throwable {
public void testDoubleStringBuffer() throws Exception {
createClass("package java.lang; public class StringBuffer {}");
doTest();
assertNull(myItems);
}
public void testReplaceReferenceExpressionWithTypeElement() throws Throwable {
public void testReplaceReferenceExpressionWithTypeElement() throws Exception {
createClass("package foo.bar; public class ABCDEF {}");
doTest();
}
public void testCamelHumpPrefix() throws Throwable {
public void testCamelHumpPrefix() throws Exception {
String path = BASE_PATH + "/java/";
configureByFile(path + getTestName(false) + ".java");
complete();
@@ -95,7 +97,7 @@ public class ClassNameCompletionTest extends CompletionTestCase {
private void doTest() throws Exception {
String path = BASE_PATH + "/java/";
configureByFile(path + getTestName(false) + ".java");
checkResultByFile(path + getTestName(false) + "_after.java");
checkResultByFile(path + getTestName(false) + "_after.java");
}
public void testNameCompletionJava() throws Exception {
@@ -108,14 +110,14 @@ public class ClassNameCompletionTest extends CompletionTestCase {
checkResultByFile(path + "/test2-result.java");
}
public void testImplementsFiltering1() throws Exception{
public void testImplementsFiltering1() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/test4-source.java");
performAction();
checkResultByFile(path + "/test4-result.java");
}
public void testImplementsFiltering2() throws Exception{
public void testImplementsFiltering2() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/test3-source.java");
performAction();
@@ -135,7 +137,7 @@ public class ClassNameCompletionTest extends CompletionTestCase {
return "testAnnotationFiltering".equals(getName());
}
public void testAnnotationFiltering() throws Exception{
public void testAnnotationFiltering() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/test7-source.java");
performAction();
@@ -174,38 +176,66 @@ public class ClassNameCompletionTest extends CompletionTestCase {
checkResultByFile(path + "/test13-result.java");
}
public void testInMethodCall() throws Throwable {
public void testInMethodCall() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/methodCall-source.java");
performAction();
checkResultByFile(path + "/methodCall-result.java");
}
public void testInMethodCallQualifier() throws Throwable {
public void testInMethodCallQualifier() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/methodCall1-source.java");
performAction();
checkResultByFile(path + "/methodCall1-result.java");
}
public void testInVariableDeclarationType() throws Throwable {
public void testInVariableDeclarationType() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/varType-source.java");
performAction();
checkResultByFile(path + "/varType-result.java");
}
public void testExtraSpace() throws Throwable { doJavaTest(); }
public void testExtraSpace() throws Exception { doJavaTest(); }
public void testAnnotation() throws Throwable { doJavaTest(); }
public void testAnnotation() throws Exception { doJavaTest(); }
public void testInStaticImport() throws Throwable { doJavaTest(); }
public void testInStaticImport() throws Exception { doJavaTest(); }
public void testInCommentWithPackagePrefix() throws Throwable { doJavaTest(); }
public void testInCommentWithPackagePrefix() throws Exception { doJavaTest(); }
public void testQualifyNameOnSecondCompletion() throws Exception {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Exception {
final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType());
createClass(module, "package foo.bar; class AxBxCxDxEx {}");
}
}.execute().throwException();
configureByFileNoCompletion(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-source.java");
new CodeCompletionHandlerBase(CompletionType.CLASS_NAME).invokeCompletion(myProject, myEditor, 2, false);
checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java");
}
public void testInCatchType1() throws Exception { doJavaTest(); }
public void testInCatchType2() throws Exception { doJavaTest(); }
public void testInMultiCatchType1() throws Exception {
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
doJavaTest();
}
public void testInMultiCatchType2() throws Exception {
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
doJavaTest();
}
private void doJavaTest() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/" + getTestName(false) + "-source.java");
configureByFileNoCompletion(path + "/" + getTestName(false) + "-source.java");
performAction();
checkResultByFile(path + "/" + getTestName(false) + "-result.java");
}
@@ -223,24 +253,11 @@ public class ClassNameCompletionTest extends CompletionTestCase {
CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.CLASS_NAME);
handler.invokeCompletion(myProject, myEditor);
final LookupManager instance = LookupManager.getInstance(myProject);
if(instance instanceof LookupManagerImpl){
if (instance instanceof LookupManagerImpl) {
final LookupManagerImpl testLookupManager = ((LookupManagerImpl)instance);
if(testLookupManager.getActiveLookup() != null)
if (testLookupManager.getActiveLookup() != null) {
testLookupManager.forceSelection(Lookup.NORMAL_SELECT_CHAR, 0);
}
}
}
public void testQualifyNameOnSecondCompletion() throws Throwable {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType());
createClass(module, "package foo.bar; class AxBxCxDxEx {}");
}
}.execute().throwException();
configureByFileNoCompletion(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-source.java");
new CodeCompletionHandlerBase(CompletionType.CLASS_NAME).invokeCompletion(myProject, myEditor, 2, false);
checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java");
}
}
@@ -121,7 +121,7 @@ public class VariablesCompletionTest extends CompletionTestCase {
configureByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName.java");
complete();
checkResultByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName.java");
testByCount(2, "creAnInt", "createStylesheetCombobox");
doTestByCount(2, "creAnInt", "createStylesheetCombobox");
}
public void testArrayMethodName() throws Throwable {
@@ -126,11 +126,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
return configureByFile(vFile, projectFile);
}
protected PsiFile configureByText(final FileType fileType, @NonNls final String text) throws Throwable {
protected PsiFile configureByText(final FileType fileType, @NonNls final String text) throws Exception {
return configureByText(fileType, text, null);
}
protected PsiFile configureByText(final FileType fileType, @NonNls final String text, final String _extension) throws Throwable {
protected PsiFile configureByText(final FileType fileType, @NonNls final String text, final String _extension) throws Exception {
final String extension = _extension == null ? fileType.getDefaultExtension():_extension;
File dir = createTempDirectory();
@@ -139,7 +139,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
if (fileTypeManager.getFileTypeByExtension(extension) != fileType) {
new WriteCommandAction(getProject()) {
@Override
protected void run(Result result) throws Throwable {
protected void run(Result result) throws Exception {
fileTypeManager.associateExtension(fileType, extension);
}
}.execute();
@@ -7,6 +7,7 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
import com.intellij.testFramework.PlatformTestCase;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
@@ -51,7 +52,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase {
new CodeCompletionHandlerBase(myType).invokeCompletion(myProject, myEditor, time, false);
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
myItems = lookup == null ? null : lookup.getItems().toArray(new LookupElement[lookup.getItems().size()]);
myPrefix = lookup == null ? "" : lookup.getItems().get(0).getPrefixMatcher().getPrefix();
}
@@ -61,6 +62,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase {
protected void selectItem(LookupElement item, char ch) {
final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(myProject).getActiveLookup();
assert lookup != null;
lookup.setCurrentItem(item);
lookup.finishLookup(ch);
}
@@ -69,19 +71,18 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase {
selectItem(item, (char)0);
}
protected void testByCount(int finalCount, String... values) {
protected void doTestByCount(int finalCount, String... values) {
int index = 0;
if (myItems == null) {
assertEquals(0, finalCount);
return;
}
for (int i = 0; i < myItems.length; i++) {
final LookupElement myItem = myItems[i];
for (int j = 0; j < values.length; j++) {
if (values[j] == null) {
for (final LookupElement myItem : myItems) {
for (String value : values) {
if (value == null) {
assertFalse("Unacceptable value reached", true);
}
if (values[j].equals(myItem.getLookupString())) {
if (value.equals(myItem.getLookupString())) {
index++;
break;
}
@@ -90,6 +91,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase {
assertEquals(Arrays.toString(myItems), finalCount, index);
}
@Nullable
protected LookupImpl getActiveLookup() {
return (LookupImpl)LookupManager.getActiveLookup(myEditor);
}
@@ -209,9 +209,9 @@ public abstract class InspectionTool extends InspectionProfileEntry {
return null;
}
public InspectionNode createToolNode(final InspectionRVContentProvider provider, final InspectionTreeNode parentNode, final boolean showSructure) {
public InspectionNode createToolNode(final InspectionRVContentProvider provider, final InspectionTreeNode parentNode, final boolean showStructure) {
final InspectionNode toolNode = new InspectionNode(this);
provider.appendToolNodeContent(toolNode, parentNode, showSructure);
provider.appendToolNodeContent(toolNode, parentNode, showStructure);
return toolNode;
}
@@ -127,14 +127,10 @@ public class InspectionResultsViewComparator implements Comparator {
}
private static int compareEntities(final RefEntity entity1, final RefEntity entity2) {
if (entity1 != null && entity2 != null) {
final int nameComparison = entity1.getName().compareToIgnoreCase(entity2.getName());
if (nameComparison != 0) {
return nameComparison;
}
}
if (entity1 instanceof RefElement && entity2 instanceof RefElement) {
return PsiUtilBase.compareElementsByPosition(((RefElement)entity1).getElement(), ((RefElement)entity2).getElement());
} else if (entity1 != null && entity2 != null) {
return entity1.getName().compareToIgnoreCase(entity2.getName());
}
return 0;
}
@@ -15,16 +15,11 @@
*/
package com.intellij.ide.navigationToolbar;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.psi.PsiElement;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.Icons;
import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import javax.swing.*;
import java.awt.*;
@@ -32,7 +27,7 @@ import java.awt.*;
/**
* @author Konstantin Bulenkov
*/
class NavBarItem extends SimpleColoredComponent implements DataProvider{
class NavBarItem extends SimpleColoredComponent {
private final String myText;
private final SimpleTextAttributes myAttributes;
private final int myIndex;
@@ -91,10 +86,11 @@ class NavBarItem extends SimpleColoredComponent implements DataProvider{
setIcon(myIcon);
final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
boolean focused = isPopupElement ? myPanel.isNodePopupActive() : focusOwner == myPanel;
final boolean focused = isPopupElement || (focusOwner == myPanel && !myPanel.isNodePopupShowing());
final NavBarModel model = myPanel.getModel();
boolean selected = isPopupElement ? myPanel.isSelectedInPopup(myObject) : model.getSelectedIndex() == myIndex;
final boolean selected = isPopupElement ? myPanel.isSelectedInPopup(myObject)
: model.getSelectedIndex() == myIndex;
setPaintFocusBorder(!focused && selected && !isPopupElement);
setFocusBorderAroundIcon(false);
@@ -136,21 +132,4 @@ class NavBarItem extends SimpleColoredComponent implements DataProvider{
}
};
}
@Override
public Object getData(@NonNls String dataId) {
if (PlatformDataKeys.PROJECT.is(dataId)) {
return myPanel.getProject();
}
if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
return myObject instanceof PsiElement ? myObject : null;
}
if (LangDataKeys.PSI_FILE.is(dataId)) {
return myObject instanceof PsiElement ? ((PsiElement)myObject).getContainingFile() : null;
}
return null;
}
}
@@ -119,7 +119,7 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
public boolean isNodePopupActive() {
return (myNodePopup != null && myNodePopup.isVisible() && myNodePopup.isFocused())
|| (myNodeHint != null && myNodeHint.isVisible() && myNodeHint.getComponent().hasFocus());
|| (myNodeHint != null && myNodeHint.isVisible());
}
public LightweightHint getHint() {
@@ -153,8 +153,7 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
}
public void enter() {
final Object o = myModel.getSelectedValue();
navigateInsideBar(optimizeTarget(o));
navigateInsideBar(myModel.getSelectedValue());
}
public void moveHome() {
@@ -439,7 +438,7 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
public PopupStep onChosen(final Object selectedValue, final boolean finalChoice) {
return doFinalStep(new Runnable() {
public void run() {
navigateInsideBar(optimizeTarget(selectedValue));
navigateInsideBar(selectedValue);
}
});
}
@@ -488,25 +487,26 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
}
void navigateInsideBar(final Object object) {
final Object obj = optimizeTarget(object);
myContextObject = null;
myUpdateQueue.cancelAllUpdates();
myUpdateQueue.queueModelUpdateForObject(object);
myUpdateQueue.queueModelUpdateForObject(obj);
myUpdateQueue.queueRebuildUi();
myUpdateQueue.queueAfterAll(new Runnable() {
public void run() {
int index = myModel.indexOf(object);
int index = myModel.indexOf(obj);
if (index >= 0) {
myModel.setSelectedIndex(index);
}
if (myModel.hasChildren(object)) {
if (myModel.hasChildren(obj)) {
restorePopup();
}
else {
doubleClick(object);
doubleClick(obj);
}
}
}, NavBarUpdateQueue.ID.NAVIGATE_INSIDE);
@@ -16,35 +16,39 @@
package com.intellij.ide.navigationToolbar;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.HintHint;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.LightweightHint;
import com.intellij.ui.ListenerUtil;
import com.intellij.ui.*;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.components.JBList;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.speedSearch.ListWithFilter;
import com.intellij.util.Function;
import com.intellij.util.NotNullFunction;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
/**
* @author Konstantin Bulenkov
*/
public class NavBarPopup extends LightweightHint {
private static final String JBLIST_KEY = "OriginalList";
private final NavBarPanel myPanel;
private int myIndex;
public NavBarPopup(NavBarPanel panel, Object[] siblings, final int selectedIndex) {
super(createPopupContent(panel, siblings, selectedIndex));
super(createPopupContent(panel, siblings));
myPanel = panel;
myIndex = selectedIndex;
setFocusRequestor(getComponent());
setForceShowAsPopup(true);
ListenerUtil.addMouseListener(getComponent(), new MouseAdapter() {
@@ -66,6 +70,11 @@ public class NavBarPopup extends LightweightHint {
IdeFocusManager.getInstance(myPanel.getProject()).requestFocus(myPanel, true);
myPanel.rightClick(selectedIndex);
e.consume();
} else {
final Object value = getList().getSelectedValue();
if (value != null) {
myPanel.navigateInsideBar(value);
}
}
}
});
@@ -87,10 +96,11 @@ public class NavBarPopup extends LightweightHint {
});
} else {
show(myPanel, p.x, p.y, myPanel, new HintHint(myPanel, p));
getList().setSelectedIndex(myIndex);
}
}
private static JBList createPopupContent(final NavBarPanel panel, Object[] siblings, int selectedIndex) {
private static JComponent createPopupContent(final NavBarPanel panel, Object[] siblings) {
final JBList list = new JBList(siblings);
list.setDataProvider(new DataProvider() {
@Override
@@ -105,26 +115,47 @@ public class NavBarPopup extends LightweightHint {
return new NavBarItem(panel, obj);
}
});
list.setBorder(IdeBorderFactory.createEmptyBorder(5,5,5,5));
list.setSelectedIndex(selectedIndex);
list.setBorder(IdeBorderFactory.createEmptyBorder(5, 5, 5, 5));
installMoveAction(list, panel, -1, KeyEvent.VK_LEFT);
installMoveAction(list, panel, 1, KeyEvent.VK_RIGHT);
installEnterAction(list, panel, KeyEvent.VK_ENTER);
return list;
installEscapeAction(list, panel, KeyEvent.VK_ESCAPE);
final JComponent component = ListWithFilter.wrap(list, new MyListWrapper(list), new Function<Object, String>() {
@Override
public String fun(Object o) {
return NavBarPresentation.getPresentableText(o, panel.getWindow());
}
});
component.putClientProperty(JBLIST_KEY, list);
return component;
}
private static void installEnterAction(final JBList list, final NavBarPanel panel, int keyCode) {
final AbstractAction action = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
panel.navigateInsideBar(NavBarPanel.optimizeTarget(list.getSelectedValue()));
panel.navigateInsideBar(list.getSelectedValue());
}
};
list.registerKeyboardAction(action, KeyStroke.getKeyStroke(keyCode, 0), JComponent.WHEN_FOCUSED);
}
private static void installEscapeAction(final JBList list, final NavBarPanel panel, int keyCode) {
final AbstractAction action = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
panel.cancelPopup();
}
};
list.registerKeyboardAction(action, KeyStroke.getKeyStroke(keyCode, 0), JComponent.WHEN_FOCUSED);
}
public Object getSelectedValue() {
return ((JBList)getComponent()).getSelectedValue();
return getList().getSelectedValue();
}
private JBList getList() {
return ((JBList)getComponent().getClientProperty(JBLIST_KEY));
}
private static void installMoveAction(JBList list, final NavBarPanel panel, final int direction, final int keyCode) {
@@ -138,4 +169,60 @@ public class NavBarPopup extends LightweightHint {
};
list.registerKeyboardAction(action, KeyStroke.getKeyStroke(keyCode, 0), JComponent.WHEN_FOCUSED);
}
static class MyListWrapper extends JBScrollPane implements DataProvider {
private static final int MAX_SIZE = 20;
private final JList myList;
public MyListWrapper(final JList list) {
super(list);
list.addMouseMotionListener(new MouseMotionAdapter() {
boolean myIsEngaged = false;
public void mouseMoved(MouseEvent e) {
if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) {
final Point point = e.getPoint();
final int index = list.locationToIndex(point);
list.setSelectedIndex(index);
} else {
myIsEngaged = true;
}
}
});
ListScrollingUtil.installActions(list);
final int modelSize = list.getModel().getSize();
setBorder(BorderFactory.createEmptyBorder());
if (modelSize > 0 && modelSize <= MAX_SIZE) {
list.setVisibleRowCount(0);
getViewport().setPreferredSize(list.getPreferredSize());
} else {
list.setVisibleRowCount(MAX_SIZE);
}
myList = list;
}
@Nullable
public Object getData(@NonNls String dataId) {
if (PlatformDataKeys.SELECTED_ITEM.is(dataId)){
return myList.getSelectedValue();
}
return null;
}
public void setBorder(Border border) {
if (myList != null){
myList.setBorder(border);
}
}
public void requestFocus() {
myList.requestFocus();
}
public synchronized void addMouseListener(MouseListener l) {
myList.addMouseListener(l);
}
}
}
@@ -192,7 +192,7 @@ public class PopupChooserBuilder {
(list != null ? list : myChooserComponent).addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (UIUtil.isActionClick(e) && !isSelectionButtonDown(e) && !e.isConsumed()) {
if (UIUtil.isActionClick(e) && !UIUtil.isSelectionButtonDown(e) && !e.isConsumed()) {
closePopup(true, e, true);
}
}
@@ -385,10 +385,6 @@ public class PopupChooserBuilder {
return this;
}
private static boolean isSelectionButtonDown(MouseEvent e) {
return e.isShiftDown() || e.isControlDown() || e.isMetaDown();
}
public PopupChooserBuilder setSettingButton(Component abutton) {
mySettingsButtons = abutton;
return this;
@@ -409,7 +405,7 @@ public class PopupChooserBuilder {
list.addMouseMotionListener(new MouseMotionAdapter() {
boolean myIsEngaged = false;
public void mouseMoved(MouseEvent e) {
if (myIsEngaged && !isSelectionButtonDown(e)) {
if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) {
Point point = e.getPoint();
int index = list.locationToIndex(point);
list.setSelectedIndex(index);
@@ -16,9 +16,6 @@
package com.intellij.ui;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
@@ -44,6 +41,10 @@ public class ListScrollingUtil {
protected static final String SELECT_LAST_ROW_ACTION_ID = "selectLastRow";
@NonNls
protected static final String SELECT_FIRST_ROW_ACTION_ID = "selectFirstRow";
@NonNls
protected static final String MOVE_HOME_ID = "MOVE_HOME";
@NonNls
protected static final String MOVE_END_ID = "MOVE_END";
public static final int ROW_PADDING = 2;
@@ -267,17 +268,18 @@ public class ListScrollingUtil {
moveHome(list);
}
});
new AnAction() {
public void actionPerformed(AnActionEvent e) {
actionMap.put(MOVE_HOME_ID, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
moveHome(list);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), list);
new AnAction() {
public void actionPerformed(AnActionEvent e) {
});
actionMap.put(MOVE_END_ID, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
moveEnd(list);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)), list);
});
InputMap map = list.getInputMap(JComponent.WHEN_FOCUSED);
UIUtil.maybeInstall(map, SCROLLUP_ACTION_ID, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0));
@@ -286,6 +288,7 @@ public class ListScrollingUtil {
UIUtil.maybeInstall(map, SELECT_NEXT_ROW_ACTION_ID, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0));
UIUtil.maybeInstall(map, SELECT_FIRST_ROW_ACTION_ID, KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0));
UIUtil.maybeInstall(map, SELECT_LAST_ROW_ACTION_ID, KeyStroke.getKeyStroke(KeyEvent.VK_END, 0));
UIUtil.maybeInstall(map, MOVE_HOME_ID, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
UIUtil.maybeInstall(map, MOVE_END_ID, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
}
}
@@ -363,7 +363,6 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar {
for (String opt : options) {
if (isStopWord(opt)) continue;
final String processed = PorterStemmerUtil.stem(opt);
assert processed != null;
if (isStopWord(processed)) continue;
result.add(opt);
}
@@ -377,7 +376,7 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar {
for (String opt : options) {
if (isStopWord(opt)) continue;
opt = PorterStemmerUtil.stem(opt);
assert opt != null;
if (opt == null) continue;
result.add(opt);
}
return result;
@@ -316,14 +316,11 @@ public class SelectionModelImpl implements SelectionModel, PrioritizedDocumentLi
}
FoldRegion endFold = foldingModel.getCollapsedRegionAtOffset(endOffset);
if (endFold != null) {
VisualPosition visualFoldStart = myEditor.offsetToVisualPosition(endFold.getStartOffset());
if (endFold != null && endFold.getStartOffset() < endOffset) {
// All visual positions that lay at collapsed fold region placeholder are mapped to the same offset. Hence, there are
// at least two distinct situations - selection end is located inside collapsed fold region placeholder and just before it.
// We want to expand selection to the fold region end at the former case and keep selection as-is at the latest one.
if (visualFoldStart.column < endPosition.column) {
endOffset = endFold.getEndOffset();
}
endOffset = endFold.getEndOffset();
}
int oldSelectionStart;
@@ -1749,6 +1749,10 @@ public class UIUtil {
}
}
public static boolean isSelectionButtonDown(MouseEvent e) {
return e.isShiftDown() || e.isControlDown() || e.isMetaDown();
}
public static void setComboBoxEditorBounds(int x, int y, int width, int height, JComponent editor) {
if(SystemInfo.isMac && isUnderAquaLookAndFeel()) {
// fix for too wide combobox editor, see AquaComboBoxUI.layoutContainer:
@@ -73,6 +73,8 @@ filename
fileset
filesets
filesystem
finalizer
finalizers
foreach
formatter
freelist
@@ -194,18 +194,42 @@ public class HtmlUnknownTagInspection extends HtmlLocalInspectionTool {
return myCustomValuesEnabled;
}
private static boolean isInRightPlace(@NotNull XmlTag tag, @NotNull XmlElementDescriptor tagDescriptor) {
XmlTag parentTag = tag.getParentTag();
if (parentTag == null) {
return true;
}
XmlElementDescriptor parentDescriptor = parentTag.getDescriptor();
if (parentDescriptor == null) {
return true;
}
XmlElementDescriptor[] suitableChildDescriptors = parentDescriptor.getElementsDescriptors(parentTag);
for (XmlElementDescriptor descriptor : suitableChildDescriptors) {
if (descriptor.getName().equalsIgnoreCase(tagDescriptor.getName())) {
return true;
}
}
return false;
}
protected void checkTag(@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (XmlHighlightVisitor.skipValidation(tag)) {
return;
}
final XmlElementDescriptor descriptor = tag.getDescriptor();
if (tag instanceof HtmlTag && (descriptor instanceof AnyXmlElementDescriptor || descriptor == null)) {
if (tag instanceof HtmlTag &&
(descriptor == null || descriptor instanceof AnyXmlElementDescriptor || !isInRightPlace(tag, descriptor))) {
final String name = tag.getName();
if (!isCustomValuesEnabled() || !isCustomValue(name)) {
final AddCustomTagOrAttributeIntentionAction action =
new AddCustomTagOrAttributeIntentionAction(getShortName(), name, XmlEntitiesInspection.UNKNOWN_TAG);
final String message = XmlErrorMessages.message("unknown.html.tag", name);
// todo: support "element is not allowed" message for html5
// some tags in html5 cannot be found in xhtml5.xsd if they are located in incorrect context, so they get any-element descriptor (ex. "canvas: tag)
final String message = descriptor == null || descriptor instanceof AnyXmlElementDescriptor
? XmlErrorMessages.message("unknown.html.tag", name)
: XmlErrorMessages.message("element.is.not.allowed.here", name);
final PsiElement startTagName = XmlTagUtil.getStartTagNameElement(tag);
assert startTagName != null;
@@ -275,7 +275,7 @@ public class ColorSampleLookupValue implements LookupValueWithUIHint, DeferredUs
}
public String getPresentation() {
return myName;
return myName != null ? myName : myValue;
}
public String getValue() {
@@ -363,7 +363,7 @@ public class ColorSampleLookupValue implements LookupValueWithUIHint, DeferredUs
}
public String getTypeHint() {
return myValue.charAt(0) == '#' ? myValue : null;
return myName != null && myValue.charAt(0) == '#' ? myValue : null;
}
@SuppressWarnings({"HardCodedStringLiteral"})
@@ -380,7 +380,7 @@ public class ColorSampleLookupValue implements LookupValueWithUIHint, DeferredUs
}
public int getPriority() {
return Character.isLowerCase(myName.charAt(0)) ? HIGHER : NORMAL;
return myName == null || Character.isLowerCase(myName.charAt(0)) ? HIGHER : NORMAL;
}
public static String getHexCodeForColorName(String colorName) {