use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class PackageElementNode method getVirtualFiles.
@NotNull
public VirtualFile[] getVirtualFiles() {
final PackageElement value = getValue();
if (value == null) {
return VirtualFile.EMPTY_ARRAY;
}
final PsiDirectory[] directories = PackageUtil.getDirectories(value.getPackage(), value.getModule(), isLibraryElement());
final VirtualFile[] result = new VirtualFile[directories.length];
for (int i = 0; i < directories.length; i++) {
PsiDirectory directory = directories[i];
result[i] = directory.getVirtualFile();
}
return result;
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class DestinationFolderComboBox method updateErrorMessage.
private void updateErrorMessage(Pass<String> updateErrorMessage, ProjectFileIndex fileIndex, Object selectedItem) {
updateErrorMessage.pass(null);
if (myInitialTargetDirectory != null && selectedItem instanceof DirectoryChooser.ItemWrapper && selectedItem != NULL_WRAPPER) {
final PsiDirectory directory = ((DirectoryChooser.ItemWrapper) selectedItem).getDirectory();
final boolean isSelectionInTestSourceContent = fileIndex.isInTestSourceContent(directory.getVirtualFile());
final boolean inTestSourceContent = fileIndex.isInTestSourceContent(myInitialTargetDirectory.getVirtualFile());
if (isSelectionInTestSourceContent != inTestSourceContent) {
if (inTestSourceContent && reportBaseInTestSelectionInSource()) {
updateErrorMessage.pass("Source root is selected while the test root is expected");
}
if (isSelectionInTestSourceContent && reportBaseInSourceSelectionInTest()) {
updateErrorMessage.pass("Test root is selected while the source root is expected");
}
}
}
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class DestinationFolderComboBox method setData.
public void setData(final Project project, final PsiDirectory initialTargetDirectory, final Pass<String> errorMessageUpdater, final EditorComboBox editorComboBox) {
myInitialTargetDirectory = initialTargetDirectory;
mySourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(project);
new ComboboxSpeedSearch(getComboBox()) {
@Override
protected String getElementText(Object element) {
if (element == NULL_WRAPPER)
return LEAVE_IN_SAME_SOURCE_ROOT;
if (element instanceof DirectoryChooser.ItemWrapper) {
final VirtualFile virtualFile = ((DirectoryChooser.ItemWrapper) element).getDirectory().getVirtualFile();
final Module module = ModuleUtil.findModuleForFile(virtualFile, project);
if (module != null) {
return module.getName();
}
}
return super.getElementText(element);
}
};
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
getComboBox().setRenderer(new ListCellRendererWrapper<DirectoryChooser.ItemWrapper>() {
@Override
public void customize(JList list, DirectoryChooser.ItemWrapper itemWrapper, int index, boolean selected, boolean hasFocus) {
if (itemWrapper != NULL_WRAPPER && itemWrapper != null) {
setIcon(itemWrapper.getIcon(fileIndex));
setText(itemWrapper.getRelativeToProjectPath());
} else {
setText(LEAVE_IN_SAME_SOURCE_ROOT);
}
}
});
final VirtualFile initialSourceRoot = initialTargetDirectory != null ? fileIndex.getSourceRootForFile(initialTargetDirectory.getVirtualFile()) : null;
final VirtualFile[] selection = new VirtualFile[] { initialSourceRoot };
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
VirtualFile root = MoveClassesOrPackagesUtil.chooseSourceRoot(new PackageWrapper(PsiManager.getInstance(project), getTargetPackage()), mySourceRoots, initialTargetDirectory);
if (root == null)
return;
final ComboBoxModel model = getComboBox().getModel();
for (int i = 0; i < model.getSize(); i++) {
DirectoryChooser.ItemWrapper item = (DirectoryChooser.ItemWrapper) model.getElementAt(i);
if (item != NULL_WRAPPER && Comparing.equal(fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()), root)) {
getComboBox().setSelectedItem(item);
getComboBox().repaint();
return;
}
}
setComboboxModel(getComboBox(), root, root, fileIndex, mySourceRoots, project, true, errorMessageUpdater);
}
});
editorComboBox.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
JComboBox comboBox = getComboBox();
DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper) comboBox.getSelectedItem();
setComboboxModel(comboBox, selectedItem != null && selectedItem != NULL_WRAPPER ? fileIndex.getSourceRootForFile(selectedItem.getDirectory().getVirtualFile()) : initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater);
}
});
setComboboxModel(getComboBox(), initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater);
getComboBox().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Object selectedItem = getComboBox().getSelectedItem();
updateErrorMessage(errorMessageUpdater, fileIndex, selectedItem);
if (selectedItem instanceof DirectoryChooser.ItemWrapper && selectedItem != NULL_WRAPPER) {
PsiDirectory directory = ((DirectoryChooser.ItemWrapper) selectedItem).getDirectory();
if (directory != null) {
selection[0] = fileIndex.getSourceRootForFile(directory.getVirtualFile());
}
}
}
});
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class SameNamesJoiner method hasElementWithTheSameName.
private boolean hasElementWithTheSameName(PsiFile element) {
PsiDirectory psiDirectory = element.getParent();
PsiElement[] children = psiDirectory.getChildren();
for (int i = 0; i < children.length; i++) {
PsiElement child = children[i];
if (child != element && element.getVirtualFile().getNameWithoutExtension().equals(((PsiFile) child).getVirtualFile().getNameWithoutExtension())) {
return true;
}
}
return false;
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class PsiCachedValue method getTimeStamp.
@Override
protected long getTimeStamp(Object dependency) {
if (dependency instanceof PsiDirectory) {
return myManager.getModificationTracker().getOutOfCodeBlockModificationCount();
}
if (dependency instanceof PsiElement) {
PsiElement element = (PsiElement) dependency;
if (!element.isValid())
return -1;
PsiFile containingFile = element.getContainingFile();
if (containingFile != null)
return containingFile.getModificationStamp();
}
if (dependency == PsiModificationTracker.MODIFICATION_COUNT) {
return myManager.getModificationTracker().getModificationCount();
}
if (dependency == PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT) {
return myManager.getModificationTracker().getOutOfCodeBlockModificationCount();
}
if (dependency == PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT) {
return myManager.getModificationTracker().getJavaStructureModificationCount();
}
return super.getTimeStamp(dependency);
}
Aggregations