Search in sources :

Example 1 with PsiAnnotationParameterList

use of com.intellij.psi.PsiAnnotationParameterList in project google-cloud-intellij by GoogleCloudPlatform.

the class ApiNameInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final com.intellij.codeInspection.ProblemsHolder holder, boolean isOnTheFly) {
    return new EndpointPsiElementVisitor() {

        @Override
        public void visitAnnotation(PsiAnnotation annotation) {
            if (annotation == null) {
                return;
            }
            if (!GctConstants.APP_ENGINE_ANNOTATION_API.equals(annotation.getQualifiedName())) {
                return;
            }
            // Need to check for user added attributes because default values are used when not
            // specified by user and we are only interested in the user specified values
            PsiAnnotationParameterList parameterList = annotation.getParameterList();
            if (parameterList.getAttributes().length == 0) {
                return;
            }
            PsiAnnotationMemberValue annotationMemberValue = annotation.findAttributeValue(API_NAME_ATTRIBUTE);
            if (annotationMemberValue == null) {
                return;
            }
            String nameValueWithQuotes = annotationMemberValue.getText();
            String nameValue = EndpointUtilities.removeBeginningAndEndingQuotes(nameValueWithQuotes);
            // Empty API name is valid
            if (nameValue.isEmpty()) {
                return;
            }
            if (!API_NAME_PATTERN.matcher(nameValue).matches()) {
                holder.registerProblem(annotationMemberValue, "Invalid api name: it must start with a lower case letter and consists only of " + "letter and digits", new MyQuickFix());
            }
        }
    };
}
Also used : PsiAnnotation(com.intellij.psi.PsiAnnotation) PsiAnnotationParameterList(com.intellij.psi.PsiAnnotationParameterList) PsiAnnotationMemberValue(com.intellij.psi.PsiAnnotationMemberValue) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiAnnotation (com.intellij.psi.PsiAnnotation)1 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)1 PsiAnnotationParameterList (com.intellij.psi.PsiAnnotationParameterList)1 NotNull (org.jetbrains.annotations.NotNull)1