use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class LightUnusedHighlightingFixtureTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.enableInspections(new UnusedDeclarationInspection(true));
PlatformTestUtil.registerExtension(ImplicitUsageProvider.EP_NAME, new ImplicitUsageProvider() {
@Override
public boolean isImplicitUsage(PsiElement element) {
return isImplicitWrite(element);
}
@Override
public boolean isImplicitRead(PsiElement element) {
return false;
}
@Override
public boolean isImplicitWrite(PsiElement element) {
return element instanceof PsiField && "implicitWrite".equals(((PsiNamedElement) element).getName());
}
}, getTestRootDisposable());
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class AdvHighlightingTest method testSameClassesInSourceAndLib.
public void testSameClassesInSourceAndLib() throws Exception {
String path = PathManagerEx.getTestDataPath() + BASE_PATH + "/" + getTestName(true);
VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
assert root != null : path;
loadAllModulesUnder(root);
configureByExistingFile(root.findFileByRelativePath("src/ppp/SomeClass.java"));
PsiField field = ((PsiJavaFile) myFile).getClasses()[0].findFieldByName("f", false);
assert field != null;
PsiClass aClass = ((PsiClassType) field.getType()).resolve();
assert aClass != null;
assertEquals("ppp.BadClass", aClass.getQualifiedName());
//lies in source
VirtualFile vFile1 = myFile.getVirtualFile();
VirtualFile vFile2 = aClass.getContainingFile().getVirtualFile();
assert vFile1 != null;
assert vFile2 != null;
assertEquals(vFile1.getParent(), vFile2.getParent());
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class PsiFieldFavoriteNodeProvider method getFavoriteNodes.
@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null)
return null;
PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(context);
if (elements == null) {
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
if (element != null) {
elements = new PsiElement[] { element };
}
}
if (elements != null) {
final Collection<AbstractTreeNode> result = new ArrayList<>();
for (PsiElement element : elements) {
if (element instanceof PsiField) {
result.add(new FieldSmartPointerNode(project, element, viewSettings));
}
}
return result.isEmpty() ? null : result;
}
return null;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class KnownElementWeigher method weigh.
@Override
public Comparable weigh(@NotNull final PsiElement element, @NotNull final ProximityLocation location) {
Project project = location.getProject();
if (project == null)
return 0;
Comparable tests = getTestFrameworkWeight(element, location, project);
if (tests != null)
return tests;
if (!SdkOrLibraryWeigher.isJdkElement(element, project)) {
return 0;
}
if (element instanceof PsiClass) {
return getJdkClassProximity((PsiClass) element);
}
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) element;
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null) {
String methodName = method.getName();
if ("finalize".equals(methodName) || "registerNatives".equals(methodName) || methodName.startsWith("wait") || methodName.startsWith("notify")) {
if (JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
return -1;
}
}
if (isGetClass(method)) {
return -1;
}
if ("subSequence".equals(methodName)) {
if (JAVA_LANG_STRING.equals(containingClass.getQualifiedName())) {
return -1;
}
}
if (JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
return 0;
}
return getJdkClassProximity(method.getContainingClass());
}
}
if (element instanceof PsiField) {
return getJdkClassProximity(((PsiField) element).getContainingClass());
}
return 0;
}
use of com.intellij.psi.PsiField in project intellij-community by JetBrains.
the class CompositeShortNamesCache method getFieldsByName.
@Override
@NotNull
public PsiField[] getFieldsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
Merger<PsiField> merger = null;
for (PsiShortNamesCache cache : myCaches) {
PsiField[] classes = cache.getFieldsByName(name, scope);
if (classes.length != 0) {
if (merger == null)
merger = new Merger<>();
merger.add(classes);
}
}
PsiField[] result = merger == null ? null : merger.getResult();
return result == null ? PsiField.EMPTY_ARRAY : result;
}
Aggregations