本文整理汇总了Java中javax.lang.model.type.ExecutableType.getReturnType方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableType.getReturnType方法的具体用法?Java ExecutableType.getReturnType怎么用?Java ExecutableType.getReturnType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.type.ExecutableType
的用法示例。
在下文中一共展示了ExecutableType.getReturnType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: asInheritedMemberReturnType
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
static TypeMirror asInheritedMemberReturnType(
ProcessingEnvironment processing,
TypeElement typeElement,
ExecutableElement method) {
ExecutableType asMethodOfType =
(ExecutableType) processing.getTypeUtils()
.asMemberOf((DeclaredType) typeElement.asType(), method);
return asMethodOfType.getReturnType();
}
示例2: getType
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
public TypeMirror getType(Element element) throws WitchException {
if (element.getKind().isField()) {
return element.asType();
} else if (element.getKind() == ElementKind.METHOD) {
ExecutableType ext = (ExecutableType) element.asType();
return ext.getReturnType();
}
return null;
}
示例3: addComputedValueRef
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
private void addComputedValueRef( @Nonnull final AnnotationMirror annotation,
@Nonnull final ExecutableElement method,
@Nonnull final ExecutableType methodType )
throws ArezProcessorException
{
MethodChecks.mustBeOverridable( Constants.COMPUTED_VALUE_REF_ANNOTATION_CLASSNAME, method );
MethodChecks.mustNotHaveAnyParameters( Constants.COMPUTED_VALUE_REF_ANNOTATION_CLASSNAME, method );
MethodChecks.mustNotThrowAnyExceptions( Constants.COMPUTED_VALUE_REF_ANNOTATION_CLASSNAME, method );
final TypeMirror returnType = methodType.getReturnType();
if ( TypeKind.DECLARED != returnType.getKind() ||
!toRawType( returnType ).toString().equals( "arez.ComputedValue" ) )
{
throw new ArezProcessorException( "Method annotated with @ComputedValueRef must return an instance of " +
"arez.ComputedValue", method );
}
final String declaredName = getAnnotationParameter( annotation, "name" );
final String name;
if ( ProcessorUtil.isSentinelName( declaredName ) )
{
name = ProcessorUtil.deriveName( method, COMPUTED_VALUE_REF_PATTERN, declaredName );
if ( null == name )
{
throw new ArezProcessorException( "Method annotated with @ComputedValueRef should specify name or be " +
"named according to the convention get[Name]ComputedValue", method );
}
}
else
{
name = declaredName;
if ( !ProcessorUtil.isJavaIdentifier( name ) )
{
throw new ArezProcessorException( "Method annotated with @ComputedValueRef specified invalid name " + name,
method );
}
}
findOrCreateComputed( name ).setRefMethod( method, methodType );
}
示例4: checkMimeLocation
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
private void checkMimeLocation(TypeElement clazz, AnnotationMirror am) {
for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : am.getElementValues().entrySet()) {
if (!e.getKey().getSimpleName().contentEquals("instanceProviderClass")) continue;
TypeMirror ipc = (TypeMirror) e.getValue().getValue();
if (ipc == null || ipc.getKind() != TypeKind.DECLARED) continue; //the compiler should have given the error
TypeElement instanceProvider = processingEnv.getElementUtils().getTypeElement("org.netbeans.spi.editor.mimelookup.InstanceProvider");
if (instanceProvider == null) {
return ;
}
ExecutableElement createInstance = null;
for (ExecutableElement ee : ElementFilter.methodsIn(instanceProvider.getEnclosedElements())) {
if (ee.getSimpleName().contentEquals("createInstance")) { //TODO: check parameters
createInstance = ee;
break;
}
}
if (createInstance == null) {
throw new IllegalStateException("No instanceCreate in InstanceProvider!");
}
DeclaredType dipc = (DeclaredType) ipc;
Types tu = processingEnv.getTypeUtils();
ExecutableType member = (ExecutableType) tu.asMemberOf(dipc, createInstance);
TypeMirror result = member.getReturnType();
TypeMirror jlObject = processingEnv.getElementUtils().getTypeElement("java.lang.Object").asType();
if (!tu.isSameType(tu.erasure(result), jlObject)) {
if (!tu.isSubtype(tu.erasure(result), tu.erasure(clazz.asType()))) {
processingEnv.getMessager().printMessage(Kind.ERROR, "The InstanceProvider does not create instances of type " + clazz.getQualifiedName(), clazz, am, e.getValue());
}
}
TypeElement tipc = (TypeElement) dipc.asElement();
if (!tipc.getModifiers().contains(Modifier.PUBLIC)) {
processingEnv.getMessager().printMessage(Kind.ERROR, "The InstanceProvider implementation is not public.", clazz, am, e.getValue());
}
for (ExecutableElement c : ElementFilter.constructorsIn(tipc.getEnclosedElements())) {
if (c.getParameters().isEmpty() && c.getModifiers().contains(Modifier.PUBLIC)) {
//OK
return;
}
}
processingEnv.getMessager().printMessage(Kind.ERROR, "The InstanceProvider implementation does not provide a public no-arg constructor.", clazz, am, e.getValue());
}
}
示例5: process
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment environment) {
for(final Element element : environment.getElementsAnnotatedWith(Put.class)) {
final Put annotation = element.getAnnotation(Put.class);
if(ElementKind.METHOD != element.getKind()) {
throw new DataSinkDefinitionException(
"Must use @Put with methods only! Tried to use with " + element.getSimpleName()
+ ", which is not a method.");
}
final Set<Modifier> modifiers = element.getModifiers();
if(!modifiers.contains(Modifier.PUBLIC)) {
throw new DataSinkDefinitionException(
"Must use @Put with public methods only! Tried to use with " + element.getSimpleName()
+ ", which is not public.");
}
if(modifiers.contains(Modifier.STATIC)) {
throw new DataSinkDefinitionException(
"Must use @Put with non-static methods only! Tried to use with " + element.getSimpleName()
+ ", which is static.");
}
final ExecutableType method = (ExecutableType)element.asType();
final Types types = processingEnv.getTypeUtils();
final Elements elements = processingEnv.getElementUtils();
// annotation.value() will throw the exception because it doesn't have compiled class information yet, and is of type Class<?>.
TypeMirror annotatedType = null;
try {
annotation.value();
} catch(final MirroredTypeException e) {
annotatedType = e.getTypeMirror();
}
if(TypeKind.VOID != method.getReturnType().getKind()) {
throw new DataSinkDefinitionException(
"@Put method must have void return! Tried to use with " + element.getSimpleName() + ", which returns "
+ method.getReturnType() + ".");
}
if(method.getParameterTypes().size() != 2) {
throw new DataSinkDefinitionException("@Put methods must take 2 arguments: T item, PipelineContext context. Tried to use with "
+ element.getSimpleName() + ", which has a different signature.");
}
final TypeMirror contextType = elements.getTypeElement(PipelineContext.class.getName()).asType();
if(!types.isAssignable(annotatedType, method.getParameterTypes().get(0))) {
throw new DataSinkDefinitionException(
"@Put method annotated value type must be assignable from the method's first argument type. Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(0) + ".");
}
if(!types.isAssignable(method.getParameterTypes().get(1), contextType)) {
throw new DataSinkDefinitionException("@Put method second argument must be assignable from " + contextType + ". Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(1) + ".");
}
}
return true;
}
示例6: process
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment environment) {
for(final Element element : environment.getElementsAnnotatedWith(PutMany.class)) {
final PutMany annotation = element.getAnnotation(PutMany.class);
if(ElementKind.METHOD != element.getKind()) {
throw new DataSinkDefinitionException(
"Must use @PutMany with methods only! Tried to use with " + element.getSimpleName()
+ ", which is not a method.");
}
final Set<Modifier> modifiers = element.getModifiers();
if(!modifiers.contains(Modifier.PUBLIC)) {
throw new DataSinkDefinitionException(
"Must use @PutMany with public methods only! Tried to use with " + element.getSimpleName()
+ ", which is not public.");
}
if(modifiers.contains(Modifier.STATIC)) {
throw new DataSinkDefinitionException(
"Must use @PutMany with non-static methods only! Tried to use with " + element.getSimpleName()
+ ", which is static.");
}
final ExecutableType method = (ExecutableType)element.asType();
final Types types = processingEnv.getTypeUtils();
final Elements elements = processingEnv.getElementUtils();
// annotation.value() will throw the exception because it doesn't have compiled class information yet, and is of type Class<?>.
TypeMirror annotatedType = null;
try {
annotation.value();
} catch(final MirroredTypeException e) {
annotatedType = e.getTypeMirror();
}
if(TypeKind.VOID != method.getReturnType().getKind()) {
throw new DataSinkDefinitionException("@PutMany method must have void return! Tried to use with " + element.getSimpleName() + ", which returns "
+ method.getReturnType() + ".");
}
if(method.getParameterTypes().size() != 2) {
throw new DataSinkDefinitionException("@PutMany methods must take 2 arguments: Iterable<T> items, PipelineContext context. Tried to use with "
+ element.getSimpleName() + ", which has a different signature.");
}
final TypeElement iterableType = elements.getTypeElement(Iterable.class.getName());
final TypeMirror[] genericType = new TypeMirror[] {annotatedType};
final DeclaredType itemsType = types.getDeclaredType(iterableType, genericType);
final TypeMirror contextType = elements.getTypeElement(PipelineContext.class.getName()).asType();
if(!types.isAssignable(itemsType, method.getParameterTypes().get(0))) {
throw new DataSinkDefinitionException(
"@PutMany method annotated value must be assignable from the generic type of the method's first argument . Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(0) + ".");
}
if(!types.isAssignable(method.getParameterTypes().get(1), contextType)) {
throw new DataSinkDefinitionException("@PutMany method second argument must be assignable from " + contextType + ". Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(1) + ".");
}
}
return true;
}
示例7: process
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment environment) {
for(final Element element : environment.getElementsAnnotatedWith(GetMany.class)) {
final GetMany annotation = element.getAnnotation(GetMany.class);
if(ElementKind.METHOD != element.getKind()) {
throw new DataSourceDefinitionException(
"Must use @GetMany with methods only! Tried to use with " + element.getSimpleName()
+ ", which is not a method.");
}
final Set<Modifier> modifiers = element.getModifiers();
if(!modifiers.contains(Modifier.PUBLIC)) {
throw new DataSourceDefinitionException(
"Must use @GetMany with public methods only! Tried to use with " + element.getSimpleName()
+ ", which is not public.");
}
if(modifiers.contains(Modifier.STATIC)) {
throw new DataSourceDefinitionException(
"Must use @GetMany with non-static methods only! Tried to use with " + element.getSimpleName()
+ ", which is static.");
}
final ExecutableType method = (ExecutableType)element.asType();
final Types types = processingEnv.getTypeUtils();
final Elements elements = processingEnv.getElementUtils();
// annotation.value() will throw the exception because it doesn't have compiled class information yet, and is of type Class<?>.
TypeMirror annotatedType = null;
try {
annotation.value();
} catch(final MirroredTypeException e) {
annotatedType = e.getTypeMirror();
}
final TypeElement closeableIteratorType = elements.getTypeElement(CloseableIterator.class.getName());
final DeclaredType returnType = types.getDeclaredType(closeableIteratorType, annotatedType);
if(!types.isAssignable(method.getReturnType(), returnType)) {
throw new DataSourceDefinitionException(
"@GetMany methods must return a CloseableIterator over a type which is assignable from the annotation value. Tried to use with "
+ element.getSimpleName() + ", which returns " + method.getReturnType() + ".");
}
if(method.getParameterTypes().size() != 2) {
throw new DataSourceDefinitionException(
"@GetMany methods must take 2 arguments: Map<String, Object> query, PipelineContext context. Tried to use with "
+ element.getSimpleName() + ", which has a different signature.");
}
final TypeMirror stringType = elements.getTypeElement(String.class.getName()).asType();
final TypeMirror objectType = elements.getTypeElement(Object.class.getName()).asType();
final TypeElement mapType = elements.getTypeElement(Map.class.getName());
final TypeMirror[] genericTypes = new TypeMirror[] {stringType, objectType};
final DeclaredType queryType = types.getDeclaredType(mapType, genericTypes);
final TypeMirror contextType = elements.getTypeElement(PipelineContext.class.getName()).asType();
if(!types.isAssignable(method.getParameterTypes().get(0), queryType)) {
throw new DataSourceDefinitionException("@GetMany method first argument must be assignable from " + queryType + ". Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(0) + ".");
}
if(!types.isAssignable(method.getParameterTypes().get(1), contextType)) {
throw new DataSourceDefinitionException("@GetMany method second argument must be assignable from " + contextType + ". Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(1) + ".");
}
}
return true;
}
示例8: process
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment environment) {
for(final Element element : environment.getElementsAnnotatedWith(Get.class)) {
final Get annotation = element.getAnnotation(Get.class);
if(ElementKind.METHOD != element.getKind()) {
throw new DataSourceDefinitionException(
"Must use @Get with methods only! Tried to use with " + element.getSimpleName()
+ ", which is not a method.");
}
final Set<Modifier> modifiers = element.getModifiers();
if(!modifiers.contains(Modifier.PUBLIC)) {
throw new DataSourceDefinitionException(
"Must use @Get with public methods only! Tried to use with " + element.getSimpleName()
+ ", which is not public.");
}
if(modifiers.contains(Modifier.STATIC)) {
throw new DataSourceDefinitionException(
"Must use @Get with non-static methods only! Tried to use with " + element.getSimpleName()
+ ", which is static.");
}
final ExecutableType method = (ExecutableType)element.asType();
final Types types = processingEnv.getTypeUtils();
final Elements elements = processingEnv.getElementUtils();
// annotation.value() will throw the exception because it doesn't have compiled class information yet, and is of type Class<?>.
TypeMirror annotatedType = null;
try {
annotation.value();
} catch(final MirroredTypeException e) {
annotatedType = e.getTypeMirror();
}
if(!types.isAssignable(method.getReturnType(), annotatedType)) {
throw new DataSourceDefinitionException("@Get method return type must be assignable from the annotation value! Tried to use with "
+ element.getSimpleName() + ", which returns " + method.getReturnType() + ".");
}
if(method.getParameterTypes().size() != 2) {
throw new DataSourceDefinitionException(
"@Get methods must take 2 arguments: Map<String, Object> query, PipelineContext context. Tried to use with "
+ element.getSimpleName()
+ ", which has a different signature.");
}
final TypeMirror stringType = elements.getTypeElement(String.class.getName()).asType();
final TypeMirror objectType = elements.getTypeElement(Object.class.getName()).asType();
final TypeElement mapType = elements.getTypeElement(Map.class.getName());
final TypeMirror[] genericTypes = new TypeMirror[] {stringType, objectType};
final DeclaredType queryType = types.getDeclaredType(mapType, genericTypes);
final TypeMirror contextType = elements.getTypeElement(PipelineContext.class.getName()).asType();
if(!types.isAssignable(method.getParameterTypes().get(0), queryType)) {
throw new DataSourceDefinitionException("@Get method first argument must be assignable from " + queryType + ". Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(0) + ".");
}
if(!types.isAssignable(method.getParameterTypes().get(1), contextType)) {
throw new DataSourceDefinitionException("@Get method second argument must be assignable from " + contextType + ". Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(1) + ".");
}
}
return true;
}
示例9: executableElementToProperty
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
private Property executableElementToProperty(Element element, String componentInfoName) {
String propertyName = element.getSimpleName().toString();
SimpleProperty simpleProperty = element.getAnnotation(SimpleProperty.class);
if (!(element.asType() instanceof ExecutableType)) {
throw new RuntimeException("element.asType() is not an ExecutableType for " +
propertyName);
}
Property property = new Property(propertyName,
simpleProperty.description(),
simpleProperty.category(),
simpleProperty.userVisible(),
elementUtils.isDeprecated(element));
// Get parameters to tell if this is a getter or setter.
ExecutableType executableType = (ExecutableType) element.asType();
List<? extends TypeMirror> parameters = executableType.getParameterTypes();
// Check if it is a setter or getter, and set the property's readable, writable,
// and type fields appropriately.
TypeMirror typeMirror;
if (parameters.size() == 0) {
// It is a getter.
property.readable = true;
typeMirror = executableType.getReturnType();
if (typeMirror.getKind().equals(TypeKind.VOID)) {
throw new RuntimeException("Property method is void and has no parameters: "
+ propertyName);
}
} else {
// It is a setter.
property.writable = true;
if (parameters.size() != 1) {
throw new RuntimeException("Too many parameters for setter for " +
propertyName);
}
typeMirror = parameters.get(0);
}
// Use typeMirror to set the property's type.
if (!typeMirror.getKind().equals(TypeKind.VOID)) {
property.type = typeMirror.toString();
}
property.componentInfoName = componentInfoName;
return property;
}
示例10: addObservableRef
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
private void addObservableRef( @Nonnull final AnnotationMirror annotation,
@Nonnull final ExecutableElement method,
@Nonnull final ExecutableType methodType )
throws ArezProcessorException
{
MethodChecks.mustBeOverridable( Constants.OBSERVABLE_REF_ANNOTATION_CLASSNAME, method );
MethodChecks.mustNotHaveAnyParameters( Constants.OBSERVABLE_REF_ANNOTATION_CLASSNAME, method );
MethodChecks.mustNotThrowAnyExceptions( Constants.OBSERVABLE_REF_ANNOTATION_CLASSNAME, method );
final TypeMirror returnType = methodType.getReturnType();
if ( TypeKind.DECLARED != returnType.getKind() ||
!toRawType( returnType ).toString().equals( "arez.Observable" ) )
{
throw new ArezProcessorException( "Method annotated with @ObservableRef must return an instance of " +
"arez.Observable", method );
}
final String declaredName = getAnnotationParameter( annotation, "name" );
final String name;
if ( ProcessorUtil.isSentinelName( declaredName ) )
{
name = ProcessorUtil.deriveName( method, OBSERVABLE_REF_PATTERN, declaredName );
if ( null == name )
{
throw new ArezProcessorException( "Method annotated with @ObservableRef should specify name or be " +
"named according to the convention get[Name]Observable", method );
}
}
else
{
name = declaredName;
if ( !ProcessorUtil.isJavaIdentifier( name ) )
{
throw new ArezProcessorException( "Method annotated with @ObservableRef specified invalid name " + name,
method );
}
}
final ObservableDescriptor observable = findOrCreateObservable( name );
if ( observable.hasRefMethod() )
{
throw new ArezProcessorException( "Method annotated with @ObservableRef defines duplicate ref accessor for " +
"observable named " + name, method );
}
observable.setRefMethod( method, methodType );
}