use of org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.VariableDeclarationStatement in project camel by apache.
the class CamelJavaParserHelper method findFieldInBlock.
@SuppressWarnings("unchecked")
private static FieldSource<JavaClassSource> findFieldInBlock(JavaClassSource clazz, Block block, String fieldName) {
for (Object statement : block.statements()) {
// try local statements first in the block
if (statement instanceof VariableDeclarationStatement) {
final Type type = ((VariableDeclarationStatement) statement).getType();
for (Object obj : ((VariableDeclarationStatement) statement).fragments()) {
if (obj instanceof VariableDeclarationFragment) {
VariableDeclarationFragment fragment = (VariableDeclarationFragment) obj;
SimpleName name = fragment.getName();
if (name != null && fieldName.equals(name.getIdentifier())) {
return new StatementFieldSource(clazz, fragment, type);
}
}
}
}
// okay the field may be burried inside an anonymous inner class as a field declaration
// outside the configure method, so lets go back to the parent and see what we can find
ASTNode node = block.getParent();
if (node instanceof MethodDeclaration) {
node = node.getParent();
}
if (node instanceof AnonymousClassDeclaration) {
List declarations = ((AnonymousClassDeclaration) node).bodyDeclarations();
for (Object dec : declarations) {
if (dec instanceof FieldDeclaration) {
FieldDeclaration fd = (FieldDeclaration) dec;
final Type type = fd.getType();
for (Object obj : fd.fragments()) {
if (obj instanceof VariableDeclarationFragment) {
VariableDeclarationFragment fragment = (VariableDeclarationFragment) obj;
SimpleName name = fragment.getName();
if (name != null && fieldName.equals(name.getIdentifier())) {
return new StatementFieldSource(clazz, fragment, type);
}
}
}
}
}
}
}
return null;
}
Aggregations