本文整理汇总了Java中javax.lang.model.util.Elements.getAllMembers方法的典型用法代码示例。如果您正苦于以下问题:Java Elements.getAllMembers方法的具体用法?Java Elements.getAllMembers怎么用?Java Elements.getAllMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.util.Elements
的用法示例。
在下文中一共展示了Elements.getAllMembers方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: hides
import javax.lang.model.util.Elements; //导入方法依赖的package包/类
private Element hides(Element field, String name, CompilationInfo info) {
Elements elements = info.getElements();
ElementUtilities utils = info.getElementUtilities();
TypeElement jc = utils.enclosingTypeElement(field);
for (Element el:elements.getAllMembers(jc)) {
//TODO:
// if (utils.willHide(el, field, name)) {
// return el;
// }
if (el.getKind().isField()) {
if (el.getSimpleName().toString().equals(name)) {
if (!el.getEnclosingElement().equals(field.getEnclosingElement())) {
return el;
}
}
}
}
return null;
}
示例3: getSetter
import javax.lang.model.util.Elements; //导入方法依赖的package包/类
public static String getSetter(Element element, Elements elements) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
String elementName = element.getSimpleName().toString();
String elementNameLowerCase = elementName.toLowerCase();
List<String> possibleMethodNames = new ArrayList<>();
possibleMethodNames.add("set" + elementNameLowerCase);
// Handle the case where variables are named in the form mVariableName instead of just variableName
if (elementName.length() > 1 && elementName.charAt(0) == 'm' && (elementName.charAt(1) >= 'A' && elementName.charAt(1) <= 'Z')) {
possibleMethodNames.add("set" + elementNameLowerCase.substring(1));
}
List<? extends Element> elementMembers = elements.getAllMembers(enclosingElement);
List<ExecutableElement> elementMethods = ElementFilter.methodsIn(elementMembers);
for (ExecutableElement methodElement : elementMethods) {
String methodNameString = methodElement.getSimpleName().toString();
String methodNameLowerCase = methodNameString.toLowerCase();
if (possibleMethodNames.contains(methodNameLowerCase)) {
if (methodElement.getParameters().size() == 1) {
if (methodElement.getParameters().get(0).asType().toString().equals(element.asType().toString())) {
return methodNameString;
}
}
}
}
return null;
}
示例4: collectExistingMethodNames
import javax.lang.model.util.Elements; //导入方法依赖的package包/类
/**
* Collects names of accessible no-argument methods that are present
* in the given class and its superclasses. Methods inherited from the
* class's superclasses are taken into account, too.
*
* @param clazz class whose methods' names should be collected
* @param reservedMethodNames collection to which the method names
* should be added
*/
private void collectExistingMethodNames(TypeElement clazz,
Collection<String> reservedMethodNames) {
final Elements elements = workingCopy.getElements();
List<? extends Element> allMembers = elements.getAllMembers(clazz);
List<? extends ExecutableElement> methods = ElementFilter.methodsIn(allMembers);
if (!methods.isEmpty()) {
for (ExecutableElement method : methods) {
if (method.getParameters().isEmpty()) {
reservedMethodNames.add(method.getSimpleName().toString());
}
}
}
}
示例5: hidesSupTypeMember
import javax.lang.model.util.Elements; //导入方法依赖的package包/类
private boolean hidesSupTypeMember(Element methElement, TypeElement superTypeElement) {
Elements elements = workingCopy.getElements();
List<? extends Element> containedElements = elements.getAllMembers(superTypeElement);
for (Element elem : containedElements) {
boolean isPresentInSuperType = methElement.equals(elem) ||
elements.hides(methElement, elem);
if ((elem != null) && isStatic(elem) && isPresentInSuperType) {
return true;
}
}
return false;
}
示例6: isHidingMember
import javax.lang.model.util.Elements; //导入方法依赖的package包/类
private boolean isHidingMember(TypeElement subTypeElement, Element variableElement,
TypeElement superTypeElement) {
//TODO: We do not handle nested types yet (includes enums)
Elements elements = workingCopy.getElements();
List<? extends Element> memberElements = elements.getAllMembers(superTypeElement);
for (Element elem : memberElements) {
if(variableElement.equals(elem) || elements.hides(variableElement, elem)){
return true;
}
}
return false;
}
示例7: getGetter
import javax.lang.model.util.Elements; //导入方法依赖的package包/类
public static String getGetter(Element element, Elements elements) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
TypeKind elementTypeKind = element.asType().getKind();
String elementName = element.getSimpleName().toString();
String elementNameLowerCase = elementName.toLowerCase();
List<String> possibleMethodNames = new ArrayList<>();
possibleMethodNames.add("get" + elementNameLowerCase);
if (elementTypeKind == TypeKind.BOOLEAN) {
possibleMethodNames.add("is" + elementNameLowerCase);
possibleMethodNames.add("has" + elementNameLowerCase);
possibleMethodNames.add(elementNameLowerCase);
}
// Handle the case where variables are named in the form mVariableName instead of just variableName
if (elementName.length() > 1 && elementName.charAt(0) == 'm' && (elementName.charAt(1) >= 'A' && elementName.charAt(1) <= 'Z')) {
possibleMethodNames.add("get" + elementNameLowerCase.substring(1));
if (elementTypeKind == TypeKind.BOOLEAN) {
possibleMethodNames.add("is" + elementNameLowerCase.substring(1));
possibleMethodNames.add("has" + elementNameLowerCase.substring(1));
possibleMethodNames.add(elementNameLowerCase.substring(1));
}
}
List<? extends Element> elementMembers = elements.getAllMembers(enclosingElement);
List<ExecutableElement> elementMethods = ElementFilter.methodsIn(elementMembers);
for (ExecutableElement methodElement : elementMethods) {
if (methodElement.getParameters().size() == 0) {
String methodNameString = methodElement.getSimpleName().toString();
String methodNameLowerCase = methodNameString.toLowerCase();
if (possibleMethodNames.contains(methodNameLowerCase)) {
if (methodElement.getParameters().size() == 0) {
if (methodElement.getReturnType().toString().equals(element.asType().toString())) {
return methodNameString;
}
}
}
}
}
return null;
}