Search in sources :

Example 26 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 27 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class EncapsulateFieldsTest method testMoveJavadocToGetter.

public void testMoveJavadocToGetter() throws Exception {
    doTest((rootDir, rootAfter) -> {
        final PsiClass aClass = myJavaFacade.findClass("A", GlobalSearchScope.projectScope(myProject));
        assertNotNull("Tested class not found", aClass);
        final PsiField field = aClass.findFieldByName("i", false);
        assertNotNull(field);
        doTest(aClass, null, true, true, field);
    });
}
Also used : PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass)

Example 28 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class ExtractClassTest method testPublicVisibility.

public void testPublicVisibility() throws Exception {
    doTest((rootDir, rootAfter) -> {
        PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
        assertNotNull("Class Test not found", aClass);
        final ArrayList<PsiMethod> methods = new ArrayList<>();
        methods.add(aClass.findMethodsByName("foos", false)[0]);
        final ArrayList<PsiField> fields = new ArrayList<>();
        fields.add(aClass.findFieldByName("myT", false));
        final ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, methods, new ArrayList<>(), "", null, "Extracted", PsiModifier.PUBLIC, false, Collections.<MemberInfo>emptyList());
        processor.run();
        LocalFileSystem.getInstance().refresh(false);
        FileDocumentManager.getInstance().saveAllDocuments();
    });
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) ExtractClassProcessor(com.intellij.refactoring.extractclass.ExtractClassProcessor)

Example 29 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class ExtractClassTest method doTestField.

private void doTestField(final String conflicts, final boolean generateGettersSetters) throws Exception {
    doTest((rootDir, rootAfter) -> {
        PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
        assertNotNull("Class Test not found", aClass);
        final ArrayList<PsiMethod> methods = new ArrayList<>();
        final ArrayList<PsiField> fields = new ArrayList<>();
        fields.add(aClass.findFieldByName("myT", false));
        doTest(aClass, methods, fields, conflicts, generateGettersSetters);
    });
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList)

Example 30 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class ExtractClassTest method testPublicFieldDelegation.

public void testPublicFieldDelegation() throws Exception {
    doTest((rootDir, rootAfter) -> {
        PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
        assertNotNull("Class Test not found", aClass);
        final ArrayList<PsiField> fields = new ArrayList<>();
        fields.add(aClass.findFieldByName("myT", false));
        ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, new ArrayList<>(), new ArrayList<>(), "", "Extracted");
        processor.run();
        LocalFileSystem.getInstance().refresh(false);
        FileDocumentManager.getInstance().saveAllDocuments();
    });
}
Also used : PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) ExtractClassProcessor(com.intellij.refactoring.extractclass.ExtractClassProcessor)

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