inline: exclude non code usages inside inlined elements

This commit is contained in:
Anna Kozlova
2012-06-05 21:27:13 +04:00
parent fa185d9485
commit 2bc65585ca
2 changed files with 16 additions and 4 deletions
@@ -105,7 +105,13 @@ public class InlineConstantFieldProcessor extends BaseRefactoringProcessor {
usages.add(info);
}
if (mySearchInCommentsAndStrings || mySearchForTextOccurrences) {
TextOccurrencesUtil.UsageInfoFactory nonCodeUsageFactory = new NonCodeUsageInfoFactory(myField, myField.getName());
TextOccurrencesUtil.UsageInfoFactory nonCodeUsageFactory = new NonCodeUsageInfoFactory(myField, myField.getName()){
@Override
public UsageInfo createUsageInfo(@NotNull PsiElement usage, int startOffset, int endOffset) {
if (PsiTreeUtil.isAncestor(myField, usage, false)) return null;
return super.createUsageInfo(usage, startOffset, endOffset);
}
};
if (mySearchInCommentsAndStrings) {
String stringToSearch =
ElementDescriptionUtil.getElementDescription(myField, NonCodeSearchDescriptionLocation.STRINGS_AND_COMMENTS);
@@ -131,16 +131,22 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
}
if (mySearchInComments || mySearchForTextOccurrences) {
final NonCodeUsageInfoFactory infoFactory = new NonCodeUsageInfoFactory(myMethod, myMethod.getName()) {
@Override
public UsageInfo createUsageInfo(@NotNull PsiElement usage, int startOffset, int endOffset) {
if (PsiTreeUtil.isAncestor(myMethod, usage, false)) return null;
return super.createUsageInfo(usage, startOffset, endOffset);
}
};
if (mySearchInComments) {
String stringToSearch = ElementDescriptionUtil.getElementDescription(myMethod, NonCodeSearchDescriptionLocation.STRINGS_AND_COMMENTS);
TextOccurrencesUtil.addUsagesInStringsAndComments(myMethod, stringToSearch, usages, new NonCodeUsageInfoFactory(myMethod, myMethod.getName()));
TextOccurrencesUtil.addUsagesInStringsAndComments(myMethod, stringToSearch, usages, infoFactory);
}
if (mySearchForTextOccurrences) {
String stringToSearch = ElementDescriptionUtil.getElementDescription(myMethod, NonCodeSearchDescriptionLocation.NON_JAVA);
TextOccurrencesUtil
.addTextOccurences(myMethod, stringToSearch, GlobalSearchScope.projectScope(myProject), usages, new NonCodeUsageInfoFactory(myMethod, myMethod.getName()));
.addTextOccurences(myMethod, stringToSearch, GlobalSearchScope.projectScope(myProject), usages, infoFactory);
}
}