本文整理汇总了Java中javax.lang.model.element.ExecutableElement.getParameters方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableElement.getParameters方法的具体用法?Java ExecutableElement.getParameters怎么用?Java ExecutableElement.getParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.ExecutableElement
的用法示例。
在下文中一共展示了ExecutableElement.getParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMethodDeclaredByInterface
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Checks whether the interface declare given method
*
* @param trgInterface interface to be declaring the method
* @param srcMethod method to be declared
* @return {@literal true} if the method is declared by the interface, {@literal false} otherwise
*/
private static boolean isMethodDeclaredByInterface(TypeElement trgInterface, ExecutableElement srcMethod) {
List<? extends Element> enclosedElements = trgInterface.getEnclosedElements();
List<? extends VariableElement> methodParameters = srcMethod.getParameters();
for (Element enclosedElement : enclosedElements) {
if (enclosedElement instanceof ExecutableElement) {
ExecutableElement exElement = (ExecutableElement) enclosedElement;
List<? extends VariableElement> elementParameters = exElement.getParameters();
if (srcMethod.getSimpleName() != exElement.getSimpleName()
|| (methodParameters.size() != elementParameters.size())) {
continue;
}
for (int i = 0; i < methodParameters.size(); i++) {
if (!((VariableElement) methodParameters.get(i)).asType().toString().equals(
((VariableElement) elementParameters.get(i)).asType().toString())) {
continue;
}
}
return true;
}
}
return false;
}
示例2: getModeParameterCount
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
protected int getModeParameterCount(ExecutableElement method, WebParam.Mode mode) {
WebParam webParam;
int cnt = 0;
for (VariableElement param : method.getParameters()) {
webParam = param.getAnnotation(WebParam.class);
if (webParam != null) {
if (webParam.header())
continue;
if (isEquivalentModes(mode, webParam.mode()))
cnt++;
} else {
if (isEquivalentModes(mode, WebParam.Mode.IN)) {
cnt++;
}
}
}
return cnt;
}
示例3: asMemberOf
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Resolves a {@link VariableElement} parameter to a method or constructor based on the given
* container, or a member of a class. For parameters to a method or constructor, the variable's
* enclosing element must be a supertype of the container type. For example, given a
* {@code container} of type {@code Set<String>}, and a variable corresponding to the {@code E e}
* parameter in the {@code Set.add(E e)} method, this will return a TypeMirror for {@code String}.
*/
public static TypeMirror asMemberOf(Types types, DeclaredType container,
VariableElement variable) {
if (variable.getKind().equals(ElementKind.PARAMETER)) {
ExecutableElement methodOrConstructor =
MoreElements.asExecutable(variable.getEnclosingElement());
ExecutableType resolvedMethodOrConstructor = MoreTypes.asExecutable(
types.asMemberOf(container, methodOrConstructor));
List<? extends VariableElement> parameters = methodOrConstructor.getParameters();
List<? extends TypeMirror> parameterTypes =
resolvedMethodOrConstructor.getParameterTypes();
checkState(parameters.size() == parameterTypes.size());
for (int i = 0; i < parameters.size(); i++) {
// We need to capture the parameter type of the variable we're concerned about,
// for later printing. This is the only way to do it since we can't use
// types.asMemberOf on variables of methods.
if (parameters.get(i).equals(variable)) {
return parameterTypes.get(i);
}
}
throw new IllegalStateException("Could not find variable: " + variable);
} else {
return types.asMemberOf(container, variable);
}
}
示例4: TimedMethodModel
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
TimedMethodModel(ModelContext ctx, ExecutableElement method, TimeThis annotation) throws ModelException {
this.annotation = annotation;
this.method = method;
this.scope = getScope(method);
String msg = "method " + method.getSimpleName() + " in " + method.getEnclosingElement();
List<? extends VariableElement> params = method.getParameters();
if (params.isEmpty()) {
throw new ModelException(msg + ": expected at least one " + ProcessingContext.class.getCanonicalName() + " parameter");
}
boolean first = true;
for (VariableElement param : params) {
TypeMirror paramType = param.asType();
if (first) {
if (!ctx.isProcessingContext(paramType)) {
throw new ModelException(msg + ": first parameter must be of type " + ProcessingContext.class.getCanonicalName());
}
first = false;
continue;
}
checkPublicType(ctx, paramType, method, false, msg);
}
TypeMirror returnType = method.getReturnType();
checkPublicType(ctx, returnType, method, true, msg);
}
示例5: jniMethodName
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
protected final String jniMethodName(ExecutableElement method, String cname,
boolean longName)
throws TypeSignature.SignatureException {
String res = "Java_" + cname + "_" + method.getSimpleName();
if (longName) {
TypeMirror mType = types.erasure(method.getReturnType());
List<? extends VariableElement> params = method.getParameters();
List<TypeMirror> argTypes = new ArrayList<>();
for (VariableElement param: params) {
argTypes.add(types.erasure(param.asType()));
}
res = res + "__";
for (TypeMirror t: argTypes) {
String tname = t.toString();
TypeSignature newTypeSig = new TypeSignature(elems);
String sig = newTypeSig.getTypeSignature(tname);
res = res + nameToIdentifier(sig);
}
}
return res;
}
示例6: completeParamName
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void completeParamName(DocTreePath tag, String prefix, int substitutionOffset, JavadocContext jdctx) {
if (EXECUTABLE.contains(jdctx.commentFor.getKind())) {
List<? extends DocTree> blockTags = jdctx.comment.getBlockTags();
ExecutableElement method = (ExecutableElement) jdctx.commentFor;
for (VariableElement param : method.getParameters()) {
String name = param.getSimpleName().toString();
if (!containsParam(blockTags, name) && name.startsWith(prefix)) {
items.add(JavadocCompletionItem.createNameItem(name, substitutionOffset));
}
}
completeTypeVarName(jdctx.commentFor, prefix, substitutionOffset);
} else if (jdctx.commentFor.getKind().isClass() || jdctx.commentFor.getKind().isInterface()) {
completeTypeVarName(jdctx.commentFor, prefix, substitutionOffset);
}
}
示例7: JavadocExecutableItem
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public JavadocExecutableItem(CompletionItem jmethod,
ExecutableElement ee, int substitutionOffset) {
this.delegate = jmethod;
this.substitutionOffset = substitutionOffset;
this.name = ee.getKind() == ElementKind.METHOD
? ee.getSimpleName()
: ee.getEnclosingElement().getSimpleName();
List<? extends VariableElement> params = ee.getParameters();
this.paramTypes = new String[params.size()];
int i = 0;
for (VariableElement p : params) {
TypeMirror asType = p.asType();
this.paramTypes[i++] = resolveTypeName(asType, ee.isVarArgs()).toString();
}
}
示例8: getMethodParams
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private List<ParamInfo> getMethodParams(Element classElement) {
List<ParamInfo> methodParams = new LinkedList<ParamInfo>();
ExecutableElement methodElement = (ExecutableElement) classElement;
for (VariableElement methodParam : methodElement.getParameters()) {
try {
String name = getParamName(methodParam);
ParamInfo.Type type = getParamType(methodParam);
String clsName = getParamClsName(methodParam);
methodParams.add(new ParamInfo(name, type, clsName));
} catch (IllegalArgumentException ex) {
// Do nothing, thrown when we are missing some info.
}
}
return methodParams;
}
示例9: getMethodParameters
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private String getMethodParameters(ExecutableElement method) {
List<? extends Element> parameters = method.getParameters();
List<String> names = new ArrayList<>(parameters.size());
for (Element parameter : parameters) {
names.add(parameter.getSimpleName().toString());
}
return StringUtils.join(names, PARAMETER_SEPARATOR);
}
示例10: build
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public PropertyInfo build(Element element, Property property)
throws ReactPropertyException {
String methodName = element.getSimpleName().toString();
ExecutableElement method = (ExecutableElement) element;
List<? extends VariableElement> parameters = method.getParameters();
if (parameters.size() != getArgCount(mClassInfo.getType(), property)) {
throw new ReactPropertyException("Wrong number of args", element);
}
int index = 0;
if (mClassInfo.getType() == SettableType.VIEW_MANAGER) {
TypeMirror mirror = parameters.get(index++).asType();
if (!mTypes.isSubtype(mirror, mElements.getTypeElement("android.view.View").asType())) {
throw new ReactPropertyException("First argument must be a subclass of View", element);
}
}
if (property instanceof GroupProperty) {
TypeName indexType = TypeName.get(parameters.get(index++).asType());
if (!indexType.equals(TypeName.INT)) {
throw new ReactPropertyException(
"Argument " + index + " must be an int for @ReactPropGroup",
element);
}
}
TypeName propertyType = TypeName.get(parameters.get(index++).asType());
if (!DEFAULT_TYPES.containsKey(propertyType)) {
throw new ReactPropertyException(
"Argument " + index + " must be of a supported type",
element);
}
return new PropertyInfo(methodName, propertyType, element, property);
}
示例11: getComparableParameterNames
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static List<String> getComparableParameterNames(
ExecutableElement element, boolean skipFirst) {
List<? extends VariableElement> parameters = element.getParameters();
if (skipFirst) {
parameters = parameters.subList(1, parameters.size());
}
List<String> result = new ArrayList<>(parameters.size());
for (VariableElement parameter : parameters) {
result.add(parameter.asType().toString());
}
return result;
}
示例12: MethodViewBinding
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Constructor
* @author leibing
* @createTime 2017/3/2
* @lastModify 2017/3/2
* @param element 注解元素
* @return
*/
public MethodViewBinding(Element element) throws IllegalArgumentException {
// 注解元素
mElement = (ExecutableElement) element;
// 点击事件注解
OnClick click = element.getAnnotation(OnClick.class);
// id集合
mIds = click.value();
// 方法名
mMethodName = element.getSimpleName().toString();
// 参数
List<? extends VariableElement> parameters = mElement.getParameters();
if (parameters.size() > 1) {
// 参数不能超过1个
throw new IllegalArgumentException(
String.format("The method annotated with @%s must less two parameters", OnClick.class.getSimpleName()));
}
if (parameters.size() == 1) {
// 如果有参数必须是View类型
VariableElement variableElement = parameters.get(0);
if (!variableElement.asType().toString().equals(ProxyClass.VIEW.toString())) {
throw new IllegalArgumentException(
String.format("The method parameter must be %s type", ProxyClass.VIEW.toString()));
}
mParameterExit = true;
mParameterName = variableElement.getSimpleName().toString();
}
}
示例13: isValidMethod
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* @return true if it is a valid method to inplement, false otherwise
*/
private boolean isValidMethod(ExecutableElement method) {
boolean error = true;
List<? extends VariableElement> methodParameters = method.getParameters();
if (!methodParameters.isEmpty()) {
this.processorUtil.error(method, "Methods inside AutoJackson classes should not have method parameters.");
error = false;
}
List<? extends TypeParameterElement> methodTypeParameters = method.getTypeParameters();
if (!methodTypeParameters.isEmpty()) {
this.processorUtil.error(method, "Methods inside AutoJackson methods should not have type parameters.");
error = false;
}
return error;
}
示例14: signature
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
String signature(ExecutableElement e) {
StringBuilder sb = new StringBuilder("(");
String sep = "";
for (VariableElement p: e.getParameters()) {
sb.append(sep);
sb.append(types.erasure(p.asType()).toString());
sep = ",";
}
sb.append(")");
return sb.toString();
}
示例15: verifyImplAnnotations
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
protected void verifyImplAnnotations(TypeElement d) {
for (ExecutableElement method : ElementFilter.methodsIn(d.getEnclosedElements())) {
checkForInvalidImplAnnotation(method, WebMethod.class);
checkForInvalidImplAnnotation(method, Oneway.class);
checkForInvalidImplAnnotation(method, WebResult.class);
for (VariableElement param : method.getParameters()) {
checkForInvalidImplAnnotation(param, WebParam.class);
}
}
}