Search in sources :

Example 26 with PsiModifierList

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

the class AndroidLayoutXmlTagNameProvider method isDeclarationDeprecated.

private static boolean isDeclarationDeprecated(@Nullable PsiElement declaration) {
    if (!(declaration instanceof PsiClass)) {
        return false;
    }
    final PsiClass aClass = (PsiClass) declaration;
    final PsiModifierList modifierList = aClass.getModifierList();
    if (modifierList == null) {
        return false;
    }
    return modifierList.findAnnotation("java.lang.Deprecated") != null;
}
Also used : PsiClass(com.intellij.psi.PsiClass) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 27 with PsiModifierList

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

the class AndroidActivityAliasCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    if (parameters.getCompletionType() != CompletionType.BASIC) {
        return;
    }
    final Editor editor = parameters.getEditor();
    LaunchOptionConfigurableContext context = editor.getUserData(LaunchOptionConfigurableContext.KEY);
    if (context == null) {
        return;
    }
    final Module module = context.getModule();
    if (module == null) {
        return;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return;
    }
    final String prefix = parameters.getEditor().getDocument().getText().substring(0, parameters.getOffset());
    result = result.withPrefixMatcher(prefix);
    final PsiClass activityClass = JavaPsiFacade.getInstance(module.getProject()).findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, module.getModuleWithDependenciesAndLibrariesScope(false));
    if (activityClass != null) {
        final CompletionResultSet finalResult = result;
        ClassInheritorsSearch.search(activityClass, module.getModuleWithDependenciesScope(), true, true, false).forEach(new Processor<PsiClass>() {

            @Override
            public boolean process(PsiClass psiClass) {
                final PsiModifierList modifierList = psiClass.getModifierList();
                if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.PUBLIC) && !modifierList.hasModifierProperty(PsiModifier.ABSTRACT)) {
                    final String qName = psiClass.getQualifiedName();
                    if (qName != null && qName.length() > 0) {
                        finalResult.addElement(JavaLookupElementBuilder.forClass(psiClass, qName));
                    }
                }
                return true;
            }
        });
    }
    final Set<String> aliases = collectActivityAliases(facet);
    if (aliases.size() > 0) {
        for (String alias : aliases) {
            LookupElementBuilder element = LookupElementBuilder.create(alias);
            final String shortName = StringUtilRt.getShortName(alias);
            if (!shortName.equals(alias)) {
                element = element.withLookupString(shortName);
            }
            result.addElement(element);
        }
    }
    result.stopHere();
}
Also used : LaunchOptionConfigurableContext(com.android.tools.idea.run.editor.LaunchOptionConfigurableContext) PsiClass(com.intellij.psi.PsiClass) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) Editor(com.intellij.openapi.editor.Editor) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 28 with PsiModifierList

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

the class AndroidClassBrowserBase method showDialog.

@Override
protected String showDialog() {
    Project project = getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    Module module = myModuleSelector.getModule();
    if (module == null) {
        Messages.showErrorDialog(project, ExecutionBundle.message("module.not.specified.error.text"), CommonBundle.getErrorTitle());
        return null;
    }
    GlobalSearchScope scope = myIncludeLibraryClasses ? module.getModuleWithDependenciesAndLibrariesScope(true) : module.getModuleWithDependenciesScope();
    PsiClass initialSelection = facade.findClass(getText(), scope);
    TreeClassChooser chooser = createTreeClassChooser(project, scope, initialSelection, new ClassFilter() {

        @Override
        public boolean isAccepted(PsiClass aClass) {
            if (aClass.isInterface())
                return false;
            final PsiModifierList modifierList = aClass.getModifierList();
            return modifierList == null || !modifierList.hasModifierProperty(PsiModifier.ABSTRACT);
        }
    });
    if (chooser == null)
        return null;
    chooser.showDialog();
    PsiClass selClass = chooser.getSelected();
    return selClass != null ? selClass.getQualifiedName() : null;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Project(com.intellij.openapi.project.Project) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ClassFilter(com.intellij.ide.util.ClassFilter) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 29 with PsiModifierList

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

the class ChangeModifierFix method doFix.

@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
    final PsiElement element = descriptor.getPsiElement();
    final PsiModifierListOwner modifierListOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class);
    if (modifierListOwner == null) {
        return;
    }
    final PsiModifierList modifiers = modifierListOwner.getModifierList();
    if (modifiers == null) {
        return;
    }
    modifiers.setModifierProperty(modifierText, true);
}
Also used : PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) PsiElement(com.intellij.psi.PsiElement) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 30 with PsiModifierList

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

the class SuperTypeGroup method getAccessLevel.

@Override
public int getAccessLevel() {
    final PsiClass superClass = getSuperClass();
    PsiModifierList modifierList = superClass == null ? null : superClass.getModifierList();
    return modifierList == null ? PsiUtil.ACCESS_LEVEL_PUBLIC : PsiUtil.getAccessLevel(modifierList);
}
Also used : PsiClass(com.intellij.psi.PsiClass) PsiModifierList(com.intellij.psi.PsiModifierList)

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