use of com.intellij.usageView.UsageInfo in project intellij-plugins by JetBrains.
the class DartServerFindUsagesTest method testBoolUsagesWithScope.
public void testBoolUsagesWithScope() throws Exception {
final PsiFile psiFile1 = myFixture.configureByText("file.dart", "/// [bool]\n" + "<caret>bool foo() {\n" + " var bool = #bool;\n" + "}");
final PsiFile psiFile2 = myFixture.addFileToProject("file1.dart", "bool x;");
// warm up
myFixture.doHighlighting();
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "iterable.dart");
myFixture.openFileInEditor(psiFile1.getVirtualFile());
final String[] allProjectUsages = { "PsiCommentImpl in " + psiFile1.getName() + "@5:9 (non-code usage)", "DartReferenceExpressionImpl in " + psiFile1.getName() + "@11:15", "DartReferenceExpressionImpl in file1.dart@0:4" };
checkUsages(new LocalSearchScope(psiFile1), "PsiCommentImpl in " + psiFile1.getName() + "@5:9 (non-code usage)", "DartReferenceExpressionImpl in " + psiFile1.getName() + "@11:15");
checkUsages(new LocalSearchScope(psiFile2), "DartReferenceExpressionImpl in file1.dart@0:4");
checkUsages(new LocalSearchScope(new PsiFile[] { psiFile1, psiFile2 }), allProjectUsages);
checkUsages(GlobalSearchScope.fileScope(getProject(), psiFile1.getVirtualFile()), "PsiCommentImpl in " + psiFile1.getName() + "@5:9 (non-code usage)", "DartReferenceExpressionImpl in " + psiFile1.getName() + "@11:15");
checkUsages(GlobalSearchScope.fileScope(getProject(), psiFile2.getVirtualFile()), "DartReferenceExpressionImpl in file1.dart@0:4");
checkUsages(GlobalSearchScope.filesScope(getProject(), Arrays.asList(psiFile1.getVirtualFile(), psiFile2.getVirtualFile())), allProjectUsages);
checkUsages(GlobalSearchScope.projectScope(getProject()), allProjectUsages);
final Collection<UsageInfo> usages = findUsages(GlobalSearchScope.allScope(getProject()));
assertTrue(String.valueOf(usages.size()), usages.size() > 15);
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class AndroidLibraryProjectTest method findCodeUsages.
private List<UsageInfo> findCodeUsages(String path, String dir) throws Throwable {
String newFilePath = dir + path;
VirtualFile file = myFixture.copyFileToProject(BASE_PATH + path, newFilePath);
Collection<UsageInfo> usages = AndroidFindUsagesTest.findUsages(file, myFixture);
List<UsageInfo> result = new ArrayList<>();
for (UsageInfo usage : usages) {
if (!usage.isNonCodeUsage) {
result.add(usage);
}
}
return result;
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class AndroidLibraryProjectTest method buildFileList.
private static String buildFileList(Collection<UsageInfo> infos) {
final StringBuilder result = new StringBuilder();
for (UsageInfo info : infos) {
final PsiFile file = info.getFile();
final VirtualFile vFile = file != null ? file.getVirtualFile() : null;
final String path = vFile != null ? vFile.getPath() : "null";
result.append(path).append('\n');
}
return result.toString();
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class NlIdPropertyItem method setValue.
@Override
public void setValue(Object value) {
String newId = value != null ? stripIdPrefix(value.toString()) : "";
String oldId = getValue();
XmlTag tag = getTag();
if (ourRefactoringChoice != REFACTOR_NO && oldId != null && !oldId.isEmpty() && !newId.isEmpty() && !oldId.equals(newId) && tag != null && tag.isValid()) {
// Offer rename refactoring?
XmlAttribute attribute = tag.getAttribute(SdkConstants.ATTR_ID, SdkConstants.ANDROID_URI);
if (attribute != null) {
Module module = getModel().getModule();
Project project = module.getProject();
XmlAttributeValue valueElement = attribute.getValueElement();
if (valueElement != null && valueElement.isValid()) {
// Exact replace only, no comment/text occurrence changes since it is non-interactive
ValueResourceElementWrapper wrapper = new ValueResourceElementWrapper(valueElement);
RenameProcessor processor = new RenameProcessor(project, wrapper, NEW_ID_PREFIX + newId, false, /*comments*/
false);
processor.setPreviewUsages(false);
// Do a quick usage search to see if we need to ask about renaming
UsageInfo[] usages = processor.findUsages();
if (usages.length > 0) {
int choice = ourRefactoringChoice;
if (choice == REFACTOR_ASK) {
DialogBuilder builder = createDialogBuilder(project);
builder.setTitle("Update Usages?");
// UGH!
JPanel panel = new JPanel(new BorderLayout());
JLabel label = new JLabel("<html>" + "Update usages as well?<br>" + "This will update all XML references and Java R field references.<br>" + "<br>" + "</html>");
panel.add(label, BorderLayout.CENTER);
JBCheckBox checkBox = new JBCheckBox("Don't ask again during this session");
panel.add(checkBox, BorderLayout.SOUTH);
builder.setCenterPanel(panel);
builder.setDimensionServiceKey("idPropertyDimension");
builder.removeAllActions();
DialogBuilder.CustomizableAction yesAction = builder.addOkAction();
yesAction.setText(Messages.YES_BUTTON);
builder.addActionDescriptor(dialogWrapper -> new AbstractAction(Messages.NO_BUTTON) {
@Override
public void actionPerformed(ActionEvent actionEvent) {
dialogWrapper.close(DialogWrapper.NEXT_USER_EXIT_CODE);
}
});
builder.addCancelAction();
int exitCode = builder.show();
choice = exitCode == DialogWrapper.OK_EXIT_CODE ? REFACTOR_YES : exitCode == DialogWrapper.NEXT_USER_EXIT_CODE ? REFACTOR_NO : ourRefactoringChoice;
//noinspection AssignmentToStaticFieldFromInstanceMethod
ourRefactoringChoice = checkBox.isSelected() ? choice : REFACTOR_ASK;
if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) {
return;
}
}
if (choice == REFACTOR_YES) {
processor.run();
return;
}
}
}
}
}
super.setValue(!StringUtil.isEmpty(newId) ? NEW_ID_PREFIX + newId : null);
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class AndroidInferNullityAnnotationAction method applyRunnable.
// Intellij code from InferNullityAnnotationsAction.
private static Runnable applyRunnable(Project project, Computable<UsageInfo[]> computable) {
return () -> {
LocalHistoryAction action = LocalHistory.getInstance().startAction(INFER_NULLITY_ANNOTATIONS);
try {
new WriteCommandAction(project, INFER_NULLITY_ANNOTATIONS) {
@Override
protected void run(@NotNull Result result) throws Throwable {
UsageInfo[] infos = computable.compute();
if (infos.length > 0) {
Set<PsiElement> elements = new LinkedHashSet<>();
for (UsageInfo info : infos) {
PsiElement element = info.getElement();
if (element != null) {
ContainerUtil.addIfNotNull(elements, element.getContainingFile());
}
}
if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements))
return;
SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, INFER_NULLITY_ANNOTATIONS, false);
progressTask.setMinIterationTime(200);
progressTask.setTask(new AnnotateTask(project, progressTask, infos));
ProgressManager.getInstance().run(progressTask);
} else {
NullityInferrer.nothingFoundMessage(project);
}
}
}.execute();
} finally {
action.finish();
}
};
}
Aggregations