From df9e776747de458d9ceb069ad6d9ff8e357df84b Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 25 Jan 2011 19:26:00 +0100 Subject: [PATCH] don't let the following nasty angle braces spoil the qualifier casting --- .../completion/JavaCompletionContributor.java | 6 +++ .../normal/QualifierCastingBeforeLt.java | 37 +++++++++++++++++++ .../QualifierCastingBeforeLt_after.java | 37 +++++++++++++++++++ .../completion/NormalCompletionTest.groovy | 1 + 4 files changed, 81 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/QualifierCastingBeforeLt.java create mode 100644 java/java-tests/testData/codeInsight/completion/normal/QualifierCastingBeforeLt_after.java diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java index bdc0e27dd101..0dd46fd058a7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -509,6 +509,12 @@ public class JavaCompletionContributor extends CompletionContributor { return; } + final PsiJavaCodeReferenceElement ref = PsiTreeUtil.findElementOfClassAtOffset(file, context.getStartOffset(), PsiJavaCodeReferenceElement.class, false); + if (ref != null && !(ref instanceof PsiReferenceExpression)) { + context.setDummyIdentifier(CompletionInitializationContext.DUMMY_IDENTIFIER.trim() + ";"); + return; + } + final PsiElement element = file.findElementAt(context.getStartOffset()); if (psiElement().inside(PsiAnnotation.class).accepts(element)) { diff --git a/java/java-tests/testData/codeInsight/completion/normal/QualifierCastingBeforeLt.java b/java/java-tests/testData/codeInsight/completion/normal/QualifierCastingBeforeLt.java new file mode 100644 index 000000000000..d784b3457ee3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/QualifierCastingBeforeLt.java @@ -0,0 +1,37 @@ +/* + * 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. + */ +import javax.swing.*; +import java.awt.*; + +public class Bar { + + static class CellWrapper { + public boolean isSeparator() { + return true; + } + } + + static class MyRenderer extends DefaultListCellRenderer { + public Component getListCellRendererComponent(JList list, Object value, int index, boolean s, boolean focus) { + assert value instanceof CellWrapper; + + value.is + + } + } + +} + diff --git a/java/java-tests/testData/codeInsight/completion/normal/QualifierCastingBeforeLt_after.java b/java/java-tests/testData/codeInsight/completion/normal/QualifierCastingBeforeLt_after.java new file mode 100644 index 000000000000..9095c2be7d6b --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/QualifierCastingBeforeLt_after.java @@ -0,0 +1,37 @@ +/* + * 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. + */ +import javax.swing.*; +import java.awt.*; + +public class Bar { + + static class CellWrapper { + public boolean isSeparator() { + return true; + } + } + + static class MyRenderer extends DefaultListCellRenderer { + public Component getListCellRendererComponent(JList list, Object value, int index, boolean s, boolean focus) { + assert value instanceof CellWrapper; + + ((CellWrapper) value).isSeparator() + + } + } + +} + diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 929029d0b467..0b9e799a9157 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -788,6 +788,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase { public void testCastTooComplexInstanceofedQualifier() throws Throwable { doAntiTest(); } public void testDontCastInstanceofedQualifier() throws Throwable { doTest(); } public void testQualifierCastingWithUnknownAssignments() throws Throwable { doTest(); } + public void testQualifierCastingBeforeLt() throws Throwable { doTest(); } public void testWildcardsInLookup() throws Exception { configure()