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


Java CodeGeneration.getSetterMethodBodyContent方法代码示例

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


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

示例1: createSetter

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration createSetter(ParameterInfo pi, String declaringType, CompilationUnitRewrite cuRewrite) throws CoreException {
	AST ast= cuRewrite.getAST();
	ICompilationUnit cu= cuRewrite.getCu();
	IJavaProject project= cu.getJavaProject();

	MethodDeclaration methodDeclaration= ast.newMethodDeclaration();
	String fieldName= pi.getNewName();
	String setterName= getSetterName(pi, ast, project);
	String lineDelim= StubUtility.getLineDelimiterUsed(cu);
	String bareFieldname= NamingConventions.getBaseName(NamingConventions.VK_INSTANCE_FIELD, fieldName, project);
	String paramName= StubUtility.suggestArgumentName(project, bareFieldname, null);
	if (createComments(project)) {
		String comment= CodeGeneration.getSetterComment(cu, declaringType, setterName, fieldName, pi.getNewTypeName(), paramName, bareFieldname, lineDelim);
		if (comment != null)
			methodDeclaration.setJavadoc((Javadoc) cuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC));
	}
	methodDeclaration.setName(ast.newSimpleName(setterName));
	methodDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
	SingleVariableDeclaration variable= ast.newSingleVariableDeclaration();
	variable.setType(importBinding(pi.getNewTypeBinding(), cuRewrite));
	variable.setName(ast.newSimpleName(paramName));
	methodDeclaration.parameters().add(variable);
	Block block= ast.newBlock();
	methodDeclaration.setBody(block);
	boolean useThis= StubUtility.useThisForFieldAccess(project);
	if (useThis || fieldName.equals(paramName)) {
		fieldName= "this." + fieldName; //$NON-NLS-1$
	}
	String bodyContent= CodeGeneration.getSetterMethodBodyContent(cu, declaringType, setterName, fieldName, paramName, lineDelim);
	ASTNode setterBody= cuRewrite.getASTRewrite().createStringPlaceholder(bodyContent, ASTNode.EXPRESSION_STATEMENT);
	block.statements().add(setterBody);
	return methodDeclaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:ParameterObjectFactory.java

示例2: createSetterMethod

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration createSetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter)
    throws CoreException {
  FieldDeclaration field =
      (FieldDeclaration) ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
  Type type = field.getType();
  MethodDeclaration result = ast.newMethodDeclaration();
  result.setName(ast.newSimpleName(fSetterName));
  result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
  if (fSetterMustReturnValue) {
    result.setReturnType2((Type) rewriter.createCopyTarget(type));
  }
  SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
  result.parameters().add(param);
  param.setName(ast.newSimpleName(fArgName));
  param.setType((Type) rewriter.createCopyTarget(type));
  List<Dimension> extraDimensions =
      DimensionRewrite.copyDimensions(fFieldDeclaration.extraDimensions(), rewriter);
  param.extraDimensions().addAll(extraDimensions);

  Block block = ast.newBlock();
  result.setBody(block);

  String fieldAccess = createFieldAccess();
  String body =
      CodeGeneration.getSetterMethodBodyContent(
          fField.getCompilationUnit(),
          getTypeName(field.getParent()),
          fSetterName,
          fieldAccess,
          fArgName,
          lineDelimiter);
  if (body != null) {
    ASTNode setterNode = rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
    block.statements().add(setterNode);
  } else {
    Assignment ass = ast.newAssignment();
    ass.setLeftHandSide(
        (Expression) rewriter.createStringPlaceholder(fieldAccess, ASTNode.QUALIFIED_NAME));
    ass.setRightHandSide(ast.newSimpleName(fArgName));
    block.statements().add(ass);
  }
  if (fSetterMustReturnValue) {
    ReturnStatement rs = ast.newReturnStatement();
    rs.setExpression(ast.newSimpleName(fArgName));
    block.statements().add(rs);
  }
  if (fGenerateJavadoc) {
    String string =
        CodeGeneration.getSetterComment(
            fField.getCompilationUnit(),
            getTypeName(field.getParent()),
            fSetterName,
            fField.getElementName(),
            ASTNodes.asString(type),
            fArgName,
            StubUtility.getBaseName(fField),
            lineDelimiter);
    if (string != null) {
      Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
      result.setJavadoc(javadoc);
    }
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:65,代码来源:SelfEncapsulateFieldRefactoring.java

示例3: createSetterMethod

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration createSetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException {
	FieldDeclaration field= (FieldDeclaration)ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
	Type type= field.getType();
	MethodDeclaration result= ast.newMethodDeclaration();
	result.setName(ast.newSimpleName(fSetterName));
	result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
	if (fSetterMustReturnValue) {
		result.setReturnType2((Type)rewriter.createCopyTarget(type));
	}
	SingleVariableDeclaration param= ast.newSingleVariableDeclaration();
	result.parameters().add(param);
	param.setName(ast.newSimpleName(fArgName));
	param.setType((Type)rewriter.createCopyTarget(type));
	List<Dimension> extraDimensions= DimensionRewrite.copyDimensions(fFieldDeclaration.extraDimensions(), rewriter);
	param.extraDimensions().addAll(extraDimensions);

	Block block= ast.newBlock();
	result.setBody(block);

	String fieldAccess= createFieldAccess();
	String body= CodeGeneration.getSetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fSetterName, fieldAccess, fArgName, lineDelimiter);
	if (body != null) {
		ASTNode setterNode= rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
		block.statements().add(setterNode);
	} else {
		Assignment ass= ast.newAssignment();
		ass.setLeftHandSide((Expression) rewriter.createStringPlaceholder(fieldAccess, ASTNode.QUALIFIED_NAME));
		ass.setRightHandSide(ast.newSimpleName(fArgName));
		block.statements().add(ass);
	}
       if (fSetterMustReturnValue) {
       	ReturnStatement rs= ast.newReturnStatement();
       	rs.setExpression(ast.newSimpleName(fArgName));
       	block.statements().add(rs);
       }
       if (fGenerateJavadoc) {
		String string= CodeGeneration.getSetterComment(
			fField.getCompilationUnit() , getTypeName(field.getParent()), fSetterName,
			fField.getElementName(), ASTNodes.asString(type), fArgName,
			StubUtility.getBaseName(fField),
			lineDelimiter);
		if (string != null) {
			Javadoc javadoc= (Javadoc)fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
			result.setJavadoc(javadoc);
		}
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:49,代码来源:SelfEncapsulateFieldRefactoring.java

示例4: getSetterStub

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
/**
 * Create a stub for a getter of the given field using getter/setter templates. The resulting code
 * has to be formatted and indented.
 * @param field The field to create a getter for
 * @param setterName The chosen name for the setter
 * @param addComments If <code>true</code>, comments will be added.
 * @param flags The flags signaling visibility, if static, synchronized or final
 * @return Returns the generated stub.
 * @throws CoreException when stub creation failed
 */
public static String getSetterStub(IField field, String setterName, boolean addComments, int flags) throws CoreException {

	String fieldName= field.getElementName();
	IType parentType= field.getDeclaringType();

	String returnSig= field.getTypeSignature();
	String typeName= Signature.toString(returnSig);

	IJavaProject project= field.getJavaProject();

	String accessorName= StubUtility.getBaseName(field);
	String argname= StubUtility.suggestArgumentName(project, accessorName, EMPTY);

	boolean isStatic= Flags.isStatic(flags);
	boolean isSync= Flags.isSynchronized(flags);
	boolean isFinal= Flags.isFinal(flags);

	String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
	StringBuffer buf= new StringBuffer();
	if (addComments) {
		String comment= CodeGeneration.getSetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, field.getElementName(), typeName, argname, accessorName, lineDelim);
		if (comment != null) {
			buf.append(comment);
			buf.append(lineDelim);
		}
	}
	buf.append(JdtFlags.getVisibilityString(flags));
	buf.append(' ');
	if (isStatic)
		buf.append("static "); //$NON-NLS-1$
	if (isSync)
		buf.append("synchronized "); //$NON-NLS-1$
	if (isFinal)
		buf.append("final "); //$NON-NLS-1$

	buf.append("void "); //$NON-NLS-1$
	buf.append(setterName);
	buf.append('(');
	buf.append(typeName);
	buf.append(' ');
	buf.append(argname);
	buf.append(") {"); //$NON-NLS-1$
	buf.append(lineDelim);

	boolean useThis= StubUtility.useThisForFieldAccess(project);
	if (argname.equals(fieldName) || (useThis && !isStatic)) {
		if (isStatic)
			fieldName= parentType.getElementName() + '.' + fieldName;
		else
			fieldName= "this." + fieldName; //$NON-NLS-1$
	}
	String body= CodeGeneration.getSetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, fieldName, argname, lineDelim);
	if (body != null) {
		buf.append(body);
	}
	buf.append("}"); //$NON-NLS-1$
	buf.append(lineDelim);
	return buf.toString();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:70,代码来源:GetterSetterUtil.java

示例5: createSetterMethod

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration createSetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException {
	FieldDeclaration field= (FieldDeclaration)ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
	Type type= field.getType();
	MethodDeclaration result= ast.newMethodDeclaration();
	result.setName(ast.newSimpleName(fSetterName));
	result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
	if (fSetterMustReturnValue) {
		result.setReturnType2((Type)rewriter.createCopyTarget(type));
	}
	SingleVariableDeclaration param= ast.newSingleVariableDeclaration();
	result.parameters().add(param);
	param.setName(ast.newSimpleName(fArgName));
	param.setType((Type)rewriter.createCopyTarget(type));
	param.setExtraDimensions(fFieldDeclaration.getExtraDimensions());

	Block block= ast.newBlock();
	result.setBody(block);

	String fieldAccess= createFieldAccess();
	String body= CodeGeneration.getSetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fSetterName, fieldAccess, fArgName, lineDelimiter);
	if (body != null) {
		ASTNode setterNode= rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
		block.statements().add(setterNode);
	} else {
		Assignment ass= ast.newAssignment();
		ass.setLeftHandSide((Expression) rewriter.createStringPlaceholder(fieldAccess, ASTNode.QUALIFIED_NAME));
		ass.setRightHandSide(ast.newSimpleName(fArgName));
		block.statements().add(ass);
	}
       if (fSetterMustReturnValue) {
       	ReturnStatement rs= ast.newReturnStatement();
       	rs.setExpression(ast.newSimpleName(fArgName));
       	block.statements().add(rs);
       }
       if (fGenerateJavadoc) {
		String string= CodeGeneration.getSetterComment(
			fField.getCompilationUnit() , getTypeName(field.getParent()), fSetterName,
			fField.getElementName(), ASTNodes.asString(type), fArgName,
			StubUtility.getBaseName(fField),
			lineDelimiter);
		if (string != null) {
			Javadoc javadoc= (Javadoc)fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
			result.setJavadoc(javadoc);
		}
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:48,代码来源:SelfEncapsulateFieldRefactoring.java


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