当前位置: 首页>>代码示例>>Java>>正文


Java TypeDeclaration.getMembers方法代码示例

本文整理汇总了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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:FinalRClassBuilder.java

示例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 + ".");
	}
}
 
开发者ID:umlet,项目名称:umlet,代码行数:24,代码来源:JpJavaClass.java

示例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);
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:SharedSteps.java

示例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);
            }
        }
    }
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:13,代码来源:MethodChangerWithoutVisitor.java

示例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 );
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:14,代码来源:SharedSteps.java

示例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);
}
 
开发者ID:BenDol,项目名称:Databind,代码行数:41,代码来源:NodeToTypeElementCompiler.java

示例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;
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:12,代码来源:EntityCastor.java

示例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;
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:67,代码来源:Parser.java

示例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);
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:ASTHelper.java

示例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);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:18,代码来源:ASTHelper.java

示例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);
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:18,代码来源:ASTHelper.java


注:本文中的com.github.javaparser.ast.body.TypeDeclaration.getMembers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。