use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TreeConverter method convertAssignOp.
private TreeNode convertAssignOp(JCTree.JCAssignOp node) {
Assignment newNode = new Assignment();
String operatorName = node.getOperator().getSimpleName().toString() + "=";
return newNode.setOperator(Assignment.Operator.fromJdtOperatorName(operatorName)).setLeftHandSide((Expression) convert(node.getVariable())).setRightHandSide((Expression) convert(node.getExpression()));
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TreeConverter method convertAnnotation.
private TreeNode convertAnnotation(JCTree.JCAnnotation node) {
List<JCTree.JCExpression> args = node.getArguments();
String annotationName = node.getAnnotationType().toString();
boolean isPropertyAnnotation = annotationName.equals(Property.class.getSimpleName()) || annotationName.equals(Property.class.getName());
Annotation newNode;
if (isPropertyAnnotation) {
newNode = new PropertyAnnotation().setAnnotationMirror(node.attribute);
if (!args.isEmpty()) {
for (String attr : ElementUtil.parsePropertyAttribute(node.attribute)) {
((PropertyAnnotation) newNode).addAttribute(attr);
}
}
} else if (args.isEmpty()) {
newNode = new MarkerAnnotation().setAnnotationMirror(node.attribute);
} else if (args.size() == 1) {
JCTree.JCAssign assign = (JCTree.JCAssign) args.get(0);
newNode = new SingleMemberAnnotation().setValue((Expression) convert(assign.rhs));
} else {
NormalAnnotation normalAnn = new NormalAnnotation();
for (JCTree.JCExpression obj : node.getArguments()) {
JCTree.JCAssign assign = (JCTree.JCAssign) obj;
Symbol sym = ((JCTree.JCIdent) assign.lhs).sym;
MemberValuePair memberPair = new MemberValuePair().setName(convertSimpleName(sym, sym.asType(), getPosition(assign.lhs))).setValue((Expression) convert(assign.rhs));
normalAnn.addValue(memberPair);
}
newNode = normalAnn;
}
return newNode.setAnnotationMirror(node.attribute).setTypeName((Name) convert(node.getAnnotationType()));
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TreeConverter method convertNewArray.
private TreeNode convertNewArray(JCTree.JCNewArray node) {
ArrayCreation newNode = new ArrayCreation();
List<Expression> dimensions = new ArrayList<>();
for (JCTree.JCExpression dimension : node.getDimensions()) {
dimensions.add((Expression) convert(dimension));
}
javax.lang.model.type.ArrayType type = (javax.lang.model.type.ArrayType) node.type;
if (node.getInitializers() != null) {
ArrayInitializer initializers = new ArrayInitializer(type);
for (JCTree.JCExpression initializer : node.getInitializers()) {
initializers.addExpression((Expression) convert(initializer));
}
newNode.setInitializer(initializers);
}
return newNode.setType((ArrayType) new ArrayType(type).setPosition(getPosition(node))).setDimensions(dimensions);
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TranslationUtil method createAnnotationValue.
public Expression createAnnotationValue(TypeMirror type, AnnotationValue aValue) {
Object value = aValue.getValue();
if (value == null) {
return new NullLiteral(typeUtil.getNull());
} else if (value instanceof VariableElement) {
return new SimpleName((VariableElement) value);
} else if (TypeUtil.isArray(type)) {
assert value instanceof List;
ArrayType arrayType = (ArrayType) type;
@SuppressWarnings("unchecked") List<? extends AnnotationValue> list = (List<? extends AnnotationValue>) value;
List<Expression> generatedValues = new ArrayList<>();
for (AnnotationValue elem : list) {
generatedValues.add(createAnnotationValue(arrayType.getComponentType(), elem));
}
return createObjectArray(generatedValues, arrayType);
} else if (TypeUtil.isAnnotation(type)) {
assert value instanceof AnnotationMirror;
return createAnnotation((AnnotationMirror) value);
} else if (value instanceof TypeMirror) {
return new TypeLiteral((TypeMirror) value, typeUtil);
} else {
// Boolean, Character, Number, String
return TreeUtil.newLiteral(value, typeUtil);
}
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TreeConverter method convertExpressionMethodReference.
private static TreeNode convertExpressionMethodReference(org.eclipse.jdt.core.dom.ExpressionMethodReference node) {
IMethodBinding methodBinding = node.resolveMethodBinding();
ExpressionMethodReference newNode = new ExpressionMethodReference();
Expression expression = (Expression) convert(node.getExpression());
boolean consumesFirstParam = !BindingUtil.isStatic(methodBinding) && expression instanceof Name && !ElementUtil.isVariable(((Name) expression).getElement());
convertMethodReference(node, newNode, methodBinding, consumesFirstParam);
return newNode.setName((SimpleName) TreeConverter.convert(node.getName())).setExpression(expression);
}
Aggregations