本文整理汇总了Java中japa.parser.ast.body.TypeDeclaration.getMembers方法的典型用法代码示例。如果您正苦于以下问题:Java TypeDeclaration.getMembers方法的具体用法?Java TypeDeclaration.getMembers怎么用?Java TypeDeclaration.getMembers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类japa.parser.ast.body.TypeDeclaration
的用法示例。
在下文中一共展示了TypeDeclaration.getMembers方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJavaMethods
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private void getJavaMethods (ArrayList<JavaMethod> methods, TypeDeclaration type) {
classStack.push(type);
if (type.getMembers() != null) {
for (BodyDeclaration member : type.getMembers()) {
if (member instanceof ClassOrInterfaceDeclaration || member instanceof EnumDeclaration) {
getJavaMethods(methods, (TypeDeclaration)member);
} else {
if (member instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration)member;
if (!ModifierSet.hasModifier(((MethodDeclaration)member).getModifiers(), ModifierSet.NATIVE)) continue;
methods.add(createMethod(method));
}
}
}
}
classStack.pop();
}
示例2: getDeclaration
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
public static FieldDeclaration getDeclaration(CompilationUnit unit, Field field) {
TypeDeclaration typeDecl = getDeclaration(unit, field.getDeclaringClass());
if (typeDecl == null) {
return null;
}
for (BodyDeclaration decl : typeDecl.getMembers()) {
if (decl instanceof FieldDeclaration) {
FieldDeclaration fieldDecl = (FieldDeclaration) decl;
List<VariableDeclarator> variables = fieldDecl.getVariables();
if (variables.size() != 1) {
continue;
}
if (field.getName().equals(variables.get(0).getId().getName())) {
return fieldDecl;
}
}
}
return null;
}
示例3: getNode
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
public static Node getNode(TypeDeclaration typeDecl, String name) {
if (typeDecl.getMembers() == null) {
return null;
}
for (BodyDeclaration bodyDecl : typeDecl.getMembers()) {
String bodyDeclName = getName(bodyDecl);
if (bodyDeclName != null && name.startsWith(bodyDeclName)) {
if (name.length() == bodyDeclName.length()) {
return bodyDecl;
}
else if (bodyDecl instanceof MethodDeclaration || bodyDecl instanceof ConstructorDeclaration) {
if (signatureMatches(bodyDecl, name.substring(bodyDeclName.length()))) {
return bodyDecl;
}
}
else if (bodyDecl instanceof TypeDeclaration) {
return getNode((TypeDeclaration) bodyDecl, name.substring(bodyDeclName.length() + 1));
}
}
}
return null;
}
示例4: find
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private static MethodDeclaration find( TypeDeclaration decl , MethodDeclaration analogous )
{
for( BodyDeclaration bodyDecl : decl.getMembers( ) )
{
if( bodyDecl instanceof MethodDeclaration )
{
MethodDeclaration methodDecl = ( MethodDeclaration ) bodyDecl;
if( methodDecl.getName( ).equals( analogous.getName( ) )
&& methodDecl.getModifiers( ) == analogous.getModifiers( )
&& sameTypes( methodDecl.getParameters( ) , analogous.getParameters( ) ) )
{
return methodDecl;
}
}
}
return null;
}
示例5: feedTestClass
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private void feedTestClass(TypeDeclaration type, UseCase useCase) throws IOException {
if (type.getComment() != null) {
useCase.setComment(type.getComment().getContent());
}
int scenarioIndex = 0;
for (BodyDeclaration bodyDeclaration : type.getMembers()) {
if (bodyDeclaration instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
if (containsAnnotation(methodDeclaration, "Test")) {
feedAndOrderScenario(scenarioIndex, methodDeclaration, useCase);
scenarioIndex++;
} else if (containsAnnotation(methodDeclaration, "BeforeClass")) {
feedTestContext(methodDeclaration, useCase.beforeUseCase,useCase);
} else if (containsAnnotation(methodDeclaration, "AfterClass")) {
feedTestContext(methodDeclaration, useCase.afterUseCase,useCase);
} else if (containsAnnotation(methodDeclaration, "Before")) {
feedTestContext(methodDeclaration, useCase.beforeScenario,useCase);
} else if (containsAnnotation(methodDeclaration, "After")) {
feedTestContext(methodDeclaration, useCase.afterScenario,useCase);
} else {
feedTestFixture(methodDeclaration, useCase);
}
}
}
useCase.helpers.completeDescriptionFromSource(configuration);
}
示例6: countAccessorMethods
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private int countAccessorMethods()
{
int count = 0;
List<TypeDeclaration> types = compUnit.getTypes();
if (types != null)
for (TypeDeclaration type : types)
{
List<BodyDeclaration> members = type.getMembers();
if (members != null)
for (BodyDeclaration member : members)
{
if (member instanceof MethodDeclaration)
{
MethodDeclaration method = (MethodDeclaration) member;
if (isAccessorMethod(method))
++count;
}
}
}
return count;
}
示例7: getAttributesNames
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private LinkedList<String> getAttributesNames()
{
List<TypeDeclaration> types = compUnit.getTypes();
LinkedList<String> attNames = new LinkedList<String>();
if (types != null)
{
for (TypeDeclaration type : types)
{
List<BodyDeclaration> members = type.getMembers();
if (members != null)
for (BodyDeclaration member : members)
if (member instanceof FieldDeclaration)
{
FieldDeclaration t = (FieldDeclaration) member;
List<VariableDeclarator> variables = t.getVariables();
for (VariableDeclarator v : variables)
attNames.add(v.getId().getName());
}
}
}
return attNames;
}
示例8: changeMethods
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private static void changeMethods(CompilationUnit cu, String rootClass) {
addImport(cu, rootClass);
String rootClassShort = rootClass
.substring(rootClass.lastIndexOf(".") + 1);
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;
if (isSetRootComponentMethod(method)) {
changeSetRootMethod(method, rootClassShort);
}
} else if (member instanceof FieldDeclaration) {
FieldDeclaration field = (FieldDeclaration) member;
if (isRootField(field)) {
changeRootField(field, rootClassShort);
}
}
}
}
}
示例9: ensureClaraFieldExists
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
public int[] ensureClaraFieldExists(String id, String className) {
List<TypeDeclaration> types = cu.getTypes();
for (TypeDeclaration type : types) {
List<BodyDeclaration> members = type.getMembers();
if (members==null) {
break;
}
for (BodyDeclaration member : members) {
if (member instanceof FieldDeclaration) {
FieldDeclaration field = (FieldDeclaration) member;
if (isClaraField(field, id, className)) {
return getMemberRowCol(field);
}
}
}
}
FieldDeclaration fd = addClaraField(id, className);
reparse();
String name = fd.getVariables().get(0).getId().getName();
int[] hmm = getFieldRowCol(name);
return hmm;
}
示例10: Declaration
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
public Declaration(TypeDeclaration decl) {
className = decl.getName();
methods = new ArrayList<String>();
attributes = new HashSet<String>();
processAnnotations(decl);
for (BodyDeclaration method : decl.getMembers()) {
processAnnotations(method);
if (method instanceof MethodDeclaration)
methods.add(((MethodDeclaration)method).getName());
}
}
示例11: insertBuilder
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private static List<String> insertBuilder( TypeDeclaration builderParentDecl , File javaFile ) throws Exception
{
List<String> lines = readLines( javaFile );
String[ ] classNames = getNestedClassNames( builderParentDecl );
List<BodyDeclaration> members = builderParentDecl.getMembers( );
for( int m = members.size( ) - 1 ; m >= 0 ; m-- )
{
BodyDeclaration decl = members.get( m );
// re-parse after every insertion, since the end line of the
// destination type will have changed
CompilationUnit compunit = parse( lines );
TypeDeclaration destType = find( compunit , classNames );
BodyDeclaration toReplace = null;
if( decl instanceof MethodDeclaration )
{
toReplace = find( destType , ( MethodDeclaration ) decl );
}
else if( decl instanceof TypeDeclaration )
{
toReplace = find( destType , ( ( TypeDeclaration ) decl ).getName( ) );
}
if( toReplace != null )
{
replace( lines , getTotalLineRegion( toReplace ) , decl.toString( ) );
}
else
{
insert( lines , destType.getEndLine( ) - 1 , destType.getEndColumn( ) - 1 , decl.toString( ) );
}
}
return lines;
}
示例12: feedHelperClass
import japa.parser.ast.body.TypeDeclaration; //导入方法依赖的package包/类
private void feedHelperClass(TypeDeclaration type, Helper helper) {
for (BodyDeclaration bodyDeclaration : type.getMembers()) {
if (bodyDeclaration instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
feedTestFixture(methodDeclaration, helper);
}
}
}
示例13: addMember
import japa.parser.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);
}