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()]);
}
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()));
}
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);
}
}
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);
}
}
}
}
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);
}
}
}
Aggregations