本文整理汇总了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;
}
示例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++;
}
}
}
}
}
示例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++;
}
}
}
}
}
}
示例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;
}
示例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++;
}
}
}
}
}
示例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);
}
}
}
示例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())));
}
}
示例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));
}
}
示例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);
}
示例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);
}
示例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;
}