use of com.google.devtools.j2objc.ast.SourcePosition in project j2objc by google.
the class TreeConverter method convertMemberReference.
private TreeNode convertMemberReference(JCTree.JCMemberReference node) {
Element element = node.sym;
SourcePosition pos = getPosition(node);
if (ElementUtil.isConstructor(element)) {
CreationReference newNode = new CreationReference();
convertMethodReference(node, newNode);
return newNode.setType(Type.newType(nameType(node.expr)));
}
if (node.hasKind(JCTree.JCMemberReference.ReferenceKind.SUPER)) {
SuperMethodReference newNode = new SuperMethodReference();
convertMethodReference(node, newNode);
if (node.getQualifierExpression().getKind() == Kind.IDENTIFIER) {
// super::foo
return newNode;
} else {
// Qualifier expression is <name>."super", so it's always a JCFieldAccess.
JCTree.JCFieldAccess expr = (JCTree.JCFieldAccess) node.getQualifierExpression();
return newNode.setQualifier(convertSimpleName(nameSymbol(expr.selected), expr.type, getPosition(expr.selected)));
}
}
if (node.hasKind(JCTree.JCMemberReference.ReferenceKind.UNBOUND) || node.hasKind(JCTree.JCMemberReference.ReferenceKind.STATIC)) {
TypeMethodReference newNode = new TypeMethodReference();
convertMethodReference(node, newNode);
return newNode.setName(convertSimpleName(node.sym, node.type, pos)).setType(convertType(node.type, pos, false));
}
ExpressionMethodReference newNode = new ExpressionMethodReference();
convertMethodReference(node, newNode);
return newNode.setName(convertSimpleName(node.sym, node.type, pos)).setExpression((Expression) convert(node.getQualifierExpression()));
}
use of com.google.devtools.j2objc.ast.SourcePosition in project j2objc by google.
the class TreeConverter method convertSingleVariable.
private TreeNode convertSingleVariable(JCTree.JCVariableDecl node) {
VarSymbol var = node.sym;
SourcePosition pos = getPosition(node);
boolean isVarargs = (node.sym.flags() & Flags.VARARGS) > 0;
Type newType = convertType(var.asType(), pos, isVarargs);
return new SingleVariableDeclaration().setType(newType).setIsVarargs(isVarargs).setAnnotations(convertAnnotations(node.getModifiers())).setVariableElement(var).setInitializer((Expression) convert(node.getInitializer()));
}
use of com.google.devtools.j2objc.ast.SourcePosition in project j2objc by google.
the class TreeConverter method convertFieldAccess.
private TreeNode convertFieldAccess(JCTree.JCFieldAccess node) {
String fieldName = node.name.toString();
SourcePosition pos = getPosition(node);
JCTree.JCExpression selected = node.getExpression();
if (fieldName.equals("this")) {
return new ThisExpression().setQualifier((Name) convert(selected)).setTypeMirror(node.sym.asType());
}
if ("super".equals(getMemberName(selected))) {
SuperFieldAccess newNode = new SuperFieldAccess().setVariableElement((VariableElement) node.sym).setName(convertSimpleName(node.sym, node.type, pos));
if (selected.getKind() == Kind.MEMBER_SELECT) {
newNode.setQualifier((Name) convert(((JCTree.JCFieldAccess) selected).getExpression()));
}
return newNode;
}
if (node.getIdentifier().toString().equals("class")) {
return new TypeLiteral(node.type).setType((Type) convertType(selected.type, pos, false).setPosition(getPosition(node)));
}
if (selected.getKind() == Kind.IDENTIFIER && (!node.sym.getKind().isField() || ElementUtil.isConstant((VariableElement) node.sym))) {
if (selected.toString().equals("this")) {
// Just return the constant.
return new SimpleName(node.sym);
}
JCIdent ident = (JCTree.JCIdent) selected;
return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier(convertSimpleName(ident.sym, ident.type, pos)).setElement(node.sym);
}
if (selected.getKind() == Kind.MEMBER_SELECT) {
TreeNode newSelected = convertFieldAccess((JCTree.JCFieldAccess) selected).setPosition(pos);
if (newSelected.getKind() == TreeNode.Kind.QUALIFIED_NAME) {
return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier((QualifiedName) newSelected).setElement(node.sym);
}
}
if (ElementUtil.isConstant((VariableElement) node.sym) && ElementUtil.isStatic(node.sym) && !(selected.getKind() == Kind.METHOD_INVOCATION)) {
return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier((Name) convert(selected)).setElement(node.sym);
}
return new FieldAccess().setVariableElement((VariableElement) node.sym).setExpression((Expression) convert(selected)).setName(convertSimpleName(node.sym, node.type, pos).setTypeMirror(node.type));
}
use of com.google.devtools.j2objc.ast.SourcePosition in project j2objc by google.
the class TreeConverter method getPosition.
private static SourcePosition getPosition(ASTNode jdtNode) {
int startPosition = jdtNode.getStartPosition();
int length = jdtNode.getLength();
ASTNode root = jdtNode.getRoot();
if (root instanceof org.eclipse.jdt.core.dom.CompilationUnit) {
int line = ((org.eclipse.jdt.core.dom.CompilationUnit) root).getLineNumber(startPosition);
return new SourcePosition(startPosition, length, line);
} else {
return new SourcePosition(startPosition, length);
}
}
Aggregations