本文整理汇总了Java中javax.lang.model.element.ExecutableElement.isVarArgs方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableElement.isVarArgs方法的具体用法?Java ExecutableElement.isVarArgs怎么用?Java ExecutableElement.isVarArgs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.ExecutableElement
的用法示例。
在下文中一共展示了ExecutableElement.isVarArgs方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findConstructor
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static boolean findConstructor(Element el, Types t, List<TypeMirror> paramTypes) {
boolean found = false;
OUTER: for (ExecutableElement ee : ElementFilter.constructorsIn(el.getEnclosedElements())) {
if (ee.isVarArgs() || ee.getParameters().size() != paramTypes.size()) {
continue;
}
Iterator<? extends VariableElement> p = ee.getParameters().iterator();
Iterator<TypeMirror> expectedType = paramTypes.iterator();
while (p.hasNext() && expectedType.hasNext()) {
if (!t.isAssignable(expectedType.next(), p.next().asType())) {
continue OUTER;
}
}
found = true;
break;
}
return found;
}
示例2: makeSignature
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public String makeSignature(ExecutableElement e, boolean full, boolean ignoreTypeParameters) {
StringBuilder result = new StringBuilder();
result.append("(");
Iterator<? extends VariableElement> iterator = e.getParameters().iterator();
while (iterator.hasNext()) {
VariableElement next = iterator.next();
TypeMirror type = next.asType();
result.append(getTypeSignature(type, full, ignoreTypeParameters));
if (iterator.hasNext()) {
result.append(", ");
}
}
if (e.isVarArgs()) {
int len = result.length();
result.replace(len - 2, len, "...");
}
result.append(")");
return result.toString();
}
示例3: ReplaceConstructorWithBuilderUI
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private ReplaceConstructorWithBuilderUI(TreePathHandle constructor, CompilationInfo info) {
this.refactoring = new ReplaceConstructorWithBuilderRefactoring(constructor);
ExecutableElement contructorElement = (ExecutableElement) constructor.resolveElement(info);
this.name = contructorElement.getSimpleName().toString();
MethodTree constTree = (MethodTree) constructor.resolve(info).getLeaf();
paramaterNames = new ArrayList<String>();
parameterTypes = new ArrayList<String>();
parameterTypeVars = new ArrayList<Boolean>();
boolean varargs = contructorElement.isVarArgs();
List<? extends VariableElement> parameterElements = contructorElement.getParameters();
List<? extends VariableTree> parameters = constTree.getParameters();
for (int i = 0; i < parameters.size(); i++) {
VariableTree var = parameters.get(i);
paramaterNames.add(var.getName().toString());
String type = contructorElement.getParameters().get(i).asType().toString();
if(varargs && i+1 == parameters.size()) {
if(var.getType().getKind() == Tree.Kind.ARRAY_TYPE) {
ArrayTypeTree att = (ArrayTypeTree) var.getType();
type = att.getType().toString();
type += "..."; //NOI18N
}
}
parameterTypes.add(type);
parameterTypeVars.add(parameterElements.get(i).asType().getKind() == TypeKind.TYPEVAR);
}
TypeElement typeEl = (TypeElement) contructorElement.getEnclosingElement();
if(typeEl.getNestingKind() != NestingKind.TOP_LEVEL) {
PackageElement packageOf = info.getElements().getPackageOf(typeEl);
builderFQN = packageOf.toString() + "." + typeEl.getSimpleName().toString();
} else {
builderFQN = typeEl.getQualifiedName().toString();
}
buildMethodName = "create" + typeEl.getSimpleName();
}
示例4: isVarargsParameter
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static boolean isVarargsParameter(CompilationInfo ci, TreePath invPath) {
if (invPath.getLeaf().getKind() != Tree.Kind.METHOD_INVOCATION) {
return false;
}
MethodInvocationTree mit = (MethodInvocationTree)invPath.getLeaf();
Element e = ci.getTrees().getElement(invPath);
if (e == null || e.getKind() != ElementKind.METHOD) {
return false;
}
ExecutableElement ee = (ExecutableElement)e;
return ee.isVarArgs() && mit.getArguments().size() == ee.getParameters().size();
}
示例5: createHtmlHeader
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static String createHtmlHeader(boolean deprecated, ExecutableElement e) {
StringBuilder sb = new StringBuilder();
sb.append("<html>");
if (deprecated) sb.append("<s>");
if (e.getKind() == ElementKind.CONSTRUCTOR) {
sb.append(e.getEnclosingElement().getSimpleName());
} else {
sb.append(e.getSimpleName());
}
if (deprecated) sb.append("</s>");
sb.append("("); // NOI18N
for(Iterator<? extends VariableElement> it = e.getParameters().iterator(); it.hasNext(); ) {
VariableElement param = it.next();
if (!it.hasNext() && e.isVarArgs() && param.asType().getKind() == TypeKind.ARRAY) {
sb.append(translateToHTML(print(((ArrayType) param.asType()).getComponentType())));
sb.append("...");
} else {
sb.append(translateToHTML(print(param.asType())));
}
sb.append(" "); // NOI18N
sb.append(param.getSimpleName());
if (it.hasNext()) {
sb.append(", "); // NOI18N
}
}
sb.append(")"); // NOI18N
if ( e.getKind() != ElementKind.CONSTRUCTOR ) {
TypeMirror rt = e.getReturnType();
if ( rt.getKind() != TypeKind.VOID ) {
sb.append(" : "); // NOI18N
sb.append(translateToHTML(print(e.getReturnType())));
}
}
return sb.toString();
}
示例6: MethodEntity
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public MethodEntity(ExecutableElement methodElement, Types typeMirror, Elements elementUtils) {
this.methodElement = methodElement;
this.returnType = methodElement.getReturnType().toString();
this.parameterElements = methodElement.getParameters();
this.isVarArgs = methodElement.isVarArgs();
this.methodName = methodElement.getSimpleName().toString();
this.exceptionTypes = methodElement.getThrownTypes();
this.typeParameterElements = methodElement.getTypeParameters();
this.classSimpleName = methodElement.getEnclosingElement().getSimpleName().toString();
this.classQualifiedName = ((TypeElement) methodElement.getEnclosingElement()).getQualifiedName().toString();
this.packageName = elementUtils.getPackageOf(methodElement).getQualifiedName().toString();
}
示例7: parameterType
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private Stream<TypeMirror> parameterType(ExecutableElement method, ExecutableType methodType, int paramIndex, boolean allowVarArgsArray) {
int paramCount = methodType.getParameterTypes().size();
if (paramIndex >= paramCount && !method.isVarArgs())
return Stream.empty();
if (paramIndex < paramCount - 1 || !method.isVarArgs())
return Stream.of(methodType.getParameterTypes().get(paramIndex));
TypeMirror varargType = methodType.getParameterTypes().get(paramCount - 1);
TypeMirror elemenType = ((ArrayType) varargType).getComponentType();
if (paramIndex >= paramCount || !allowVarArgsArray)
return Stream.of(elemenType);
return Stream.of(varargType, elemenType);
}
示例8: generateRequestBuilderOverride
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Generates an override of a particular method in {@code com.bumptech.glide.RequestBuilder} that
* returns {@code com.bumptech.glide.RequestBuilder} so that it returns our generated subclass
* instead.
*/
private MethodSpec generateRequestBuilderOverride(ExecutableElement methodToOverride) {
// We've already verified that this method returns a RequestBuilder and RequestBuilders have
// exactly one type argument, so this is safe unless those assumptions change.
TypeMirror typeArgument =
((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);
ParameterizedTypeName generatedRequestBuilderOfType =
ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));
MethodSpec.Builder builder = ProcessorUtil.overriding(methodToOverride)
.returns(generatedRequestBuilderOfType)
.addCode(CodeBlock.builder()
.add("return ($T) super.$N(",
generatedRequestBuilderOfType, methodToOverride.getSimpleName())
.add(FluentIterable.from(methodToOverride.getParameters())
.transform(new Function<VariableElement, String>() {
@Override
public String apply(VariableElement input) {
return input.getSimpleName().toString();
}
})
.join(Joiner.on(", ")))
.add(");\n")
.build());
for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
builder = builder.addAnnotation(AnnotationSpec.get(mirror));
}
if (methodToOverride.isVarArgs()) {
builder = builder
.addModifiers(Modifier.FINAL)
.addAnnotation(SafeVarargs.class)
.addAnnotation(
AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "varargs")
.build());
}
return builder.build();
}
示例9: createHtmlHeader
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/** Creates HTML display name of the Executable element */
private String createHtmlHeader(CompilationInfo info, ExecutableElement e, boolean isDeprecated,boolean isInherited, boolean fqn, TypeElement overridenFrom) {
StringBuilder sb = new StringBuilder();
if ( isDeprecated ) {
sb.append("<s>"); // NOI18N
}
if( isInherited ) {
sb.append( "<font color=" + ui.getInheritedColor() + ">" ); // NOI18N
}
Name name = e.getKind() == ElementKind.CONSTRUCTOR ? e.getEnclosingElement().getSimpleName() : e.getSimpleName();
sb.append(Utils.escape(name.toString()));
if ( isDeprecated ) {
sb.append("</s>"); // NOI18N
}
sb.append("("); // NOI18N
List<? extends VariableElement> params = e.getParameters();
for( Iterator<? extends VariableElement> it = params.iterator(); it.hasNext(); ) {
VariableElement param = it.next();
sb.append( "<font color=" + ui.getTypeColor() + ">" ); // NOI18N
final boolean vararg = !it.hasNext() && e.isVarArgs();
sb.append(printArg(info, param.asType(),vararg, fqn));
sb.append("</font>"); // NOI18N
sb.append(" "); // NOI18N
sb.append(Utils.escape(param.getSimpleName().toString()));
if ( it.hasNext() ) {
sb.append(", "); // NOI18N
}
}
sb.append(")"); // NOI18N
if ( e.getKind() != ElementKind.CONSTRUCTOR ) {
TypeMirror rt = e.getReturnType();
if ( rt.getKind() != TypeKind.VOID ) {
sb.append(" : "); // NOI18N
sb.append( "<font color=" + ui.getTypeColor() + ">" ); // NOI18N
sb.append(print(info, e.getReturnType(), fqn));
sb.append("</font>"); // NOI18N
}
}
if (!isInherited && overridenFrom != null) {
sb.append(" ↑ "); //NOI18N
sb.append(print(info, overridenFrom.asType(), fqn));
}
return sb.toString();
}
示例10: visitMethodOrNew
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private List<? extends TypeMirror> visitMethodOrNew(Tree node, Object p, List<? extends ExpressionTree> args,
ExecutableType execType) {
List<TypeMirror> proposed = new ArrayList<TypeMirror>();
int[] index = new int[1];
if (theExpression == null) {
List<ExecutableElement> methods = org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(info, getCurrentPath(), proposed, index);
if (methods.isEmpty()) {
return null;
} else {
initExpression(args.get(index[0]));
return proposed;
}
} else {
Element el = info.getTrees().getElement(getCurrentPath());
if (el == null) {
return null;
}
if (theExpression.getLeaf() != node &&
(el.getKind() == ElementKind.METHOD || el.getKind() == ElementKind.CONSTRUCTOR)) {
int argIndex = args.indexOf(theExpression.getLeaf());
this.parentExecutable = getCurrentPath();
TypeMirror argm;
ExecutableElement ee = (ExecutableElement)el;
boolean allowEntireVararg = false;
boolean varargPosition = false;
if (ee.isVarArgs() && (varargPosition = argIndex >= ee.getParameters().size() -1)) {
// all parameters after the vararg will be reported at the varargs position.
allowEntireVararg = argIndex == ee.getParameters().size() -1;
argIndex = ee.getParameters().size() - 1;
if (allowEntireVararg) {
this.argIndex = ee.getParameters().size() - 1;
} else {
this.argIndex = ee.getParameters().size();
}
} else {
this.argIndex = argIndex;
}
if (execType != null) {
// handle varargs arguments; if the argtype is a vararg, then either array of the type (reported in argm),
// or the component can be passed.
argm = execType.getParameterTypes().get(argIndex);
// XXX hack
argm = decapture(argm);
} else {
argm = ((ExecutableElement)el).getParameters().get(argIndex).asType();
}
if (argm == null || argm.getKind() == TypeKind.ERROR) {
targetArgType = null;
return null;
}
if (varargPosition && argm.getKind() == TypeKind.ARRAY) {
TypeMirror ctype = ((ArrayType)argm).getComponentType();
if (allowEntireVararg) {
targetArgType = argm;
return Arrays.asList(new TypeMirror[] { argm, ctype });
}
argm = ctype;
}
targetArgType = argm;
return Collections.singletonList(argm);
}
}
return null;
}
示例11: parse
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
static Value parse(Element element, ProcessingEnvironment processingEnv) {
Messager messager = processingEnv.getMessager();
if (element.getKind() != ElementKind.METHOD) {
messager.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"Value specs must be methods, found %s: %s",
element.getKind().toString().toLowerCase(), element),
element);
return null;
}
ExecutableElement methodElement = (ExecutableElement) element;
if (!isValueSpecMarker(methodElement.getReturnType(), processingEnv)) {
messager.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"Value specs must return dataenum_case, found %s: %s",
methodElement.getReturnType(), element),
element);
return null;
}
if (methodElement.getTypeParameters().size() != 0) {
messager.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"Type parameters must be specified on the top-level interface, found: %s", element),
element);
return null;
}
if (methodElement.isVarArgs()) {
messager.printMessage(
Diagnostic.Kind.ERROR,
String.format("Vararg parameters not permitted: %s", element),
element);
return null;
}
List<Parameter> parameters = new ArrayList<>();
for (VariableElement parameterElement : methodElement.getParameters()) {
String parameterName = parameterElement.getSimpleName().toString();
TypeName parameterType = TypeName.get(parameterElement.asType());
boolean nullable = false;
for (AnnotationMirror annotation : parameterElement.getAnnotationMirrors()) {
if (isNullableAnnotation(annotation)) {
nullable = true;
break;
}
}
parameters.add(new Parameter(parameterName, parameterType, nullable));
}
String valueSimpleName = methodElement.getSimpleName().toString();
return new Value(valueSimpleName, parameters);
}