Search in sources :

Example 76 with PsiMethod

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

the class FormatCommentsProcessor method formatCommentsInner.

/**
   * Formats PsiDocComments of current ASTNode element and all his children PsiDocComments
   */
@NotNull
private static TextRange formatCommentsInner(@NotNull Project project, @NotNull ASTNode element, @NotNull final TextRange markedRange) {
    TextRange resultTextRange = markedRange;
    final PsiElement elementPsi = element.getPsi();
    boolean shouldFormat = markedRange.contains(element.getTextRange());
    if (shouldFormat) {
        final ASTNode rangeAnchor;
        // its parent.
        if (elementPsi instanceof PsiDocComment) {
            rangeAnchor = element.getTreeParent();
        } else {
            rangeAnchor = element;
        }
        TextRange before = rangeAnchor.getTextRange();
        new CommentFormatter(project).processComment(element);
        int deltaRange = rangeAnchor.getTextRange().getLength() - before.getLength();
        resultTextRange = new TextRange(markedRange.getStartOffset(), markedRange.getEndOffset() + deltaRange);
    }
    // If element is out of range its children are also out of range. So in both cases formatting is finished. It's just for optimization.
    if ((shouldFormat && (elementPsi instanceof PsiMethod || elementPsi instanceof PsiField || elementPsi instanceof PsiDocComment)) || markedRange.getEndOffset() < element.getStartOffset()) {
        return resultTextRange;
    }
    ASTNode current = element.getFirstChildNode();
    while (current != null) {
        // When element is PsiClass its PsiDocComment is formatted up to this moment, so we didn't need to format it again.
        if (!(shouldFormat && current.getPsi() instanceof PsiDocComment && elementPsi instanceof PsiClass)) {
            resultTextRange = formatCommentsInner(project, current, resultTextRange);
        }
        current = current.getTreeNext();
    }
    return resultTextRange;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiMethod(com.intellij.psi.PsiMethod) PsiField(com.intellij.psi.PsiField) ASTNode(com.intellij.lang.ASTNode) PsiClass(com.intellij.psi.PsiClass) TextRange(com.intellij.openapi.util.TextRange) CommentFormatter(com.intellij.psi.impl.source.codeStyle.javadoc.CommentFormatter) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with PsiMethod

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

the class JavaChildBlockWrapFactory method create.

/**
   * Creates {@link Wrap wrap} to be used with the children blocks of the the given block.
   *
   * @param block                   target block which sub-blocks should use wrap created by the current method
   * @param settings                code formatting settings to consider during wrap construction
   * @param reservedWrapsProvider   reserved {@code 'element type -> wrap instance'} mappings provider. <b>Note:</b> this
   *                                argument is considered to be a part of legacy heritage and is intended to be removed as
   *                                soon as formatting code refactoring is done
   * @return                        wrap to use for the sub-blocks of the given block
   */
@Nullable
public Wrap create(ASTBlock block, CommonCodeStyleSettings settings, ReservedWrapsProvider reservedWrapsProvider) {
    ASTNode node = block.getNode();
    Wrap wrap = block.getWrap();
    final IElementType nodeType = node.getElementType();
    if (nodeType == JavaElementType.EXTENDS_LIST || nodeType == JavaElementType.IMPLEMENTS_LIST) {
        return Wrap.createWrap(settings.EXTENDS_LIST_WRAP, false);
    } else if (node instanceof PsiPolyadicExpression) {
        Wrap actualWrap = wrap != null ? wrap : reservedWrapsProvider.getReservedWrap(JavaElementType.BINARY_EXPRESSION);
        if (actualWrap == null) {
            return Wrap.createWrap(settings.BINARY_OPERATION_WRAP, false);
        } else {
            if (JavaFormatterUtil.areSamePriorityBinaryExpressions(node, node.getTreeParent())) {
                return actualWrap;
            } else {
                return Wrap.createChildWrap(actualWrap, WrapType.byLegacyRepresentation(settings.BINARY_OPERATION_WRAP), false);
            }
        }
    } else if (nodeType == JavaElementType.CONDITIONAL_EXPRESSION) {
        return Wrap.createWrap(settings.TERNARY_OPERATION_WRAP, false);
    } else if (nodeType == JavaElementType.ASSERT_STATEMENT) {
        return Wrap.createWrap(settings.ASSERT_STATEMENT_WRAP, false);
    } else if (nodeType == JavaElementType.FOR_STATEMENT) {
        return Wrap.createWrap(settings.FOR_STATEMENT_WRAP, false);
    } else if (nodeType == JavaElementType.THROWS_LIST) {
        return Wrap.createWrap(settings.THROWS_LIST_WRAP, true);
    } else if (nodeType == JavaElementType.CODE_BLOCK) {
        if (settings.KEEP_SIMPLE_METHODS_IN_ONE_LINE && node.getPsi().getParent() instanceof PsiMethod && !node.textContains('\n')) {
            return null;
        }
        return Wrap.createWrap(WrapType.NORMAL, false);
    } else if (JavaFormatterUtil.isAssignment(node)) {
        return Wrap.createWrap(settings.ASSIGNMENT_WRAP, true);
    } else {
        return null;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Wrap(com.intellij.formatting.Wrap) PsiPolyadicExpression(com.intellij.psi.PsiPolyadicExpression) PsiMethod(com.intellij.psi.PsiMethod) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable)

Example 78 with PsiMethod

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

the class MemberSelectionTable method isAbstractColumnEditable.

@Override
protected boolean isAbstractColumnEditable(int rowIndex) {
    MemberInfo info = myMemberInfos.get(rowIndex);
    if (!(info.getMember() instanceof PsiMethod))
        return false;
    if (info.isStatic())
        return false;
    PsiMethod method = (PsiMethod) info.getMember();
    if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
        if (myMemberInfoModel.isFixedAbstract(info) != null) {
            return false;
        }
    }
    return info.isChecked() && myMemberInfoModel.isAbstractEnabled(info);
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiMethod(com.intellij.psi.PsiMethod)

Example 79 with PsiMethod

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

the class MemberSelectionTable method getOverrideIcon.

@Override
protected Icon getOverrideIcon(MemberInfo memberInfo) {
    PsiMember member = memberInfo.getMember();
    Icon overrideIcon = MemberSelectionTable.EMPTY_OVERRIDE_ICON;
    if (member instanceof PsiMethod) {
        if (Boolean.TRUE.equals(memberInfo.getOverrides())) {
            overrideIcon = AllIcons.General.OverridingMethod;
        } else if (Boolean.FALSE.equals(memberInfo.getOverrides())) {
            overrideIcon = AllIcons.General.ImplementingMethod;
        } else {
            overrideIcon = MemberSelectionTable.EMPTY_OVERRIDE_ICON;
        }
    }
    return overrideIcon;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) RowIcon(com.intellij.ui.RowIcon) PsiMember(com.intellij.psi.PsiMember)

Example 80 with PsiMethod

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

the class JavaCallHierarchyTest method doJavaCallTypeHierarchyTest.

private void doJavaCallTypeHierarchyTest(final String classFqn, final String methodName, final String... fileNames) throws Exception {
    doHierarchyTest(() -> {
        final PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass(classFqn, ProjectScope.getProjectScope(getProject()));
        final PsiMethod method = psiClass.findMethodsByName(methodName, false)[0];
        return new CallerMethodsTreeStructure(getProject(), method, HierarchyBrowserBaseEx.SCOPE_PROJECT);
    }, fileNames);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) CallerMethodsTreeStructure(com.intellij.ide.hierarchy.call.CallerMethodsTreeStructure) PsiClass(com.intellij.psi.PsiClass)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)232 PsiClass (com.intellij.psi.PsiClass)97 PsiElement (com.intellij.psi.PsiElement)71 ArrayList (java.util.ArrayList)24 NotNull (org.jetbrains.annotations.NotNull)22 Nullable (org.jetbrains.annotations.Nullable)19 Project (com.intellij.openapi.project.Project)16 PsiField (com.intellij.psi.PsiField)13 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)12 Location (com.intellij.execution.Location)11 JavaEvaluator (com.android.tools.klint.client.api.JavaEvaluator)9 PsiReference (com.intellij.psi.PsiReference)9 PsiFile (com.intellij.psi.PsiFile)8 PsiAnnotation (com.intellij.psi.PsiAnnotation)7 List (java.util.List)7 Nullable (com.android.annotations.Nullable)6 Module (com.intellij.openapi.module.Module)6 PsiType (com.intellij.psi.PsiType)6 SearchScope (com.intellij.psi.search.SearchScope)6 PsiParameter (com.intellij.psi.PsiParameter)5