本文整理汇总了Java中javax.lang.model.type.ExecutableType类的典型用法代码示例。如果您正苦于以下问题:Java ExecutableType类的具体用法?Java ExecutableType怎么用?Java ExecutableType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExecutableType类属于javax.lang.model.type包,在下文中一共展示了ExecutableType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: isHidden
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
private boolean isHidden(Element member, List<? extends Element> members, Elements elements, Types types) {
for (ListIterator<? extends Element> it = members.listIterator(); it.hasNext();) {
Element hider = it.next();
if (hider == member)
return true;
if (hider.getSimpleName().contentEquals(member.getSimpleName())) {
if (elements.hides(member, hider)) {
it.remove();
} else {
if (member instanceof VariableElement && hider instanceof VariableElement
&& (!member.getKind().isField() || hider.getKind().isField()))
return true;
TypeMirror memberType = member.asType();
TypeMirror hiderType = hider.asType();
if (memberType.getKind() == TypeKind.EXECUTABLE && hiderType.getKind() == TypeKind.EXECUTABLE) {
if (types.isSubsignature((ExecutableType)hiderType, (ExecutableType)memberType))
return true;
} else {
return false;
}
}
}
}
return false;
}
示例3: visitNewClass
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
@Override
public List<? extends TypeMirror> visitNewClass(NewClassTree node, Object p) {
TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
if (tm == null || tm.getKind() != TypeKind.DECLARED) {
return null;
}
Element el = info.getTrees().getElement(getCurrentPath());
if (el == null) {
return null;
}
if (theExpression.getLeaf() != node.getEnclosingExpression()) {
ExecutableType execType = (ExecutableType)info.getTypes().asMemberOf((DeclaredType)tm, el);
return visitMethodOrNew(node, p, node.getArguments(), execType);
} else {
DeclaredType dt = (DeclaredType)tm;
if (dt.getEnclosingType() == null) {
return null;
}
return Collections.singletonList(dt.getEnclosingType());
}
}
示例4: findExecutableMember
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
private ExecutableElement findExecutableMember(TypeElement clazz, String methodName, List<TypeMirror> paramTypes, Types types) {
List<ExecutableElement> members = methodName.contentEquals(clazz.getSimpleName())
? ElementFilter.constructorsIn(clazz.getEnclosedElements())
: ElementFilter.methodsIn(clazz.getEnclosedElements());
outer: for (ExecutableElement ee : members) {
if (ee.getKind() == ElementKind.CONSTRUCTOR || methodName.contentEquals(ee.getSimpleName())) {
List<? extends TypeMirror> memberParamTypes = ((ExecutableType) ee.asType()).getParameterTypes();
if (memberParamTypes.size() == paramTypes.size()) {
Iterator<TypeMirror> it = paramTypes.iterator();
for (TypeMirror memberParamType : memberParamTypes) {
TypeMirror type = it.next();
if (types.isSameType(type, memberParamType)) {
continue outer;
}
}
return ee;
}
}
}
return null;
}
示例5: enumerateMethods
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
private static void enumerateMethods( @Nonnull final TypeElement scope,
@Nonnull final Types typeUtils,
@Nonnull final TypeElement element,
@Nonnull final Map<String, ExecutableElement> methods )
{
final TypeMirror superclass = element.getSuperclass();
if ( TypeKind.NONE != superclass.getKind() )
{
enumerateMethods( scope, typeUtils, (TypeElement) ( (DeclaredType) superclass ).asElement(), methods );
}
for ( final TypeMirror interfaceType : element.getInterfaces() )
{
final TypeElement interfaceElement = (TypeElement) ( (DeclaredType) interfaceType ).asElement();
enumerateMethods( scope, typeUtils, interfaceElement, methods );
}
for ( final Element member : element.getEnclosedElements() )
{
if ( member.getKind() == ElementKind.METHOD )
{
final ExecutableType methodType =
(ExecutableType) typeUtils.asMemberOf( (DeclaredType) scope.asType(), member );
methods.put( member.getSimpleName() + methodType.toString(), (ExecutableElement) member );
}
}
}
示例6: addAutorun
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
private void addAutorun( @Nonnull final AnnotationMirror annotation,
@Nonnull final ExecutableElement method,
@Nonnull final ExecutableType methodType )
throws ArezProcessorException
{
MethodChecks.mustBeOverridable( Constants.AUTORUN_ANNOTATION_CLASSNAME, method );
MethodChecks.mustNotHaveAnyParameters( Constants.AUTORUN_ANNOTATION_CLASSNAME, method );
MethodChecks.mustNotThrowAnyExceptions( Constants.AUTORUN_ANNOTATION_CLASSNAME, method );
MethodChecks.mustNotReturnAnyValue( Constants.AUTORUN_ANNOTATION_CLASSNAME, method );
final String name = deriveAutorunName( method, annotation );
checkNameUnique( name, method, Constants.AUTORUN_ANNOTATION_CLASSNAME );
final boolean mutation = getAnnotationParameter( annotation, "mutation" );
final AutorunDescriptor autorun = new AutorunDescriptor( this, name, mutation, method, methodType );
_autoruns.put( autorun.getName(), autorun );
}
示例7: determineLifecycleMethods
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
private void determineLifecycleMethods( @Nonnull final TypeElement typeElement,
@Nonnull final ComponentDescriptor descriptor )
{
/*
* Get the list of lifecycle methods that have been overridden by typeElement
* a parent class, or by a default method method implemented by typeElement or
* a parent class.
*/
final Collection<ExecutableElement> lifecycleMethods = getComponentLifecycleMethods().values();
final Elements elementUtils = processingEnv.getElementUtils();
final Types typeUtils = processingEnv.getTypeUtils();
final TypeElement componentType = elementUtils.getTypeElement( Constants.COMPONENT_CLASSNAME );
final List<MethodDescriptor> overriddenLifecycleMethods =
// Get all methods on type parent classes, and default methods from interfaces
ProcessorUtil.getMethods( typeElement, processingEnv.getTypeUtils() ).stream()
// Only keep methods that override the lifecycle methods
.filter( m -> lifecycleMethods.stream().anyMatch( l -> elementUtils.overrides( m, l, typeElement ) ) )
//Remove those that come from the base classes
.filter( m -> m.getEnclosingElement() != componentType )
.map( m -> new MethodDescriptor( m, (ExecutableType) typeUtils.asMemberOf( descriptor.getDeclaredType(), m ) ) )
.collect( Collectors.toList() );
descriptor.setLifecycleMethods( overriddenLifecycleMethods );
}
示例8: 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();
}
示例9: doGet
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
@Override
protected ExecutableElement doGet(ProcessingEnvironment env) {
TypeElement typeElt = env.getElementUtils().getTypeElement(fqn.getName());
if (typeElt != null) {
next:
for (ExecutableElement executableElement : ElementFilter.methodsIn(typeElt.getEnclosedElements())) {
if (executableElement.getSimpleName().toString().equals(name)) {
List<? extends TypeMirror> parameterTypes = ((ExecutableType)executableElement.asType()).getParameterTypes();
int len = parameterTypes.size();
if (len == this.parameterTypes.size()) {
for (int i = 0;i < len;i++) {
if (!parameterTypes.get(i).toString().equals(this.parameterTypes.get(i))) {
continue next;
}
}
return executableElement;
}
}
}
}
return null;
}
示例10: filterExecutableTypesByArguments
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
private List<Pair<ExecutableElement, ExecutableType>> filterExecutableTypesByArguments(AnalyzeTask at, Iterable<Pair<ExecutableElement, ExecutableType>> candidateMethods, List<TypeMirror> precedingActualTypes) {
List<Pair<ExecutableElement, ExecutableType>> candidate = new ArrayList<>();
int paramIndex = precedingActualTypes.size();
OUTER:
for (Pair<ExecutableElement, ExecutableType> method : candidateMethods) {
boolean varargInvocation = paramIndex >= method.snd.getParameterTypes().size();
for (int i = 0; i < paramIndex; i++) {
TypeMirror actual = precedingActualTypes.get(i);
if (this.parameterType(method.fst, method.snd, i, !varargInvocation)
.noneMatch(formal -> at.getTypes().isAssignable(actual, formal))) {
continue OUTER;
}
}
candidate.add(method);
}
return candidate;
}
示例11: process
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!ran) {
ran = true;
ExecutableElement m = getFirstMethodIn("C");
System.err.println("method: " + m);
TypeMirror type = (DeclaredType)m.getParameters().get(0).asType();
System.err.println("parameters[0]: " + type);
if (!isParameterized(type))
throw new AssertionError(type);
type = ((ExecutableType)m.asType()).getParameterTypes().get(0);
System.err.println("parameterTypes[0]: " + type);
if (!isParameterized(type))
throw new AssertionError(type);
System.err.println();
}
return true;
}
示例12: equal
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
private static boolean equal(TypeMirror a, TypeMirror b, Set<ComparedElements> visiting) {
// TypeMirror.equals is not guaranteed to return true for types that are equal, but we can
// assume that if it does return true then the types are equal. This check also avoids getting
// stuck in infinite recursion when Eclipse decrees that the upper bound of the second K in
// <K extends Comparable<K>> is a distinct but equal K.
// The javac implementation of ExecutableType, at least in some versions, does not take thrown
// exceptions into account in its equals implementation, so avoid this optimization for
// ExecutableType.
if (Objects.equal(a, b) && !(a instanceof ExecutableType)) {
return true;
}
EqualVisitorParam p = new EqualVisitorParam();
p.type = b;
p.visiting = visiting;
if (INTERSECTION_TYPE != null) {
if (isIntersectionType(a)) {
return equalIntersectionTypes(a, b, visiting);
} else if (isIntersectionType(b)) {
return false;
}
}
return (a == b) || (a != null && b != null && a.accept(EQUAL_VISITOR, p));
}
示例13: 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);
}
}
示例14: setRefMethod
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
void setRefMethod( @Nonnull final ExecutableElement method, @Nonnull final ExecutableType methodType )
throws ArezProcessorException
{
MethodChecks.mustBeSubclassCallable( 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 );
if ( null != _refMethod )
{
throw new ArezProcessorException( "@ComputedValueRef target duplicates existing method named " +
_refMethod.getSimpleName(), method );
}
else
{
_refMethod = Objects.requireNonNull( method );
_refMethodType = Objects.requireNonNull( methodType );
}
}
示例15: setTrackedMethod
import javax.lang.model.type.ExecutableType; //导入依赖的package包/类
void setTrackedMethod( final boolean mutation,
final boolean reportParameters,
@Nonnull final ExecutableElement method,
@Nonnull final ExecutableType trackedMethodType )
{
MethodChecks.mustBeOverridable( Constants.TRACK_ANNOTATION_CLASSNAME, method );
if ( null != _trackedMethod )
{
throw new ArezProcessorException( "@Track target duplicates existing method named " +
_trackedMethod.getSimpleName(), method );
}
else
{
_mutation = mutation;
_reportParameters = reportParameters;
_trackedMethod = Objects.requireNonNull( method );
_trackedMethodType = Objects.requireNonNull( trackedMethodType );
}
}