本文整理匯總了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);
}
示例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));
}