Search in sources :

Example 11 with PsiModifierListOwner

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

the class AndroidLintAnimatorKeepInspection method getQuickFixes.

@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
    return new AndroidLintQuickFix[] { new AndroidLintQuickFix() {

        @Override
        public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
            if (!ObjectAnimatorDetector.isAddKeepErrorMessage(message, TextFormat.RAW)) {
                return;
            }
            PsiModifierListOwner container = PsiTreeUtil.getParentOfType(startElement, PsiModifierListOwner.class);
            if (container == null) {
                return;
            }
            if (!FileModificationService.getInstance().preparePsiElementForWrite(container)) {
                return;
            }
            final PsiModifierList modifierList = container.getModifierList();
            if (modifierList != null) {
                PsiAnnotation annotation = AnnotationUtil.findAnnotation(container, KEEP_ANNOTATION);
                if (annotation == null) {
                    Project project = startElement.getProject();
                    new AddAnnotationFix(KEEP_ANNOTATION, container).invoke(project, null, container.getContainingFile());
                }
            }
        }

        @Override
        public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
            return true;
        }

        @NotNull
        @Override
        public String getName() {
            return "Annotate with @Keep";
        }
    } };
}
Also used : Project(com.intellij.openapi.project.Project) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) PsiAnnotation(com.intellij.psi.PsiAnnotation) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) AddAnnotationFix(com.intellij.codeInsight.intention.AddAnnotationFix) PsiModifierList(com.intellij.psi.PsiModifierList) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PsiModifierListOwner

use of com.intellij.psi.PsiModifierListOwner 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)

Aggregations

PsiModifierListOwner (com.intellij.psi.PsiModifierListOwner)12 PsiElement (com.intellij.psi.PsiElement)4 PsiModifierList (com.intellij.psi.PsiModifierList)3 AddAnnotationFix (com.intellij.codeInsight.intention.AddAnnotationFix)2 Project (com.intellij.openapi.project.Project)2 PsiAnnotation (com.intellij.psi.PsiAnnotation)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiDocCommentOwner (com.intellij.psi.PsiDocCommentOwner)1 PsiFile (com.intellij.psi.PsiFile)1 PsiLiteralExpressionImpl (com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl)1 AndroidLintQuickFix (org.jetbrains.android.inspections.lint.AndroidLintQuickFix)1 JavaAnnotationImpl (org.jetbrains.kotlin.load.java.structure.impl.JavaAnnotationImpl)1 JavaModifierListOwnerImpl (org.jetbrains.kotlin.load.java.structure.impl.JavaModifierListOwnerImpl)1 BaseInspectionVisitor (org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor)1 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1