IDEA-147762 code completion doesn't show JPA '@Id' import

This commit is contained in:
peter
2015-11-11 17:31:36 +01:00
parent 4ae9f8ec57
commit 3dcb251345
3 changed files with 72 additions and 6 deletions
+1
View File
@@ -12,5 +12,6 @@
<orderEntry type="module" module-name="core-impl" exported="" />
<orderEntry type="module" module-name="resources-en" />
<orderEntry type="library" name="asm5" level="project" />
<orderEntry type="library" name="Guava" level="project" />
</component>
</module>
@@ -15,11 +15,13 @@
*/
package com.intellij.psi.impl.source.tree.java;
import com.google.common.annotations.VisibleForTesting;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.LogUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.TextRange;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -47,6 +49,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.*;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -486,17 +489,37 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
PsiScopesUtil.resolveAndWalk(filterProcessor, this, null, true);
}
public static boolean seemsScrambled(PsiClass aClass) {
if (!(aClass instanceof PsiCompiledElement)) {
return false;
}
public static boolean seemsScrambled(@Nullable PsiClass aClass) {
return aClass instanceof PsiCompiledElement && seemsScrambledByStructure(aClass);
}
@VisibleForTesting
public static boolean seemsScrambledByStructure(@NotNull PsiClass aClass) {
PsiClass containingClass = aClass.getContainingClass();
if (containingClass != null && !seemsScrambled(containingClass)) {
if (containingClass != null && !seemsScrambledByStructure(containingClass)) {
return false;
}
final String name = aClass.getName();
if (seemsScrambled(aClass.getName())) {
List<PsiMethod> methods = ContainerUtil.filter(aClass.getMethods(), new Condition<PsiMethod>() {
@Override
public boolean value(PsiMethod method) {
return !method.hasModifierProperty(PsiModifier.PRIVATE);
}
});
return !methods.isEmpty() && ContainerUtil.and(methods, new Condition<PsiMethod>() {
@Override
public boolean value(PsiMethod method) {
return seemsScrambled(method.getName());
}
});
}
return false;
}
private static boolean seemsScrambled(String name) {
return name != null && !name.isEmpty() && name.length() <= 2;
}
@@ -0,0 +1,42 @@
/*
* Copyright 2000-2015 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.testFramework.fixtures.LightCodeInsightFixtureTestCase
import static com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl.seemsScrambledByStructure
/**
* @author peter
*/
class SeemsScrambledTest extends LightCodeInsightFixtureTestCase {
public void "test Id annotation"() {
assert !seemsScrambledByStructure(myFixture.addClass('public @interface Id {}'))
}
public void "test inner enum"() {
assert !seemsScrambledByStructure(myFixture.addClass('public class Foo { enum v1 {} }').innerClasses[0])
}
public void "test scrambled"() {
assert seemsScrambledByStructure(myFixture.addClass('public class a { void b() {} }'))
}
public void "test has non-scrambled method"() {
assert !seemsScrambledByStructure(myFixture.addClass('public class a { void doSomething() {} }'))
}
}