Search in sources :

Example 36 with PsiField

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());
}
Also used : PsiField(com.intellij.psi.PsiField) UnusedDeclarationInspection(com.intellij.codeInspection.deadCode.UnusedDeclarationInspection) PsiElement(com.intellij.psi.PsiElement)

Example 37 with PsiField

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiClassType(com.intellij.psi.PsiClassType) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) PsiJavaFile(com.intellij.psi.PsiJavaFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiJavaFile(com.intellij.psi.PsiJavaFile) File(java.io.File)

Example 38 with PsiField

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;
}
Also used : Project(com.intellij.openapi.project.Project) FieldSmartPointerNode(com.intellij.ide.favoritesTreeView.smartPointerPsiNodes.FieldSmartPointerNode) PsiField(com.intellij.psi.PsiField) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiElement(com.intellij.psi.PsiElement)

Example 39 with PsiField

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;
}
Also used : Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass)

Example 40 with PsiField

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;
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) PsiField(com.intellij.psi.PsiField) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiField (com.intellij.psi.PsiField)86 PsiClass (com.intellij.psi.PsiClass)34 PsiElement (com.intellij.psi.PsiElement)27 ArrayList (java.util.ArrayList)13 PsiMethod (com.intellij.psi.PsiMethod)11 NotNull (org.jetbrains.annotations.NotNull)11 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)8 PsiReference (com.intellij.psi.PsiReference)7 PsiType (com.intellij.psi.PsiType)7 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 Nullable (org.jetbrains.annotations.Nullable)6 Nullable (com.android.annotations.Nullable)5 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiExpression (com.intellij.psi.PsiExpression)5 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 ResourceType (com.android.resources.ResourceType)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)4 PsiFile (com.intellij.psi.PsiFile)4