Search in sources :

Example 31 with PsiModifierList

use of com.intellij.psi.PsiModifierList in project intellij-community by JetBrains.

the class GrTypeDefinitionRangeHandler method getDeclarationRange.

@NotNull
@Override
public TextRange getDeclarationRange(@NotNull GrTypeDefinition aClass) {
    if (aClass instanceof GrAnonymousClassDefinition) {
        GrNewExpression call = (GrNewExpression) aClass.getParent();
        int startOffset = call.getTextRange().getStartOffset();
        int endOffset = call.getArgumentList().getTextRange().getEndOffset();
        return new TextRange(startOffset, endOffset);
    } else {
        final PsiModifierList modifierList = aClass.getModifierList();
        int startOffset = modifierList == null ? aClass.getTextRange().getStartOffset() : modifierList.getTextRange().getStartOffset();
        final GrImplementsClause implementsList = aClass.getImplementsClause();
        int endOffset = implementsList == null ? aClass.getTextRange().getEndOffset() : implementsList.getTextRange().getEndOffset();
        return new TextRange(startOffset, endOffset);
    }
}
Also used : GrNewExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression) GrImplementsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause) GrAnonymousClassDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition) TextRange(com.intellij.openapi.util.TextRange) PsiModifierList(com.intellij.psi.PsiModifierList) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with PsiModifierList

use of com.intellij.psi.PsiModifierList in project intellij-community by JetBrains.

the class MakeClassFinalFix method doFix.

@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
    final PsiElement element = descriptor.getPsiElement();
    final PsiClass containingClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
    if (containingClass == null) {
        return;
    }
    final PsiModifierList modifierList = containingClass.getModifierList();
    if (modifierList == null) {
        return;
    }
    if (!isOnTheFly()) {
        if (ClassInheritorsSearch.search(containingClass).findFirst() != null) {
            return;
        }
        doMakeFinal(modifierList);
        return;
    }
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final Query<PsiClass> search = ClassInheritorsSearch.search(containingClass);
    search.forEach(aClass -> {
        conflicts.putValue(containingClass, InspectionGadgetsBundle.message("0.will.no.longer.be.overridable.by.1", RefactoringUIUtil.getDescription(containingClass, false), RefactoringUIUtil.getDescription(aClass, false)));
        return true;
    });
    final boolean conflictsDialogOK;
    if (!conflicts.isEmpty()) {
        ConflictsDialog conflictsDialog = new ConflictsDialog(element.getProject(), conflicts, () -> doMakeFinal(modifierList));
        conflictsDialogOK = conflictsDialog.showAndGet();
    } else {
        conflictsDialogOK = true;
    }
    if (conflictsDialogOK) {
        doMakeFinal(modifierList);
    }
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) PsiClass(com.intellij.psi.PsiClass) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) PsiElement(com.intellij.psi.PsiElement) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 33 with PsiModifierList

use of com.intellij.psi.PsiModifierList in project intellij-community by JetBrains.

the class MemberSelectionTable method setVisibilityIcon.

@Override
protected void setVisibilityIcon(MemberInfo memberInfo, RowIcon icon) {
    PsiMember member = memberInfo.getMember();
    PsiModifierList modifiers = member != null ? member.getModifierList() : null;
    if (modifiers != null) {
        VisibilityIcons.setVisibilityIcon(modifiers, icon);
    } else {
        icon.setIcon(IconUtil.getEmptyIcon(true), VISIBILITY_ICON_POSITION);
    }
}
Also used : PsiMember(com.intellij.psi.PsiMember) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 34 with PsiModifierList

use of com.intellij.psi.PsiModifierList in project kotlin by JetBrains.

the class JavaScriptInterfaceDetector method isJavaScriptAnnotated.

private static boolean isJavaScriptAnnotated(PsiClass clz) {
    while (clz != null) {
        PsiModifierList modifierList = clz.getModifierList();
        if (modifierList != null && modifierList.findAnnotation(JAVASCRIPT_INTERFACE_CLS) != null) {
            return true;
        }
        for (PsiMethod method : clz.getMethods()) {
            if (method.getModifierList().findAnnotation(JAVASCRIPT_INTERFACE_CLS) != null) {
                return true;
            }
        }
        clz = clz.getSuperClass();
    }
    return false;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 35 with PsiModifierList

use of com.intellij.psi.PsiModifierList in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineForbiddenCodeInspection method checkFile.

@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
    final Project project = manager.getProject();
    Module module = ModuleUtilCore.findModuleForPsiElement(file);
    final AppEngineStandardFacet appEngineStandardFacet = AppEngineStandardFacet.getAppEngineFacetByModule(module);
    if (appEngineStandardFacet == null) {
        return null;
    }
    if (appEngineStandardFacet.getRuntimeJavaVersion().atLeast(JavaVersion.JAVA_1_8)) {
        return null;
    }
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
    file.accept(new JavaRecursiveElementWalkingVisitor() {

        CloudSdkInternals sdkInternals = CloudSdkInternals.getInstance();

        @Override
        public void visitDocComment(PsiDocComment comment) {
        }

        @Override
        public void visitMethod(PsiMethod method) {
            final PsiModifierList modifierList = method.getModifierList();
            if (modifierList.hasModifierProperty(PsiModifier.NATIVE)) {
                if (!isNativeMethodAllowed(method)) {
                    problems.add(manager.createProblemDescriptor(modifierList, "Native methods aren't allowed in App Engine application", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                }
            }
            super.visitMethod(method);
        }

        @Override
        public void visitNewExpression(PsiNewExpression expression) {
            final PsiJavaCodeReferenceElement classReference = expression.getClassReference();
            if (classReference != null) {
                final PsiElement resolved = classReference.resolve();
                if (resolved instanceof PsiClass) {
                    final String qualifiedName = ((PsiClass) resolved).getQualifiedName();
                    if (qualifiedName != null && sdkInternals.isMethodInBlacklist(qualifiedName, "new")) {
                        final String message = "App Engine application should not create new instances of '" + qualifiedName + "' class";
                        problems.add(manager.createProblemDescriptor(classReference, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                    }
                }
            }
            super.visitNewExpression(expression);
        }

        @Override
        public void visitMethodCallExpression(PsiMethodCallExpression expression) {
            final PsiReferenceExpression methodExpression = expression.getMethodExpression();
            final PsiElement element = methodExpression.resolve();
            if (element instanceof PsiMethod) {
                final PsiMethod method = (PsiMethod) element;
                final PsiClass psiClass = method.getContainingClass();
                if (psiClass != null) {
                    final String qualifiedName = psiClass.getQualifiedName();
                    final String methodName = method.getName();
                    if (qualifiedName != null && sdkInternals.isMethodInBlacklist(qualifiedName, methodName)) {
                        final String message = "AppEngine application should not call '" + StringUtil.getShortName(qualifiedName) + "" + methodName + "' method";
                        problems.add(manager.createProblemDescriptor(methodExpression, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                    }
                }
            }
            super.visitMethodCallExpression(expression);
        }

        @Override
        public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
            final PsiElement resolved = reference.resolve();
            if (resolved instanceof PsiClass) {
                final PsiFile psiFile = resolved.getContainingFile();
                if (psiFile != null) {
                    final VirtualFile virtualFile = psiFile.getVirtualFile();
                    if (virtualFile != null && !fileIndex.isInSource(virtualFile)) {
                        final List<OrderEntry> list = fileIndex.getOrderEntriesForFile(virtualFile);
                        for (OrderEntry entry : list) {
                            if (entry instanceof JdkOrderEntry) {
                                final String className = ClassUtil.getJVMClassName((PsiClass) resolved);
                                if (className != null && !sdkInternals.isClassInWhiteList(className)) {
                                    problems.add(manager.createProblemDescriptor(reference, "Class '" + className + "' is not included in App Engine JRE White List", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                                }
                            }
                        }
                    }
                }
            }
            super.visitReferenceElement(reference);
        }
    });
    return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiMethod(com.intellij.psi.PsiMethod) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) ArrayList(java.util.ArrayList) CloudSdkInternals(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkInternals) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) PsiFile(com.intellij.psi.PsiFile) ArrayList(java.util.ArrayList) PsiModifierList(com.intellij.psi.PsiModifierList) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) JavaRecursiveElementWalkingVisitor(com.intellij.psi.JavaRecursiveElementWalkingVisitor) PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) PsiClass(com.intellij.psi.PsiClass) PsiNewExpression(com.intellij.psi.PsiNewExpression) PsiModifierList(com.intellij.psi.PsiModifierList) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) AppEngineStandardFacet(com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacet) Module(com.intellij.openapi.module.Module)

Aggregations

PsiModifierList (com.intellij.psi.PsiModifierList)43 PsiAnnotation (com.intellij.psi.PsiAnnotation)18 PsiClass (com.intellij.psi.PsiClass)13 PsiMethod (com.intellij.psi.PsiMethod)12 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)6 PsiElement (com.intellij.psi.PsiElement)6 NotNull (org.jetbrains.annotations.NotNull)6 Project (com.intellij.openapi.project.Project)5 Module (com.intellij.openapi.module.Module)3 PsiModifierListOwner (com.intellij.psi.PsiModifierListOwner)3 PsiParameter (com.intellij.psi.PsiParameter)3 Test (org.junit.Test)3 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)2 ClassFilter (com.intellij.ide.util.ClassFilter)2 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2 Document (com.intellij.openapi.editor.Document)2 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)2 PsiFile (com.intellij.psi.PsiFile)2 PsiMember (com.intellij.psi.PsiMember)2 PsiNameValuePair (com.intellij.psi.PsiNameValuePair)2