use of com.github.javaparser.ast.expr.SingleMemberAnnotationExpr in project checker-framework by typetools.
the class DoubleJavaParserVisitor method visit.
@Override
public void visit(final SingleMemberAnnotationExpr node1, final Node other) {
SingleMemberAnnotationExpr node2 = (SingleMemberAnnotationExpr) other;
defaultAction(node1, node2);
node1.getMemberValue().accept(this, node2.getMemberValue());
node1.getName().accept(this, node2.getName());
}
use of com.github.javaparser.ast.expr.SingleMemberAnnotationExpr in project javaparser by javaparser.
the class AnnotationsResolutionTest method solveReflectionSingleMemberAnnotation.
@Test
void solveReflectionSingleMemberAnnotation() {
// parse compilation unit and get annotation expression
CompilationUnit cu = parseSample("Annotations");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CC");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo");
SingleMemberAnnotationExpr annotationExpr = (SingleMemberAnnotationExpr) method.getBody().get().getStatement(0).asExpressionStmt().getExpression().asVariableDeclarationExpr().getAnnotation(0);
// resolve annotation expression
ResolvedAnnotationDeclaration resolved = annotationExpr.resolve();
// check that the expected annotation declaration equals the resolved annotation declaration
assertEquals("java.lang.SuppressWarnings", resolved.getQualifiedName());
assertEquals("java.lang", resolved.getPackageName());
assertEquals("SuppressWarnings", resolved.getName());
}
use of com.github.javaparser.ast.expr.SingleMemberAnnotationExpr in project javaparser by javaparser.
the class AnnotationsResolutionTest method solveJavaParserSingleMemberAnnotation.
@Test
void solveJavaParserSingleMemberAnnotation() {
// parse compilation unit and get annotation expression
CompilationUnit cu = parseSample("Annotations");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CC");
SingleMemberAnnotationExpr annotationExpr = (SingleMemberAnnotationExpr) clazz.getAnnotation(0);
// resolve annotation expression
ResolvedAnnotationDeclaration resolved = annotationExpr.resolve();
// check that the expected annotation declaration equals the resolved annotation declaration
assertEquals("foo.bar.MyAnnotationWithSingleValue", resolved.getQualifiedName());
assertEquals("foo.bar", resolved.getPackageName());
assertEquals("MyAnnotationWithSingleValue", resolved.getName());
}
use of com.github.javaparser.ast.expr.SingleMemberAnnotationExpr in project kogito-runtimes by kiegroup.
the class PMMLRestResourceGeneratorTest method setPathValue.
@Test
void setPathValue() {
final Optional<SingleMemberAnnotationExpr> retrievedOpt = TEMPLATE.findFirst(SingleMemberAnnotationExpr.class);
assertTrue(retrievedOpt.isPresent());
SingleMemberAnnotationExpr retrieved = retrievedOpt.get();
assertEquals("Path", retrieved.getName().asString());
pmmlRestResourceGenerator.setPathValue(TEMPLATE);
String classPrefix = getSanitizedClassName(KIE_PMML_MODEL.getName());
String expected = URLEncoder.encode(classPrefix).replaceAll("\\+", " ");
assertEquals(expected, retrieved.getMemberValue().asStringLiteralExpr().asString());
}
use of com.github.javaparser.ast.expr.SingleMemberAnnotationExpr in project automatiko-engine by automatiko-io.
the class DependencyInjectionAnnotator method withSecurityRoles.
/**
* Annotates given node with set of roles to enforce security
*
* @param node node to be annotated
* @param roles roles that are allowed
*/
default <T extends NodeWithAnnotations<?>> T withSecurityRoles(T node, String[] roles) {
if (roles != null && roles.length > 0) {
List<Expression> rolesExpr = new ArrayList<>();
for (String role : roles) {
rolesExpr.add(new StringLiteralExpr(role.trim()));
}
node.addAnnotation(new SingleMemberAnnotationExpr(new Name("javax.annotation.security.RolesAllowed"), new ArrayInitializerExpr(NodeList.nodeList(rolesExpr))));
}
return node;
}
Aggregations