Java 类com.intellij.psi.impl.source.javadoc.PsiDocParamRef 实例源码

项目:intellij-ce-playground    文件:ConvertToInstanceMethodProcessor.java   
private void processParameterUsage(ParameterUsageInfo usage) throws IncorrectOperationException {
  final PsiReference reference = usage.getReferenceExpression();
  if (reference instanceof PsiReferenceExpression) {
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)reference;
    PsiElement parent = referenceExpression.getParent();
    if (parent instanceof PsiReferenceExpression && sameUnqualified(parent)) {
      referenceExpression.delete();
    }
    else {
      final PsiExpression expression =
        JavaPsiFacade.getInstance(myMethod.getProject()).getElementFactory().createExpressionFromText("this", null);
      referenceExpression.replace(expression);
    }
  } else {
    final PsiElement element = reference.getElement();
    if (element instanceof PsiDocParamRef) {
      element.getParent().delete();
    }
  }
}
项目:tools-idea    文件:ConvertToInstanceMethodProcessor.java   
private void processParameterUsage(ParameterUsageInfo usage) throws IncorrectOperationException {
  final PsiReference reference = usage.getReferenceExpression();
  if (reference instanceof PsiReferenceExpression) {
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)reference;
    if (referenceExpression.getParent() instanceof PsiReferenceExpression) {
      // todo: check for correctness
      referenceExpression.delete();
    }
    else {
      final PsiExpression expression =
        JavaPsiFacade.getInstance(myMethod.getProject()).getElementFactory().createExpressionFromText("this", null);
      referenceExpression.replace(expression);
    }
  } else {
    final PsiElement element = reference.getElement();
    if (element instanceof PsiDocParamRef) {
      element.getParent().delete();
    }
  }
}
项目:consulo-java    文件:JavaDocCompletionContributor.java   
private static PsiParameter getDocTagParam(PsiElement tag)
{
    if(tag instanceof PsiDocTag && "param".equals(((PsiDocTag) tag).getName()))
    {
        PsiDocTagValue value = ((PsiDocTag) tag).getValueElement();
        if(value instanceof PsiDocParamRef)
        {
            final PsiReference psiReference = value.getReference();
            PsiElement target = psiReference != null ? psiReference.resolve() : null;
            if(target instanceof PsiParameter)
            {
                return (PsiParameter) target;
            }
        }
    }
    return null;
}
项目:consulo-java    文件:ConvertToInstanceMethodProcessor.java   
private void processParameterUsage(ParameterUsageInfo usage) throws IncorrectOperationException {
  final PsiReference reference = usage.getReferenceExpression();
  if (reference instanceof PsiReferenceExpression) {
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)reference;
    if (referenceExpression.getParent() instanceof PsiReferenceExpression) {
      // todo: check for correctness
      referenceExpression.delete();
    }
    else {
      final PsiExpression expression =
        JavaPsiFacade.getInstance(myMethod.getProject()).getElementFactory().createExpressionFromText("this", null);
      referenceExpression.replace(expression);
    }
  } else {
    final PsiElement element = reference.getElement();
    if (element instanceof PsiDocParamRef) {
      element.getParent().delete();
    }
  }
}
项目:intellij-ce-playground    文件:JavaDocLocalInspectionBase.java   
public static boolean isFound(final PsiDocTag[] tags, final PsiElement param) {
  for (PsiDocTag tag : tags) {
    if ("param".equals(tag.getName())) {
      PsiDocTagValue value = tag.getValueElement();
      if (value instanceof PsiDocParamRef) {
        PsiDocParamRef paramRef = (PsiDocParamRef)value;
        final PsiReference psiReference = paramRef.getReference();
        if (psiReference != null && psiReference.isReferenceTo(param)) {
          return true;
        }
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:JavaDocCompletionContributor.java   
private static PsiParameter getDocTagParam(PsiElement tag) {
  if (tag instanceof PsiDocTag && "param".equals(((PsiDocTag)tag).getName())) {
    PsiDocTagValue value = ((PsiDocTag)tag).getValueElement();
    if (value instanceof PsiDocParamRef) {
      final PsiReference psiReference = value.getReference();
      PsiElement target = psiReference != null ? psiReference.resolve() : null;
      if (target instanceof PsiParameter) {
        return (PsiParameter)target;
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:JavadocTypedHandler.java   
@Nullable
private static PsiElement getDocumentingParameter(PsiDocTag tag) {
  for (PsiElement element : tag.getChildren()) {
    if (element instanceof PsiDocParamRef) {
      return element;
    }
  }
  return null;
}
项目:tools-idea    文件:JavaDocLocalInspection.java   
public static boolean isFound(final PsiDocTag[] tags, final PsiElement param) {
  for (PsiDocTag tag : tags) {
    if ("param".equals(tag.getName())) {
      PsiDocTagValue value = tag.getValueElement();
      if (value instanceof PsiDocParamRef) {
        PsiDocParamRef paramRef = (PsiDocParamRef)value;
        final PsiReference psiReference = paramRef.getReference();
        if (psiReference != null && psiReference.isReferenceTo(param)) {
          return true;
        }
      }
    }
  }
  return false;
}
项目:tools-idea    文件:JavaDocCompletionContributor.java   
private static PsiParameter getDocTagParam(PsiElement tag) {
  if (tag instanceof PsiDocTag && "param".equals(((PsiDocTag)tag).getName())) {
    PsiDocTagValue value = ((PsiDocTag)tag).getValueElement();
    if (value instanceof PsiDocParamRef) {
      final PsiReference psiReference = value.getReference();
      PsiElement target = psiReference != null ? psiReference.resolve() : null;
      if (target instanceof PsiParameter) {
        return (PsiParameter)target;
      }
    }
  }
  return null;
}
项目:tools-idea    文件:IntroduceParameterObjectProcessor.java   
private void fixJavadocForConstructor(PsiClass psiClass) {
  final PsiDocComment docComment = method.getDocComment();
  if (docComment != null) {
    final List<PsiDocTag> mergedTags = new ArrayList<PsiDocTag>();
    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 = method.getParameterList().getParameterIndex((PsiParameter)resolve);
              if (ArrayUtil.find(paramsToMerge, parameterIndex) < 0) continue;
            }
          }
        }
        mergedTags.add((PsiDocTag)paramTag.copy());
      }
    }

    PsiMethod compatibleParamObjectConstructor = null;
    if (myExistingClassCompatibleConstructor != null && myExistingClassCompatibleConstructor.getDocComment() == null) {
      compatibleParamObjectConstructor = myExistingClassCompatibleConstructor;
    } else if (!myUseExistingClass){
      compatibleParamObjectConstructor = psiClass.getConstructors()[0];
    }

    if (compatibleParamObjectConstructor != null) {
      PsiDocComment psiDocComment = JavaPsiFacade.getElementFactory(myProject).createDocCommentFromText("/**\n*/");
      psiDocComment = (PsiDocComment)compatibleParamObjectConstructor.addBefore(psiDocComment, compatibleParamObjectConstructor.getFirstChild());

      for (PsiDocTag tag : mergedTags) {
        psiDocComment.add(tag);
      }
    }
  }
}
项目:consulo-java    文件:JavaDocLocalInspection.java   
public static boolean isFound(final PsiDocTag[] tags, final PsiElement param) {
  for (PsiDocTag tag : tags) {
    if ("param".equals(tag.getName())) {
      PsiDocTagValue value = tag.getValueElement();
      if (value instanceof PsiDocParamRef) {
        PsiDocParamRef paramRef = (PsiDocParamRef)value;
        final PsiReference psiReference = paramRef.getReference();
        if (psiReference != null && psiReference.isReferenceTo(param)) {
          return true;
        }
      }
    }
  }
  return false;
}
项目:consulo-java    文件:IntroduceParameterObjectProcessor.java   
private void fixJavadocForConstructor(PsiClass psiClass) {
  final PsiDocComment docComment = method.getDocComment();
  if (docComment != null) {
    final List<PsiDocTag> mergedTags = new ArrayList<PsiDocTag>();
    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 = method.getParameterList().getParameterIndex((PsiParameter)resolve);
              if (ArrayUtil.find(paramsToMerge, parameterIndex) < 0) continue;
            }
          }
        }
        mergedTags.add((PsiDocTag)paramTag.copy());
      }
    }

    PsiMethod compatibleParamObjectConstructor = null;
    if (myExistingClassCompatibleConstructor != null && myExistingClassCompatibleConstructor.getDocComment() == null) {
      compatibleParamObjectConstructor = myExistingClassCompatibleConstructor;
    } else if (!myUseExistingClass){
      compatibleParamObjectConstructor = psiClass.getConstructors()[0];
    }

    if (compatibleParamObjectConstructor != null) {
      PsiDocComment psiDocComment = JavaPsiFacade.getElementFactory(myProject).createDocCommentFromText("/**\n*/");
      psiDocComment = (PsiDocComment)compatibleParamObjectConstructor.addBefore(psiDocComment, compatibleParamObjectConstructor.getFirstChild());

      for (PsiDocTag tag : mergedTags) {
        psiDocComment.add(tag);
      }
    }
  }
}
项目:intellij-ce-playground    文件:JavadocTypedHandler.java   
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()));
}
项目:intellij-ce-playground    文件:JavaDocumentationProvider.java   
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<String, String>();
  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);
  }
}
项目:tools-idea    文件:JavadocTypedHandler.java   
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 = element.getPrevSibling();
  }

  if (element == null) {
    return false;
  }

  if (element instanceof PsiDocParamRef) {
    element = element.getParent();
  }

  if (element instanceof PsiDocTag) {
    // We don't want to provide closing tag for the type parameters, i.e. at situations like the one below:
    // /**
    //  * @param <T>[caret]
    //  */
    PsiDocTag tag = (PsiDocTag)element;
    if ("param".equals(tag.getName())) {
      final PsiDocTagValue value = tag.getValueElement();
      if (value == null || value.getTextRange().getEndOffset() == offset) {
        return false;
      } 
    } 
  }

  ASTNode node = element.getNode();
  return node != null 
         && (JavaDocTokenType.ALL_JAVADOC_TOKENS.contains(node.getElementType())
             || JavaDocElementType.ALL_JAVADOC_ELEMENTS.contains(node.getElementType()));
}
项目:consulo-java    文件:JavadocTypedHandler.java   
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 = element.getPrevSibling();
  }

  if (element == null) {
    return false;
  }

  if (element instanceof PsiDocParamRef) {
    element = element.getParent();
  }

  if (element instanceof PsiDocTag) {
    // We don't want to provide closing tag for the type parameters, i.e. at situations like the one below:
    // /**
    //  * @param <T>[caret]
    //  */
    PsiDocTag tag = (PsiDocTag)element;
    if ("param".equals(tag.getName())) {
      final PsiDocTagValue value = tag.getValueElement();
      if (value == null || value.getTextRange().getEndOffset() == offset) {
        return false;
      } 
    } 
  }

  ASTNode node = element.getNode();
  return node != null 
         && (JavaDocTokenType.ALL_JAVADOC_TOKENS.contains(node.getElementType())
             || JavaDocElementType.ALL_JAVADOC_ELEMENTS.contains(node.getElementType()));
}
项目:consulo-java    文件:JavaDocumentationProvider.java   
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);
    }
}