[ann] Exceptions with interfaces in multi-catch: completion fix

This commit is contained in:
Roman Shevchenko
2011-05-18 17:17:22 +04:00
parent 932a6ce982
commit 6c93e44f46
5 changed files with 197 additions and 200 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -117,11 +117,19 @@ public class PsiScopesUtil {
substitutor = substitutor.put(arrayTypeParameters[0], ((PsiArrayType)type).getComponentType());
}
arrayClass.processDeclarations(processor, ResolveState.initial().put(PsiSubstitutor.KEY, substitutor), arrayClass, place);
} else if (type instanceof PsiIntersectionType) {
}
else if (type instanceof PsiIntersectionType) {
for (PsiType psiType : ((PsiIntersectionType)type).getConjuncts()) {
processTypeDeclarations(psiType, place, processor);
}
} else {
}
else if (type instanceof PsiDisjunctionType) {
final PsiType lub = ((PsiDisjunctionType)type).getLeastUpperBound();
if (lub != null) {
processTypeDeclarations(lub, place, processor);
}
}
else {
final JavaResolveResult result = PsiUtil.resolveGenericsClassInType(type);
final PsiClass clazz = (PsiClass)result.getElement();
if (clazz != null) {
@@ -0,0 +1,33 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* 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.
*/
class C {
static class E extends Exception { }
interface I { void i(); }
static class E1 extends E implements I { public void i() { } }
static class E2 extends E implements I { public void i() { } }
void m(boolean f) {
try {
if (f)
throw new E1();
else
throw new E2();
}
catch (E1 | E2 e) {
e.<caret>
}
}
}
@@ -0,0 +1,110 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* 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 com.intellij.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
/**
* @author ik
* Date: 21.01.2003
*/
public class DotCompletionTest extends LightCompletionTestCase {
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath() + "/codeInsight/completion/dot/";
}
public void testInstance() throws Exception {
configureByFile("Dot1.java");
assertEquals("", myPrefix);
assertContainsItems("a", "foo");
}
public void testClass() throws Exception {
configureByFile("Dot2.java");
assertEquals("", myPrefix);
assertContainsItems("a", "foo");
}
public void testAnonymous() throws Exception {
configureByFile("Dot3.java");
assertEquals("", myPrefix);
assertContainsItems("a", "foo");
}
public void testShowStatic() throws Exception {
CodeInsightSettings settings = CodeInsightSettings.getInstance();
boolean oldSetting = settings.SHOW_STATIC_AFTER_INSTANCE;
settings.SHOW_STATIC_AFTER_INSTANCE = false;
try {
configureByFile("Dot4.java");
assertEquals("", myPrefix);
assertContainsItems("foo");
assertNotContainItems("a");
}
finally {
settings.SHOW_STATIC_AFTER_INSTANCE = oldSetting;
}
}
public void testImports() throws Exception {
configureByFile("Dot5.java");
assertContainsItems("util", "lang");
}
public void testArrayElement() throws Exception {
configureByFile("Dot6.java");
assertContainsItems("toString", "substring");
}
public void testArray() throws Exception {
configureByFile("Dot7.java");
assertContainsItems("clone", "length");
}
public void testDuplicatesFromInheritance() throws Exception {
configureByFile("Dot8.java");
assertContainsItems("toString");
}
public void testConstructorExclusion() throws Exception {
configureByFile("Dot9.java");
assertContainsItems("foo");
assertNotContainItems("A");
}
public void testPrimitiveArray() throws Exception {
configureByFile("Dot10.java");
assertContainsItems("clone", "length");
}
public void testThisExpression() throws Exception {
configureByFile("Dot11.java");
assertContainsItems("foo", "foo1");
}
public void testSuperExpression() throws Exception {
configureByFile("Dot12.java");
assertContainsItems("foo");
assertNotContainItems("foo1");
}
public void testMultiCatch() throws Exception {
configureByFile("MultiCatch.java");
assertContainsItems("i", "addSuppressed", "getMessage", "printStackTrace");
}
}
@@ -1,197 +0,0 @@
package com.intellij.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.lookup.LookupElement;
/**
* Created by IntelliJ IDEA.
* User: ik
* Date: 21.01.2003
* Time: 16:31:32
* To change this template use Options | File Templates.
*/
public class DotTest extends LightCompletionTestCase {
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testInstance() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot1.java");
assertEquals("", myPrefix);
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("a".equals(myItem.getLookupString()) || "foo".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(2, index);
}
public void testClass() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot2.java");
assertEquals("", myPrefix);
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("a".equals(myItem.getLookupString()) || "foo".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(2, index);
}
public void testAnonymous() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot3.java");
assertEquals("", myPrefix);
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("a".equals(myItem.getLookupString()) || "foo".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(2, index);
}
public void testShowStatic() throws Exception {
CodeInsightSettings settings = CodeInsightSettings.getInstance();
boolean oldSetting = settings.SHOW_STATIC_AFTER_INSTANCE;
settings.SHOW_STATIC_AFTER_INSTANCE = false;
configureByFile("/codeInsight/completion/dot/Dot4.java");
settings.SHOW_STATIC_AFTER_INSTANCE = oldSetting;
assertEquals("", myPrefix);
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("a".equals(myItem.getLookupString()) || "foo".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(1, index);
}
public void testImports() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot5.java");
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("util".equals(myItem.getLookupString()) || "lang".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(2, index);
}
public void testArrayElement() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot6.java");
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("toString".equals(myItem.getLookupString()) || "substring".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(3, index);
}
public void testArray() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot7.java");
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("length".equals(myItem.getLookupString()) || "clone".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(2, index);
}
public void testDuplicatesFromInherance() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot8.java");
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("toString".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(1, index);
}
public void testConstructorExclusion() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot9.java");
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("A".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(0, index);
}
public void testPrimitiveArray() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot10.java");
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("clone".equals(myItem.getLookupString()) || "length".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(2, index);
}
public void testThisExpression() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot11.java");
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("foo1".equals(myItem.getLookupString()) || "foo".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(2, index);
}
public void testSuperExpression() throws Exception {
configureByFile("/codeInsight/completion/dot/Dot12.java");
assertNotNull(myItems);
int index = 0;
for (final LookupElement myItem : myItems) {
if ("foo1".equals(myItem.getLookupString()) || "foo".equals(myItem.getLookupString())) {
index++;
}
}
assertEquals(1, index);
}
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* 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 com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
@@ -6,9 +21,11 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.NonNls;
import java.util.Arrays;
import java.util.Set;
/**
* @author mike
@@ -99,6 +116,32 @@ public abstract class LightCompletionTestCase extends LightCodeInsightTestCase {
}
}
protected void assertContainsItems(final String... expected) {
final Set<String> actual = getLookupStrings();
for (String s : expected) {
assertTrue("Expected '" + s + "' not found in " + actual,
actual.contains(s));
}
}
protected void assertNotContainItems(final String... unexpected) {
final Set<String> actual = getLookupStrings();
for (String s : unexpected) {
assertFalse("Unexpected '" + s + "' presented in " + actual,
actual.contains(s));
}
}
private Set<String> getLookupStrings() {
final Set<String> actual = new HashSet<String>();
if (myItems != null) {
for (LookupElement lookupElement : myItems) {
actual.add(lookupElement.getLookupString());
}
}
return actual;
}
protected static LookupImpl getLookup() {
return (LookupImpl)LookupManager.getActiveLookup(myEditor);
}