本文整理汇总了Java中com.github.javaparser.ast.body.TypeDeclaration.getMembers方法的典型用法代码示例。如果您正苦于以下问题:Java TypeDeclaration.getMembers方法的具体用法?Java TypeDeclaration.getMembers怎么用?Java TypeDeclaration.getMembers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.body.TypeDeclaration
的用法示例。
在下文中一共展示了TypeDeclaration.getMembers方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addResourceType
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private static void addResourceType(List<String> supportedTypes, TypeSpec.Builder result,
TypeDeclaration node) {
if (!supportedTypes.contains(node.getName())) {
return;
}
String type = node.getName();
TypeSpec.Builder resourceType = TypeSpec.classBuilder(type).addModifiers(PUBLIC, STATIC, FINAL);
for (BodyDeclaration field : node.getMembers()) {
if (field instanceof FieldDeclaration) {
addResourceField(resourceType, ((FieldDeclaration) field).getVariables().get(0),
getSupportAnnotationClass(type));
}
}
result.addType(resourceType.build());
}
示例2: extractInformation
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private void extractInformation(String filename) throws ClassParserException {
List<TypeDeclaration> types = cu.getTypes();
for (TypeDeclaration type : types) {
if (type instanceof ClassOrInterfaceDeclaration) {
clazz = (ClassOrInterfaceDeclaration) type;
}
List<BodyDeclaration> members = type.getMembers();
for (BodyDeclaration member : members) {
if (member instanceof FieldDeclaration) {
fields.add((FieldDeclaration) member);
}
else if (member instanceof ConstructorDeclaration) {
constructors.add((ConstructorDeclaration) member);
}
else if (member instanceof MethodDeclaration) {
methods.add((MethodDeclaration) member);
}
}
}
if (clazz == null) {
throw new ClassParserException("No toplevel type declaration found in " + filename + ".");
}
}
示例3: getMethodByPositionAndClassPosition
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
public static MethodDeclaration getMethodByPositionAndClassPosition(CompilationUnit compilationUnit,
int methodPosition, int classPosition) {
TypeDeclaration type = compilationUnit.getTypes().get(classPosition -1);
int memberCount = 0;
int methodCount = 0;
for(BodyDeclaration bodyDeclaration : type.getMembers()) {
if(bodyDeclaration instanceof MethodDeclaration){
if(methodCount == methodPosition -1) {
return (MethodDeclaration) type.getMembers().get(memberCount);
}
methodCount++;
}
memberCount++;
}
throw new IllegalArgumentException("Method not found at position " +methodPosition+ "in class " + classPosition);
}
示例4: changeMethods
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private static void changeMethods(CompilationUnit cu) {
List<TypeDeclaration> types = cu.getTypes();
for (TypeDeclaration type : types) {
List<BodyDeclaration> members = type.getMembers();
for (BodyDeclaration member : members) {
if (member instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) member;
changeMethod(method);
}
}
}
}
示例5: getMemberByTypeAndPosition
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
public static BodyDeclaration getMemberByTypeAndPosition(TypeDeclaration typeDeclaration, int position,
Class<? extends BodyDeclaration> typeClass){
int typeCount = 0;
for(BodyDeclaration declaration : typeDeclaration.getMembers()){
if(declaration.getClass().equals(typeClass)){
if(typeCount == position){
return declaration;
}
typeCount++;
}
}
throw new IllegalArgumentException("No member " + typeClass + " at position: " + position );
}
示例6: doCompile
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
@Override
protected UnitCache<EmulTypeElement> doCompile(TypeDeclaration unit) {
String unitName = unit.getName();
String qualifiedName = TypeUtil.determineQualifiedName(
getCompileUnit(), unit.getNameExpr());
TypeMirror type = new EmulType(new StringName(qualifiedName), TypeKind.DECLARED);
Name name = new StringName(unitName);
ElementKind kind = ElementKind.OTHER;
List<Element> members = new ArrayList<>();
Set<Modifier> modifierSet = ModifierUtil.asSet(unit.getModifiers());
if(unit instanceof AnnotationDeclaration) {
kind = ElementKind.ANNOTATION_TYPE;
} else if(unit instanceof EnumDeclaration) {
kind = ElementKind.ENUM;
} else if(unit instanceof ClassOrInterfaceDeclaration) {
if(((ClassOrInterfaceDeclaration) unit).isInterface()) {
kind = ElementKind.INTERFACE;
} else {
kind = ElementKind.CLASS;
}
}
EmulTypeElement element = new EmulTypeElement(type, kind, parent, members,
modifierSet, name, name, NestingKind.TOP_LEVEL);
// Children
NodeToElementCompiler compiler = new NodeToElementCompiler(getCompileUnit(), element);
for(BodyDeclaration member : unit.getMembers()) {
Element childElem = compiler.compile(member);
if(childElem != null) {
members.add(childElem);
}
}
return new UnitCache<>(element);
}
示例7: findModel
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private EnumDeclaration findModel(TypeDeclaration mainType) {
for(BodyDeclaration member:mainType.getMembers()){
if(member instanceof EnumDeclaration){
EnumDeclaration mem=(EnumDeclaration)member;
if(mem.getName().equals("Field")){
return (EnumDeclaration) member;
}
}
}
return null;
}
示例8: parseEnum
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
/**
*
* @param td
* the parsed enum
* @return
* an enum structure
*/
private EnumDecl parseEnum(TypeDeclaration td) {
// enum
EnumDeclaration enumeration = (EnumDeclaration) td;
EnumDecl enumDecl = new EnumDecl();
ClassRef superClass = new ClassRef();
if (td.getComment()!= null) {
List<String> javadoc = ParserUtils.prepareComments(td.getComment().getContent());
enumDecl.setDoc(javadoc);
}
enumDecl.setName(td.getName());
enumDecl.setVisibility(visibility(td.getModifiers()));
if (enumeration.getEntries() != null) {
List<Ident> entries = new ArrayList<>();
for (Ident entry : entries) {
Ident ident = new Ident(entry.getName());
entries.add(ident);
this.loc++;
}
enumDecl.setEnumConstants(entries);
}
List<InterfaceRef> implems = new ArrayList<>();
if (enumeration.getImplements() != null) {
for (ClassOrInterfaceType obj : enumeration.getImplements()) {
InterfaceRef implInterface = new InterfaceRef(null, obj.toString());
implems.add(implInterface);
}
}
enumDecl.setImplementedInterfaces(implems);
List<Attribute> attributes = new ArrayList<>();
List<ConstructorDecl> constructors = new ArrayList<>();
List<Method> methods = new ArrayList<>();
if (td.getMembers() != null) {
for (BodyDeclaration bodyElmt : td.getMembers()) {
if (bodyElmt instanceof FieldDeclaration) { // attribute
FieldDeclaration fd = (FieldDeclaration) bodyElmt;
attributes.addAll(parseAttribute(fd));
this.loc++;
} else if (bodyElmt instanceof ConstructorDeclaration) { // constructor
ConstructorDeclaration cd = (ConstructorDeclaration) bodyElmt;
constructors.add(parseConstructor(cd, attributes, superClass.getClassName()));
this.loc++;
} else if (bodyElmt instanceof MethodDeclaration) { // method
MethodDeclaration md = (MethodDeclaration) bodyElmt;
methods.add(parseMethod(md, attributes));
this.loc++;
} else if (bodyElmt instanceof ClassOrInterfaceDeclaration) {
this.classes.add(parseClass((TypeDeclaration) bodyElmt));
this.loc++;
}
}
}
enumDecl.setAttributes(attributes);
enumDecl.setConstructors(constructors);
enumDecl.setMethods(methods);
return enumDecl;
}
示例9: addMember
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
/**
* Adds the given declaration to the specified type. The list of members
* will be initialized if it is <code>null</code>.
*
* @param type
* type declaration
* @param decl
* member declaration
*/
public static void addMember(TypeDeclaration type, BodyDeclaration decl) {
List<BodyDeclaration> members = type.getMembers();
if (isNullOrEmpty(members)) {
members = new ArrayList<BodyDeclaration>();
type.setMembers(members);
}
members.add(decl);
}
示例10: addMember
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
/**
* Adds the given declaration to the specified type. The list of members
* will be initialized if it is <code>null</code>.
*
* @param type
* type declaration
* @param decl
* member declaration
*/
public static void addMember(TypeDeclaration type, BodyDeclaration decl) {
List<BodyDeclaration> members = type.getMembers();
if (members == null) {
members = new ArrayList<BodyDeclaration>();
type.setMembers(members);
}
members.add(decl);
}
示例11: addMember
import com.github.javaparser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
/**
* Adds the given declaration to the specified type. The list of members
* will be initialized if it is <code>null</code>.
*
* @param type
* type declaration
* @param decl
* member declaration
*/
public static void addMember(TypeDeclaration type, BodyDeclaration decl) {
List<BodyDeclaration> members = type.getMembers();
if (isNullOrEmpty(members)) {
members = new ArrayList<BodyDeclaration>();
type.setMembers(members);
}
members.add(decl);
}