Java 类com.intellij.psi.javadoc.PsiDocToken 实例源码

项目:intellij-ce-playground    文件:HtmlTagCanBeJavadocTagInspection.java   
@Override
public void visitDocToken(PsiDocToken token) {
  super.visitDocToken(token);
  final IElementType tokenType = token.getTokenType();
  if (!JavaDocTokenType.DOC_COMMENT_DATA.equals(tokenType)) {
    return;
  }
  @NonNls final String text = token.getText();
  int startIndex = 0;
  while (true) {
    startIndex = StringUtil.indexOfIgnoreCase(text, "<code>", startIndex);
    if (startIndex < 0) {
      return;
    }
    if (hasMatchingCloseTag(token, startIndex + 6)) {
      registerErrorAtOffset(token, startIndex, 6);
    }
    startIndex++;
  }
}
项目:intellij-ce-playground    文件:DanglingJavadocInspection.java   
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
  final PsiElement element = descriptor.getPsiElement();
  final PsiElement docComment = element.getParent();
  final StringBuilder newCommentText = new StringBuilder();
  for (PsiElement child : docComment.getChildren()) {
    if (child instanceof PsiDocToken) {
      final PsiDocToken docToken = (PsiDocToken)child;
      final IElementType tokenType = docToken.getTokenType();
      if (JavaDocTokenType.DOC_COMMENT_START.equals(tokenType)) {
        newCommentText.append("/*");
      }
      else if (!JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS.equals(tokenType)) {
        newCommentText.append(child.getText());
      }
    }
    else {
      newCommentText.append(child.getText());
    }
  }
  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
  final PsiComment newComment = factory.createCommentFromText(newCommentText.toString(), element);
  docComment.replace(newComment);
}
项目:intellij-ce-playground    文件:JavaReferenceContributor.java   
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {

    final JavaClassListReferenceProvider classListProvider = new JavaClassListReferenceProvider();
    registrar.registerReferenceProvider(xmlAttributeValue(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);
    registrar.registerReferenceProvider(xmlTag(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);

    final PsiReferenceProvider filePathReferenceProvider = new FilePathReferenceProvider();
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
      public boolean isAcceptable(Object element, PsiElement context) {
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) context;
        final Map<String, Object> annotationParams = new HashMap<String, Object>();
        annotationParams.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null);
        return !JavaI18nUtil.mustBePropertyKey(context.getProject(), literalExpression, annotationParams);
      }

      public boolean isClassAcceptable(Class hintClass) {
        return true;
      }
    })), filePathReferenceProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiDocToken.class),
                                        CommentsReferenceContributor.COMMENTS_REFERENCE_PROVIDER_TYPE.getProvider());
  }
项目:tools-idea    文件:HtmlTagCanBeJavadocTagInspection.java   
@Override
public void visitDocToken(PsiDocToken token) {
  super.visitDocToken(token);
  if (!PsiUtil.isLanguageLevel5OrHigher(token)) {
    return;
  }
  final IElementType tokenType = token.getTokenType();
  if (!JavaDocTokenType.DOC_COMMENT_DATA.equals(tokenType)) {
    return;
  }
  @NonNls final String text = token.getText();
  int startIndex = 0;
  while (true) {
    startIndex = text.indexOf("<code>", startIndex);
    if (startIndex < 0) {
      return;
    }
    if (hasMatchingCloseTag(token, startIndex + 6)) {
      registerErrorAtOffset(token, startIndex, 6, Integer.valueOf(startIndex));
    }
    startIndex++;
  }
}
项目:consulo-java    文件:JavaDocLocalInspection.java   
private static String extractTagDescription(PsiDocTag tag) {
  StringBuilder buf = new StringBuilder();
  PsiElement[] children = tag.getChildren();
  for (PsiElement child : children) {
    if (child instanceof PsiDocToken) {
      PsiDocToken token = (PsiDocToken)child;
      if (token.getTokenType() == JavaDocTokenType.DOC_COMMENT_DATA) {
        buf.append(token.getText());
      }
    }
    else if (child instanceof PsiDocTagValue) {
      buf.append(child.getText());
    } else if (child instanceof PsiInlineDocTag) {
      buf.append(child.getText());
    }
  }

  String s = buf.toString();
  return s.trim();
}
项目:consulo-java    文件:JavaDocInfoGenerator.java   
private static boolean isInPre(PsiDocTag tag)
{
    PsiElement sibling = tag.getPrevSibling();
    while(sibling != null)
    {
        if(sibling instanceof PsiDocToken)
        {
            String text = sibling.getText().toLowerCase();
            int pos = text.lastIndexOf("pre>");
            if(pos > 0)
            {
                switch(text.charAt(pos - 1))
                {
                    case '<':
                        return true;
                    case '/':
                        return false;
                }
            }
        }
        sibling = sibling.getPrevSibling();
    }
    return false;
}
项目:consulo-java    文件:HtmlTagCanBeJavadocTagInspection.java   
@Override
public void visitDocToken(PsiDocToken token) {
  super.visitDocToken(token);
  if (!PsiUtil.isLanguageLevel5OrHigher(token)) {
    return;
  }
  final IElementType tokenType = token.getTokenType();
  if (!JavaDocTokenType.DOC_COMMENT_DATA.equals(tokenType)) {
    return;
  }
  @NonNls final String text = token.getText();
  int startIndex = 0;
  while (true) {
    startIndex = text.indexOf("<code>", startIndex);
    if (startIndex < 0) {
      return;
    }
    if (hasMatchingCloseTag(token, startIndex + 6)) {
      registerErrorAtOffset(token, startIndex, 6, Integer.valueOf(startIndex));
    }
    startIndex++;
  }
}
项目:intellij-ce-playground    文件:PsiDocTokenImpl.java   
@NotNull
@Override
public PsiReference[] getReferences() {
  if (getTokenType() == JavaDocTokenType.DOC_COMMENT_DATA) {
    return ReferenceProvidersRegistry.getReferencesFromProviders(this, PsiDocToken.class);
  }
  return super.getReferences();
}
项目:intellij-ce-playground    文件:SeeDocTagInfo.java   
@Override
public Object[] getPossibleValues(PsiElement context, PsiElement place, String prefix) {
  if (place instanceof PsiDocToken) {
    PsiDocToken token = (PsiDocToken) place;
    if (token.getTokenType() == JavaDocTokenType.DOC_TAG_VALUE_SHARP_TOKEN) {
      return getPossibleMethodsAndFields(context, place, prefix);
    } else if (token.getTokenType() == JavaDocTokenType.DOC_TAG_VALUE_LPAREN) {
      if (token.getPrevSibling() == null) return ArrayUtil.EMPTY_OBJECT_ARRAY;
      final String methodName = token.getPrevSibling().getText();

      PsiElement targetContext = getTargetContext(context, place);

      List<PsiMethod> result = new ArrayList<PsiMethod>();
      final PsiMethod[] methods = PsiDocMethodOrFieldRef.getAllMethods(targetContext, place);
      for (final PsiMethod method : methods) {
        if (method.getName().equals(methodName)) {
          result.add(method);
        }
      }
      return ArrayUtil.toObjectArray(result);
    } else if (token.getTokenType() == JavaDocTokenType.DOC_TAG_VALUE_TOKEN && place.getParent() instanceof PsiDocMethodOrFieldRef) {
      return getPossibleMethodsAndFields(context, place, prefix);
    }
  }

  return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
项目:intellij-ce-playground    文件:DocDataHandler.java   
private static String getTextFromNode(final PsiElement node, String text1) {
  PsiElement nextSibling = node.getNextSibling();
  if (nextSibling instanceof PsiDocTagValue) {
    text1 += nextSibling.getText();

    nextSibling = nextSibling.getNextSibling();
    if (nextSibling instanceof PsiDocToken && ((PsiDocToken)nextSibling).getTokenType() == JavaDocTokenType.DOC_COMMENT_DATA) {
      text1 += nextSibling.getText();
    }
  }
  return text1;
}
项目:intellij-ce-playground    文件:DocValuesIterator.java   
public DocValuesIterator(PsiElement start) {
  for(PsiElement e = start; e != null; e = e.getNextSibling()) {
    if (e instanceof PsiDocTagValue) tokens.add(e);
    else if (e instanceof PsiDocToken && ((PsiDocToken)e).getTokenType() == tokenType) {
      tokens.add(e);
      e = advanceToNext(e);
    }
  }
}
项目:intellij-ce-playground    文件:DocValuesIterator.java   
static PsiElement advanceToNext(PsiElement e) {
  PsiElement nextSibling = e.getNextSibling();
  if (nextSibling instanceof PsiDocTagValue) e = nextSibling;

  nextSibling = e.getNextSibling();

  if (nextSibling instanceof PsiDocToken &&
      ((PsiDocToken)nextSibling).getTokenType() == tokenType
     ) {
    e = nextSibling;
  }
  return e;
}
项目:intellij-ce-playground    文件:DocTagSelectioner.java   
public static TextRange getDocTagRange(PsiDocTag e, CharSequence documentText, int minOffset) {
  TextRange range = e.getTextRange();

  int endOffset = range.getEndOffset();
  int startOffset = range.getStartOffset();

  PsiElement[] children = e.getChildren();

  for (int i = children.length - 1; i >= 0; i--) {
    PsiElement child = children[i];

    int childStartOffset = child.getTextRange().getStartOffset();

    if (childStartOffset <= minOffset) {
      break;
    }

    if (child instanceof PsiDocToken) {
      PsiDocToken token = (PsiDocToken)child;

      IElementType type = token.getTokenType();
      char[] chars = token.textToCharArray();
      int shift = CharArrayUtil.shiftForward(chars, 0, " \t\n\r");

      if (shift != chars.length && type != JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) {
        break;
      }
    }
    else if (!(child instanceof PsiWhiteSpace)) {
      break;
    }

    endOffset = Math.min(childStartOffset, endOffset);
  }

  startOffset = CharArrayUtil.shiftBackward(documentText, startOffset - 1, "* \t") + 1;

  return new TextRange(startOffset, endOffset);
}
项目:tools-idea    文件:DocTagSelectioner.java   
public static TextRange getDocTagRange(PsiDocTag e, CharSequence documentText, int minOffset) {
  TextRange range = e.getTextRange();

  int endOffset = range.getEndOffset();
  int startOffset = range.getStartOffset();

  PsiElement[] children = e.getChildren();

  for (int i = children.length - 1; i >= 0; i--) {
    PsiElement child = children[i];

    int childStartOffset = child.getTextRange().getStartOffset();

    if (childStartOffset <= minOffset) {
      break;
    }

    if (child instanceof PsiDocToken) {
      PsiDocToken token = (PsiDocToken)child;

      IElementType type = token.getTokenType();
      char[] chars = token.textToCharArray();
      int shift = CharArrayUtil.shiftForward(chars, 0, " \t\n\r");

      if (shift != chars.length && type != JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) {
        break;
      }
    }
    else if (!(child instanceof PsiWhiteSpace)) {
      break;
    }

    endOffset = Math.min(childStartOffset, endOffset);
  }

  startOffset = CharArrayUtil.shiftBackward(documentText, startOffset - 1, "* \t") + 1;

  return new TextRange(startOffset, endOffset);
}
项目:tools-idea    文件:SeeDocTagInfo.java   
@Override
public Object[] getPossibleValues(PsiElement context, PsiElement place, String prefix) {
  if (place instanceof PsiDocToken) {
    PsiDocToken token = (PsiDocToken) place;
    if (token.getTokenType() == JavaDocTokenType.DOC_TAG_VALUE_SHARP_TOKEN) {
      return getPossibleMethodsAndFields(context, place, prefix);
    } else if (token.getTokenType() == JavaDocTokenType.DOC_TAG_VALUE_LPAREN) {
      if (token.getPrevSibling() == null) return ArrayUtil.EMPTY_OBJECT_ARRAY;
      final String methodName = token.getPrevSibling().getText();

      PsiElement targetContext = getTargetContext(context, place);

      List<PsiMethod> result = new ArrayList<PsiMethod>();
      final PsiMethod[] methods = PsiDocMethodOrFieldRef.getAllMethods(targetContext, place);
      for (final PsiMethod method : methods) {
        if (method.getName().equals(methodName)) {
          result.add(method);
        }
      }
      return ArrayUtil.toObjectArray(result);
    } else if (token.getTokenType() == JavaDocTokenType.DOC_TAG_VALUE_TOKEN && place.getParent() instanceof PsiDocMethodOrFieldRef) {
      return getPossibleMethodsAndFields(context, place, prefix);
    }
  }

  return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
项目:tools-idea    文件:UnnecessaryInheritDocInspection.java   
@Override
public void visitDocTag(PsiDocTag tag) {
  if (!(tag instanceof PsiInlineDocTag)) {
    return;
  }
  @NonNls final String name = tag.getName();
  if (!"inheritDoc".equals(name)) {
    return;
  }
  final PsiDocComment docComment = tag.getContainingComment();
  if (docComment == null) {
    return;
  }
  final PsiDocToken[] docTokens = PsiTreeUtil.getChildrenOfType(
    docComment, PsiDocToken.class);
  if (docTokens == null) {
    return;
  }
  for (PsiDocToken docToken : docTokens) {
    final IElementType tokenType = docToken.getTokenType();
    if (!JavaDocTokenType.DOC_COMMENT_DATA.equals(tokenType)) {
      continue;
    }
    if (!StringUtil.isEmptyOrSpaces(docToken.getText())) {
      return;
    }
  }
  registerError(tag);
}
项目:consulo-java    文件:JavaDocLocalInspection.java   
private static String extractThrowsTagDescription(PsiDocTag tag) {
  StringBuilder buf = new StringBuilder();
  PsiElement[] children = tag.getChildren();
  for (PsiElement child : children) {
    if (child instanceof PsiDocToken) {
      PsiDocToken token = (PsiDocToken)child;
      if (token.getTokenType() == JavaDocTokenType.DOC_COMMENT_DATA) {
        buf.append(token.getText());
      }
    }
  }

  return buf.toString().trim();
}
项目:consulo-java    文件:UnnecessaryInheritDocInspection.java   
@Override
public void visitDocTag(PsiDocTag tag) {
  if (!(tag instanceof PsiInlineDocTag)) {
    return;
  }
  @NonNls final String name = tag.getName();
  if (!"inheritDoc".equals(name)) {
    return;
  }
  final PsiDocComment docComment = tag.getContainingComment();
  if (docComment == null) {
    return;
  }
  final PsiDocToken[] docTokens = PsiTreeUtil.getChildrenOfType(
    docComment, PsiDocToken.class);
  if (docTokens == null) {
    return;
  }
  for (PsiDocToken docToken : docTokens) {
    final IElementType tokenType = docToken.getTokenType();
    if (!JavaDocTokenType.DOC_COMMENT_DATA.equals(tokenType)) {
      continue;
    }
    if (!StringUtil.isEmptyOrSpaces(docToken.getText())) {
      return;
    }
  }
  registerError(tag);
}
项目:Android_Lint_SRP_Practice_Example    文件:PsiClassStructureDetector.java   
@Override
public void visitDocToken(PsiDocToken token) {
    mVisitor.report("PsiDocToken", token.getText(), token);
    super.visitElement(token);
}
项目:intellij-ce-playground    文件:TokenTypeFilter.java   
@Override
public boolean isClassAcceptable(Class hintClass){
  return ReflectionUtil.isAssignable(PsiDocToken.class, hintClass) || ReflectionUtil.isAssignable(XmlToken.class, hintClass);
}
项目:tools-idea    文件:TokenTypeFilter.java   
@Override
public boolean isClassAcceptable(Class hintClass){
  return ReflectionCache.isAssignable(PsiDocToken.class, hintClass) || ReflectionCache.isAssignable(XmlToken.class, hintClass);
}
项目:consulo-java    文件:JavaElementVisitor.java   
public void visitDocToken(PsiDocToken token)
{
    visitElement(token);
}
项目:consulo-java    文件:DocTagSelectioner.java   
@RequiredReadAction
public static TextRange getDocTagRange(PsiDocTag e, CharSequence documentText, int minOffset)
{
    TextRange range = e.getTextRange();

    int endOffset = range.getEndOffset();
    int startOffset = range.getStartOffset();

    PsiElement[] children = e.getChildren();

    for(int i = children.length - 1; i >= 0; i--)
    {
        PsiElement child = children[i];

        int childStartOffset = child.getTextRange().getStartOffset();

        if(childStartOffset <= minOffset)
        {
            break;
        }

        if(child instanceof PsiDocToken)
        {
            PsiDocToken token = (PsiDocToken) child;

            IElementType type = token.getTokenType();
            char[] chars = token.textToCharArray();
            int shift = CharArrayUtil.shiftForward(chars, 0, " \t\n\r");

            if(shift != chars.length && type != JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS)
            {
                break;
            }
        }
        else if(!(child instanceof PsiWhiteSpace))
        {
            break;
        }

        endOffset = Math.min(childStartOffset, endOffset);
    }

    startOffset = CharArrayUtil.shiftBackward(documentText, startOffset - 1, "* \t") + 1;

    return new TextRange(startOffset, endOffset);
}
项目:consulo-java    文件:TokenTypeFilter.java   
@Override
public boolean isClassAcceptable(Class hintClass){
  return ReflectionUtil.isAssignable(PsiDocToken.class, hintClass) || ReflectionUtil.isAssignable(XmlToken.class, hintClass);
}