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


Java MethodDeclaration.setBody方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.MethodDeclaration.setBody方法的典型用法代码示例。如果您正苦于以下问题:Java MethodDeclaration.setBody方法的具体用法?Java MethodDeclaration.setBody怎么用?Java MethodDeclaration.setBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.MethodDeclaration的用法示例。


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

示例1: createNewWithMethod

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
private MethodDeclaration createNewWithMethod(AST ast, String fieldName, Block newBlock,
        SingleVariableDeclaration methodParameterDeclaration, TypeDeclaration builderType,
        BuilderField builderField) {
    MethodDeclaration builderMethod = ast.newMethodDeclaration();
    builderMethod.setName(ast.newSimpleName(builderClassMethodNameGeneratorService.build(fieldName)));
    builderMethod.setReturnType2(ast.newSimpleType(
            ast.newName(builderType.getName().getIdentifier())));
    builderMethod.setBody(newBlock);
    builderMethod.parameters().add(methodParameterDeclaration);

    javadocAdder.addJavadocForWithMethod(ast, fieldName, builderMethod);
    if (preferencesManager.getPreferenceValue(ADD_NONNULL_ON_RETURN)) {
        markerAnnotationAttacher.attachNonNull(ast, builderMethod);
    }
    builderMethod.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));

    return builderMethod;
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:19,代码来源:RegularBuilderWithMethodAdderFragment.java

示例2: addBuilderMethodToCompilationUnit

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public void addBuilderMethodToCompilationUnit(CompilationUnitModificationDomain modificationDomain, TypeDeclaration builderType,
        StagedBuilderProperties currentStage) {
    AST ast = modificationDomain.getAst();
    ListRewrite listRewrite = modificationDomain.getListRewrite();
    BuilderField firstField = currentStage.getNamedVariableDeclarationField().get(0);

    StagedBuilderProperties nextStage = currentStage.getNextStage().orElse(currentStage);
    MethodDeclaration staticWithMethod = stagedBuilderWithMethodDefiniationCreatorFragment.createNewWithMethod(ast, firstField, nextStage);
    staticWithMethod.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));

    String parameterName = firstField.getBuilderFieldName();
    String withMethodName = staticWithMethod.getName().toString();
    Block block = newBuilderAndWithMethodCallCreationFragment.createReturnBlock(ast, builderType, withMethodName, parameterName);

    javadocAdder.addJavadocForWithBuilderMethod(ast, builderType.getName().toString(), parameterName, staticWithMethod);

    staticWithMethod.setBody(block);

    listRewrite.insertLast(staticWithMethod, null);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:21,代码来源:StagedBuilderCreationWithMethodAdder.java

示例3: addWithMethodToBuilder

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public void addWithMethodToBuilder(AST ast, TypeDeclaration stagedBuilderType,
        BuilderField builderField,
        StagedBuilderProperties nextStage) {
    Block newBlock = createWithMethodBody(ast, builderField);
    MethodDeclaration newWithMethod = stagedBuilderWithMethodDefiniationCreatorFragment.createNewWithMethod(ast,
            builderField, nextStage);
    newWithMethod.setBody(newBlock);
    markerAnnotationAttacher.attachAnnotation(ast, newWithMethod, OVERRIDE_ANNOTATION);
    stagedBuilderType.bodyDeclarations().add(newWithMethod);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:11,代码来源:StagedBuilderWithMethodAdderFragment.java

示例4: addEmptyPrivateConstructor

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public void addEmptyPrivateConstructor(AST ast, TypeDeclaration builderType) {
    MethodDeclaration privateConstructorMethod = ast.newMethodDeclaration();
    privateConstructorMethod.setBody(ast.newBlock());
    privateConstructorMethod.setConstructor(true);
    privateConstructorMethod.setName(ast.newSimpleName(builderType.getName().toString()));
    privateConstructorMethod.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
    builderType.bodyDeclarations().add(privateConstructorMethod);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:9,代码来源:PrivateConstructorAdderFragment.java

示例5: addPrivateConstructorToCompilationUnit

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public void addPrivateConstructorToCompilationUnit(AST ast, TypeDeclaration originalType, TypeDeclaration builderType, ListRewrite listRewrite,
        List<BuilderField> builderFields) {
    Block body = privateConstructorBodyCreationFragment.createBody(ast, builderType, builderFields);
    MethodDeclaration privateConstructorDefinition = privateConstructorMethodDefinitionCreationFragment.createPrivateConstructorDefinition(ast, originalType, builderType,
            builderFields);
    privateConstructorDefinition.setBody(body);
    privateConstructorInsertionFragment.insertMethodToFirstPlace(originalType, listRewrite, privateConstructorDefinition);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:9,代码来源:PrivateInitializingConstructorCreator.java

示例6: addBuilderMethodToCompilationUnit

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public void addBuilderMethodToCompilationUnit(CompilationUnitModificationDomain modificationDomain, TypeDeclaration builderType,
        StagedBuilderProperties stagedBuilderStages) {
    AST ast = modificationDomain.getAst();
    TypeDeclaration typeDeclaration = modificationDomain.getOriginalType();
    ListRewrite listRewrite = modificationDomain.getListRewrite();
    Block builderMethodBlock = blockWithNewBuilderCreationFragment.createReturnBlock(ast, builderType);
    MethodDeclaration builderMethod = builderMethodDefinitionCreatorFragment.createBuilderMethod(ast, typeDeclaration, stagedBuilderStages.getInterfaceName());
    builderMethod.setBody(builderMethodBlock);
    listRewrite.insertLast(builderMethod, null);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:11,代码来源:StagedBuilderCreationBuilderMethodAdder.java

示例7: createNewMethod

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
private MethodDeclaration createNewMethod(ASTNode[] selectedNodes, String lineDelimiter, TextEditGroup substitute) throws CoreException {
	MethodDeclaration result = createNewMethodDeclaration();
	result.setBody(createMethodBody(selectedNodes, substitute, result.getModifiers()));
	if (fGenerateJavadoc) {
		AbstractTypeDeclaration enclosingType = (AbstractTypeDeclaration) ASTNodes.getParent(fAnalyzer.getEnclosingBodyDeclaration(), AbstractTypeDeclaration.class);
		String string = CodeGeneration.getMethodComment(fCUnit, enclosingType.getName().getIdentifier(), result, null, lineDelimiter);
		if (string != null) {
			Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
			result.setJavadoc(javadoc);
		}
	}
	return result;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:14,代码来源:ExtractMethodRefactoring.java

示例8: addBuildMethodToBuilder

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public MethodDeclaration addBuildMethodToBuilder(AST ast, TypeDeclaration originalType) {
    Block block = buildMethodBodyCreatorFragment.createBody(ast, originalType);
    MethodDeclaration method = buildMethodDeclarationCreatorFragment.createMethod(ast, originalType);
    method.setBody(block);
    return method;
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:7,代码来源:BuildMethodCreatorFragment.java

示例9: addBuilderMethodToCompilationUnit

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public void addBuilderMethodToCompilationUnit(AST ast, ListRewrite listRewrite, TypeDeclaration typeDeclaration, TypeDeclaration builderType) {
    Block builderMethodBlock = blockWithNewBuilderCreationFragment.createReturnBlock(ast, builderType);
    MethodDeclaration builderMethod = builderMethodDefinitionCreatorFragment.createBuilderMethod(ast, typeDeclaration, builderType.getName().toString());
    builderMethod.setBody(builderMethodBlock);
    listRewrite.insertLast(builderMethod, null);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:7,代码来源:RegularBuilderBuilderMethodCreator.java

示例10: getStub

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
private MethodDeclaration getStub(ASTRewrite rewrite, ASTNode targetTypeDecl) throws CoreException {
	ImportRewriteContext context=new ContextSensitiveImportRewriteContext(targetTypeDecl, getImportRewrite());

	AST ast= targetTypeDecl.getAST();
	MethodDeclaration decl= ast.newMethodDeclaration();

	SimpleName newNameNode= getNewName(rewrite);

	decl.setConstructor(isConstructor());

	addNewModifiers(rewrite, targetTypeDecl, decl.modifiers());

	ArrayList<String> takenNames= new ArrayList<>();
	addNewTypeParameters(rewrite, takenNames, decl.typeParameters(), context);

	decl.setName(newNameNode);

	IVariableBinding[] declaredFields= fSenderBinding.getDeclaredFields();
	for (int i= 0; i < declaredFields.length; i++) { // avoid to take parameter names that are equal to field names
		takenNames.add(declaredFields[i].getName());
	}

	String bodyStatement= ""; //$NON-NLS-1$
	boolean isAbstractMethod= Modifier.isAbstract(decl.getModifiers()) || (fSenderBinding.isInterface() && !Modifier.isStatic(decl.getModifiers()) && !Modifier.isDefault(decl.getModifiers()));
	if (!isConstructor()) {
		Type returnType= getNewMethodType(rewrite, context);
		decl.setReturnType2(returnType);

		boolean isVoid= returnType instanceof PrimitiveType && PrimitiveType.VOID.equals(((PrimitiveType)returnType).getPrimitiveTypeCode());
		if (!isAbstractMethod && !isVoid) {
			ReturnStatement returnStatement= ast.newReturnStatement();
			returnStatement.setExpression(ASTNodeFactory.newDefaultExpression(ast, returnType, 0));
			bodyStatement= ASTNodes.asFormattedString(returnStatement, 0, String.valueOf('\n'), getCompilationUnit().getJavaProject().getOptions(true));
		}
	}

	addNewParameters(rewrite, takenNames, decl.parameters(), context);
	addNewExceptions(rewrite, decl.thrownExceptionTypes(), context);

	Block body= null;
	if (!isAbstractMethod && !Flags.isAbstract(decl.getModifiers())) {
		body= ast.newBlock();
		if (bodyStatement.length() > 0) {
			ReturnStatement todoNode = (ReturnStatement) rewrite.createStringPlaceholder(bodyStatement,
					ASTNode.RETURN_STATEMENT);
			body.statements().add(todoNode);
		}
	}
	decl.setBody(body);

	CodeGenerationSettings settings = PreferenceManager.getCodeGenerationSettings(getCompilationUnit().getResource());
	if (settings.createComments && !fSenderBinding.isAnonymous()) {
		String string = CodeGeneration.getMethodComment(getCompilationUnit(), fSenderBinding.getName(), decl, null,
				String.valueOf('\n'));
		if (string != null) {
			Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
			decl.setJavadoc(javadoc);
		}
	}
	return decl;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:62,代码来源:AbstractMethodCorrectionProposal.java

示例11: getSignature

import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
/**
 * Returns the signature of the new method.
 *
 * @param methodName
 *            the method name used for the new method
 * @return the signature of the extracted method
 */
public String getSignature(String methodName) {
	MethodDeclaration methodDecl = createNewMethodDeclaration();
	methodDecl.setBody(null);
	String str = ASTNodes.asString(methodDecl);
	return str.substring(0, str.indexOf(';'));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:14,代码来源:ExtractMethodRefactoring.java


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