本文整理汇总了Java中javax.lang.model.element.TypeElement.getEnclosedElements方法的典型用法代码示例。如果您正苦于以下问题:Java TypeElement.getEnclosedElements方法的具体用法?Java TypeElement.getEnclosedElements怎么用?Java TypeElement.getEnclosedElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.TypeElement
的用法示例。
在下文中一共展示了TypeElement.getEnclosedElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BundlerClassInfo
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public BundlerClassInfo(TypeElement te) {
typeElement = te;
className = ClassName.get(typeElement);
for (Element e : te.getEnclosedElements()) {
if (e.getKind() == ElementKind.FIELD) {
VariableElement ve = (VariableElement) e;
fields.add(ve);
}
if (e.getKind() == ElementKind.METHOD) {
ExecutableElement ee = (ExecutableElement) e;
methods.add(ee);
}
}
}
示例2: visitType
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public TypeElement visitType(TypeElement typeElement, String binaryName) {
String bName = ElementUtilities.getBinaryName(typeElement);
if(binaryName.equals(bName)) {
return typeElement;
} else if(binaryName.startsWith(bName)) {
for(Element child : typeElement.getEnclosedElements()) {
if(!child.getKind().isClass()) {
continue;
}
TypeElement retVal = child.accept(this, binaryName);
if(retVal != null) {
return retVal;
}
}
}
return null;
}
示例3: overriddenMethod
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public ExecutableElement overriddenMethod(ExecutableElement method) {
if (isStatic(method)) {
return null;
}
final TypeElement origin = getEnclosingTypeElement(method);
for (TypeMirror t = getSuperType(origin);
t.getKind() == DECLARED;
t = getSuperType(asTypeElement(t))) {
TypeElement te = asTypeElement(t);
if (te == null) {
return null;
}
List<? extends Element> methods = te.getEnclosedElements();
for (ExecutableElement ee : ElementFilter.methodsIn(methods)) {
if (configuration.workArounds.overrides(method, ee, origin)) {
return ee;
}
}
if (t.equals(getObjectType()))
return null;
}
return null;
}
示例4: parseCompiledR
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
for (Element element : rClass.getEnclosedElements()) {
String innerClassName = element.getSimpleName().toString();
if (innerClassName.equals("string")) {
for (Element enclosedElement : element.getEnclosedElements()) {
if (enclosedElement instanceof VariableElement) {
VariableElement variableElement = (VariableElement) enclosedElement;
Object value = variableElement.getConstantValue();
if (value instanceof Integer) {
int id = (Integer) value;
ClassName rClassName = ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R", innerClassName);
String resourceName = variableElement.getSimpleName().toString();
QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
}
}
}
}
}
}
示例5: enumerateFieldElements
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private static void enumerateFieldElements( @Nonnull final TypeElement element,
@Nonnull final Map<String, VariableElement> fields )
{
final TypeMirror superclass = element.getSuperclass();
if ( TypeKind.NONE != superclass.getKind() )
{
enumerateFieldElements( (TypeElement) ( (DeclaredType) superclass ).asElement(), fields );
}
for ( final Element member : element.getEnclosedElements() )
{
if ( member.getKind() == ElementKind.FIELD )
{
fields.put( member.getSimpleName().toString(), (VariableElement) member );
}
}
}
示例6: parseCompiledR
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
for (Element element : rClass.getEnclosedElements()) {
String innerClassName = element.getSimpleName().toString();
if (supportedTypes.contains(innerClassName)) {
for (Element enclosedElement : element.getEnclosedElements()) {
if (enclosedElement instanceof VariableElement) {
VariableElement variableElement = (VariableElement) enclosedElement;
Object value = variableElement.getConstantValue();
if (value instanceof Integer) {
int id = (Integer) value;
ClassName rClassName = ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R", innerClassName);
String resourceName = variableElement.getSimpleName().toString();
QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
}
}
}
}
}
}
示例7: hasTestableMethods
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
*/
private boolean hasTestableMethods(TypeElement classElem) {
List<? extends Element> enclosedElems = classElem.getEnclosedElements();
if (enclosedElems.isEmpty()) {
return false;
}
List<ExecutableElement> methods = ElementFilter.methodsIn(enclosedElems);
if (methods.isEmpty()) {
return false;
}
for (ExecutableElement method : methods) {
if (isMethodTestable(method)) {
return true;
}
}
return false;
}
示例8: createInitialObjects
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public List<ResourceImpl> createInitialObjects() {
final List<ResourceImpl> result = new ArrayList<ResourceImpl>();
TypeElement departmentType = helper.getCompilationController().getElements().getTypeElement("foo.Department");
for (Element element : departmentType.getEnclosedElements()) {
if (isResource(element)) {
result.add(new ResourceImpl(helper, departmentType, element));
}
}
return result;
}
示例9: getExistingMethods
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* Returns a list of methods contained directly in the given class.
*
* @param classElem class whose methods should be returned
* @return list of methods in the given class
*/
private static List<ExecutableElement> getExistingMethods(
final TypeElement classElem) {
List<? extends Element> elements = classElem.getEnclosedElements();
if (elements.isEmpty()) {
return Collections.<ExecutableElement>emptyList();
}
List<ExecutableElement> methods = ElementFilter.methodsIn(elements);
return !methods.isEmpty() ? methods
: Collections.<ExecutableElement>emptyList();
}
示例10: AttributesHelper
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public AttributesHelper(AnnotationModelHelper helper, TypeElement typeElement, PropertyHandler propertyHandler) {
this.helper = helper;
this.typeElement = typeElement;
this.propertyHandler = propertyHandler;
if (typeElement == null) {
fieldAccess = true;
return;
}
List<? extends Element> elements = typeElement.getEnclosedElements();
fieldAccess = EntityMappingsUtilities.hasFieldAccess(helper, elements);
}
示例11: getFields
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
List<Element> getFields(TypeElement klass) {
List<Element> out = new ArrayList<>();
for (Element e : klass.getEnclosedElements()) {
if (e.getKind() == ElementKind.FIELD) {
out.add(e);
}
}
return out;
}
示例12: findMethod
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/** Gets the method we are looking for
*/
private static ElementHandle findMethod(CompilationController ctrl, TypeElement ce, String member) {
TreeUtilities utils = ctrl.getTreeUtilities();
int pi = member.indexOf( '(' );
String name = member.substring( 0, pi );
StringTokenizer tokenizer = new StringTokenizer( member.substring( pi ), " ,()" ); // NOI18N
List<TypeMirror> paramList = new ArrayList<TypeMirror>();
while( tokenizer.hasMoreTokens() ) {
String token = tokenizer.nextToken();
if (token.endsWith("...")) { // NOI18N
// translate varargs to array
token = token.substring(0, token.length() - 3);
token += "[]"; // NOI18N
}
TypeMirror type = utils.parseType(token, ce);
paramList.add(type);
}
// search method or constructor
for (Element e: ce.getEnclosedElements()) {
if (e.getKind() == ElementKind.METHOD
&& name.equals(e.getSimpleName().toString())
&& compareTypes(ctrl, paramList, ((ExecutableElement) e).getParameters())) {
return ElementHandle.create(e);
} else if (e.getKind() == ElementKind.CONSTRUCTOR
&& name.equals(ce.getSimpleName().toString())
&& compareTypes(ctrl, paramList, ((ExecutableElement) e).getParameters())) {
return ElementHandle.create(e);
}
}
return null;
}
示例13: create
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public List<? extends CodeGenerator> create(Lookup context) {
ArrayList<CodeGenerator> ret = new ArrayList<>();
JTextComponent component = context.lookup(JTextComponent.class);
CompilationController controller = context.lookup(CompilationController.class);
if (component == null || controller == null) {
return ret;
}
TreePath path = context.lookup(TreePath.class);
path = path != null ? controller.getTreeUtilities().getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, path) : null;
if (path == null) {
return ret;
}
try {
controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
} catch (IOException ioe) {
return ret;
}
TypeElement typeElement = (TypeElement) controller.getTrees().getElement(path);
if (typeElement == null || !typeElement.getKind().isClass()) {
return ret;
}
List<ElementNode.Description> descriptions = new ArrayList<>();
for (Element element : typeElement.getEnclosedElements()) {
switch (element.getKind()) {
case METHOD:
if (element.getSimpleName().contentEquals("toString") && ((ExecutableElement) element).getParameters().isEmpty()) { //NOI18N
return ret;
}
break;
case FIELD:
if (!ERROR.contentEquals(element.getSimpleName()) && !element.getModifiers().contains(Modifier.STATIC)) {
descriptions.add(ElementNode.Description.create(controller, element, null, true, true));
}
}
}
ret.add(new ToStringGenerator(component, ElementNode.Description.create(controller, typeElement, descriptions, false, false)));
return ret;
}
示例14: buildAnnotatedClass
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private AnnotatedClass buildAnnotatedClass(TypeElement typeElement) throws
NoPackageNameException, IOException {
HashMap<String, TypeMirror> variableMap = new HashMap<>();
ArrayList<String> variableNames = new ArrayList<>();
for (Element element : typeElement.getEnclosedElements()) {
//过滤 字段 的Element
if (!(element instanceof VariableElement)) {
continue;
}
//过滤 static final 字段
if (element.getModifiers().contains(STATIC) || element.getModifiers().contains(FINAL)) {
continue;
}
VariableElement variableElement = (VariableElement) element;
variableNames.add(variableElement.getSimpleName().toString());
variableMap.put(
variableElement.getSimpleName().toString(),
variableElement.asType()
);
}
//打印 用于测试 是否为 parcelable
if (isParcelable(typeElement)) {
String message = String.format("Classes %s is parceleble.", ANNOTATION);
//messager.printMessage(Diagnostic.Kind.OTHER, message, typeElement);
}
return new AnnotatedClass(typeElement, variableNames, variableMap,
isParcelable(typeElement));
}
示例15: isCallbackMethodAnnotationValid
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public boolean isCallbackMethodAnnotationValid(Element element, String annotationName) {
TypeElement enclosingElement = (TypeElement)element.getEnclosingElement();
if (enclosingElement.getAnnotation(JsonObject.class) == null) {
error(enclosingElement, "%s: @%s methods can only be in classes annotated with @%s.", enclosingElement.getQualifiedName(), annotationName, JsonObject.class.getSimpleName());
return false;
}
ExecutableElement executableElement = (ExecutableElement)element;
if (executableElement.getParameters().size() > 0) {
error(element, "%s: @%s methods must not take any parameters.", enclosingElement.getQualifiedName(), annotationName);
return false;
}
List<? extends Element> allElements = enclosingElement.getEnclosedElements();
int methodInstances = 0;
for (Element enclosedElement : allElements) {
for (AnnotationMirror am : enclosedElement.getAnnotationMirrors()) {
if (am.getAnnotationType().asElement().getSimpleName().toString().equals(annotationName)) {
methodInstances++;
}
}
}
if (methodInstances != 1) {
error(element, "%s: There can only be one @%s method per class.", enclosingElement.getQualifiedName(), annotationName);
return false;
}
return true;
}