001/* 002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 */ 009 010package org.eclipse.golo.compiler.ir; 011 012import org.eclipse.golo.runtime.OperatorType; 013import org.eclipse.golo.compiler.parser.GoloASTNode; 014 015public class MethodInvocation extends AbstractInvocation { 016 017 private boolean nullSafeGuarded = false; 018 019 MethodInvocation(String name) { 020 super(name); 021 } 022 023 @Override 024 public MethodInvocation ofAST(GoloASTNode node) { 025 super.ofAST(node); 026 return this; 027 } 028 029 public void setNullSafeGuarded(boolean nullSafeGuarded) { 030 this.nullSafeGuarded = nullSafeGuarded; 031 } 032 033 public boolean isNullSafeGuarded() { 034 return nullSafeGuarded; 035 } 036 037 public MethodInvocation nullSafe(boolean v) { 038 setNullSafeGuarded(v); 039 return this; 040 } 041 042 public MethodInvocation nullSafe() { 043 return nullSafe(true); 044 } 045 046 public BinaryOperation on(Object target) { 047 return Builders.binaryOperation(OperatorType.METHOD_CALL) 048 .left(ExpressionStatement.of(target)) 049 .right(this); 050 } 051 052 @Override 053 public MethodInvocation withArgs(Object... args) { 054 super.withArgs(args); 055 return this; 056 } 057 058 @Override 059 public void accept(GoloIrVisitor visitor) { 060 visitor.visitMethodInvocation(this); 061 } 062}