當前位置: 首頁>>代碼示例>>Java>>正文


Java ProblemDescriptor.getTextRangeInElement方法代碼示例

本文整理匯總了Java中com.intellij.codeInspection.ProblemDescriptor.getTextRangeInElement方法的典型用法代碼示例。如果您正苦於以下問題:Java ProblemDescriptor.getTextRangeInElement方法的具體用法?Java ProblemDescriptor.getTextRangeInElement怎麽用?Java ProblemDescriptor.getTextRangeInElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.codeInspection.ProblemDescriptor的用法示例。


在下文中一共展示了ProblemDescriptor.getTextRangeInElement方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final TextRange range = descriptor.getTextRangeInElement();
  PsiElement element = descriptor.getPsiElement();
  final PsiFile file = PsiTreeUtil.getParentOfType(element, PsiFile.class);
  if (file == null) {
    return;
  }
  final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
  if (document == null) {
    return;
  }
  final int startOffset = range.getStartOffset();
  final int replaceStartOffset = element.getTextOffset() + startOffset;
  int startTag = range.getEndOffset();
  @NonNls String text = element.getText();
  if (!"<code>".equalsIgnoreCase(text.substring(startOffset, startTag))) {
    return;
  }
  @NonNls final StringBuilder newCommentText = new StringBuilder("{@code");
  int endTag = StringUtil.indexOfIgnoreCase(text, "</code>", startTag);
  while (endTag < 0) {
    appendElementText(text, startTag, text.length(), newCommentText);
    element = element.getNextSibling();
    if (element == null) return;
    startTag = 0;
    text = element.getText();
    endTag = StringUtil.indexOfIgnoreCase(text, "</code>", 0);
  }
  appendElementText(text, startTag, endTag, newCommentText);
  newCommentText.append('}');
  final int replaceEndOffset = element.getTextOffset() + endTag + 7;
  final String oldText = document.getText(new TextRange(replaceStartOffset, replaceEndOffset));
  if (!StringUtil.startsWithIgnoreCase(oldText, "<code>") || !StringUtil.endsWithIgnoreCase(oldText, "</code>")) { // sanity check
    return;
  }
  document.replaceString(replaceStartOffset, replaceEndOffset, newCommentText);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:39,代碼來源:HtmlTagCanBeJavadocTagInspection.java

示例2: doFix

import com.intellij.codeInspection.ProblemDescriptor; //導入方法依賴的package包/類
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
  final TextRange textRange = descriptor.getTextRangeInElement();
  final PsiElement element = descriptor.getPsiElement();
  if (!(element instanceof PsiFile)) {
    return;
  }
  final PsiFile file = (PsiFile)element;
  final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
  if (document == null) {
    return;
  }
  document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), String.valueOf(c));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:15,代碼來源:UnnecessaryUnicodeEscapeInspection.java


注:本文中的com.intellij.codeInspection.ProblemDescriptor.getTextRangeInElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。