本文整理汇总了Java中javax.lang.model.type.ExecutableType.getParameterTypes方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableType.getParameterTypes方法的具体用法?Java ExecutableType.getParameterTypes怎么用?Java ExecutableType.getParameterTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.type.ExecutableType
的用法示例。
在下文中一共展示了ExecutableType.getParameterTypes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateParamVariables
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
/**
*/
private List<VariableTree> generateParamVariables(
WorkingCopy workingCopy,
ExecutableType srcMethod,
String[] varNames) {
TreeMaker maker = workingCopy.getTreeMaker();
List<? extends TypeMirror> params = srcMethod.getParameterTypes();
if ((params == null) || params.isEmpty()) {
return Collections.<VariableTree>emptyList();
}
Set<Modifier> noModifiers = Collections.<Modifier>emptySet();
List<VariableTree> paramVariables = new ArrayList<VariableTree>(params.size());
int index = 0;
for (TypeMirror param : params) {
if (param.getKind() == TypeKind.TYPEVAR){
param = getSuperType(workingCopy, param);
}
paramVariables.add(
maker.Variable(maker.Modifiers(noModifiers),
varNames[index++],
maker.Type(param),
getDefaultValue(maker, param)));
}
return paramVariables;
}
示例2: ExposedMethod
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
public ExposedMethod(Element element) {
ExecutableType method = (ExecutableType) element.asType();
TypeElement declaringClass = (TypeElement) element.getEnclosingElement();
this.name = element.getSimpleName().toString();
this.originalMethod = declaringClass.getQualifiedName().toString() + "." + element.getSimpleName();
this.returnType = method.getReturnType().toString();
this.params = new ArrayList<>();
int count = 0;
for (TypeMirror param : method.getParameterTypes()) {
this.params.add(param.toString());
String[] components = param.toString().toLowerCase().split("\\.");
String paramName = components[components.length - 1];
if (paramName.endsWith(">")) {
paramName = paramName.substring(0, paramName.length() - 1);
}
this.params.add(paramName + count);
count++;
}
this.thrown = Stream.of(method.getThrownTypes()).map(new Function<TypeMirror, String>() {
@Override
public String apply(TypeMirror typeMirror) {
return typeMirror.toString();
}
}).toList();
}
示例3: asMemberOf
import javax.lang.model.type.ExecutableType; //导入方法依赖的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: generateParamVariables
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
/**
*/
private List<VariableTree> generateParamVariables(
WorkingCopy workingCopy,
ExecutableType srcMethod,
String[] varNames) {
TreeMaker maker = workingCopy.getTreeMaker();
List<? extends TypeMirror> params = srcMethod.getParameterTypes();
if ((params == null) || params.isEmpty()) {
return Collections.<VariableTree>emptyList();
}
Set<Modifier> noModifiers = Collections.<Modifier>emptySet();
List<VariableTree> paramVariables = new ArrayList<VariableTree>(params.size());
int index = 0;
for (TypeMirror param : params) {
if (param.getKind() == TypeKind.TYPEVAR){
param = getSuperType(workingCopy, param);
}
if (param.getKind() == TypeKind.DECLARED) {
boolean typeVar = containsTypeVar((DeclaredType) param, false);
if (typeVar) {
return null;
}
}
param = getTypeMirror(workingCopy, param);
paramVariables.add(
maker.Variable(maker.Modifiers(noModifiers),
varNames[index++],
maker.Type(param),
getDefaultValue(maker, param)));
}
return paramVariables;
}
示例5: run
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
@Override
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
if (!TreeUtilities.CLASS_TREE_KINDS.contains(treePath.getLeaf().getKind())) return Collections.emptyList();
Element el = info.getTrees().getElement(treePath);
if (el == null || !el.getKind().isClass()) return Collections.emptyList();
TypeElement clazz = (TypeElement) el;
TypeMirror superType = clazz.getSuperclass();
if (superType.getKind() != TypeKind.DECLARED) return Collections.emptyList();
TypeElement superClazz = (TypeElement) info.getTypes().asElement(superType);
DeclaredType targetType = (DeclaredType) clazz.asType();
Scope classScope = info.getTrees().getScope(treePath);
List<Fix> result = new ArrayList<Fix>();
for (ExecutableElement constr : ElementFilter.constructorsIn(superClazz.getEnclosedElements())) {
if (!info.getTrees().isAccessible(classScope, constr, (DeclaredType) superType)) continue;
StringBuilder name = new StringBuilder();
name.append(clazz.getSimpleName()).append("(");
ExecutableType target = (ExecutableType) info.getTypes().asMemberOf(targetType, constr);
boolean firstParam = true;
for (TypeMirror p : target.getParameterTypes()) {
if (!firstParam) name.append(", ");
firstParam = false;
name.append(info.getTypeUtilities().getTypeName(p));
}
name.append(")");
result.add(new FixImpl(info, treePath, constr, StringEscapeUtils.escapeHtml(name.toString())).toEditorFix());
}
return result;
}
示例6: determineEventHandlers
import javax.lang.model.type.ExecutableType; //导入方法依赖的package包/类
private void determineEventHandlers( @Nonnull final ComponentDescriptor descriptor )
{
final List<EventHandlerDescriptor> eventHandlers =
ProcessorUtil.getMethods( descriptor.getElement(), processingEnv.getTypeUtils() ).stream()
.filter( m -> null != ProcessorUtil.findAnnotationByType( m, Constants.EVENT_HANDLER_ANNOTATION_CLASSNAME ) )
.map( m -> createEventHandlerDescriptor( descriptor, m ) )
.collect( Collectors.toList() );
for ( final EventHandlerDescriptor eventHandler : eventHandlers )
{
final ExecutableElement method = eventHandler.getMethod();
final TypeElement handlerType = getEventHandlerType( method );
if ( ElementKind.INTERFACE != handlerType.getKind() )
{
throw new ReactProcessorException( "The @EventHandler specified an invalid type that is not an interface.",
eventHandler.getMethod() );
}
if ( null == ProcessorUtil.findAnnotationByType( handlerType, Constants.JS_FUNCTION_CLASSNAME ) )
{
throw new ReactProcessorException( "The @EventHandler specified an invalid type that is not annotated " +
"with the annotation jsinterop.annotations.JsFunction.",
eventHandler.getMethod() );
}
final EventHandlerDescriptor matched = eventHandlers.stream()
.filter( h -> h != eventHandler && h.getName().equals( eventHandler.getName() ) )
.findAny().orElse( null );
if ( null != matched )
{
throw new ReactProcessorException( "The @EventHandler has the same name as the event handler defined by " +
matched.getMethod() + ".", eventHandler.getMethod() );
}
final EventHandlerDescriptor matched2 = eventHandlers.stream()
.filter( h -> h != eventHandler &&
h.getMethod().getSimpleName().equals( eventHandler.getMethod().getSimpleName() ) )
.findAny().orElse( null );
if ( null != matched2 )
{
throw new ReactProcessorException( "The @EventHandler has the same method name as the event handler defined " +
"by " + matched2.getMethod() + ".", eventHandler.getMethod() );
}
final ExecutableType methodType = eventHandler.getMethodType();
final List<? extends TypeMirror> parameters = methodType.getParameterTypes();
if ( !parameters.isEmpty() )
{
// Our annotated handler method has parameters so they should exactly align
// in count and type with the parameters in the event handler method
final ExecutableElement target = eventHandler.getEventHandlerMethod();
final List<? extends VariableElement> targetParameters = target.getParameters();
if ( targetParameters.size() != parameters.size() )
{
throw new ReactProcessorException( "The @EventHandler target has " + parameters.size() + " parameters " +
"but the type parameter specified a handler with method type " +
eventHandler.getEventHandlerType().getQualifiedName() + " that has " +
"handler method with " + targetParameters.size() + " parameters. The " +
"@EventHandler target should have zero parameters or match the number " +
"of parameter in the target method " + target.getSimpleName() + ".",
eventHandler.getMethod() );
}
for ( int i = 0; i < parameters.size(); i++ )
{
final TypeMirror parameterType = parameters.get( i );
final VariableElement element = targetParameters.get( i );
final TypeMirror targetParameterType = element.asType();
final TypeMirror targetErased = processingEnv.getTypeUtils().erasure( targetParameterType );
final TypeMirror parameterErased = processingEnv.getTypeUtils().erasure( parameterType );
if ( !processingEnv.getTypeUtils().isAssignable( targetErased, parameterErased ) )
{
throw new ReactProcessorException( "The @EventHandler target parameter named " +
eventHandler.getMethod().getParameters().get( i ).getSimpleName() +
" of type " + parameterType + " is not assignable from target type " +
targetParameterType + " of parameter " + element.getSimpleName() +
" in method " + eventHandler.getEventHandlerType().getQualifiedName() +
"." + target.getSimpleName() + ".",
eventHandler.getMethod() );
}
}
}
}
descriptor.setEventHandlers( eventHandlers );
}
示例7: 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;
}