Search in sources :

Example 6 with PsiModifierList

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

the class SuppressParameterFix method createSuppression.

@Override
protected void createSuppression(@NotNull Project project, @NotNull PsiElement element, @NotNull PsiElement cont) throws IncorrectOperationException {
    PsiModifierListOwner container = (PsiModifierListOwner) cont;
    final PsiModifierList modifierList = container.getModifierList();
    if (modifierList != null) {
        final String id = SuppressFix.getID(container, myAlternativeID);
        JavaSuppressionUtil.addSuppressAnnotation(project, container, container, id != null ? id : myID);
    }
}
Also used : PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 7 with PsiModifierList

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

the class VisibilityListener method perform.

/**
   * to be performed in write action
   */
public void perform(final PsiVariable variable) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();
    final Document document = myEditor.getDocument();
    LOG.assertTrue(variable != null);
    final PsiModifierList modifierList = variable.getModifierList();
    LOG.assertTrue(modifierList != null);
    int textOffset = modifierList.getTextOffset();
    final String modifierListText = modifierList.getText();
    int length = PsiModifier.PUBLIC.length();
    int idx = modifierListText.indexOf(PsiModifier.PUBLIC);
    if (idx == -1) {
        idx = modifierListText.indexOf(PsiModifier.PROTECTED);
        length = PsiModifier.PROTECTED.length();
    }
    if (idx == -1) {
        idx = modifierListText.indexOf(PsiModifier.PRIVATE);
        length = PsiModifier.PRIVATE.length();
    }
    String visibility = getVisibility();
    if (visibility == PsiModifier.PACKAGE_LOCAL) {
        visibility = "";
    }
    final boolean wasPackageLocal = idx == -1;
    final boolean isPackageLocal = visibility.isEmpty();
    final int startOffset = textOffset + (wasPackageLocal ? 0 : idx);
    final int endOffset;
    if (wasPackageLocal) {
        endOffset = startOffset;
    } else {
        endOffset = textOffset + length + (isPackageLocal ? 1 : 0);
    }
    final String finalVisibility = visibility + (wasPackageLocal ? " " : "");
    Runnable runnable = () -> document.replaceString(startOffset, endOffset, finalVisibility);
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
    if (lookup != null) {
        lookup.performGuardedChange(runnable);
    } else {
        runnable.run();
    }
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) Document(com.intellij.openapi.editor.Document) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 8 with PsiModifierList

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

the class FieldAnnotationChecker method checkApplicability.

@Override
public boolean checkApplicability(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
    final String qname = annotation.getQualifiedName();
    if (!GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD.equals(qname))
        return false;
    checkScriptField(holder, annotation);
    PsiElement annoParent = annotation.getParent();
    PsiElement ownerToUse = annoParent instanceof PsiModifierList ? annoParent.getParent() : annoParent;
    if (!(ownerToUse instanceof GrVariableDeclaration)) {
        return false;
    } else {
        GrVariableDeclaration declaration = (GrVariableDeclaration) ownerToUse;
        if (declaration.getVariables().length != 1 || !PsiUtil.isLocalVariable(declaration.getVariables()[0])) {
            return false;
        }
    }
    if (!GrAnnotationImpl.isAnnotationApplicableTo(annotation, PsiAnnotation.TargetType.LOCAL_VARIABLE)) {
        GrCodeReferenceElement ref = annotation.getClassReference();
        String target = JavaErrorMessages.message("annotation.target.LOCAL_VARIABLE");
        String description = JavaErrorMessages.message("annotation.not.applicable", ref.getText(), target);
        holder.createErrorAnnotation(ref, description);
    }
    return true;
}
Also used : GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) PsiElement(com.intellij.psi.PsiElement) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 9 with PsiModifierList

use of com.intellij.psi.PsiModifierList 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 10 with PsiModifierList

use of com.intellij.psi.PsiModifierList in project smali by JesusFreke.

the class SmalideaClassDef method getAccessFlags.

@Override
public int getAccessFlags() {
    PsiModifierList modifierList = psiClass.getModifierList();
    int flags = 0;
    if (modifierList == null) {
        return flags;
    }
    if (modifierList.hasModifierProperty("public")) {
        flags |= AccessFlags.PUBLIC.getValue();
    }
    if (modifierList.hasModifierProperty("final")) {
        flags |= AccessFlags.FINAL.getValue();
    }
    if (modifierList.hasModifierProperty("abstract")) {
        flags |= AccessFlags.ABSTRACT.getValue();
    }
    if (psiClass.isInterface()) {
        flags |= AccessFlags.INTERFACE.getValue();
    }
    if (psiClass.isEnum()) {
        flags |= AccessFlags.ENUM.getValue();
    }
    if (psiClass.isAnnotationType()) {
        flags |= AccessFlags.ANNOTATION.getValue();
    }
    return flags;
}
Also used : PsiModifierList(com.intellij.psi.PsiModifierList)

Aggregations

PsiModifierList (com.intellij.psi.PsiModifierList)21 PsiClass (com.intellij.psi.PsiClass)6 PsiAnnotation (com.intellij.psi.PsiAnnotation)4 PsiElement (com.intellij.psi.PsiElement)4 PsiModifierListOwner (com.intellij.psi.PsiModifierListOwner)3 NotNull (org.jetbrains.annotations.NotNull)3 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 PsiMember (com.intellij.psi.PsiMember)2 LaunchOptionConfigurableContext (com.android.tools.idea.run.editor.LaunchOptionConfigurableContext)1 AddAnnotationFix (com.intellij.codeInsight.intention.AddAnnotationFix)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 ClassFilter (com.intellij.ide.util.ClassFilter)1 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 TextRange (com.intellij.openapi.util.TextRange)1 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)1