use of org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.VariableDeclaration in project camel by apache.
the class CamelJavaParserHelper method extractEndpointUriFromArgument.
private static void extractEndpointUriFromArgument(String node, JavaClassSource clazz, Block block, List<ParserResult> uris, Object arg, boolean strings, boolean fields) {
if (strings) {
String uri = getLiteralValue(clazz, block, (Expression) arg);
if (!Strings.isBlank(uri)) {
int position = ((Expression) arg).getStartPosition();
// if the node is fromF or toF, then replace all %X with {{%X}} as we cannot parse that value
if ("fromF".equals(node) || "toF".equals(node)) {
uri = uri.replaceAll("\\%s", "\\{\\{\\%s\\}\\}");
uri = uri.replaceAll("\\%d", "\\{\\{\\%d\\}\\}");
uri = uri.replaceAll("\\%b", "\\{\\{\\%b\\}\\}");
}
uris.add(new ParserResult(node, position, uri));
return;
}
}
if (fields && arg instanceof SimpleName) {
FieldSource field = getField(clazz, block, (SimpleName) arg);
if (field != null) {
// find the endpoint uri from the annotation
AnnotationSource annotation = field.getAnnotation("org.apache.camel.cdi.Uri");
if (annotation == null) {
annotation = field.getAnnotation("org.apache.camel.EndpointInject");
}
if (annotation != null) {
Expression exp = (Expression) annotation.getInternal();
if (exp instanceof SingleMemberAnnotation) {
exp = ((SingleMemberAnnotation) exp).getValue();
} else if (exp instanceof NormalAnnotation) {
List values = ((NormalAnnotation) exp).values();
for (Object value : values) {
MemberValuePair pair = (MemberValuePair) value;
if ("uri".equals(pair.getName().toString())) {
exp = pair.getValue();
break;
}
}
}
String uri = CamelJavaParserHelper.getLiteralValue(clazz, block, exp);
if (!Strings.isBlank(uri)) {
int position = ((SimpleName) arg).getStartPosition();
uris.add(new ParserResult(node, position, uri));
}
} else {
// the field may be initialized using variables, so we need to evaluate those expressions
Object fi = field.getInternal();
if (fi instanceof VariableDeclaration) {
Expression exp = ((VariableDeclaration) fi).getInitializer();
String uri = CamelJavaParserHelper.getLiteralValue(clazz, block, exp);
if (!Strings.isBlank(uri)) {
// we want the position of the field, and not in the route
int position = ((VariableDeclaration) fi).getStartPosition();
uris.add(new ParserResult(node, position, uri));
}
}
}
}
}
// cannot parse it so add a failure
uris.add(new ParserResult(node, -1, arg.toString(), false));
}
Aggregations