use of com.github.javaparser.ast.expr.ArrayInitializerExpr in project checker-framework by typetools.
the class StubParser method handleExpr.
/**
* Adds an annotation element (argument) to {@code builder}. The element is a Java expression.
*
* @return true if the expression was parsed and added to {@code builder}, false otherwise
*/
private boolean handleExpr(AnnotationBuilder builder, String name, Expression expr) {
ExecutableElement var = builder.findElement(name);
TypeMirror expected = var.getReturnType();
TypeKind valueKind;
if (expected.getKind() == TypeKind.ARRAY) {
valueKind = ((ArrayType) expected).getComponentType().getKind();
} else {
valueKind = expected.getKind();
}
if (expr instanceof ArrayInitializerExpr) {
if (expected.getKind() != TypeKind.ARRAY) {
stubWarn("unhandled annotation attribute type: " + expr + " and expected: " + expected);
return false;
}
List<Expression> arrayExpressions = ((ArrayInitializerExpr) expr).getValues();
Object[] values = new Object[arrayExpressions.size()];
for (int i = 0; i < arrayExpressions.size(); ++i) {
values[i] = getValueOfExpressionInAnnotation(name, arrayExpressions.get(i), valueKind);
if (values[i] == null) {
return false;
}
}
builder.setValue(name, values);
} else {
Object value = getValueOfExpressionInAnnotation(name, expr, valueKind);
if (value == null) {
return false;
}
if (expected.getKind() == TypeKind.ARRAY) {
Object[] valueArray = { value };
builder.setValue(name, valueArray);
} else {
builderSetValue(builder, name, value);
}
}
return true;
}
use of com.github.javaparser.ast.expr.ArrayInitializerExpr in project javaparser by javaparser.
the class TreeVisitorTest method issue743ConcurrentModificationProblem.
@Test
public void issue743ConcurrentModificationProblem() {
Expression expression = JavaParser.parseExpression("new int[]{1,2,3,4}");
StringBuilder result = new StringBuilder();
TreeVisitor visitor = new TreeVisitor() {
@Override
public void process(Node node) {
if (node instanceof IntegerLiteralExpr) {
node.getParentNode().ifPresent(parent -> ((ArrayInitializerExpr) parent).getValues().add(new IntegerLiteralExpr("1")));
}
result.append("<").append(node).append("> ");
}
};
visitor.visitPreOrder(expression);
System.out.println(result);
}
Aggregations