implements SourceCodeScanner and search references Follow
I implement SourceCodeScanner for search enums in project (custom lint check)
However, it is impossible to determine the logic of working with this ENUM.
I have a UClass for enum.
How can I find all the links(references) in PSI for this class in all project and analyze them?
Class "ReferencesSearch" from thit manual
https://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi_references.html not exists, and link in the manual.
And link https://upsource.jetbrains.com/idea-ce/file/idea-ce-a7b3d4e9e48efbd4ac75105e9737cea25324f11e/platform/indexing-api/com/intellij/psi/search/searches/ReferencesSearch.java from manual don't work.
Please sign in to leave a comment.
Could you please provide the code of your search?
private static final class EnumClassVisitor extends AbstractUastVisitor {
private final JavaContext mContext;
private boolean isBackFound = false;
UElement e;
EnumClassVisitor(JavaContext context) {
mContext = context;
}
@Override
public boolean visitClass(@NotNull UClass node) {
//NEED CHECK THEN THITS ENUM USED IN CLASS MODULE ACTIVITY AS STATUS !!!
//AND RESUTN FALSE ONLY IF ENUM USED
// return !checkAsModuleStateUsed(node)
return super.visitClass(node);
}
@Override
public boolean visitEnumConstant(@NotNull UEnumConstant field) {
String name = field.getName();
if (name != null && !name.startsWith("DIALOG_") && !name.startsWith("LAYOUT_") && !name.startsWith("PROGRESS_")) {
PsiElement e = field.getNavigationElement();
PsiEnumConstant psiMethod = field.getPsi();
mContext.report(STATUS_NAME, psiMethod, mContext.getNameLocation(psiMethod), "Bad name of module status. Need starts with DIALOG_, LAYOUT_ OR PROGRESS_";
}
return super.visitEnumConstant(field);
}
}
AbstractUastVisitor is meant to be used in "local" scopes, e.g. for inspections. You'll need to use ReferencesSearch to find usages across larger parts of the project. Please post your attempt to use it with a bit more details what doesn't work exactly.
I brought the current decision in the "opposite direction". I am looking for using ENUM as a module state and then throwing warnings on the announcement of this ENUM if it has not passed the test.
It is correctly displayed in the LINT HTML file, but INTELLJI correctly displays warnings only if ENUM is declared in the same file as the module, otherwise it shows a warning in the file with the module on the position from the declaration file.
I assumed that INTELLIJ correctly displays warnings only if it is in the file pointed to by the context.UASTFile and tried to do a search in the opposite direction. From ads to use. I can find all ENUM but I need to make sure that this ENUM is used as an enumeration of the statuses of a module and only then to check its constants.
Could you please repost that in English language, please? Thank you.
I edited the message and changed my language.
i can't use References Search because thits class NOTFOUND in current SDK.
may be need add gradle dependings? Or References Search is derpreated and have new implementstion?
Sorry for delay. Your resolved 'enumClass' can be in another file than the one currently visited/highlighted. So you cannot highlight these occurrences in the current file. In such case, you could revert to highlight class name instead.
thank.
Because selections can only be made in the currently visited file, I tried to search for all ENUM and select them if they are used in ModuleActivity.
But then you can not make a search for links to them. Looks like lint checks are not available ReferencesSearch
I don't know anything about Lint, but maybe com.android.tools.lint.detector.api.Scope.ALL_JAVA_FILES could help to run linter across multiple files.
Thank you!