private static String getAnnotationAttributeAsString(List<AnnotationValue> values, String attributeName, String defaultValue) { return values.stream() .filter(annotationValue -> annotationValue.name().equals(attributeName)) .map(AnnotationValue::value) .filter(Tree.class::isInstance) .map(Tree.class::cast) .map(tree -> tree.is(Tree.Kind.MEMBER_SELECT) ? ((MemberSelectExpressionTree) tree).identifier() : tree) .filter(tree -> tree.is(Tree.Kind.IDENTIFIER)) .map(IdentifierTree.class::cast) .map(IdentifierTree::name) .findFirst() .orElse(defaultValue); }
private static String getAnnotationAttributeAsString(List<AnnotationValue> values, String attributeName, String defaultValue) { return values.stream() .filter(annotationValue -> annotationValue.name().equals(attributeName)) .map(AnnotationValue::value) .filter(Tree.class::isInstance) .map(Tree.class::cast) .map(tree -> tree.is(Tree.Kind.MEMBER_SELECT) ? ((MemberSelectExpressionTree) tree).identifier() : tree) .filter(tree -> tree.is(Tree.Kind.IDENTIFIER)) .map(IdentifierTree.class::cast) .map(IdentifierTree::name) .findFirst() .orElse(defaultValue); }
private static boolean checkAnnotationParameter(List<SymbolMetadata.AnnotationValue> valuesForAnnotation, String fieldName, String expectedValue) { return valuesForAnnotation.stream() .filter(annotationValue -> fieldName.equals(annotationValue.name())) .anyMatch(annotationValue -> isExpectedValue(annotationValue.value(), expectedValue)); }
private static boolean inheritRequestMethod(Symbol.TypeSymbol symbol) { List<SymbolMetadata.AnnotationValue> annotationValues = symbol.metadata().valuesForAnnotation(REQUEST_MAPPING_CLASS); if (annotationValues != null && annotationValues.stream().anyMatch(value -> REQUEST_METHOD.equals(value.name()))) { return true; } Type superClass = symbol.superClass(); if (superClass != null && inheritRequestMethod(superClass.symbol())) { return true; } for (Type type : symbol.interfaces()) { if (inheritRequestMethod(type.symbol())) { return true; } } return false; } }
private static boolean inheritRequestMethod(Symbol.TypeSymbol symbol) { List<SymbolMetadata.AnnotationValue> annotationValues = symbol.metadata().valuesForAnnotation(REQUEST_MAPPING_CLASS); if (annotationValues != null && annotationValues.stream().anyMatch(value -> REQUEST_METHOD.equals(value.name()))) { return true; } Type superClass = symbol.superClass(); if (superClass != null && inheritRequestMethod(superClass.symbol())) { return true; } for (Type type : symbol.interfaces()) { if (inheritRequestMethod(type.symbol())) { return true; } } return false; } }
private void addToScannedPackages(SymbolMetadata.AnnotationValue annotationValue) { if (COMPONENT_SCAN_ARGUMENTS.contains(annotationValue.name()) && annotationValue.value() instanceof ExpressionTree) { ExpressionTree values = (ExpressionTree) annotationValue.value(); if (values.is(Tree.Kind.STRING_LITERAL)) { String packageName = ConstantUtils.resolveAsStringConstant(values); packagesScannedBySpring.add(packageName); } else if (values.is(Tree.Kind.NEW_ARRAY)) { for (ExpressionTree p : ((NewArrayTree) values).initializers()) { String packageName = ConstantUtils.resolveAsStringConstant(p); packagesScannedBySpring.add(packageName); } } } }
private void addToScannedPackages(SymbolMetadata.AnnotationValue annotationValue) { if (COMPONENT_SCAN_ARGUMENTS.contains(annotationValue.name()) && annotationValue.value() instanceof ExpressionTree) { ExpressionTree values = (ExpressionTree) annotationValue.value(); if (values.is(Tree.Kind.STRING_LITERAL)) { String packageName = ConstantUtils.resolveAsStringConstant(values); packagesScannedBySpring.add(packageName); } else if (values.is(Tree.Kind.NEW_ARRAY)) { for (ExpressionTree p : ((NewArrayTree) values).initializers()) { String packageName = ConstantUtils.resolveAsStringConstant(p); packagesScannedBySpring.add(packageName); } } } }
private static boolean generatesPrivateAccess(List<SymbolMetadata.AnnotationValue> values) { return values.stream().anyMatch(av -> "access".equals(av.name()) && "PRIVATE".equals(getAccessLevelValue(av.value()))); }
private static boolean generatesPrivateAccess(List<SymbolMetadata.AnnotationValue> values) { return values.stream().anyMatch(av -> "access".equals(av.name()) && "PRIVATE".equals(getAccessLevelValue(av.value()))); }
private static boolean isScopeSingleton(SymbolMetadata clazzMeta) { List<AnnotationValue> values = clazzMeta.valuesForAnnotation(SCOPE_ANNOTATION_FQN); for (AnnotationValue annotationValue : values) { if (("value".equals(annotationValue.name()) || "scopeName".equals(annotationValue.name())) && annotationValue.value() instanceof LiteralTree && !"\"singleton\"".equals(((LiteralTree) annotationValue.value()).value())) { return false; } } return true; }
private static boolean checkAnnotationParameter(List<SymbolMetadata.AnnotationValue> valuesForAnnotation, String fieldName, String expectedValue) { return valuesForAnnotation.stream() .filter(annotationValue -> fieldName.equals(annotationValue.name())) .anyMatch(annotationValue -> isExpectedValue(annotationValue.value(), expectedValue)); }
private static boolean expectAssertion(MethodTree methodTree) { List<SymbolMetadata.AnnotationValue> annotationValues = methodTree.symbol().metadata().valuesForAnnotation("org.junit.Test"); if (annotationValues != null) { for (SymbolMetadata.AnnotationValue annotationValue : annotationValues) { if ("expected".equals(annotationValue.name())) { return true; } } } return false; }
private static boolean isScopeSingleton(SymbolMetadata clazzMeta) { List<AnnotationValue> values = clazzMeta.valuesForAnnotation(SCOPE_ANNOTATION_FQN); for (AnnotationValue annotationValue : values) { if (("value".equals(annotationValue.name()) || "scopeName".equals(annotationValue.name())) && annotationValue.value() instanceof LiteralTree && !"\"singleton\"".equals(((LiteralTree) annotationValue.value()).value())) { return false; } } return true; }
private static boolean expectAssertion(MethodTree methodTree) { List<SymbolMetadata.AnnotationValue> annotationValues = methodTree.symbol().metadata().valuesForAnnotation("org.junit.Test"); if (annotationValues != null) { for (SymbolMetadata.AnnotationValue annotationValue : annotationValues) { if ("expected".equals(annotationValue.name())) { return true; } } } return false; }