Search in sources :

Example 1 with PsiClassOwner

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");
    }
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) PsiFile(com.intellij.psi.PsiFile)

Example 2 with PsiClassOwner

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);
    }
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) LightClass(com.intellij.psi.impl.light.LightClass) PsiClass(com.intellij.psi.PsiClass)

Example 3 with PsiClassOwner

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;
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PsiClassOwner

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);
        }
    };
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile)

Example 5 with PsiClassOwner

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));
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) BundleManifest(org.jetbrains.osgi.project.BundleManifest) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) RetentionPolicy(java.lang.annotation.RetentionPolicy)

Aggregations

PsiClassOwner (com.intellij.psi.PsiClassOwner)6 PsiClass (com.intellij.psi.PsiClass)3 PsiFile (com.intellij.psi.PsiFile)3 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 ColoredItemPresentation (com.intellij.navigation.ColoredItemPresentation)1 Module (com.intellij.openapi.module.Module)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 DependenciesBuilder (com.intellij.packageDependencies.DependenciesBuilder)1 PsiElement (com.intellij.psi.PsiElement)1 LightClass (com.intellij.psi.impl.light.LightClass)1 RetentionPolicy (java.lang.annotation.RetentionPolicy)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 BundleManifest (org.jetbrains.osgi.project.BundleManifest)1 OsmorcFacet (org.osmorc.facet.OsmorcFacet)1