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


Java MethodDeclaration类代码示例

本文整理汇总了Java中japa.parser.ast.body.MethodDeclaration的典型用法代码示例。如果您正苦于以下问题:Java MethodDeclaration类的具体用法?Java MethodDeclaration怎么用?Java MethodDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MethodDeclaration类属于japa.parser.ast.body包,在下文中一共展示了MethodDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
@Override
public void visit(MethodDeclaration method, A result) {
    if (CollectionUtils.isEmpty(method.getAnnotations())) {
        return;
    }
    for (AnnotationExpr annotation : method.getAnnotations()) {
        if (!annotation.getClass().equals(NormalAnnotationExpr.class)) {
            continue;
        }
        NormalAnnotationExpr annot = (NormalAnnotationExpr) annotation;
        if (annot.getName().toString().equals(SampleCode.class.getSimpleName())
                && !CollectionUtils.isEmpty(annot.getPairs())) {
            for (MemberValuePair pair : annot.getPairs()) {
                // get the 'api' parameter from the annotation to let us know which api this function belongs to
                if (StringUtils.equals(pair.getName(), "api") && !StringUtils.isBlank(pair.getValue().toString())) {
                    result.put(getCacheRowKey(type, pair.getValue().toString().replace("\"", "")), stripTestPrefix(method.getName()),
                            stripCurlyBrackets(method.getBody().toString()));
                    return;
                }
            }
        }
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:24,代码来源:SampleCodeParser.java

示例2: getJavaMethods

import japa.parser.ast.body.MethodDeclaration; //导入依赖的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();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:18,代码来源:RobustJavaMethodParser.java

示例3: getNode

import japa.parser.ast.body.MethodDeclaration; //导入依赖的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;
}
 
开发者ID:jedwards1211,项目名称:breakout,代码行数:23,代码来源:JavaParserUtils.java

示例4: methodDeclMatches

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
private static boolean methodDeclMatches(MethodDeclaration methodDecl, Method method) {
	if (!method.getName().equals(methodDecl.getName())) {
		return false;
	}

	if (!typeMatches(getRawTypeName(methodDecl.getType()), method.getReturnType())) {
		return false;
	}

	List<Parameter> declParams = methodDecl.getParameters();
	Class<?>[] methodParams = method.getParameterTypes();

	if (declParams.size() != methodParams.length) {
		return false;
	}

	for (int i = 0; i < declParams.size(); i++) {
		if (!typeMatches(getRawTypeName(declParams.get(i).getType()), methodParams[i])) {
			return false;
		}
	}

	return true;
}
 
开发者ID:jedwards1211,项目名称:breakout,代码行数:25,代码来源:JavaParserUtils.java

示例5: find

import japa.parser.ast.body.MethodDeclaration; //导入依赖的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;
}
 
开发者ID:jedwards1211,项目名称:breakout,代码行数:18,代码来源:BuilderGenerator.java

示例6: feedTestClass

import japa.parser.ast.body.MethodDeclaration; //导入依赖的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);
}
 
开发者ID:slezier,项目名称:SimpleFunctionalTest,代码行数:27,代码来源:UseCaseJavaParser.java

示例7: extractFixtureCalls

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
private ArrayList<FixtureCall> extractFixtureCalls(UseCase useCase,MethodDeclaration methodDeclaration) {
    ArrayList<FixtureCall> fixtureCalls = new ArrayList<FixtureCall>();
    if( methodDeclaration.getBody().getStmts() == null){
        System.err.println("In class "+javaClass.getCanonicalName()+" method " + methodDeclaration.getName() + " don't have any fixture call.");
        return fixtureCalls;
    }
    int line = methodDeclaration.getBody().getBeginLine();
    for (Statement stmt : methodDeclaration.getBody().getStmts()) {
        if (stmt instanceof ExpressionStmt) {
            Expression expr = ((ExpressionStmt) stmt).getExpression();
            if (expr instanceof MethodCallExpr) {
                final int emptyLines = stmt.getBeginLine() - 1 - line;
                fixtureCalls.add(extractFixtureCall(useCase, (MethodCallExpr) expr,emptyLines));
                line= stmt.getBeginLine();
            }
        }
    }
    return fixtureCalls;
}
 
开发者ID:slezier,项目名称:SimpleFunctionalTest,代码行数:20,代码来源:UseCaseJavaParser.java

示例8: countAccessorMethods

import japa.parser.ast.body.MethodDeclaration; //导入依赖的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;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:27,代码来源:NumberOfAccessorMethods.java

示例9: isGetterMethod

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
private boolean isGetterMethod(MethodDeclaration method)
{
    if ((method.getBody() != null) && (method.getBody().getStmts() != null))
    {
        LinkedList<String> attNames = getAttributesNames();
        
        if (attNames.size() == 0)
            return false;
        
        List<Statement> stmts = method.getBody().getStmts();        

        for (Statement stmt : stmts)
            for (String name : attNames)
                if ((stmt.toString().matches("(.*)return(\\s+)" + name + "(\\s*);")) && (method.getModifiers() == ModifierSet.PUBLIC) && (method.getParameters() == null))
                    return true;
    }
    
    return false;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:20,代码来源:NumberOfAccessorMethods.java

示例10: isSetterMethod

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
private boolean isSetterMethod(MethodDeclaration method)
{
    if ((method.getBody() != null) && (method.getBody().getStmts() != null))
    {
        LinkedList<String> attNames = getAttributesNames();
        
        if (attNames.size() == 0)
            return false;
        
        List<Statement> stmts = method.getBody().getStmts();        

        for (Statement stmt : stmts)
            for (String name : attNames)
                if ((method.getModifiers() == ModifierSet.PUBLIC) && (method.getParameters() != null) && (method.getParameters().size() == 1) && (method.getType().equals(new VoidType())) && (stmt.toString().matches("(.*)"+name+"(\\s*)=(.*)"+method.getParameters().get(0).getId().getName()+"(.*);")))
                    return true;
    }
    
    return false;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:20,代码来源:NumberOfAccessorMethods.java

示例11: changeMethods

import japa.parser.ast.body.MethodDeclaration; //导入依赖的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);
                }
            }
        }
    }
}
 
开发者ID:ahn,项目名称:mideaas,代码行数:24,代码来源:JavaUtil.java

示例12: addAttachSkeleton

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
private void addAttachSkeleton() {
	List<Parameter> params = Collections.emptyList();
	MethodDeclaration method = new MethodDeclaration(
			ModifierSet.PUBLIC, new VoidType(), "attach", params);
	AnnotationExpr override = new MarkerAnnotationExpr(new NameExpr("Override"));
	method.setAnnotations(Collections.singletonList(override));
	
	BlockStmt block = new BlockStmt();
	Expression e = new MethodCallExpr(new SuperExpr(), "attach");
	List<Statement> sts = Collections.singletonList((Statement)new ExpressionStmt(e));
	block.setStmts(sts);
	method.setBody(block);
	
	if (getType().getMembers()==null) {
		getType().setMembers(new LinkedList<BodyDeclaration>());
	}
	getType().getMembers().add(method);
}
 
开发者ID:ahn,项目名称:mideaas,代码行数:19,代码来源:ControllerCode.java

示例13: addOnBecomingVisibleMethod

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
@SuppressWarnings("unused")
private void addOnBecomingVisibleMethod() {
	List<Parameter> params = Collections.emptyList();
	MethodDeclaration method = new MethodDeclaration(
			ModifierSet.PUBLIC, new VoidType(), "onBecomingVisible", params);
	AnnotationExpr override = new MarkerAnnotationExpr(new NameExpr("Override"));
	method.setAnnotations(Collections.singletonList(override));
	
	BlockStmt block = new BlockStmt();
	Expression e = new MethodCallExpr(new SuperExpr(), "onBecomingVisible");
	List<Statement> sts = Collections.singletonList((Statement)new ExpressionStmt(e));
	block.setStmts(sts);
	method.setBody(block);
	
	if (getType().getMembers()==null) {
		getType().setMembers(new LinkedList<BodyDeclaration>());
	}
	getType().getMembers().add(method);
}
 
开发者ID:ahn,项目名称:mideaas,代码行数:20,代码来源:ControllerCode.java

示例14: addClaraHandler

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
private MethodDeclaration addClaraHandler(String id, String className) {
	ensureImport(className);
	String shortName = className.substring(className.lastIndexOf(".")+1);
	String handlerName = generateHandlerNameFor(id, shortName);
	
	Parameter p = new Parameter(new ClassOrInterfaceType(shortName), new VariableDeclaratorId("event"));
	MethodDeclaration handler = new MethodDeclaration(
			ModifierSet.PUBLIC, new VoidType(), handlerName, Collections.singletonList(p));
	handler.setBody(new BlockStmt());
	handler.setAnnotations(createClaraHandlerAnnotations(id));
	
	addNotification(handler, shortName+" on "+id);		
	
	addMember(handler);
	return handler;
}
 
开发者ID:ahn,项目名称:mideaas,代码行数:17,代码来源:ControllerCode.java

示例15: isClaraHandler

import japa.parser.ast.body.MethodDeclaration; //导入依赖的package包/类
private static boolean isClaraHandler(MethodDeclaration method, String id,
		String className) {
	if (method.getAnnotations()==null) {
		return false;
	}
	for (AnnotationExpr ann : method.getAnnotations()) {
		if ("UiHandler".equals(ann.getName().getName())) {
			if (ann instanceof SingleMemberAnnotationExpr) {
				SingleMemberAnnotationExpr smae = (SingleMemberAnnotationExpr)ann;
				if (smae.getMemberValue() instanceof StringLiteralExpr) {
					String v = ((StringLiteralExpr)smae.getMemberValue()).getValue();
					if (id.equals(v)) {
						return hasOneParamWithType(method, className);
					}
				}
			}
		}
	}
	return false;
}
 
开发者ID:ahn,项目名称:mideaas,代码行数:21,代码来源:ControllerCode.java


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