public static boolean appendAnnotations(@NotNull StringBuilder sb, @NotNull List<PsiAnnotation> annotations, boolean canonical) { boolean updated = false; for (PsiAnnotation annotation : annotations) { if (canonical) { String name = annotation.getQualifiedName(); if (name != null) { sb.append('@').append(name).append(annotation.getParameterList().getText()).append(' '); updated = true; } } else { PsiJavaCodeReferenceElement refElement = annotation.getNameReferenceElement(); if (refElement != null) { sb.append('@').append(refElement.getText()).append(' '); updated = true; } } } return updated; } }
/** * Implementation of dynamicProxy.toString() */ private String toStringImpl() { StringBuilder result = new StringBuilder(128); result.append('@'); result.append(type.getName()); result.append('('); boolean firstMember = true; PsiNameValuePair[] attributes = myAnnotation.getParameterList().getAttributes(); for (PsiNameValuePair e : attributes) { if (firstMember) { firstMember = false; } else { result.append(", "); } result.append(e.getName()); result.append('='); PsiAnnotationMemberValue value = e.getValue(); result.append(value == null ? "null" : value.getText()); } result.append(')'); return result.toString(); } }
@NotNull private static List<String> getAnnotationsInner(PsiModifierListOwner element) { PsiModifierList modifierList = element.getModifierList(); if (modifierList == null) return ContainerUtilRt.emptyList(); List<String> result = new ArrayList<>(); for (PsiAnnotation annotation : modifierList.getAnnotations()) { if (annotation.getParameterList().getAttributes().length > 0) continue; ContainerUtil.addIfNotNull(result, annotation.getQualifiedName()); } return result; } }
@Nullable private static PsiAnnotationMemberValue getAnnotationValue(@NonNull PsiAnnotation annotation) { PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes(); for (PsiNameValuePair pair : attributes) { if (pair.getName() == null || pair.getName().equals(ATTR_VALUE)) { return pair.getValue(); } } return null; }
.getElementFactory() .createAnnotationFromText(newNamedValue, null); assert (newAnnotation.getParameterList().getAttributes().length == 1); annotation.getParameterList().replace(newAnnotation.getParameterList());
PsiAnnotationParameterList parameterList = annotation.getParameterList(); if (parameterList.getAttributes().length == 0) { return;
/** * Returns true if the given AST modifier has a suppress annotation for the * given issue (which can be null to check for the "all" annotation) * * @param issue the issue to be checked * @param modifierList the modifier to check * @return true if the issue or all issues should be suppressed for this * modifier */ public static boolean isSuppressed(@NonNull Issue issue, @Nullable PsiModifierList modifierList) { if (modifierList == null) { return false; } for (PsiAnnotation annotation : modifierList.getAnnotations()) { String fqcn = annotation.getQualifiedName(); if (fqcn != null && (fqcn.equals(FQCN_SUPPRESS_LINT) || fqcn.equals(SUPPRESS_WARNINGS_FQCN) || fqcn.equals(SUPPRESS_LINT))) { // when missing imports PsiAnnotationParameterList parameterList = annotation.getParameterList(); for (PsiNameValuePair pair : parameterList.getAttributes()) { if (isSuppressed(issue, pair.getValue())) { return true; } } } } return false; }
/** * Returns the value for @Named if it exists for <code>psiParameter</code> or null if it does not * exist. * * @param psiParameter The parameter whose @Named value is to be returned. * @return The @Named value if it exists for <code>psiParameter</code> or null if it does not * exist. */ @Nullable public PsiAnnotationMemberValue getNamedAnnotationValue(PsiParameter psiParameter) { PsiModifierList modifierList = psiParameter.getModifierList(); if (modifierList == null) { return null; } PsiAnnotation annotation = modifierList.findAnnotation("javax.inject.Named"); if (annotation == null) { annotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED); if (annotation == null) { return null; } } PsiNameValuePair[] nameValuePairs = annotation.getParameterList().getAttributes(); if (nameValuePairs.length != 1) { return null; } if (nameValuePairs[0] == null) { return null; } return nameValuePairs[0].getValue(); }
PsiNameValuePair[] nameValuePairs = annotation.getParameterList().getAttributes(); if (nameValuePairs.length == 0) { return; .getElementFactory() .createAnnotationFromText(newNamedValue, null); assert (newAnnotation.getParameterList().getAttributes().length == 1); memberValue.replace(newAnnotation.getParameterList().getAttributes()[0].getValue());
final PsiNameValuePair[] attributes = containerAnnotation.getParameterList().getAttributes(); if ( attributes.length == 1 ) { final String currentMappings = attributes[0].getText();
|| fqcn.equals(SDK_SUPPRESS_ANNOTATION) PsiAnnotationParameterList parameterList = annotation.getParameterList(); for (PsiNameValuePair pair : parameterList.getAttributes()) { PsiAnnotationMemberValue v = pair.getValue();
String fqn = containerAnnotation != null ? MapstructUtil.MAPPINGS_ANNOTATION_FQN : MapstructUtil.MAPPING_ANNOTATION_FQN; PsiNameValuePair[] attributes = newAnnotation.getParameterList().getAttributes(); Optional<String> annotationToRemove = mappingsPair.getSecond() .map( PsiAnnotation::getQualifiedName );
PsiNameValuePair[] nameValuePairs = annotation.getParameterList().getAttributes(); if (nameValuePairs.length == 0) {
PsiNameValuePair[] attributes = annotation.getParameterList() .getAttributes(); for (PsiNameValuePair pair : attributes) {
return; PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes(); if (attributes.length == 1) { PsiNameValuePair attribute = attributes[0];
AnnotationsDatabase.ResolvedExternalAnnotation annotation = new AnnotationsDatabase.ResolvedExternalAnnotation(qualifiedName); for (PsiNameValuePair pairValue : psiAnnotation.getParameterList().getAttributes()) { PsiAnnotationMemberValue value = pairValue.getValue(); String name = pairValue.getName();
? modifierList.findAnnotation(fqn) : null; if (annotation != null) { PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes(); PsiNameValuePair o = attributes.length == 1 ? attributes[0] : null; if (o != null && o.getValue() instanceof PsiAnnotation) {