blob: 51744c7eacc0f0cacb84c0155f9787a09862a8df [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012 NumberFour AG
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* NumberFour AG - initial API and Implementation (Alex Panchenko)
*******************************************************************************/
package org.eclipse.dltk.javascript.typeinfo;
import java.util.List;
import org.eclipse.dltk.annotations.Nullable;
import org.eclipse.dltk.javascript.typeinference.ReferenceLocation;
import org.eclipse.dltk.javascript.typeinfo.IModelBuilder.IElement;
import org.eclipse.dltk.javascript.typeinfo.model.ParameterKind;
public class RUtils {
public static ReferenceLocation locationOf(IRElement element) {
final Object source = element.getSource();
if (source instanceof IElement) {
return ((IElement) source).getLocation();
} else {
return null;
}
}
/**
* Returns the parameter matching the specified position (e.g. it can return
* vararg parameter if position exceeds the number of declared parameters)
* or <code>null</code> if position is not correct.
*/
@Nullable
public static IRParameter getParameterFor(IRMethod method, int position) {
if (position < 0) {
return null;
}
final List<IRParameter> params = method.getParameters();
if (position < params.size()) {
return params.get(position);
} else if (!params.isEmpty()) {
final IRParameter last = params.get(params.size() - 1);
if (last.getKind() == ParameterKind.VARARGS) {
return last;
}
}
return null;
}
}