Java Code Examples for com.github.javaparser.ast.expr.Expression#isArrayInitializerExpr()
The following examples show how to use
com.github.javaparser.ast.expr.Expression#isArrayInitializerExpr() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotatedMember.java From jeddict with Apache License 2.0 | 6 votes |
static List<String> getStringAttributes(AnnotationExpr annotationExpr, String attributeName) { List<String> values = new ArrayList<>(); Optional<Expression> expOptional = getAttribute(annotationExpr, attributeName); if (expOptional.isPresent()) { Expression expression = expOptional.get(); if (expression.isStringLiteralExpr()) { values.add(expression.asStringLiteralExpr().getValue()); } else if (expression.isArrayInitializerExpr()) { List<Node> nodes = expression.asArrayInitializerExpr().getChildNodes(); for (Node node : nodes) { if (node instanceof StringLiteralExpr) { values.add(((StringLiteralExpr) node).getValue()); } else { values.add(node.toString()); } } } else { throw new UnsupportedOperationException(); } } return values; }
Example 2
Source File: AnnotatedMember.java From jeddict with Apache License 2.0 | 6 votes |
static List<String> getClassNameAttributes(AnnotationExpr annotationExpr, String attributeName) { List<String> values = new ArrayList<>(); Optional<Expression> expOptional = getAttribute(annotationExpr, attributeName); if (expOptional.isPresent()) { Expression expression = expOptional.get(); if (expression.isClassExpr()) { values.add(expression.asClassExpr().getTypeAsString()); } else if (expression.isArrayInitializerExpr()) { for (Node node : expression.asArrayInitializerExpr().getChildNodes()) { if (node instanceof ClassExpr) { values.add(((ClassExpr) node).getTypeAsString()); } else { throw new UnsupportedOperationException(); } } } else { throw new UnsupportedOperationException(); } } return values; }
Example 3
Source File: RequestMappingHelper.java From apigcc with MIT License | 5 votes |
/** * 解析HTTP Method * @param n * @return */ public static Method pickMethod(MethodDeclaration n){ if(n.isAnnotationPresent(ANNOTATION_GET_MAPPING)){ return Method.GET; } if(n.isAnnotationPresent(ANNOTATION_POST_MAPPING)){ return Method.POST; } if(n.isAnnotationPresent(ANNOTATION_PUT_MAPPING)){ return Method.PUT; } if(n.isAnnotationPresent(ANNOTATION_PATCH_MAPPING)){ return Method.PATCH; } if(n.isAnnotationPresent(ANNOTATION_DELETE_MAPPING)){ return Method.DELETE; } if(n.isAnnotationPresent(ANNOTATION_REQUEST_MAPPING)){ AnnotationExpr annotationExpr = n.getAnnotationByName(ANNOTATION_REQUEST_MAPPING).get(); Optional<Expression> expressionOptional = AnnotationHelper.attr(annotationExpr, "method"); if (expressionOptional.isPresent()) { Expression expression = expressionOptional.get(); if(expression.isArrayInitializerExpr()){ NodeList<Expression> values = expression.asArrayInitializerExpr().getValues(); if(values!=null&&values.size()>0){ return Method.valueOf(values.get(0).toString().replaceAll("RequestMethod.","")); } } return Method.of(expression.toString().replaceAll("RequestMethod.","")); } } return Method.GET; }
Example 4
Source File: AnnotatedMember.java From jeddict with Apache License 2.0 | 5 votes |
static List<String> getEnumAttributes(AnnotationExpr annotationExpr, String attributeName) { List<String> values = emptyList(); Optional<Expression> expressionOpt = getAttribute(annotationExpr, attributeName); if (expressionOpt.isPresent()) { Expression expression = expressionOpt.get(); if (expression.isFieldAccessExpr()) { values = expressionOpt .map(exp -> exp.asFieldAccessExpr()) .map(exp -> exp.getNameAsString()) .map(exp -> singletonList(exp)) .orElse(emptyList()); } else if (expression.isNameExpr()) { values = expressionOpt .map(exp -> exp.asNameExpr()) .map(exp -> exp.getNameAsString()) .map(exp -> singletonList(exp)) .orElse(emptyList()); } else if (expression.isArrayInitializerExpr()) { values = new ArrayList<>(); List<Node> nodes = expression.asArrayInitializerExpr().getChildNodes(); for (Node node : nodes) { if (node instanceof NodeWithSimpleName) { values.add(((NodeWithSimpleName) node).getNameAsString()); } else { throw new UnsupportedOperationException(); } } } else { throw new UnsupportedOperationException(); } } return values; }
Example 5
Source File: AnnotatedMember.java From jeddict with Apache License 2.0 | 5 votes |
static Stream<AnnotationExplorer> getAnnotationAttributes(AnnotationExpr annotationExpr, String attributeName) { Stream<AnnotationExplorer> annotations = Stream.of(); Optional<Expression> expressionOpt = getAttribute(annotationExpr, attributeName); if (expressionOpt.isPresent()) { Expression expression = expressionOpt.get(); if (expression.isAnnotationExpr()) { annotations = expressionOpt .map(exp -> exp.asAnnotationExpr()) .map(AnnotationExplorer::new) .map(exp -> Stream.of(exp)) .orElse(Stream.of()); } else if (expression.isArrayInitializerExpr()) { List<AnnotationExplorer> values = new ArrayList<>(); List<Node> nodes = expression.asArrayInitializerExpr().getChildNodes(); for (Node node : nodes) { if (node instanceof AnnotationExpr) { AnnotationExplorer annotation = new AnnotationExplorer((AnnotationExpr) node); values.add(annotation); } else if (node instanceof Comment) { //ignore } else { throw new UnsupportedOperationException(); } } annotations = values.stream(); } else { throw new UnsupportedOperationException(); } } return annotations; }