Search in sources :

Example 1 with PsiDocParamRef

use of com.intellij.psi.impl.source.javadoc.PsiDocParamRef in project intellij-community by JetBrains.

the class ConvertToInstanceMethodProcessor method findUsages.

@NotNull
protected UsageInfo[] findUsages() {
    LOG.assertTrue(myTargetParameter.getDeclarationScope() == myMethod);
    final Project project = myMethod.getProject();
    final PsiReference[] methodReferences = ReferencesSearch.search(myMethod, GlobalSearchScope.projectScope(project), false).toArray(PsiReference.EMPTY_ARRAY);
    List<UsageInfo> result = new ArrayList<>();
    for (final PsiReference ref : methodReferences) {
        final PsiElement element = ref.getElement();
        if (element instanceof PsiReferenceExpression) {
            if (element.getParent() instanceof PsiMethodCallExpression) {
                result.add(new MethodCallUsageInfo((PsiMethodCallExpression) element.getParent()));
            }
        } else if (element instanceof PsiDocTagValue) {
            //TODO:!!!
            result.add(new JavaDocUsageInfo(ref));
        }
    }
    for (final PsiReference ref : ReferencesSearch.search(myTargetParameter, new LocalSearchScope(myMethod), false)) {
        final PsiElement element = ref.getElement();
        if (element instanceof PsiReferenceExpression || element instanceof PsiDocParamRef) {
            result.add(new ParameterUsageInfo(ref));
        }
    }
    if (myTargetClass.isInterface()) {
        PsiClass[] implementingClasses = RefactoringHierarchyUtil.findImplementingClasses(myTargetClass);
        for (final PsiClass implementingClass : implementingClasses) {
            result.add(new ImplementingClassUsageInfo(implementingClass));
        }
    }
    return result.toArray(new UsageInfo[result.size()]);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiDocTagValue(com.intellij.psi.javadoc.PsiDocTagValue) Project(com.intellij.openapi.project.Project) PsiDocParamRef(com.intellij.psi.impl.source.javadoc.PsiDocParamRef) UsageInfo(com.intellij.usageView.UsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiDocParamRef

use of com.intellij.psi.impl.source.javadoc.PsiDocParamRef in project intellij-community by JetBrains.

the class JavadocTypedHandler method isAppropriatePlace.

private static boolean isAppropriatePlace(Editor editor, PsiFile file) {
    FileViewProvider provider = file.getViewProvider();
    int offset = editor.getCaretModel().getOffset();
    final PsiElement elementAtCaret;
    if (offset < editor.getDocument().getTextLength()) {
        elementAtCaret = provider.findElementAt(offset);
    } else {
        elementAtCaret = provider.findElementAt(editor.getDocument().getTextLength() - 1);
    }
    PsiElement element = elementAtCaret;
    while (element instanceof PsiWhiteSpace || element != null && containsOnlyWhiteSpaces(element.getText())) {
        element = element.getPrevSibling();
    }
    if (element == null) {
        return false;
    }
    if (element instanceof PsiDocParamRef) {
        element = element.getParent();
    }
    if (element instanceof PsiDocTag) {
        PsiDocTag tag = (PsiDocTag) element;
        if ("param".equals(tag.getName()) && isTypeParamBracketClosedAfterParamTag(tag, offset)) {
            return false;
        }
    }
    // The contents of inline tags is not HTML, so the paired tag completion isn't appropriate there.
    if (PsiTreeUtil.getParentOfType(element, PsiInlineDocTag.class, false) != null) {
        return false;
    }
    ASTNode node = element.getNode();
    return node != null && (JavaDocTokenType.ALL_JAVADOC_TOKENS.contains(node.getElementType()) || JavaDocElementType.ALL_JAVADOC_ELEMENTS.contains(node.getElementType()));
}
Also used : PsiDocTag(com.intellij.psi.javadoc.PsiDocTag) PsiInlineDocTag(com.intellij.psi.javadoc.PsiInlineDocTag) ASTNode(com.intellij.lang.ASTNode) PsiDocParamRef(com.intellij.psi.impl.source.javadoc.PsiDocParamRef)

Example 3 with PsiDocParamRef

use of com.intellij.psi.impl.source.javadoc.PsiDocParamRef in project intellij-community by JetBrains.

the class JavaDocumentationProvider method generateParametersTakingDocFromSuperMethods.

public static void generateParametersTakingDocFromSuperMethods(Project project, StringBuilder builder, CodeDocumentationAwareCommenter commenter, PsiMethod psiMethod) {
    final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
    final Map<String, String> param2Description = new HashMap<>();
    final PsiMethod[] superMethods = psiMethod.findSuperMethods();
    for (PsiMethod superMethod : superMethods) {
        final PsiDocComment comment = superMethod.getDocComment();
        if (comment != null) {
            final PsiDocTag[] params = comment.findTagsByName("param");
            for (PsiDocTag param : params) {
                final PsiElement[] dataElements = param.getDataElements();
                if (dataElements != null) {
                    String paramName = null;
                    for (PsiElement dataElement : dataElements) {
                        if (dataElement instanceof PsiDocParamRef) {
                            //noinspection ConstantConditions
                            paramName = dataElement.getReference().getCanonicalText();
                            break;
                        }
                    }
                    if (paramName != null) {
                        param2Description.put(paramName, param.getText());
                    }
                }
            }
        }
    }
    for (PsiParameter parameter : parameters) {
        String description = param2Description.get(parameter.getName());
        if (description != null) {
            builder.append(CodeDocumentationUtil.createDocCommentLine("", project, commenter));
            if (description.indexOf('\n') > -1)
                description = description.substring(0, description.lastIndexOf('\n'));
            builder.append(description);
        } else {
            builder.append(CodeDocumentationUtil.createDocCommentLine(PARAM_TAG, project, commenter));
            builder.append(parameter.getName());
        }
        builder.append(LINE_SEPARATOR);
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiDocTag(com.intellij.psi.javadoc.PsiDocTag) HashMap(com.intellij.util.containers.HashMap) PsiDocParamRef(com.intellij.psi.impl.source.javadoc.PsiDocParamRef)

Example 4 with PsiDocParamRef

use of com.intellij.psi.impl.source.javadoc.PsiDocParamRef in project intellij-community by JetBrains.

the class ConstructorJavadocUsageInfo method fixUsage.

@Override
public void fixUsage() throws IncorrectOperationException {
    final PsiDocComment docComment = myMethod.getDocComment();
    if (docComment != null) {
        final List<PsiDocTag> mergedTags = new ArrayList<>();
        final PsiDocTag[] paramTags = docComment.findTagsByName("param");
        for (PsiDocTag paramTag : paramTags) {
            final PsiElement[] dataElements = paramTag.getDataElements();
            if (dataElements.length > 0) {
                if (dataElements[0] instanceof PsiDocParamRef) {
                    final PsiReference reference = dataElements[0].getReference();
                    if (reference != null) {
                        final PsiElement resolve = reference.resolve();
                        if (resolve instanceof PsiParameter) {
                            final int parameterIndex = myMethod.getParameterList().getParameterIndex((PsiParameter) resolve);
                            if (myDescriptor.getParameterInfo(parameterIndex) == null)
                                continue;
                        }
                    }
                }
                mergedTags.add((PsiDocTag) paramTag.copy());
            }
        }
        PsiMethod compatibleParamObjectConstructor = null;
        final PsiMethod existingConstructor = myDescriptor.getExistingClassCompatibleConstructor();
        if (existingConstructor != null && existingConstructor.getDocComment() == null) {
            compatibleParamObjectConstructor = existingConstructor;
        } else if (!myDescriptor.isUseExistingClass()) {
            compatibleParamObjectConstructor = myDescriptor.getExistingClass().getConstructors()[0];
        }
        if (compatibleParamObjectConstructor != null) {
            PsiDocComment psiDocComment = JavaPsiFacade.getElementFactory(myMethod.getProject()).createDocCommentFromText("/**\n*/");
            psiDocComment = (PsiDocComment) compatibleParamObjectConstructor.addBefore(psiDocComment, compatibleParamObjectConstructor.getFirstChild());
            for (PsiDocTag tag : mergedTags) {
                psiDocComment.add(tag);
            }
        }
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiDocTag(com.intellij.psi.javadoc.PsiDocTag) ArrayList(java.util.ArrayList) PsiDocParamRef(com.intellij.psi.impl.source.javadoc.PsiDocParamRef)

Example 5 with PsiDocParamRef

use of com.intellij.psi.impl.source.javadoc.PsiDocParamRef in project intellij-community by JetBrains.

the class JavaRainbowVisitor method visit.

@Override
public void visit(@NotNull PsiElement element) {
    if (element instanceof PsiReferenceExpression || element instanceof PsiLocalVariable || element instanceof PsiParameter || element instanceof PsiDocParamRef) {
        PsiElement context = PsiTreeUtil.findFirstParent(element, p -> p instanceof PsiMethod);
        if (context != null) {
            PsiElement rainbowElement = element instanceof PsiReferenceExpression || element instanceof PsiDocParamRef ? element : ((PsiVariable) element).getNameIdentifier();
            PsiElement resolved = element instanceof PsiReferenceExpression ? ((PsiReferenceExpression) element).resolve() : element instanceof PsiDocParamRef ? element.getReference() == null ? null : element.getReference().resolve() : element;
            HighlightInfo attrs = getRainbowSymbolKey(context, rainbowElement, resolved);
            addInfo(attrs);
        }
    }
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) PsiDocParamRef(com.intellij.psi.impl.source.javadoc.PsiDocParamRef)

Aggregations

PsiDocParamRef (com.intellij.psi.impl.source.javadoc.PsiDocParamRef)5 PsiDocTag (com.intellij.psi.javadoc.PsiDocTag)3 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)2 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 ASTNode (com.intellij.lang.ASTNode)1 Project (com.intellij.openapi.project.Project)1 PsiDocTagValue (com.intellij.psi.javadoc.PsiDocTagValue)1 PsiInlineDocTag (com.intellij.psi.javadoc.PsiInlineDocTag)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 UsageInfo (com.intellij.usageView.UsageInfo)1 HashMap (com.intellij.util.containers.HashMap)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1