本文整理汇总了Java中javax.lang.model.util.Elements.overrides方法的典型用法代码示例。如果您正苦于以下问题:Java Elements.overrides方法的具体用法?Java Elements.overrides怎么用?Java Elements.overrides使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.util.Elements
的用法示例。
在下文中一共展示了Elements.overrides方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMethodAvailable
import javax.lang.model.util.Elements; //导入方法依赖的package包/类
private boolean isMethodAvailable(TypeElement subTypeElement,
ExecutableElement execElem, TypeElement superTypeElement) {
Elements elements = workingCopy.getElements();
List<? extends Element> memberElements = elements.getAllMembers(superTypeElement);
for (Element elem : memberElements) {
if(ElementKind.METHOD.equals(elem.getKind())){
if(execElem.getModifiers().contains(Modifier.STATIC) && elements.hides(execElem, elem)){
return true;
}else{
if(execElem.equals(elem) || elements.overrides(execElem, (ExecutableElement)elem,
subTypeElement)){
return true;
}
}
}
}
return false;
}
示例2: getLocalAndInheritedMethods
import javax.lang.model.util.Elements; //导入方法依赖的package包/类
/**
* Returns the set of all non-private methods from {@code type}, including methods that it
* inherits from its ancestors. Inherited methods that are overridden are not included in the
* result. So if {@code type} defines {@code public String toString()}, the returned set will
* contain that method, but not the {@code toString()} method defined by {@code Object}.
* <p/>
* <p>The returned set may contain more than one method with the same signature, if
* {@code type} inherits those methods from different ancestors. For example, if it
* inherits from unrelated interfaces {@code One} and {@code Two} which each define
* {@code void foo();}, and if it does not itself override the {@code foo()} method,
* then both {@code One.foo()} and {@code Two.foo()} will be in the returned set.
*
* @param type the type whose own and inherited methods are to be returned
* @param elementUtils an {@link Elements} object, typically returned by
* {@link javax.annotation.processing.AbstractProcessor#processingEnv processingEnv}<!--
* -->.{@link javax.annotation.processing.ProcessingEnvironment.getElementUtils()
* getElementUtils()}
*/
public static ImmutableSet<ExecutableElement> getLocalAndInheritedMethods(
TypeElement type, Elements elementUtils) {
SetMultimap<String, ExecutableElement> methodMap = LinkedHashMultimap.create();
getLocalAndInheritedMethods(getPackage(type), type, methodMap);
// Find methods that are overridden. We do this using `Elements.overrides`, which means
// that it is inherently a quadratic operation, since we have to compare every method against
// every other method. We reduce the performance impact by (a) grouping methods by name, since
// a method cannot override another method with a different name, and (b) making sure that
// methods in ancestor types precede those in descendant types, which means we only have to
// check a method against the ones that follow it in that order.
Set<ExecutableElement> overridden = new LinkedHashSet<ExecutableElement>();
for (String methodName : methodMap.keySet()) {
List<ExecutableElement> methodList = ImmutableList.copyOf(methodMap.get(methodName));
for (int i = 0; i < methodList.size(); i++) {
ExecutableElement methodI = methodList.get(i);
for (int j = i + 1; j < methodList.size(); j++) {
ExecutableElement methodJ = methodList.get(j);
if (elementUtils.overrides(methodJ, methodI, type)) {
overridden.add(methodI);
}
}
}
}
Set<ExecutableElement> methods = new LinkedHashSet<ExecutableElement>(methodMap.values());
methods.removeAll(overridden);
return ImmutableSet.copyOf(methods);
}