com.intellij.psi.PsiAnnotation

Here are the examples of the java api com.intellij.psi.PsiAnnotation taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

101 Examples 7

19 Source : Utils.java
with Apache License 2.0
from kingwang666

public static boolean matchAnnotation(@NotNull PsiAnnotation[] annotations, @NotNull String name) {
    return getAnnotation(annotations, name, true) != null;
}

19 Source : Utils.java
with Apache License 2.0
from kingwang666

public static boolean findAnnotation(@NotNull PsiAnnotation[] annotations, @NotNull String name) {
    return getAnnotation(annotations, name, false) != null;
}

19 Source : NonNullFactory.java
with Apache License 2.0
from kingwang666

public static boolean hasNullable(@NotNull PsiAnnotation[] annotations) {
    for (PsiAnnotation annotation : annotations) {
        for (String name : sSupportedNullable) {
            if (name.equals(annotation.getQualifiedName())) {
                return true;
            }
        }
    }
    return false;
}

19 Source : NonNullFactory.java
with Apache License 2.0
from kingwang666

public static boolean hasNonNull(@NotNull PsiAnnotation[] annotations) {
    for (PsiAnnotation annotation : annotations) {
        for (String name : sSupportedNonNull) {
            if (name.equals(annotation.getQualifiedName())) {
                return true;
            }
        }
    }
    return false;
}

19 Source : ElementUtils.java
with MIT License
from ironSource

public static boolean isOneOfTypes(final PsiAnnotation annotation, final Clreplaced<? extends Annotation>... configClreplacedes) {
    for (Clreplaced<? extends Annotation> configClreplaced : configClreplacedes) {
        if (isOfType(annotation, configClreplaced)) {
            return true;
        }
    }
    return false;
}

19 Source : ElementUtils.java
with MIT License
from ironSource

public static boolean isOfType(final PsiAnnotation annotation, final Clreplaced<? extends Annotation> configClreplaced) {
    return annotation != null && configClreplaced.getCanonicalName().equals(annotation.getQualifiedName());
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isRemoteValueAnnotation(final PsiAnnotation psiAnnotation) {
    return ElementUtils.isAnnotationOfType(psiAnnotation, RemoteIntValue.clreplaced) || ElementUtils.isAnnotationOfType(psiAnnotation, RemoteStringValue.clreplaced);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static Object getDefaultValueAttribute(final PsiAnnotation configAnnotation) {
    return getAttributeValue(configAnnotation, ATTRIBUTE_DEFAULT_VALUE);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isTextConfigAnnotation(PsiAnnotation annotation) {
    return ElementUtils.isOfType(annotation, TextConfig.clreplaced);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

private static boolean isGroupAnnotation(final PsiAnnotation annotation) {
    return ElementUtils.isOfType(annotation, ConfigGroup.clreplaced);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isFloatConfigAnnotation(final PsiAnnotation node) {
    return ElementUtils.isAnnotationOfType(node, FloatConfig.clreplaced);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static PsiArrayInitializerMemberValue getConfigGroupValuesAttribute(final PsiAnnotation configGroupAnnotation) {
    return (PsiArrayInitializerMemberValue) configGroupAnnotation.findAttributeValue(null);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static PsiClreplaced getJsonTypeAttribute(final PsiAnnotation annotation) {
    return getClreplacedAttribute(annotation, ATTRIBUTE_JSON_TYPE);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isConfigGroupAnnotation(final PsiAnnotation node) {
    return ElementUtils.isAnnotationOfType(node, ConfigGroup.clreplaced);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isJsonConfigAnnotation(final PsiAnnotation node) {
    return ElementUtils.isAnnotationOfType(node, JsonConfig.clreplaced);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static PsiClreplaced getEnumClreplacedAttribute(final PsiAnnotation annotation) {
    return getClreplacedAttribute(annotation, ATTRIBUTE_ENUM_CLreplaced);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isColorConfigAnnotation(final PsiAnnotation node) {
    return ElementUtils.isAnnotationOfType(node, ColorConfig.clreplaced);
}

19 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isBooleanConfigAnnotation(final PsiAnnotation node) {
    return ElementUtils.isAnnotationOfType(node, BooleanConfig.clreplaced);
}

19 Source : IdeaUtils.java
with Apache License 2.0
from camel-tooling

public PsiType findAnnotatedElementType(PsiAnnotation annotation) {
    PsiField field = PsiTreeUtil.getParentOfType(annotation, PsiField.clreplaced);
    if (field != null) {
        return field.getType();
    } else {
        PsiMethod method = PsiTreeUtil.getParentOfType(annotation, PsiMethod.clreplaced);
        if (method != null && method.getParameterList().getParametersCount() == 1) {
            return method.getParameterList().getParameters()[0].getType();
        }
        return null;
    }
}

19 Source : IdeaUtils.java
with Apache License 2.0
from camel-tooling

/**
 * Is the element from a java annotation with the given name.
 */
public boolean isElementFromAnnotation(@NotNull PsiElement element, @NotNull String annotationName) {
    // java method call
    PsiAnnotation ann = PsiTreeUtil.getParentOfType(element, PsiAnnotation.clreplaced, false);
    if (ann != null) {
        return annotationName.equals(ann.getQualifiedName());
    }
    return false;
}

18 Source : SpringSecurityDebugEnabledTest.java
with Apache License 2.0
from momosecurity

public void testDebugDisable() {
    Project project = myFixture.getProject();
    PsiAnnotation annotation = (PsiAnnotation) JavaPsiFacade.getElementFactory(project).createAnnotationFromText("@EnableWebSecurity(debug = true)", null);
    PsiNameValuePair[] nameValuePairs = annotation.getParameterList().getAttributes();
    MockProblemDescriptor descriptor = new MockProblemDescriptor(nameValuePairs[0], "", ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
    SpringSecurityDebugEnabled.SpringSecurityDebugDisable quickFix = new SpringSecurityDebugEnabled.SpringSecurityDebugDisable();
    quickFix.applyFix(project, descriptor);
    PsiNameValuePair[] nameValuePairs1 = annotation.getParameterList().getAttributes();
    replacedert nameValuePairs1.length == 1;
    replacedert "false".equals(nameValuePairs1[0].getLiteralValue());
}

18 Source : Utils.java
with Apache License 2.0
from kingwang666

@Nullable
public static PsiAnnotation getAnnotation(@NotNull PsiAnnotation[] annotations, @NotNull String name) {
    return getAnnotation(annotations, name, false);
}

18 Source : ElementUtils.java
with MIT License
from ironSource

static boolean isAnnotationOfType(PsiAnnotation node, Clreplaced<? extends Annotation> annotationClreplaced) {
    return annotationClreplaced.getCanonicalName().equalsIgnoreCase(node.getQualifiedName());
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static int getGenericTypesCount(final PsiAnnotation annotation) {
    final PsiArrayInitializerMemberValue attributeValue = (PsiArrayInitializerMemberValue) annotation.findAttributeValue(ATTRIBUTE_GENERIC_TYPES);
    return attributeValue != null ? attributeValue.getInitializers().length : 0;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static PsiAnnotation getRemoteValueAnnotation(PsiField field) {
    for (final PsiAnnotation psiAnnotation : field.getAnnotations()) {
        if (isRemoteValueAnnotation(psiAnnotation)) {
            return psiAnnotation;
        }
    }
    return null;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static int getConfigAnnotationsCount(@NotNull final PsiField node) {
    int count = 0;
    for (PsiAnnotation annotation : node.getAnnotations()) {
        if (isConfigAnnotation(annotation)) {
            count++;
        }
    }
    return count;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static Object getRemoteValue(PsiField field) {
    for (final PsiAnnotation psiAnnotation : field.getAnnotations()) {
        if (isRemoteValueAnnotation(psiAnnotation)) {
            return getAttributeValue(psiAnnotation, null);
        }
    }
    return null;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static PsiAnnotation getDefaultConfigAnnotation(final PsiField field) {
    for (PsiAnnotation psiAnnotation : field.getAnnotations()) {
        if (ElementUtils.isOfType(psiAnnotation, DefaultConfig.clreplaced)) {
            return psiAnnotation;
        }
    }
    return null;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isConfigGroupField(@NotNull final PsiField node) {
    for (PsiAnnotation annotation : node.getAnnotations()) {
        if (isConfigGroupAnnotation(annotation)) {
            return true;
        }
    }
    return false;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static PsiAnnotation extractConfigAnnotation(PsiField field) {
    for (PsiAnnotation psiAnnotation : field.getAnnotations()) {
        if (isConfigAnnotation(psiAnnotation)) {
            return psiAnnotation;
        }
    }
    return null;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static PsiAnnotation getConfigAnnotation(@NotNull final PsiField node) {
    for (PsiAnnotation annotation : node.getAnnotations()) {
        if (isConfigAnnotation(annotation)) {
            return annotation;
        }
    }
    return null;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isEnumConfigAnnotation(@NotNull final PsiAnnotation node) {
    for (Clreplaced<? extends Annotation> configAnnotation : Configs.ENUM) {
        if (ElementUtils.isAnnotationOfType(node, configAnnotation)) {
            return true;
        }
    }
    return false;
}

18 Source : ConfigElementsUtils.java
with MIT License
from ironSource

private static boolean isConfigAnnotation(PsiAnnotation annotation) {
    for (Clreplaced<? extends Annotation> configClreplaced : Configs.ALL) {
        if (ElementUtils.isOfType(annotation, configClreplaced)) {
            return true;
        }
    }
    return isGroupAnnotation(annotation) || isCustomConfigAnnotation(annotation);
}

18 Source : PsiAnnotationExtractor.java
with Apache License 2.0
from facebook

/**
 * We consider an annotation to be valid for extraction if it's not an internal annotation (i.e.
 * is in the <code>com.facebook.litho</code> package and is not a source-only annotation.
 *
 * @return Whether or not to extract the given annotation.
 */
private static boolean isValidAnnotation(Project project, PsiAnnotation psiAnnotation) {
    final String text = psiAnnotation.getQualifiedName();
    if (text.startsWith("com.facebook.")) {
        return false;
    }
    PsiClreplaced annotationClreplaced = PsiSearchUtils.findClreplaced(project, psiAnnotation.getQualifiedName());
    if (annotationClreplaced == null) {
        throw new RuntimeException("Annotation clreplaced not found, text is: " + text);
    }
    final Retention retention = PsiAnnotationProxyUtils.findAnnotationInHierarchy(annotationClreplaced, Retention.clreplaced);
    return retention == null || retention.value() != RetentionPolicy.SOURCE;
}

17 Source : OkJsonUpdateLineMarkerProvider.java
with Apache License 2.0
from threefish

private PsiAnnotation getPsiAnnotation(@NotNull PsiElement psiElement) {
    if (psiElement instanceof PsiMethod) {
        PsiMethodImpl field = ((PsiMethodImpl) psiElement);
        PsiAnnotation psiAnnotation = field.getAnnotation(NutzCons.OK);
        return psiAnnotation;
    }
    return null;
}

17 Source : MapperInjectionPointsAutowiringInspection.java
with MIT License
from mustfun

/**
 * @param psiType
 * @param annotation
 * @param holder
 * @param model
 */
private void checkQualifiedAutowiring(PsiType psiType, PsiAnnotation annotation, ProblemsHolder holder, CommonSpringModel model) {
}

17 Source : Utils.java
with Apache License 2.0
from kingwang666

@Nullable
public static PsiAnnotation getAnnotation(@NotNull PsiAnnotation[] annotations, @NotNull String name, boolean match) {
    for (PsiAnnotation psiAnnotation : annotations) {
        String allName = psiAnnotation.getQualifiedName();
        if (allName == null || allName.length() == 0) {
            continue;
        }
        if ((!match && allName.endsWith(name)) || (match && allName.equals(name))) {
            return psiAnnotation;
        }
    }
    return null;
}

17 Source : ElementUtils.java
with MIT License
from ironSource

public static boolean hasAnnotation(final PsiModifierListOwner field, Clreplaced<? extends Annotation> annotationClreplaced) {
    for (PsiAnnotation psiAnnotation : field.getAnnotations()) {
        if (isOfType(psiAnnotation, annotationClreplaced)) {
            return true;
        }
    }
    return false;
}

17 Source : ElementUtils.java
with MIT License
from ironSource

public static PsiClreplaced getAnnotationDeclarationClreplaced(final PsiAnnotation configAnnotation) {
    final PsiJavaCodeReferenceElement nameReferenceElement = configAnnotation.getNameReferenceElement();
    return nameReferenceElement != null ? (PsiClreplaced) nameReferenceElement.resolve() : null;
}

17 Source : ElementUtils.java
with MIT License
from ironSource

public static boolean hasOneOfAnnotations(final PsiModifierListOwner field, Clreplaced<? extends Annotation>... annotationClreplacedes) {
    for (PsiAnnotation psiAnnotation : field.getAnnotations()) {
        if (isOneOfTypes(psiAnnotation, annotationClreplacedes)) {
            return true;
        }
    }
    return false;
}

17 Source : ConfigElementsUtils.java
with MIT License
from ironSource

private static String getEnumConfigImplClreplaced(final PsiAnnotation annotation) {
    final PsiClreplaced enumClreplaced = getEnumClreplacedAttribute(annotation);
    return enumClreplaced.getQualifiedName();
}

17 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static PsiAnnotation getFeatureRemoteConfigAnnotation(final PsiClreplaced node) {
    for (PsiAnnotation psiAnnotation : node.getAnnotations()) {
        if (ElementUtils.isOfType(psiAnnotation, FeatureRemoteConfig.clreplaced)) {
            return psiAnnotation;
        }
    }
    return null;
}

17 Source : ConfigElementsUtils.java
with MIT License
from ironSource

@SuppressWarnings("unchecked")
private static PsiClreplaced getClreplacedAttribute(final PsiAnnotation annotation, String attribute) {
    final PsiClreplacedObjectAccessExpressionImpl attributeValue = (PsiClreplacedObjectAccessExpressionImpl) annotation.findAttributeValue(attribute);
    return resolveClreplaced(attributeValue);
}

17 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static boolean isCustomConfigAnnotation(final PsiAnnotation annotation) {
    final PsiClreplaced annotationClreplaced = ElementUtils.getAnnotationDeclarationClreplaced(annotation);
    if (annotationClreplaced != null) {
        for (final PsiAnnotation annotationClreplacedAnnotation : annotationClreplaced.getAnnotations()) {
            if (ElementUtils.isOfType(annotationClreplacedAnnotation, ConfigType.clreplaced)) {
                return true;
            }
        }
    }
    return false;
}

17 Source : ConfigElementsUtils.java
with MIT License
from ironSource

public static <T> T getAttributeValue(final PsiAnnotation configAnnotation, String attribute) {
    final PsiAnnotationMemberValue attributeValue = configAnnotation.findAttributeValue(attribute);
    if (attributeValue == null) {
        return null;
    }
    final PsiConstantEvaluationHelper evaluationHelper = JavaPsiFacade.getInstance(attributeValue.getProject()).getConstantEvaluationHelper();
    return (T) evaluationHelper.computeConstantExpression(attributeValue);
}

17 Source : ConfigFieldIssueDetector.java
with MIT License
from ironSource

@Override
public final void visit(final UField node) {
    if (!ConfigElementsUtils.hasConfigAnnotation(node)) {
        return;
    }
    final PsiAnnotation annotation = ConfigElementsUtils.extractConfigAnnotation(node.getPsi());
    if (ConfigElementsUtils.isConfigGroupAnnotation(annotation)) {
        return;
    }
    visitConfigField(node);
}

17 Source : CyclicDefaultValueConfigDetector.java
with MIT License
from ironSource

private boolean hasCyclicDefaultValueConfigReference(final PsiField configField, final ArrayList<PsiField> visitedFields) {
    if (!ConfigElementsUtils.hasDefaultConfigAnnotation(configField)) {
        return false;
    }
    final PsiAnnotation defaultConfigAnnotation = ConfigElementsUtils.getDefaultConfigAnnotation(configField);
    final PsiElement defaultValueAttribute = defaultConfigAnnotation.findAttributeValue(null);
    final PsiField referencedDefaultConfigValue = ElementUtils.getReferencedField(defaultValueAttribute);
    if (visitedFields.contains(referencedDefaultConfigValue)) {
        return true;
    }
    visitedFields.add(referencedDefaultConfigValue);
    return hasCyclicDefaultValueConfigReference(referencedDefaultConfigValue, visitedFields);
}

17 Source : CyclicConfigGroupValuesDetector.java
with MIT License
from ironSource

private boolean hasCyclicConfigGroupReference(final PsiField configField, final ArrayList<PsiField> visitedFields) {
    final PsiAnnotation configAnnotation = ConfigElementsUtils.extractConfigAnnotation(configField);
    if (!ConfigElementsUtils.isConfigGroupAnnotation(configAnnotation)) {
        return false;
    }
    final PsiArrayInitializerMemberValue configGroupValues = ConfigElementsUtils.getConfigGroupValuesAttribute(configAnnotation);
    for (PsiAnnotationMemberValue configGroupValue : configGroupValues.getInitializers()) {
        final PsiField referencedConfigField = ElementUtils.getReferencedField(configGroupValue);
        if (visitedFields.contains(referencedConfigField)) {
            return true;
        }
        visitedFields.add(referencedConfigField);
        final boolean hasCyclicConfigGroupReference = hasCyclicConfigGroupReference(referencedConfigField, visitedFields);
        if (hasCyclicConfigGroupReference) {
            return true;
        }
    }
    return false;
}

17 Source : LithoPluginUtilsTest.java
with Apache License 2.0
from facebook

private static <T extends PsiModifierListOwner> T createWithAnnotation(Clreplaced<T> cls, String annotationName) {
    T withAnnotation = Mockito.mock(cls);
    PsiAnnotation annotation = createPsiAnnotation(annotationName);
    Mockito.when(withAnnotation.getAnnotations()).thenReturn(new PsiAnnotation[] { annotation });
    return withAnnotation;
}

17 Source : BeanInjectLineMarkerProvider.java
with Apache License 2.0
from camel-tooling

private PsiAnnotation getBeanInjectAnnotation(PsiElement element) {
    if (element instanceof PsiIdentifier && element.getText().equals("BeanInject")) {
        PsiAnnotation annotation = PsiTreeUtil.getParentOfType(element, PsiAnnotation.clreplaced);
        if (annotation != null && CamelIdeaUtils.BEAN_INJECT_ANNOTATION.equals(annotation.getQualifiedName())) {
            return annotation;
        }
    }
    return null;
}

See More Examples