use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class SwitchRewriter method fixStringValue.
private void fixStringValue(SwitchStatement node) {
Expression expr = node.getExpression();
TypeMirror type = expr.getTypeMirror();
if (!typeUtil.isString(type)) {
return;
}
ArrayType arrayType = typeUtil.getArrayType(type);
ArrayInitializer arrayInit = new ArrayInitializer(arrayType);
int idx = 0;
for (Statement stmt : node.getStatements()) {
if (stmt instanceof SwitchCase) {
SwitchCase caseStmt = (SwitchCase) stmt;
if (!caseStmt.isDefault()) {
arrayInit.addExpression(TreeUtil.remove(caseStmt.getExpression()));
caseStmt.setExpression(NumberLiteral.newIntLiteral(idx++, typeUtil));
}
}
}
TypeMirror intType = typeUtil.getInt();
FunctionElement indexOfFunc = new FunctionElement("JreIndexOfStr", intType, null).addParameters(type, arrayType, intType);
FunctionInvocation invocation = new FunctionInvocation(indexOfFunc, intType);
invocation.addArgument(TreeUtil.remove(expr)).addArgument(arrayInit).addArgument(NumberLiteral.newIntLiteral(idx, typeUtil));
node.setExpression(invocation);
}
use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class TranslationUtil method createAnnotation.
public Expression createAnnotation(AnnotationMirror annotationMirror) {
DeclaredType type = annotationMirror.getAnnotationType();
TypeElement typeElem = (TypeElement) type.asElement();
FunctionElement element = new FunctionElement("create_" + nameTable.getFullName(typeElem), type, typeElem);
FunctionInvocation invocation = new FunctionInvocation(element, type);
Map<? extends ExecutableElement, ? extends AnnotationValue> values = typeUtil.elementUtil().getElementValuesWithDefaults(annotationMirror);
for (ExecutableElement member : ElementUtil.getSortedAnnotationMembers(typeElem)) {
TypeMirror valueType = member.getReturnType();
element.addParameters(valueType);
invocation.addArgument(createAnnotationValue(valueType, values.get(member)));
}
return invocation;
}
Aggregations