本文整理汇总了Java中javax.lang.model.element.ExecutableElement.getReturnType方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableElement.getReturnType方法的具体用法?Java ExecutableElement.getReturnType怎么用?Java ExecutableElement.getReturnType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.ExecutableElement
的用法示例。
在下文中一共展示了ExecutableElement.getReturnType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSetter
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
protected boolean isSetter(TypeElement element, ExecutableElement x, boolean includeStatic) {
final String name = x.getSimpleName().toString();
final TypeMirror returnType = x.getReturnType();
final boolean isStatic = includeStatic && x.getParameters().size() == 2;
if (x.getParameters().size() != (isStatic ? 2 : 1)) {
return false;
}
if (isStatic && !types().isSameType(x.getParameters().get(0).asType(), element.asType())) {
return false;
}
if (!name.startsWith("set")) {
return false;
}
if (returnType.getKind().equals(TypeKind.VOID)) {
return true;
}
return x.getEnclosingElement() != null && types().isAssignable(x.getEnclosingElement().asType(), returnType);
}
示例2: replaceReturnType
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
@Override
public TypeName replaceReturnType(String currentPkg, String directParentInterface, String curClassname,
List<? extends TypeMirror> superInterfaces, TypeName superClass, ExecutableElement method) {
final TypeMirror returnType = method.getReturnType();
switch (method.getSimpleName().toString()){
case TypeCopyableFiller.NAME_COPY: {
switch (returnType.getKind()) {
case TYPEVAR: //泛型
return TypeVariableName.get(directParentInterface);
default:
return TypeName.get(returnType);
}
}
default:
return TypeName.get(returnType);
}
}
示例3: processGetters
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void processGetters() {
// Check presence !
TypeMirror listType = compilationInfo.getElements().getTypeElement(LIST_CLASS).asType();
TypeMirror mapType = compilationInfo.getElements().getTypeElement(MAP_CLASS).asType();
for (ExecutableElement m : getters) {
String n = getPropertyName(m.getSimpleName().toString());
if (allProperties.containsKey(n)) {
continue;
}
TypeMirror retType = m.getReturnType();
TypeMirror erasure = compilationInfo.getTypes().erasure(retType);
if (compilationInfo.getTypes().isAssignable(erasure, listType)) {
addListProperty(m, n);
} else if (compilationInfo.getTypes().isAssignable(erasure, mapType)) {
addMapProperty(m, n);
}
}
}
示例4: setExecutableElement
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
void setExecutableElement(ExecutableElement executableElement) {
this.executableElement = executableElement;
StringBuilder nameBuilder = new StringBuilder();
nameBuilder.append(BOLD);
nameBuilder.append(htmlName);
nameBuilder.append(BOLD_END);
nameBuilder.append('(');
List<? extends VariableElement> parameters = executableElement.getParameters();
//List<? extends TypeParameterElement> typeParameters = executableElement.getTypeParameters();
int n = parameters.size();
for (int i = 0; i < n; i++) {
if (i > 0) {
nameBuilder.append(", ");
}
//nameBuilder.append(escape(typeParameters.get(i).getSimpleName().toString()));
nameBuilder.append(escape(getTypeSimpleName(parameters.get(i).asType())));
nameBuilder.append(' ');
nameBuilder.append(PARAMETER_NAME_COLOR);
nameBuilder.append(parameters.get(i).getSimpleName());
nameBuilder.append("</font>");
}
nameBuilder.append(')');
htmlName = nameBuilder.toString();
TypeMirror returnType = executableElement.getReturnType();
rightHtmlName = getTypeSimpleName(returnType);
}
示例5: 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);
}
示例6: setComponentTypeName
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void setComponentTypeName( @Nonnull final ExecutableElement componentTypeName )
throws ArezProcessorException
{
MethodChecks.mustBeOverridable( Constants.COMPONENT_TYPE_NAME_REF_ANNOTATION_CLASSNAME, componentTypeName );
MethodChecks.mustNotHaveAnyParameters( Constants.COMPONENT_TYPE_NAME_REF_ANNOTATION_CLASSNAME, componentTypeName );
MethodChecks.mustReturnAValue( Constants.COMPONENT_TYPE_NAME_REF_ANNOTATION_CLASSNAME, componentTypeName );
MethodChecks.mustNotThrowAnyExceptions( Constants.COMPONENT_TYPE_NAME_REF_ANNOTATION_CLASSNAME, componentTypeName );
final TypeMirror returnType = componentTypeName.getReturnType();
if ( !( TypeKind.DECLARED == returnType.getKind() &&
returnType.toString().equals( String.class.getName() ) ) )
{
throw new ArezProcessorException( "@ComponentTypeNameRef target must return a String", componentTypeName );
}
if ( null != _componentTypeName )
{
throw new ArezProcessorException( "@ComponentTypeNameRef target duplicates existing method named " +
_componentTypeName.getSimpleName(), componentTypeName );
}
else
{
_componentTypeName = Objects.requireNonNull( componentTypeName );
}
}
示例7: validateStaticVoid
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static void validateStaticVoid(ExecutableElement executableElement, Class<?> clazz) {
if (!executableElement.getModifiers().contains(Modifier.STATIC)) {
throw new IllegalArgumentException("@" + clazz.getSimpleName() + " methods must be static");
}
TypeMirror returnType = executableElement.getReturnType();
if (returnType.getKind() != TypeKind.VOID) {
throw new IllegalArgumentException("@" + clazz.getSimpleName() + " methods must return void");
}
}
示例8: addMapProperty
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void addMapProperty(ExecutableElement m, String propName) {
FxProperty pi = new FxProperty(propName, FxDefinitionKind.MAP);
pi.setSimple(false);
pi.setAccessor(ElementHandle.create(m));
// must extract type arguments; assume there's a DeclaredType
DeclaredType t = ((DeclaredType)m.getReturnType());
ExecutableType getterType = findMapGetMethod(t);
pi.setType(TypeMirrorHandle.create(getterType.getReturnType()));
pi.setObservableAccessors(pi.getAccessor());
registerProperty(pi);
}
示例9: 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();
}
示例10: Property
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public Property(Types typeUtils, ExecutableElement element, String name) {
this.element = element;
this.name = name;
this.type = element.getReturnType().toString();
if (element.getReturnType().getKind().isPrimitive()) {
PrimitiveType primitiveType = (PrimitiveType) element.getReturnType();
this.nonPrimitiveType = typeUtils.boxedClass(primitiveType).toString();
this.primitive = true;
} else {
this.nonPrimitiveType = element.getReturnType().toString();
}
}
示例11: getParameterizedReturn
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public TypeName getParameterizedReturn(Element method){
if(method.getKind() == METHOD) {
ExecutableElement executableElement = (ExecutableElement) method;
final TypeMirror returnType = executableElement.getReturnType();
try {
return ((ParameterizedTypeName) ParameterizedTypeName.get(returnType)).typeArguments.get(0);
} catch (Exception e){
return TypeName.get(returnType);
}
}
return null;
}
示例12: applicable
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
@Override
public boolean applicable(Context context) {
TypeElement type = context.autoValueClass();
for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
TypeMirror rType = method.getReturnType();
TypeName returnType = TypeName.get(rType);
if (returnType.toString().equals("Node_" + type.getSimpleName())) {
return true;
}
}
return false;
}
示例13: isGetter
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
protected boolean isGetter(TypeElement element, ExecutableElement x, boolean includeStatic) {
final String name = x.getSimpleName().toString();
final TypeMirror returnType = x.getReturnType();
final boolean isStatic = includeStatic && x.getParameters().size() == 1;
if (x.getParameters().size() != (isStatic ? 1 : 0)) {
return false;
}
if (isStatic && !types().isSameType(x.getParameters().get(0).asType(), element.asType())) {
return false;
}
if (name.startsWith("get")) {
return true;
}
if (name.startsWith("is") || name.startsWith("has")) {
if (returnType.getKind().equals(TypeKind.BOOLEAN)) {
return true;
}
}
if (name.startsWith("is") || name.startsWith("has")) {
TypeMirror javaLangBoolean = types().boxedClass(types().getPrimitiveType(TypeKind.BOOLEAN)).asType();
if (returnType.getKind().equals(TypeKind.BOOLEAN) || types().isSameType(returnType, javaLangBoolean)) {
return true;
}
}
return false;
}
示例14: isGetter
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public static boolean isGetter(ExecutableElement ee) {
String methodName = ee.getSimpleName().toString();
TypeMirror retType = ee.getReturnType();
// discard private and static methods
if (ee.getModifiers().contains(Modifier.PRIVATE) || ee.getModifiers().contains(Modifier.STATIC)) {
return false;
}
boolean retVal = methodName.startsWith(GET_PREFIX) && methodName.length() > GET_PREFIX.length() && retType.getKind() != TypeKind.VOID;
retVal = retVal || methodName.startsWith(IS_PREFIX) && methodName.length() > IS_PREFIX.length() && retType.getKind() == TypeKind.BOOLEAN;
return retVal;
}
示例15: isSetter
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public static boolean isSetter(ExecutableElement ee) {
String methodName = ee.getSimpleName().toString();
TypeMirror retType = ee.getReturnType();
// discard private and static methods
if (ee.getModifiers().contains(Modifier.PRIVATE) || ee.getModifiers().contains(Modifier.STATIC)) {
return false;
}
return methodName.startsWith(SET_PREFIX) && methodName.length() > SET_PREFIX.length()
&& retType.getKind() == TypeKind.VOID && ee.getParameters().size() == 1;
}