use of com.google.devtools.j2objc.ast.ConstructorInvocation in project j2objc by google.
the class TreeConverter method needsImplicitSuperCall.
private static boolean needsImplicitSuperCall(MethodDeclaration node) {
ExecutableElement method = node.getExecutableElement();
if (!ElementUtil.isConstructor(method)) {
return false;
}
TypeMirror superType = ElementUtil.getDeclaringClass(method).getSuperclass();
if (TypeUtil.isNone(superType)) {
// java.lang.Object supertype is null.
return false;
}
List<Statement> stmts = node.getBody().getStatements();
if (stmts.isEmpty()) {
return true;
}
Statement firstStmt = stmts.get(0);
return !(firstStmt instanceof SuperConstructorInvocation || firstStmt instanceof ConstructorInvocation);
}
use of com.google.devtools.j2objc.ast.ConstructorInvocation in project j2objc by google.
the class TreeConverter method convertConstructorInvocation.
private static TreeNode convertConstructorInvocation(org.eclipse.jdt.core.dom.ConstructorInvocation node) {
IMethodBinding binding = node.resolveConstructorBinding();
ConstructorInvocation newNode = new ConstructorInvocation().setExecutablePair(new ExecutablePair(BindingConverter.getExecutableElement(binding), BindingConverter.getType(binding))).setVarargsType(getVarargsType(binding, node.arguments()));
for (Object argument : node.arguments()) {
newNode.addArgument((Expression) convert(argument));
}
return newNode;
}
use of com.google.devtools.j2objc.ast.ConstructorInvocation in project j2objc by google.
the class TreeConverter method convertMethodInvocation.
private TreeNode convertMethodInvocation(JCTree.JCMethodInvocation node) {
JCTree.JCExpression method = node.getMethodSelect();
String methodName = getMemberName(method);
ExecutableType type = (ExecutableType) method.type;
Symbol.MethodSymbol sym = (Symbol.MethodSymbol) getMemberSymbol(method);
JCTree.JCExpression target = method.getKind() == Kind.MEMBER_SELECT ? ((JCTree.JCFieldAccess) method).selected : null;
if ("this".equals(methodName)) {
ConstructorInvocation newNode = new ConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setVarargsType(node.varargsElement);
for (JCTree.JCExpression arg : node.getArguments()) {
newNode.addArgument((Expression) convert(arg));
}
return newNode;
}
if ("super".equals(methodName)) {
SuperConstructorInvocation newNode = new SuperConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setVarargsType(node.varargsElement);
if (target != null) {
newNode.setExpression((Expression) convert(target));
}
for (JCTree.JCExpression arg : node.getArguments()) {
newNode.addArgument((Expression) convert(arg));
}
return newNode;
}
if (target != null && "super".equals(getMemberName(target))) {
SuperMethodInvocation newNode = new SuperMethodInvocation().setExecutablePair(new ExecutablePair(sym, type)).setVarargsType(node.varargsElement).setName(convertSimpleName(sym, type, getPosition(node)));
if (target.getKind() == Kind.MEMBER_SELECT) {
// foo.bar.MyClass.super.print(...):
// target: foo.bar.MyClass.super
// target.selected: foo.bar.MyClass
newNode.setQualifier((Name) convert(((JCTree.JCFieldAccess) target).selected));
}
for (JCTree.JCExpression arg : node.getArguments()) {
newNode.addArgument((Expression) convert(arg));
}
return newNode;
}
MethodInvocation newNode = new MethodInvocation();
newNode.setName(convertSimpleName(sym, type, getPosition(method)));
if (target != null) {
newNode.setExpression((Expression) convert(target));
}
for (JCTree.JCExpression arg : node.getArguments()) {
newNode.addArgument((Expression) convert(arg));
}
return newNode.setTypeMirror(node.type).setExecutablePair(new ExecutablePair(sym, type)).setVarargsType(node.varargsElement);
}
use of com.google.devtools.j2objc.ast.ConstructorInvocation in project j2objc by google.
the class InitializationNormalizer method isDesignatedConstructor.
/**
* Returns true if this is a constructor that doesn't call "this(...)". This constructors are
* skipped so initializers aren't run more than once per instance creation.
*/
public static boolean isDesignatedConstructor(MethodDeclaration node) {
if (!node.isConstructor()) {
return false;
}
Block body = node.getBody();
if (body == null) {
return false;
}
List<Statement> stmts = body.getStatements();
return (stmts.isEmpty() || !(stmts.get(0) instanceof ConstructorInvocation));
}
Aggregations