Search in sources :

Example 76 with PsiField

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

the class FieldElement method copyElement.

@Override
public ASTNode copyElement() {
    final CharTable table = SharedImplUtil.findCharTableByTree(this);
    final PsiClass psiClass = ((PsiField) getPsi()).getContainingClass();
    return psiClass != null ? ChangeUtil.copyElement(this, psiClass.getTypeParameterList(), table) : super.copyElement();
}
Also used : PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) CharTable(com.intellij.util.CharTable)

Example 77 with PsiField

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

the class FieldSelectioner method select.

@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
    final PsiField field = (PsiField) e;
    final TextRange range = field.getTextRange();
    final PsiIdentifier first = field.getNameIdentifier();
    final TextRange firstRange = first.getTextRange();
    final PsiElement last = field.getInitializer();
    final int end = last == null ? firstRange.getEndOffset() : last.getTextRange().getEndOffset();
    PsiDocComment comment = field.getDocComment();
    if (comment != null) {
        TextRange commentTextRange = comment.getTextRange();
        addRangeElem(result, editorText, comment, commentTextRange.getEndOffset());
    }
    addRangeElem(result, editorText, first, end);
    //addRangeElem (result, editorText, field, textLength, field.getTypeElement(), end);
    addRangeElem(result, editorText, field.getModifierList(), range.getEndOffset());
    //addRangeElem (result, editorText, field, textLength, field.getDocComment(), end);
    result.addAll(expandToWholeLine(editorText, range));
    return result;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiField(com.intellij.psi.PsiField) PsiIdentifier(com.intellij.psi.PsiIdentifier) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Example 78 with PsiField

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

the class GenerateEqualsTestCase method performTest.

private static void performTest(Function<PsiField[], PsiField[]> equals, Function<PsiField[], PsiField[]> hashCode, Function<PsiField[], PsiField[]> nonNull, boolean insertOverride, boolean useAccessors) {
    CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
    settings.GENERATE_FINAL_LOCALS = true;
    settings.INSERT_OVERRIDE_ANNOTATION = insertOverride;
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
    try {
        PsiElement element = getFile().findElementAt(getEditor().getCaretModel().getOffset());
        if (element == null)
            return;
        PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
        if (aClass == null)
            return;
        PsiField[] fields = aClass.getFields();
        new GenerateEqualsHelper(getProject(), aClass, equals.fun(fields), hashCode.fun(fields), nonNull.fun(fields), false, useAccessors).invoke();
        FileDocumentManager.getInstance().saveAllDocuments();
    } finally {
        CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
    }
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) PsiField(com.intellij.psi.PsiField) GenerateEqualsHelper(com.intellij.codeInsight.generation.GenerateEqualsHelper) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement)

Example 79 with PsiField

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

the class WrapReturnValueTest method doTest.

private void doTest(final boolean existing, String exceptionMessage, final boolean createInnerClass) {
    try {
        doTest((rootDir, rootAfter) -> {
            PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
            assertNotNull("Class Test not found", aClass);
            PsiMethod method = aClass.findMethodsByName("foo", false)[0];
            String wrapperClassName = "Wrapper";
            PsiClass wrapperClass = myJavaFacade.findClass(wrapperClassName, GlobalSearchScope.projectScope(getProject()));
            assertTrue(!existing || wrapperClass != null);
            PsiField delegateField = existing ? wrapperClass.findFieldByName("myField", false) : null;
            new WrapReturnValueProcessor(wrapperClassName, "", null, method, existing, createInnerClass, delegateField).run();
        });
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
        if (exceptionMessage != null) {
            assertEquals(exceptionMessage, e.getMessage());
            return;
        }
        throw e;
    }
    if (exceptionMessage != null) {
        fail("Conflict was not found");
    }
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) WrapReturnValueProcessor(com.intellij.refactoring.wrapreturnvalue.WrapReturnValueProcessor)

Example 80 with PsiField

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

the class RemoveMiddleManTest method doTest.

private void doTest(final String conflict) throws Exception {
    doTest((rootDir, rootAfter) -> {
        PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
        if (aClass == null)
            aClass = myJavaFacade.findClass("p.Test", GlobalSearchScope.allScope(getProject()));
        assertNotNull("Class Test not found", aClass);
        final PsiField field = aClass.findFieldByName("myField", false);
        final Set<PsiMethod> methods = DelegationUtils.getDelegatingMethodsForField(field);
        List<MemberInfo> infos = new ArrayList<>();
        for (PsiMethod method : methods) {
            final MemberInfo info = new MemberInfo(method);
            info.setChecked(true);
            info.setToAbstract(true);
            infos.add(info);
        }
        try {
            RemoveMiddlemanProcessor processor = new RemoveMiddlemanProcessor(field, infos);
            processor.run();
            LocalFileSystem.getInstance().refresh(false);
            FileDocumentManager.getInstance().saveAllDocuments();
            if (conflict != null)
                fail("Conflict expected");
        } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
            if (conflict == null)
                throw e;
            assertEquals(conflict, e.getMessage());
        }
    });
}
Also used : RemoveMiddlemanProcessor(com.intellij.refactoring.removemiddleman.RemoveMiddlemanProcessor) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiMethod(com.intellij.psi.PsiMethod) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList)

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