Search in sources :

Example 1 with PsiModifierList

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

the class GrMemberSelectionTable method setVisibilityIcon.

@Override
protected void setVisibilityIcon(GrMemberInfo 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 2 with PsiModifierList

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

the class LightClassAnnotationsTest method doTest.

private void doTest(@NotNull String fqName) {
    PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
    if (!(psiClass instanceof KtLightClass)) {
        throw new IllegalStateException("Not a light class: " + psiClass + " (" + fqName + ")");
    }
    PsiModifierList modifierList = psiClass.getModifierList();
    assert modifierList != null : "No modifier list for " + psiClass.getText();
    StringBuilder sb = new StringBuilder();
    for (PsiAnnotation annotation : modifierList.getAnnotations()) {
        sb.append(annotation.getText()).append("\n");
    }
    KotlinTestUtils.assertEqualsToFile(new File(testDir, getTestName(false) + ".annotations.txt"), sb.toString());
}
Also used : PsiClass(com.intellij.psi.PsiClass) KtLightClass(org.jetbrains.kotlin.asJava.classes.KtLightClass) PsiAnnotation(com.intellij.psi.PsiAnnotation) File(java.io.File) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 3 with PsiModifierList

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

the class SmalideaMethod method getAccessFlags.

@Override
public int getAccessFlags() {
    if (psiMethod instanceof SmaliMethod) {
        return ((SmaliMethod) psiMethod).getModifierList().getAccessFlags();
    } else {
        int flags = 0;
        PsiModifierList modifierList = psiMethod.getModifierList();
        if (modifierList.hasModifierProperty("public")) {
            flags |= AccessFlags.PUBLIC.getValue();
        } else if (modifierList.hasModifierProperty("protected")) {
            flags |= AccessFlags.PROTECTED.getValue();
        } else if (modifierList.hasModifierProperty("private")) {
            flags |= AccessFlags.PRIVATE.getValue();
        }
        if (modifierList.hasModifierProperty("static")) {
            flags |= AccessFlags.STATIC.getValue();
        }
        if (modifierList.hasModifierProperty("final")) {
            flags |= AccessFlags.FINAL.getValue();
        }
        boolean isNative = false;
        if (modifierList.hasModifierProperty("native")) {
            flags |= AccessFlags.NATIVE.getValue();
            isNative = true;
        }
        if (modifierList.hasModifierProperty("synchronized")) {
            if (isNative) {
                flags |= AccessFlags.SYNCHRONIZED.getValue();
            } else {
                flags |= AccessFlags.DECLARED_SYNCHRONIZED.getValue();
            }
        }
        if (psiMethod.isVarArgs()) {
            flags |= AccessFlags.VARARGS.getValue();
        }
        if (modifierList.hasModifierProperty("abstract")) {
            flags |= AccessFlags.ABSTRACT.getValue();
        }
        if (modifierList.hasModifierProperty("strictfp")) {
            flags |= AccessFlags.STRICTFP.getValue();
        }
        if (psiMethod.isConstructor()) {
            flags |= AccessFlags.CONSTRUCTOR.getValue();
        }
        return flags;
    }
}
Also used : SmaliMethod(org.jf.smalidea.psi.impl.SmaliMethod) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 4 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 5 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)

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