本文整理汇总了Java中javax.lang.model.element.ExecutableElement.getTypeParameters方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableElement.getTypeParameters方法的具体用法?Java ExecutableElement.getTypeParameters怎么用?Java ExecutableElement.getTypeParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.ExecutableElement
的用法示例。
在下文中一共展示了ExecutableElement.getTypeParameters方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processTypeParameters
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private TypeExtractor processTypeParameters(ExecutableElement method, EncodedElement.Builder builder) {
boolean isStatic = method.getModifiers().contains(Modifier.STATIC);
TypeExtractor typesReader = isStatic
? new TypeExtractor(types, method)
: this.typesReader;
for (TypeParameterElement p : method.getTypeParameters()) {
String name = p.getSimpleName().toString();
ImmutableList<Defined> bounds = typesReader.getDefined(p.getBounds());
if (!isStatic) {
typesReader = typesReader.withParameter(name, bounds);
}
builder.addTypeParams(new EncodedElement.TypeParam.Builder()
.name(name)
.addAllBounds(bounds)
.build());
}
builder.typeParameters(typesReader.parameters);
return typesReader;
}
示例2: paramElementFor
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static Element paramElementFor(Element methodOrClass, ParamTree ptag) {
ElementKind kind = methodOrClass.getKind();
List<? extends Element> params = Collections.emptyList();
if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
ExecutableElement ee = (ExecutableElement) methodOrClass;
params = ptag.isTypeParameter()
? ee.getTypeParameters()
: ee.getParameters();
} else if (kind.isClass() || kind.isInterface()) {
TypeElement te = (TypeElement) methodOrClass;
params = te.getTypeParameters();
}
for (Element param : params) {
if (param.getSimpleName().contentEquals(ptag.getName().getName())) {
return param;
}
}
return null;
}
示例3: overriding
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
static MethodSpec.Builder overriding(ExecutableElement method) {
String methodName = method.getSimpleName().toString();
MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
.addAnnotation(Override.class);
Set<Modifier> modifiers = method.getModifiers();
modifiers = new LinkedHashSet<>(modifiers);
modifiers.remove(Modifier.ABSTRACT);
Modifier defaultModifier = null;
// Modifier.DEFAULT doesn't exist until Java 8.
try {
defaultModifier = Modifier.valueOf("DEFAULT");
} catch (IllegalArgumentException e) {
// Ignored.
}
modifiers.remove(defaultModifier);
builder = builder.addModifiers(modifiers);
for (TypeParameterElement typeParameterElement : method.getTypeParameters()) {
TypeVariable var = (TypeVariable) typeParameterElement.asType();
builder = builder.addTypeVariable(TypeVariableName.get(var));
}
builder = builder.returns(TypeName.get(method.getReturnType()))
.addParameters(getParameters(method))
.varargs(method.isVarArgs());
for (TypeMirror thrownType : method.getThrownTypes()) {
builder = builder.addException(TypeName.get(thrownType));
}
return builder;
}
示例4: writeMainMethod
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void writeMainMethod(Writer writer, TypeElement type, ExecutableElement executable) throws IOException {
writer.write("public " + executable.getReturnType().toString() + " " + executable.getSimpleName());
writer.write("(");
String pa = "";
List<TypeParameterElement> types = (List<TypeParameterElement>) executable.getTypeParameters();
int size = executable.getParameters().size();
for (int i = 0; i < size; i++) {
pa += types.get(i).asType().toString() + " " + executable.getParameters().get(i).getSimpleName() + " ";
}
writer.write(pa);
writer.write(")");
writeStartBody(writer);
pa = "";
for (int i = 0; i < size; i++) {
pa += " " + executable.getParameters().get(i).getSimpleName() + " ";
}
if (executable.getReturnType().toString().equals("void")) {
writer.write("Runnable _runnable = new Runnable() {" +
" @Override " + "public void run() {" + type.getSimpleName().toString() + "_.super." + executable.getSimpleName() + "(" + pa + ");" +
" }" +
" };");
writer.write("ThreadGeny.run(_runnable);");
} else {
throw new RuntimeException("method must be void returnType");
}
writeEndBody(writer);
}
示例5: 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();
}
示例6: 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;
}
示例7: generateStaticMethodEquivalentForRequestOptionsStaticMethod
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private MethodAndStaticVar generateStaticMethodEquivalentForRequestOptionsStaticMethod(
ExecutableElement staticMethod) {
boolean memoize = memoizeStaticMethodFromArguments(staticMethod);
String staticMethodName = staticMethod.getSimpleName().toString();
String equivalentInstanceMethodName =
getInstanceMethodNameFromStaticMethodName(staticMethodName);
MethodSpec.Builder methodSpecBuilder =
MethodSpec.methodBuilder(staticMethodName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addJavadoc(processorUtil.generateSeeMethodJavadoc(staticMethod))
.returns(glideOptionsName);
List<? extends VariableElement> parameters = staticMethod.getParameters();
String createNewOptionAndCall = "new $T().$N(";
if (!parameters.isEmpty()) {
for (VariableElement parameter : parameters) {
methodSpecBuilder.addParameter(getParameterSpec(parameter));
createNewOptionAndCall += parameter.getSimpleName().toString();
// use the Application Context to avoid memory leaks.
if (memoize && isAndroidContext(parameter)) {
createNewOptionAndCall += ".getApplicationContext()";
}
createNewOptionAndCall += ", ";
}
createNewOptionAndCall =
createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2);
}
createNewOptionAndCall += ")";
FieldSpec requiredStaticField = null;
if (memoize) {
// Generates code that looks like:
// if (GlideOptions.<methodName> == null) {
// GlideOptions.<methodName> = new GlideOptions().<methodName>().autoClone()
// }
// Mix in an incrementing unique id to handle method overloading.
String staticVariableName = staticMethodName + nextStaticFieldUniqueId++;
requiredStaticField = FieldSpec.builder(glideOptionsName, staticVariableName)
.addModifiers(Modifier.PRIVATE, Modifier.STATIC)
.build();
methodSpecBuilder.beginControlFlow(
"if ($T.$N == null)", glideOptionsName, staticVariableName)
.addStatement("$T.$N =\n" + createNewOptionAndCall + ".$N",
glideOptionsName, staticVariableName, glideOptionsName, equivalentInstanceMethodName,
"autoClone()")
.endControlFlow()
.addStatement("return $T.$N", glideOptionsName, staticVariableName);
} else {
// Generates code that looks like:
// return new GlideOptions().<methodName>()
methodSpecBuilder.addStatement(
"return " + createNewOptionAndCall, glideOptionsName, equivalentInstanceMethodName);
}
List<? extends TypeParameterElement> typeParameters = staticMethod.getTypeParameters();
for (TypeParameterElement typeParameterElement : typeParameters) {
methodSpecBuilder.addTypeVariable(
TypeVariableName.get(typeParameterElement.getSimpleName().toString()));
}
return new MethodAndStaticVar(methodSpecBuilder.build(), requiredStaticField);
}
示例8: generateStaticMethodEquivalentForRequestOptionsStaticMethod
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private MethodAndStaticVar generateStaticMethodEquivalentForRequestOptionsStaticMethod(
ExecutableElement staticMethod) {
boolean memoize = memoizeStaticMethodFromArguments(staticMethod);
String staticMethodName = staticMethod.getSimpleName().toString();
String equivalentInstanceMethodName =
getInstanceMethodNameFromStaticMethodName(staticMethodName);
MethodSpec.Builder methodSpecBuilder =
MethodSpec.methodBuilder(staticMethodName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addJavadoc(processorUtil.generateSeeMethodJavadoc(staticMethod))
.returns(glideOptionsName);
List<? extends VariableElement> parameters = staticMethod.getParameters();
StringBuilder createNewOptionAndCall = new StringBuilder("new $T().$N(");
if (!parameters.isEmpty()) {
methodSpecBuilder.addParameters(ProcessorUtil.getParameters(staticMethod));
for (VariableElement parameter : parameters) {
createNewOptionAndCall.append(parameter.getSimpleName().toString());
// use the Application Context to avoid memory leaks.
if (memoize && isAndroidContext(parameter)) {
createNewOptionAndCall.append(".getApplicationContext()");
}
createNewOptionAndCall.append(", ");
}
createNewOptionAndCall = new StringBuilder(
createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2));
}
createNewOptionAndCall.append(")");
FieldSpec requiredStaticField = null;
if (memoize) {
// Generates code that looks like:
// if (GlideOptions.<methodName> == null) {
// GlideOptions.<methodName> = new GlideOptions().<methodName>().autoClone()
// }
// Mix in an incrementing unique id to handle method overloading.
String staticVariableName = staticMethodName + nextStaticFieldUniqueId++;
requiredStaticField = FieldSpec.builder(glideOptionsName, staticVariableName)
.addModifiers(Modifier.PRIVATE, Modifier.STATIC)
.build();
methodSpecBuilder.beginControlFlow(
"if ($T.$N == null)", glideOptionsName, staticVariableName)
.addStatement("$T.$N =\n" + createNewOptionAndCall + ".$N",
glideOptionsName, staticVariableName, glideOptionsName, equivalentInstanceMethodName,
"autoClone()")
.endControlFlow()
.addStatement("return $T.$N", glideOptionsName, staticVariableName);
} else {
// Generates code that looks like:
// return new GlideOptions().<methodName>()
methodSpecBuilder.addStatement(
"return " + createNewOptionAndCall, glideOptionsName, equivalentInstanceMethodName);
}
List<? extends TypeParameterElement> typeParameters = staticMethod.getTypeParameters();
for (TypeParameterElement typeParameterElement : typeParameters) {
methodSpecBuilder.addTypeVariable(
TypeVariableName.get(typeParameterElement.getSimpleName().toString()));
}
methodSpecBuilder.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build());
return new MethodAndStaticVar(methodSpecBuilder.build(), requiredStaticField);
}
示例9: writeNewThread
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void writeNewThread(Writer writer, TypeElement type, ExecutableElement executable) throws IOException {
writer.write(String.format("public " + executable.getReturnType().toString() + " " + executable.getSimpleName()));
writer.write("(");
String pa = "";
List<TypeParameterElement> types = (List<TypeParameterElement>) executable.getTypeParameters();
int size = executable.getParameters().size();
for (int i = 0; i < size; i++) {
pa += types.get(i).asType().toString() + " " + executable.getParameters().get(i).getSimpleName() + " ";
}
writer.write(pa);
writer.write(")");
writeStartBody(writer);
pa = "";
for (int i = 0; i < size; i++) {
pa += " " + executable.getParameters().get(i).getSimpleName() + " ";
}
if (executable.getReturnType().toString().equals("void")) {
writer.write(" AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { @Override" + " public void run() {" +
" " + type.getSimpleName().toString() + "_.super." + executable.getSimpleName() + "(" + pa + ");" +
" }" +
" });");
} else {
writer.write("try {" + " return new AsyncTask<Void,Void," + executable.getReturnType().toString() + ">(){" +
" @Override " + " protected " + executable.getReturnType().toString() + " doInBackground(Void... params) {" +
" return " + type.getSimpleName().toString() + "_.super." + executable.getSimpleName() + "(" + pa + ");" + " }" +
" }.execute().get();" + " } catch (Exception e) {" +
" e.printStackTrace();" + " return null;" +
" }");
}
writeEndBody(writer);
}