use of com.intellij.psi.PsiClassOwner in project intellij-community by JetBrains.
the class RenameFileAction method update.
public void update(AnActionEvent e) {
PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
Presentation presentation = e.getPresentation();
String place = e.getPlace();
boolean enabled = file != null && (file instanceof PsiClassOwner || !ActionPlaces.PROJECT_VIEW_POPUP.equals(place)) && place != ActionPlaces.EDITOR_POPUP && e.getData(CommonDataKeys.PROJECT) != null;
presentation.setEnabled(enabled);
presentation.setVisible(enabled);
if (enabled) {
presentation.setText(RENAME_FILE);
presentation.setDescription("Rename selected file");
}
}
use of com.intellij.psi.PsiClassOwner in project intellij-community by JetBrains.
the class MoveJavaClassesInFileHandler method processMoveAllClassesInFile.
@Override
public void processMoveAllClassesInFile(@NotNull Map<PsiClass, Boolean> allClasses, PsiClass psiClass, PsiElement... elementsToMove) {
if (psiClass instanceof LightClass)
return;
final PsiClassOwner containingFile = (PsiClassOwner) psiClass.getContainingFile();
final PsiClass[] classes = containingFile.getClasses();
boolean all = true;
for (PsiClass aClass : classes) {
if (ArrayUtil.find(elementsToMove, aClass) == -1) {
all = false;
break;
}
}
for (PsiClass aClass : classes) {
allClasses.put(aClass, all);
}
}
use of com.intellij.psi.PsiClassOwner in project intellij-community by JetBrains.
the class JavaFileTreeElement method getChildrenBase.
@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
PsiClassOwner element = getElement();
if (element == null)
return Collections.emptyList();
PsiClass[] classes = element.getClasses();
ArrayList<StructureViewTreeElement> result = new ArrayList<>();
for (PsiClass aClass : classes) {
result.add(new JavaClassTreeElement(aClass, false, new HashSet<>()));
}
return result;
}
use of com.intellij.psi.PsiClassOwner in project intellij-community by JetBrains.
the class ClassPresentationProvider method getPresentation.
@Override
public ItemPresentation getPresentation(@NotNull final PsiClass psiClass) {
return new ColoredItemPresentation() {
@Override
public String getPresentableText() {
return ClassPresentationUtil.getNameForClass(psiClass, false);
}
@Override
public String getLocationString() {
PsiFile file = psiClass.getContainingFile();
if (file instanceof PsiClassOwner) {
PsiClassOwner classOwner = (PsiClassOwner) file;
String packageName = classOwner.getPackageName();
if (packageName.isEmpty())
return null;
return "(" + packageName + ")";
}
return null;
}
@Override
public TextAttributesKey getTextAttributesKey() {
try {
if (psiClass.isDeprecated()) {
return CodeInsightColors.DEPRECATED_ATTRIBUTES;
}
} catch (IndexNotReadyException ignore) {
}
return null;
}
@Override
public Icon getIcon(boolean open) {
return psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
}
};
}
use of com.intellij.psi.PsiClassOwner in project intellij-plugins by JetBrains.
the class PackageAccessibilityInspection method checkAccessibility.
// OSGi Core Spec 3.5 "Class Loading Architecture"
private static Problem checkAccessibility(PsiClass targetClass, OsmorcFacet facet) {
// ignores annotations invisible at runtime
if (targetClass.isAnnotationType()) {
RetentionPolicy retention = AnnotationsHighlightUtil.getRetentionPolicy(targetClass);
if (retention == RetentionPolicy.SOURCE || retention == RetentionPolicy.CLASS) {
return null;
}
}
// ignores files of unsupported type
PsiFile targetFile = targetClass.getContainingFile();
if (!(targetFile instanceof PsiClassOwner)) {
return null;
}
// accepts classes from the parent class loader (normally java.* packages from the boot class path)
String packageName = ((PsiClassOwner) targetFile).getPackageName();
if (packageName.isEmpty() || packageName.startsWith("java.")) {
return null;
}
// accepts classes from the bundle's class path (private packages)
Module requestorModule = facet.getModule();
Module targetModule = ModuleUtilCore.findModuleForPsiElement(targetClass);
if (targetModule == requestorModule) {
return null;
}
BundleManifest importer = BundleManifestCache.getInstance(targetClass.getProject()).getManifest(requestorModule);
if (importer != null && (importer.isPrivatePackage(packageName) || importer.getExportedPackage(packageName) != null)) {
return null;
}
// rejects non-exported classes (manifest missing, or a package isn't listed as exported)
BundleManifest exporter = BundleManifestCache.getInstance(targetClass.getProject()).getManifest(targetClass);
if (exporter == null || exporter.getBundleSymbolicName() == null) {
return Problem.weak(message("PackageAccessibilityInspection.non.osgi", packageName));
}
String exportedPackage = exporter.getExportedPackage(packageName);
if (exportedPackage == null) {
return Problem.error(message("PackageAccessibilityInspection.not.exported", packageName));
}
// ignores facets other than manually-edited manifests (most probably, they will have their import list correctly generated)
if (!facet.getConfiguration().isManifestManuallyEdited()) {
return null;
}
// accepts packages listed as imported or required
if (importer != null) {
if (importer.isPackageImported(packageName)) {
return null;
}
if (importer.isBundleRequired(exporter.getBundleSymbolicName())) {
return null;
}
// Attached fragments [AFAIK these should not be linked statically - r.sh]
}
return Problem.error(message("PackageAccessibilityInspection.not.imported", packageName), new ImportPackageFix(exportedPackage));
}
Aggregations