當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodDeclaration.getBody方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.MethodDeclaration.getBody方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodDeclaration.getBody方法的具體用法?Java MethodDeclaration.getBody怎麽用?Java MethodDeclaration.getBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.MethodDeclaration的用法示例。


在下文中一共展示了MethodDeclaration.getBody方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createMethod

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
public RastNode createMethod(String methodSignature, HasChildrenNodes parent, String sourceFilePath, boolean constructor, MethodDeclaration ast) {
	String methodName = ast.isConstructor() ? "" : ast.getName().getIdentifier();
	RastNode rastNode = new RastNode(++nodeCounter);
	rastNode.setType(ast.getClass().getSimpleName());
	
	Block body = ast.getBody();
	int bodyStart;
	int bodyLength;
       if (body == null) {
           rastNode.addStereotypes(Stereotype.ABSTRACT);
           bodyStart = ast.getStartPosition() + ast.getLength();
           bodyLength = 0;
       } else {
       	bodyStart = body.getStartPosition();
           bodyLength = body.getLength();
       }
       rastNode.setLocation(new Location(sourceFilePath, ast.getStartPosition(), ast.getStartPosition() + ast.getLength(), bodyStart, bodyStart + bodyLength));
	rastNode.setLocalName(methodSignature);
	rastNode.setSimpleName(methodName);
	parent.addNode(rastNode);
	keyMap.put(JavaParser.getKey(rastNode), rastNode);
	return rastNode;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:24,代碼來源:SDModel.java

示例2: checkMethodsBody

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
/**
 * Method that check the method's body to detect some
 * connection between them
 * @author Mariana Azevedo
 * @since 20/01/2016
 * @param firstMethod
 * @param secondMethod
 */
private void checkMethodsBody(MethodDeclaration firstMethod, MethodDeclaration secondMethod) {
	if (firstMethod != null && secondMethod != null){
		Block firstMethodBody = firstMethod.getBody();
		Block secondMethodBody = secondMethod.getBody();
		
		if (firstMethodBody != null && secondMethodBody != null){
		
			for (String attribute : listOfAttributes){
				if (firstMethodBody.toString().contains(attribute) && 
						secondMethodBody.toString().contains(attribute)){
					numDirectConnections++;
				}
			}
		}
	}
}
 
開發者ID:mariazevedo88,項目名稱:o3smeasures-tool,代碼行數:25,代碼來源:TightClassCohesionVisitor.java

示例3: calculateMethodCalls

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
/**
 * Method to calculate method calls in the method's body.
 */
@SuppressWarnings("unchecked")
private void calculateMethodCalls(){
	Iterator<MethodDeclaration> itMethods = methodsList.iterator();
	
	while (itMethods.hasNext()){
		
		MethodDeclaration firstMethod = itMethods.next();
		Block firstMethodBody = firstMethod.getBody();
		
		if (firstMethodBody != null){
		
			List<Statement> firstMethodStatements = firstMethodBody.statements();
			
			if (!firstMethodStatements.isEmpty()){
			
				for (IMethod mtd : listOfMethodsName){
					
					if (firstMethodStatements.toString().contains(mtd.getElementName())){
						numberMethodCalls++;
					}
				}
			}
		}
	}
}
 
開發者ID:mariazevedo88,項目名稱:o3smeasures-tool,代碼行數:29,代碼來源:ResponseForClassVisitor.java

示例4: getNumberOfDirectConnections

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
/**
 * Method to get the number of methods with direct connections.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param methodsWithDirectConn
 * @param itMethods
 * @return List 
 */
private List<MethodDeclaration> getNumberOfDirectConnections(List<MethodDeclaration> methodsWithDirectConn,
		Iterator<MethodDeclaration> itMethods) {
	
	while (itMethods.hasNext()){
	
		MethodDeclaration firstMethod = itMethods.next();
		MethodDeclaration secondMethod = null;
		
		if (itMethods.hasNext()) secondMethod = itMethods.next();
		
		if ((firstMethod != null && secondMethod != null) && 
				(firstMethod.getBody() != null && secondMethod.getBody() != null)){
			for (String attribute : listOfAttributes){
				if (firstMethod.getBody().toString().contains(attribute) && 
						secondMethod.getBody().toString().contains(attribute)){
					numDirectConnections++;
					methodsWithDirectConn.add(firstMethod);
					methodsWithDirectConn.add(secondMethod);
				}
			}
		}
	}
		
	return methodsWithDirectConn;
}
 
開發者ID:mariazevedo88,項目名稱:o3smeasures-tool,代碼行數:34,代碼來源:LooseClassCohesionVisitor.java

示例5: getNumberOfIndirectConnections

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
/**
 * Method to get the number of methods with indirect connections.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param methodsWithDirectConn
 * @param itMethods
 */
private void getNumberOfIndirectConnections(List<MethodDeclaration> methodsWithDirectConn,
		Iterator<MethodDeclaration> itMethods){
	
	int i=0;
	while (itMethods.hasNext()){
	
		MethodDeclaration firstMethod = itMethods.next();
		if (firstMethod != null){
			Block firstMethodBody = firstMethod.getBody();
		
			if (firstMethodBody != null){
				SimpleName methodDeclaration = methodsWithDirectConn.get(i).getName();
				
				if (firstMethodBody.toString().contains(methodDeclaration.toString())){
					numIndirectConnections++;
				}
			}
		}
	}
}
 
開發者ID:mariazevedo88,項目名稱:o3smeasures-tool,代碼行數:28,代碼來源:LooseClassCohesionVisitor.java

示例6: annotateMethods

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
/**
 * @param rewrite
 * @param declaration
 */
private void annotateMethods(ASTRewrite rewrite, TypeDeclaration declaration) {
	MethodDeclaration[] methods = declaration.getMethods();
	for (int i = 0; i < methods.length; i++) {
		MethodDeclaration methodDeclaration = methods[i];

		annotateMethodReturnType(rewrite, methodDeclaration);
		annotateMethodParameters(rewrite, methodDeclaration);

		DefaultingVisitor visitor = new DefaultingVisitor();
		visitor.rewrite = rewrite;
		Block body = methodDeclaration.getBody();
		if (body != null) {
			body.accept(visitor);
		}
	}
}
 
開發者ID:aroog,項目名稱:code,代碼行數:21,代碼來源:SaveAnnotations.java

示例7: MethodModel

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
MethodModel(ASTNodeFactory astNodeFactory, MethodDeclaration methodDeclaration) {
    this.astNodeFactory = astNodeFactory;
    this.methodDeclaration = methodDeclaration;
    groovism = provide();
    if (methodDeclaration.getBody() != null && methodDeclaration.getBody().statements() != null) {
        methodDeclaration.getBody().statements().forEach(statement -> body.add(wrap(statement, 1, methodType())));
    }
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:9,代碼來源:MethodModel.java

示例8: calculateClazzUsed

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
/**
 * Method that calculates the number of classes of 
 * a specific project.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param unit
 */
@SuppressWarnings("unchecked")
private void calculateClazzUsed(CompilationUnit unit){
	
	Object typeDeclaration = unit.types().stream().filter(type -> type instanceof TypeDeclaration).collect(Collectors.toList());
	MethodDeclaration [] methods = ((List<TypeDeclaration>) typeDeclaration).get(0).getMethods();
	for (MethodDeclaration method: methods){
		Block firstMethodBody = method.getBody();
		Optional.ofNullable(firstMethodBody).ifPresent(m -> checkMethodStatements(method, firstMethodBody));
	}
}
 
開發者ID:mariazevedo88,項目名稱:o3smeasures-tool,代碼行數:18,代碼來源:CouplingBetweenObjectsVisitor.java

示例9: visit

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
@Override
public boolean visit(MethodDeclaration node) {
	Block body = node.getBody();
	if (body == null) {
		return false;
	}
	Selection selection = getSelection();
	int nodeStart = body.getStartPosition();
	int nodeExclusiveEnd = nodeStart + body.getLength();
	// if selection node inside of the method body ignore method
	if (!(nodeStart < selection.getOffset() && selection.getExclusiveEnd() < nodeExclusiveEnd)) {
		return false;
	}
	return super.visit(node);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:16,代碼來源:ExtractMethodAnalyzer.java

示例10: visit

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
@Override
public boolean visit(MethodDeclaration methodDecl) {

	int modifiers = methodDecl.getModifiers();
	if(Modifier.isPublic(modifiers) && !methodDecl.isConstructor() && !methodDecl.getReturnType2().isPrimitiveType()){
		Block body = methodDecl.getBody();
		if(body!=null){
			List<Statement> statements = body.statements();
			for (Statement stmnt : statements) {
				if(stmnt instanceof ReturnStatement){
					ReturnStatement retStmnt = (ReturnStatement)stmnt;
					Expression expression = retStmnt.getExpression();
					if(expression instanceof SimpleName){
						SimpleName simpleExpr = (SimpleName)expression;
						IBinding resolveBinding = simpleExpr.resolveBinding();
						Variable variable = context.getAllBindingKeyToVariableMap(resolveBinding.getKey());
						if(variable!=null){
							context.removeEncapsulatedVariable(variable);
						}
					}
				}
			}
		}

	}

	return super.visit(methodDecl);
	 
}
 
開發者ID:aroog,項目名稱:code,代碼行數:30,代碼來源:HeuristicOwnedLocalsVisitor.java

示例11: visit

import org.eclipse.jdt.core.dom.MethodDeclaration; //導入方法依賴的package包/類
public boolean visit(MethodDeclaration methodDeclaration) {
    // ASTNode parentNode = methodDeclaration.getParent();
    // if (!(parentNode instanceof TypeDeclaration)) {
    // // ignore methods from anonymous classes
    // return false;
    // }
    String methodSignature = AstUtils.getSignatureFromMethodDeclaration(methodDeclaration);
    // if
    // (methodDeclaration.getName().getIdentifier().equals("execMultiLineCommands"))
    // {
    // System.out.println("x");
    //
    // }

    final RastNode method = model.createMethod(methodSignature, containerStack.peek(), sourceFilePath, methodDeclaration.isConstructor(), methodDeclaration);

    List<?> modifiers = methodDeclaration.modifiers();
    Set<String> annotations = extractAnnotationTypes(modifiers);
    boolean deprecated = annotations.contains("Deprecated") || AstUtils.containsDeprecatedTag(methodDeclaration.getJavadoc());
    if (deprecated) {
    	method.addStereotypes(Stereotype.DEPRECATED);
    }

    int methodModifiers = methodDeclaration.getModifiers();
    Visibility visibility = getVisibility(methodModifiers);
    boolean isStatic = (methodModifiers & Modifier.STATIC) != 0;
		
    if (!isStatic) {
    	method.addStereotypes(Stereotype.TYPE_MEMBER);
    }
    
    //method.setVisibility(visibility);
    extractParametersAndReturnType(model, methodDeclaration, method);

    Block body = methodDeclaration.getBody();
    if (body == null) {
        method.addStereotypes(Stereotype.ABSTRACT);
    } else {
        final List<String> references = new ArrayList<String>();
        body.accept(new DependenciesAstVisitor(true) {
            @Override
            protected void onMethodAccess(ASTNode node, IMethodBinding binding) {
                String methodKey = AstUtils.getKeyFromMethodBinding(binding);
                references.add(methodKey);
            }

        });
        postProcessReferences.put(method, references);
    }

    return true;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:53,代碼來源:BindingsRecoveryAstVisitor.java


注:本文中的org.eclipse.jdt.core.dom.MethodDeclaration.getBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。