Search in sources :

Example 21 with PsiField

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

the class PushDownMultifileTest method testUsagesInXml.

public void testUsagesInXml() throws Exception {
    try {
        doTest((rootDir, rootAfter) -> {
            final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
            assertTrue("Source class not found", srcClass != null);
            final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
            assertTrue("Target class not found", targetClass != null);
            final PsiField[] fields = srcClass.getFields();
            assertTrue("No methods found", fields.length > 0);
            final MemberInfo memberInfo = new MemberInfo(fields[0]);
            memberInfo.setChecked(true);
            new PushDownProcessor<>(srcClass, Collections.singletonList(memberInfo), new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
        //LocalFileSystem.getInstance().refresh(false);
        //FileDocumentManager.getInstance().saveAllDocuments();
        });
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
        assertEquals(e.getMessage(), "Class <b><code>b.B</code></b> is package-private and will not be accessible from file <b><code>A.form</code></b>.");
        return;
    }
    fail("Conflict was not detected");
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 22 with PsiField

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

the class FieldDependenciesManager method getRoots.

@NotNull
public List<ArrangementEntryDependencyInfo> getRoots() {
    List<ArrangementEntryDependencyInfo> list = ContainerUtil.newArrayList();
    for (Map.Entry<PsiField, Set<PsiField>> entry : myFieldDependencies.entrySet()) {
        ArrangementEntryDependencyInfo currentInfo = myFieldInfosMap.get(entry.getKey());
        for (PsiField usedInInitialization : entry.getValue()) {
            ArrangementEntryDependencyInfo fieldInfo = myFieldInfosMap.get(usedInInitialization);
            if (fieldInfo != null)
                currentInfo.addDependentEntryInfo(fieldInfo);
        }
        list.add(currentInfo);
    }
    return list;
}
Also used : Set(java.util.Set) PsiField(com.intellij.psi.PsiField) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with PsiField

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

the class MakeMethodStaticRefactoringImpl method getFields.

public List<PsiField> getFields() {
    final Settings settings = myProcessor.getSettings();
    List<PsiField> result = new ArrayList<>();
    final List<Settings.FieldParameter> parameterOrderList = settings.getParameterOrderList();
    for (final Settings.FieldParameter fieldParameter : parameterOrderList) {
        result.add(fieldParameter.field);
    }
    return result;
}
Also used : PsiField(com.intellij.psi.PsiField) ArrayList(java.util.ArrayList) Settings(com.intellij.refactoring.makeStatic.Settings)

Example 24 with PsiField

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

the class RemoveMiddlemanHandler method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (!(element instanceof PsiField)) {
        CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.field.to.be.refactored"), REFACTORING_NAME, getHelpID());
        return;
    }
    invoke((PsiField) element, editor);
}
Also used : ScrollingModel(com.intellij.openapi.editor.ScrollingModel) PsiField(com.intellij.psi.PsiField) PsiElement(com.intellij.psi.PsiElement)

Example 25 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)

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