本文整理汇总了Java中org.eclipse.jdt.core.dom.MethodDeclaration.setConstructor方法的典型用法代码示例。如果您正苦于以下问题:Java MethodDeclaration.setConstructor方法的具体用法?Java MethodDeclaration.setConstructor怎么用?Java MethodDeclaration.setConstructor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.setConstructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPrivateConstructorDefinition
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public MethodDeclaration createPrivateConstructorDefinition(AST ast, TypeDeclaration originalType, TypeDeclaration builderType,
List<BuilderField> builderFields) {
MethodDeclaration method = ast.newMethodDeclaration();
method.setConstructor(true);
method.setName(ast.newSimpleName(originalType.getName().toString()));
if (preferencesManager.getPreferenceValue(ADD_GENERATED_ANNOTATION)) {
generatedAnnotationPopulator.addGeneratedAnnotation(ast, method);
}
method.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
SingleVariableDeclaration methodParameterDeclaration = ast.newSingleVariableDeclaration();
methodParameterDeclaration.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));
methodParameterDeclaration.setName(ast.newSimpleName(camelCaseConverter.toLowerCamelCase(builderType.getName().toString())));
method.parameters().add(methodParameterDeclaration);
return method;
}
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:20,代码来源:PrivateConstructorMethodDefinitionCreationFragment.java
示例2: 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);
}
示例3: 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;
}