use of com.intellij.psi.PsiDirectoryContainer in project intellij-community by JetBrains.
the class ProjectViewTree method getColorForObject.
@Nullable
public static <T> Color getColorForObject(T object, Project project, @NotNull Function<T, PsiElement> converter) {
Color color = null;
final PsiElement psi = converter.fun(object);
if (psi != null) {
if (!psi.isValid())
return null;
final VirtualFile file = PsiUtilCore.getVirtualFile(psi);
if (file != null) {
color = FileColorManager.getInstance(project).getFileColor(file);
} else if (psi instanceof PsiDirectory) {
color = FileColorManager.getInstance(project).getFileColor(((PsiDirectory) psi).getVirtualFile());
} else if (psi instanceof PsiDirectoryContainer) {
final PsiDirectory[] dirs = ((PsiDirectoryContainer) psi).getDirectories();
for (PsiDirectory dir : dirs) {
Color c = FileColorManager.getInstance(project).getFileColor(dir.getVirtualFile());
if (c != null && color == null) {
color = c;
} else if (c != null) {
color = null;
break;
}
}
}
}
return color == null ? null : ColorUtil.softer(color);
}
use of com.intellij.psi.PsiDirectoryContainer in project intellij-plugins by JetBrains.
the class FlexUnitRuntimeConfigurationProducer method configureRunnerParameters.
private static boolean configureRunnerParameters(final FlexUnitRunnerParameters params, final Module module, final PsiElement element) {
final FlexBuildConfigurationManager manager = FlexBuildConfigurationManager.getInstance(module);
FlexUnitSupport support = null;
FlexBuildConfiguration bc = null;
if (module.getName().equals(params.getModuleName()) && !params.getBCName().isEmpty()) {
bc = manager.findConfigurationByName(params.getBCName());
if (bc != null) {
support = FlexUnitSupport.getSupport(bc, module);
}
}
if (support == null) {
bc = manager.getActiveConfiguration();
support = FlexUnitSupport.getSupport(bc, module);
}
if (support == null) {
for (FlexBuildConfiguration anyBC : manager.getBuildConfigurations()) {
bc = anyBC;
support = FlexUnitSupport.getSupport(bc, module);
if (support != null) {
break;
}
}
}
if (support == null) {
return false;
}
params.setModuleName(module.getName());
params.setBCName(bc.getName());
if (bc.getTargetPlatform() == TargetPlatform.Mobile) {
if (bc.getAndroidPackagingOptions().isEnabled()) {
params.setAppDescriptorForEmulator(FlashRunnerParameters.AppDescriptorForEmulator.Android);
} else if (bc.getIosPackagingOptions().isEnabled()) {
params.setAppDescriptorForEmulator(FlashRunnerParameters.AppDescriptorForEmulator.IOS);
}
}
if (element instanceof JSClass) {
final JSClass clazz = (JSClass) element;
if (!support.isTestClass(clazz, true))
return false;
forClass(clazz, params);
} else if (element instanceof JSFunction) {
final JSFunction method = (JSFunction) element;
final String methodName = method.getName();
final JSClass clazz = (JSClass) element.getParent();
if (!support.isTestClass(clazz, true))
return false;
if (methodName == null || !support.isTestMethod(method)) {
forClass(clazz, params);
} else {
params.setClassName(clazz.getQualifiedName());
params.setMethodName(methodName);
params.setScope(FlexUnitRunnerParameters.Scope.Method);
}
} else if (element instanceof PsiDirectory) {
if (!forDirectory((PsiDirectory) element, module, params))
return false;
} else if (element instanceof PsiDirectoryContainer) {
if (!forPackage((PsiDirectoryContainer) element, module, params))
return false;
} else {
return false;
}
return true;
}
use of com.intellij.psi.PsiDirectoryContainer in project intellij-community by JetBrains.
the class CommonRefactoringUtil method checkReadOnlyStatus.
private static boolean checkReadOnlyStatus(Collection<? extends PsiElement> elements, boolean recursively, Collection<VirtualFile> readonly, Collection<VirtualFile> failed) {
boolean seenNonWritablePsiFilesWithoutVirtualFile = false;
for (PsiElement element : elements) {
if (element instanceof PsiDirectory) {
final PsiDirectory dir = (PsiDirectory) element;
final VirtualFile vFile = dir.getVirtualFile();
if (vFile.getFileSystem().isReadOnly()) {
failed.add(vFile);
} else if (recursively) {
collectReadOnlyFiles(vFile, readonly);
} else {
readonly.add(vFile);
}
} else if (element instanceof PsiDirectoryContainer) {
final PsiDirectory[] directories = ((PsiDirectoryContainer) element).getDirectories();
for (PsiDirectory directory : directories) {
VirtualFile virtualFile = directory.getVirtualFile();
if (recursively) {
if (virtualFile.getFileSystem().isReadOnly()) {
failed.add(virtualFile);
} else {
collectReadOnlyFiles(virtualFile, readonly);
}
} else if (virtualFile.getFileSystem().isReadOnly()) {
failed.add(virtualFile);
} else {
readonly.add(virtualFile);
}
}
} else {
PsiFile file = element.getContainingFile();
if (file == null) {
if (!element.isWritable()) {
seenNonWritablePsiFilesWithoutVirtualFile = true;
}
} else {
final VirtualFile vFile = file.getVirtualFile();
if (vFile != null) {
readonly.add(vFile);
} else if (!element.isWritable()) {
seenNonWritablePsiFilesWithoutVirtualFile = true;
}
}
}
}
return seenNonWritablePsiFilesWithoutVirtualFile;
}
use of com.intellij.psi.PsiDirectoryContainer in project intellij-community by JetBrains.
the class DeleteUtil method generateWarningMessage.
public static String generateWarningMessage(String messageTemplate, final PsiElement[] elements) {
if (elements.length == 1) {
String name = ElementDescriptionUtil.getElementDescription(elements[0], DeleteNameDescriptionLocation.INSTANCE);
String type = ElementDescriptionUtil.getElementDescription(elements[0], DeleteTypeDescriptionLocation.SINGULAR);
return MessageFormat.format(messageTemplate, type + " \"" + name + "\"");
}
FactoryMap<String, Integer> countMap = new FactoryMap<String, Integer>() {
@Override
protected Integer create(final String key) {
return 0;
}
};
Map<String, String> pluralToSingular = new HashMap<>();
int directoryCount = 0;
String containerType = null;
for (final PsiElement elementToDelete : elements) {
String type = ElementDescriptionUtil.getElementDescription(elementToDelete, DeleteTypeDescriptionLocation.PLURAL);
pluralToSingular.put(type, ElementDescriptionUtil.getElementDescription(elementToDelete, DeleteTypeDescriptionLocation.SINGULAR));
int oldCount = countMap.get(type).intValue();
countMap.put(type, oldCount + 1);
if (elementToDelete instanceof PsiDirectoryContainer) {
containerType = type;
directoryCount += ((PsiDirectoryContainer) elementToDelete).getDirectories().length;
}
}
StringBuilder buffer = new StringBuilder();
for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
if (buffer.length() > 0) {
if (buffer.length() > 0) {
buffer.append(" ").append(IdeBundle.message("prompt.delete.and")).append(" ");
}
}
final int count = entry.getValue().intValue();
buffer.append(count).append(" ");
if (count == 1) {
buffer.append(pluralToSingular.get(entry.getKey()));
} else {
buffer.append(entry.getKey());
}
if (entry.getKey().equals(containerType)) {
buffer.append(" ").append(IdeBundle.message("prompt.delete.directory.paren", directoryCount));
}
}
return MessageFormat.format(messageTemplate, buffer.toString());
}
use of com.intellij.psi.PsiDirectoryContainer in project intellij-plugins by JetBrains.
the class FlashRunConfiguration method getRefactoringElementListener.
@Override
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
if (!myRunnerParameters.isOverrideMainClass()) {
return null;
}
final Module module = ModuleManager.getInstance(getProject()).findModuleByName(myRunnerParameters.getModuleName());
if (!(element instanceof PsiDirectoryContainer) && !(element instanceof JSPackage) && !(element instanceof JSPackageStatement) && (module == null || !module.equals(ModuleUtilCore.findModuleForPsiElement(element)))) {
return null;
}
final String currentPackage = StringUtil.getPackageName(myRunnerParameters.getOverriddenMainClass());
if ((element instanceof PsiDirectoryContainer || element instanceof JSPackage || element instanceof JSPackageStatement) && Comparing.strEqual(FlexRefactoringListenerProvider.getPackageName(element), currentPackage)) {
return new FlexRunConfigRefactoringListener.PackageRefactoringListener(this);
}
if (element instanceof PsiDirectory && containsClass(module, ((PsiDirectory) element), myRunnerParameters.getOverriddenMainClass())) {
return new FlexRunConfigRefactoringListener.PsiDirectoryRefactoringListener(this);
}
final JSClass jsClass = FlexRefactoringListenerProvider.getJSClass(element);
if (jsClass != null && Comparing.strEqual(jsClass.getQualifiedName(), myRunnerParameters.getOverriddenMainClass())) {
return new FlexRunConfigRefactoringListener.JSClassRefactoringListener(this);
}
return null;
}
Aggregations