use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class ResourceBundleStructureViewComponent method getData.
@Override
public Object getData(final String dataId) {
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
return new ResourceBundleAsVirtualFile(myResourceBundle);
} else if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
return getFileEditor();
} else if (ResourceBundle.ARRAY_DATA_KEY.is(dataId)) {
return new ResourceBundle[] { myResourceBundle };
} else if (IProperty.ARRAY_KEY.is(dataId)) {
final Collection<ResourceBundleEditorViewElement> selectedElements = ((ResourceBundleEditor) getFileEditor()).getSelectedElements();
if (selectedElements.isEmpty()) {
return null;
} else if (selectedElements.size() == 1) {
return ContainerUtil.getFirstItem(selectedElements).getProperties();
} else {
return ContainerUtil.toArray(ContainerUtil.flatten(ContainerUtil.mapNotNull(selectedElements, (NullableFunction<ResourceBundleEditorViewElement, List<IProperty>>) element -> {
final IProperty[] properties = element.getProperties();
return properties == null ? null : ContainerUtil.newArrayList(properties);
})), IProperty[]::new);
}
} else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
final List<PsiElement> elements = new ArrayList<>();
Collections.addAll(elements, getSelectedPsiFiles());
final IProperty[] properties = (IProperty[]) getData(IProperty.ARRAY_KEY.getName());
if (properties != null) {
for (IProperty property : properties) {
final PsiElement element = property.getPsiElement();
if (element.isValid()) {
elements.add(element);
}
}
}
return elements.toArray(new PsiElement[elements.size()]);
} else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
if (getSelectedPsiFiles().length != 0) {
return new ResourceBundleDeleteProvider();
}
final IProperty[] properties = IProperty.ARRAY_KEY.getData(this);
if (properties != null && properties.length != 0) {
return new PropertiesDeleteProvider(((ResourceBundleEditor) getFileEditor()).getPropertiesInsertDeleteManager(), properties);
}
} else if (UsageView.USAGE_TARGETS_KEY.is(dataId)) {
final PsiElement[] chosenElements = (PsiElement[]) getData(LangDataKeys.PSI_ELEMENT_ARRAY.getName());
if (chosenElements != null) {
final UsageTarget[] usageTargets = new UsageTarget[chosenElements.length];
for (int i = 0; i < chosenElements.length; i++) {
usageTargets[i] = new PsiElement2UsageTargetAdapter(chosenElements[i]);
}
return usageTargets;
}
} else if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
return new CopyProvider() {
@Override
public void performCopy(@NotNull final DataContext dataContext) {
final PsiElement[] selectedPsiElements = (PsiElement[]) getData(LangDataKeys.PSI_ELEMENT_ARRAY.getName());
if (selectedPsiElements != null) {
final List<String> names = new ArrayList<>(selectedPsiElements.length);
for (final PsiElement element : selectedPsiElements) {
if (element instanceof PsiNamedElement) {
names.add(((PsiNamedElement) element).getName());
}
}
CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(names, "\n")));
}
}
@Override
public boolean isCopyEnabled(@NotNull final DataContext dataContext) {
return true;
}
@Override
public boolean isCopyVisible(@NotNull final DataContext dataContext) {
return true;
}
};
}
return super.getData(dataId);
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class AntRenameTest method doTest.
private void doTest() throws Exception {
final String filename = getTestName(true) + ".xml";
VirtualFile vfile = VirtualFileManager.getInstance().findFileByUrl("file://" + getTestDataPath() + filename);
String text = FileDocumentManager.getInstance().getDocument(vfile).getText();
final int off = text.indexOf("<ren>");
text = text.replace("<ren>", "");
configureFromFileText(filename, text);
assertNotNull(myFile);
PsiElement element = TargetElementUtil.getInstance().findTargetElement(getEditor(), TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED, off);
assertNotNull(element);
assertTrue(element instanceof PsiNamedElement);
final RenameRefactoring rename = RefactoringFactory.getInstance(getProject()).createRename(element, ((PsiNamedElement) element).getName() + "-after");
rename.setSearchInComments(false);
rename.setSearchInNonJavaFiles(false);
rename.run();
checkResultByFile(filename + "-after");
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class AutomaticRenamingDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
myTable.setModel(myTableModel);
myTableModel.getSpaceAction().register();
myTableModel.addTableModelListener(e -> handleChanges());
myTable.addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
final int[] selectionRows = myTable.getSelectedRows();
if (selectionRows != null) {
compoundPopup().show(comp, x, y);
}
}
});
final TableColumnModel columnModel = myTable.getColumnModel();
columnModel.getColumn(CHECK_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
TableUtil.setupCheckboxColumn(columnModel.getColumn(CHECK_COLUMN));
columnModel.getColumn(NEW_NAME_COLUMN).setCellEditor(new StringTableCellEditor(myProject));
mySelectAllButton.addActionListener(e -> {
for (int i = 0; i < myShouldRename.length; i++) {
myShouldRename[i] = true;
}
fireDataChanged();
});
myUnselectAllButton.addActionListener(e -> {
for (int i = 0; i < myShouldRename.length; i++) {
myShouldRename[i] = false;
}
fireDataChanged();
});
myListSelectionListener = e -> {
myUsageFileLabel.setText("");
int index = myTable.getSelectionModel().getLeadSelectionIndex();
if (index != -1) {
PsiNamedElement element = myRenames[index];
UsageInfo usageInfo = new UsageInfo(element);
myUsagePreviewPanel.updateLayout(Collections.singletonList(usageInfo));
final PsiFile containingFile = element.getContainingFile();
if (containingFile != null) {
final VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile != null) {
myUsageFileLabel.setText(virtualFile.getName());
}
}
} else {
myUsagePreviewPanel.updateLayout(null);
}
};
myTable.getSelectionModel().addListSelectionListener(myListSelectionListener);
myPanelForPreview.add(myUsagePreviewPanel, BorderLayout.CENTER);
myUsagePreviewPanel.updateLayout(null);
myPanelForPreview.add(myUsageFileLabel, BorderLayout.NORTH);
mySplitPane.setDividerLocation(0.5);
GuiUtils.replaceJSplitPaneWithIDEASplitter(myPanel);
if (myTableModel.getRowCount() != 0) {
myTable.getSelectionModel().addSelectionInterval(0, 0);
}
return myPanel;
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class AutomaticRenamingDialog method populateData.
private void populateData() {
final Map<PsiNamedElement, String> renames = myRenamer.getRenames();
List<PsiNamedElement> temp = new ArrayList<>();
for (final PsiNamedElement namedElement : renames.keySet()) {
final String newName = renames.get(namedElement);
if (newName != null)
temp.add(namedElement);
}
myRenames = temp.toArray(new PsiNamedElement[temp.size()]);
Arrays.sort(myRenames, (e1, e2) -> Comparing.compare(e1.getName(), e2.getName()));
myNewNames = new String[myRenames.length];
for (int i = 0; i < myNewNames.length; i++) {
myNewNames[i] = renames.get(myRenames[i]);
}
myShouldRename = new boolean[myRenames.length];
if (myRenamer.isSelectedByDefault()) {
for (int i = 0; i < myShouldRename.length; i++) {
myShouldRename[i] = true;
}
}
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class ReplacementContext method getNewName2PatternNameMap.
public Map<String, String> getNewName2PatternNameMap() {
Map<String, String> newNameToSearchPatternNameMap = new HashMap<>(1);
final Map<String, MatchResult> variableMap = replacementInfo.getVariableMap();
if (variableMap != null) {
for (String s : variableMap.keySet()) {
final MatchResult matchResult = replacementInfo.getVariableMap().get(s);
PsiElement match = matchResult.getMatch();
match = StructuralSearchUtil.getParentIfIdentifier(match);
if (match instanceof PsiNamedElement) {
final String name = ((PsiNamedElement) match).getName();
newNameToSearchPatternNameMap.put(name, s);
}
}
}
return newNameToSearchPatternNameMap;
}
Aggregations