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


Java CodeGeneration.getMethodComment方法代码示例

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


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

示例1: getNewConstructorComment

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private Javadoc getNewConstructorComment(ASTRewrite rewrite) throws CoreException {
  if (StubUtility.doAddComments(fCu.getJavaProject())) {
    String comment =
        CodeGeneration.getMethodComment(
            fCu,
            getEnclosingTypeName(),
            getEnclosingTypeName(),
            new String[0],
            new String[0],
            null,
            null,
            StubUtility.getLineDelimiterUsed(fCu));
    if (comment != null && comment.length() > 0) {
      return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
    }
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:PromoteTempToFieldRefactoring.java

示例2: createNewMethod

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的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,项目名称:che,代码行数:21,代码来源:ExtractMethodRefactoring.java

示例3: createMethodComment

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
/**
 * adds a comment (if necessary) and an <code>@Override</code> annotation to the generated
 * method
 * 
 * @throws CoreException if creation failed
 */
protected void createMethodComment() throws CoreException {
	ITypeBinding object= fAst.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	IMethodBinding[] objms= object.getDeclaredMethods();
	IMethodBinding objectMethod= null;
	for (int i= 0; i < objms.length; i++) {
		if (objms[i].getName().equals(METHODNAME_TO_STRING) && objms[i].getParameterTypes().length == 0)
			objectMethod= objms[i];
	}
	if (fContext.isCreateComments()) {
		String docString= CodeGeneration.getMethodComment(fContext.getCompilationUnit(), fContext.getTypeBinding().getQualifiedName(), toStringMethod, objectMethod, StubUtility
				.getLineDelimiterUsed(fContext.getCompilationUnit()));
		if (docString != null) {
			Javadoc javadoc= (Javadoc)fContext.getASTRewrite().createStringPlaceholder(docString, ASTNode.JAVADOC);
			toStringMethod.setJavadoc(javadoc);
		}
	}
	if (fContext.isOverrideAnnotation() && fContext.is50orHigher())
		StubUtility2.addOverrideAnnotation(fContext.getTypeBinding().getJavaElement().getJavaProject(), fContext.getASTRewrite(), toStringMethod, objectMethod);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:AbstractToStringGenerator.java

示例4: createMethodTags

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private String createMethodTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, IMethod method)
	throws CoreException, BadLocationException
{
	IRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, false);
	IMethod inheritedMethod= getInheritedMethod(method);
	String comment= CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter);
	if (comment != null) {
		comment= comment.trim();
		boolean javadocComment= comment.startsWith("/**"); //$NON-NLS-1$
		if (!isFirstComment(document, command, method, javadocComment))
			return null;
		boolean isJavaDoc= partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$
		if (javadocComment == isJavaDoc) {
			return prepareTemplateComment(comment, indentation, method.getJavaProject(), lineDelimiter);
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:JavaDocAutoIndentStrategy.java

示例5: createConstructor

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private void createConstructor(final AbstractTypeDeclaration declaration, final ASTRewrite rewrite) throws CoreException {
	Assert.isNotNull(declaration);
	Assert.isNotNull(rewrite);
	final AST ast= declaration.getAST();
	final MethodDeclaration constructor= ast.newMethodDeclaration();
	constructor.setConstructor(true);
	constructor.setName(ast.newSimpleName(declaration.getName().getIdentifier()));
	final String comment= CodeGeneration.getMethodComment(fType.getCompilationUnit(), fType.getElementName(), fType.getElementName(), getNewConstructorParameterNames(), new String[0], null, null, StubUtility.getLineDelimiterUsed(fType.getJavaProject()));
	if (comment != null && comment.length() > 0) {
		final Javadoc doc= (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
		constructor.setJavadoc(doc);
	}
	if (fCreateInstanceField) {
		final SingleVariableDeclaration variable= ast.newSingleVariableDeclaration();
		final String name= getNameForEnclosingInstanceConstructorParameter();
		variable.setName(ast.newSimpleName(name));
		variable.setType(createEnclosingType(ast));
		constructor.parameters().add(variable);
		final Block body= ast.newBlock();
		final Assignment assignment= ast.newAssignment();
		if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
			final FieldAccess access= ast.newFieldAccess();
			access.setExpression(ast.newThisExpression());
			access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
			assignment.setLeftHandSide(access);
		} else
			assignment.setLeftHandSide(ast.newSimpleName(fEnclosingInstanceFieldName));
		assignment.setRightHandSide(ast.newSimpleName(name));
		final Statement statement= ast.newExpressionStatement(assignment);
		body.statements().add(statement);
		constructor.setBody(body);
	} else
		constructor.setBody(ast.newBlock());
	rewrite.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertFirst(constructor, null);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:MoveInnerToTopRefactoring.java

示例6: createMethodComment

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
/**
 * Creates the method comment for the specified declaration.
 *
 * @param sourceRewrite
 *            the compilation unit rewrite
 * @param declaration
 *            the method declaration
 * @param replacements
 *            the set of variable binding keys of formal parameters which
 *            must be replaced
 * @param javadoc
 *            <code>true</code> if javadoc comments are processed,
 *            <code>false</code> otherwise
 * @throws CoreException
 *             if an error occurs
 */
protected final void createMethodComment(final CompilationUnitRewrite sourceRewrite, final MethodDeclaration declaration, final Set<String> replacements, final boolean javadoc) throws CoreException {
	Assert.isNotNull(sourceRewrite);
	Assert.isNotNull(declaration);
	Assert.isNotNull(replacements);
	final IMethodBinding binding= declaration.resolveBinding();
	if (binding != null) {
		IVariableBinding variable= null;
		SingleVariableDeclaration argument= null;
		final IPackageFragment fragment= fSubType.getPackageFragment();
		final String string= fragment.isDefaultPackage() ? fSuperName : fragment.getElementName() + "." + fSuperName; //$NON-NLS-1$
		final ITypeBinding[] bindings= binding.getParameterTypes();
		final String[] names= new String[bindings.length];
		for (int offset= 0; offset < names.length; offset++) {
			argument= (SingleVariableDeclaration) declaration.parameters().get(offset);
			variable= argument.resolveBinding();
			if (variable != null) {
				if (replacements.contains(variable.getKey()))
					names[offset]= string;
				else {
					if (binding.isVarargs() && bindings[offset].isArray() && offset == names.length - 1)
						names[offset]= Bindings.getFullyQualifiedName(bindings[offset].getElementType());
					else
						names[offset]= Bindings.getFullyQualifiedName(bindings[offset]);
				}
			}
		}
		final String comment= CodeGeneration.getMethodComment(fSubType.getCompilationUnit(), fSubType.getElementName(), declaration, false, binding.getName(), string, names, StubUtility.getLineDelimiterUsed(fSubType.getJavaProject()));
		if (comment != null) {
			final ASTRewrite rewrite= sourceRewrite.getASTRewrite();
			if (declaration.getJavadoc() != null) {
				rewrite.replace(declaration.getJavadoc(), rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC), sourceRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.ExtractInterfaceProcessor_rewrite_comment, SET_EXTRACT_INTERFACE));
			} else if (javadoc) {
				rewrite.set(declaration, MethodDeclaration.JAVADOC_PROPERTY, rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC), sourceRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.ExtractInterfaceProcessor_add_comment, SET_EXTRACT_INTERFACE));
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:54,代码来源:ExtractInterfaceProcessor.java

示例7: getNewConstructorComment

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private Javadoc getNewConstructorComment(ASTRewrite rewrite) throws CoreException {
	if (StubUtility.doAddComments(fCu.getJavaProject())){
		String comment= CodeGeneration.getMethodComment(fCu, getEnclosingTypeName(), getEnclosingTypeName(), new String[0], new String[0], null, null, StubUtility.getLineDelimiterUsed(fCu));
		if (comment != null && comment.length() > 0) {
			return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:PromoteTempToFieldRefactoring.java

示例8: createNewMethod

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:ExtractMethodRefactoring.java

示例9: createMethodComment

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private void createMethodComment(MethodDeclaration newDeclaration, IMethodBinding copyFrom) throws CoreException {
	if (fSettings.createComments) {
		String string= CodeGeneration.getMethodComment(fRewrite.getCu(), fType.getQualifiedName(), newDeclaration, copyFrom, StubUtility.getLineDelimiterUsed(fRewrite.getCu()));
		if (string != null) {
			Javadoc javadoc= (Javadoc) fRewrite.getASTRewrite().createStringPlaceholder(string, ASTNode.JAVADOC);
			newDeclaration.setJavadoc(javadoc);
		}
	}
	IJavaProject project= fUnit.getJavaElement().getJavaProject();
	if (fSettings.overrideAnnotation && JavaModelUtil.is50OrHigher(project))
		StubUtility2.addOverrideAnnotation(project, fRewrite.getASTRewrite(), newDeclaration, copyFrom);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:13,代码来源:GenerateHashCodeEqualsOperation.java

示例10: createConstructorStub

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
public static MethodDeclaration createConstructorStub(
    ICompilationUnit unit,
    ASTRewrite rewrite,
    ImportRewrite imports,
    ImportRewriteContext context,
    IMethodBinding binding,
    String type,
    int modifiers,
    boolean omitSuperForDefConst,
    boolean todo,
    CodeGenerationSettings settings)
    throws CoreException {
  AST ast = rewrite.getAST();
  MethodDeclaration decl = ast.newMethodDeclaration();
  decl.modifiers()
      .addAll(
          ASTNodeFactory.newModifiers(ast, modifiers & ~Modifier.ABSTRACT & ~Modifier.NATIVE));
  decl.setName(ast.newSimpleName(type));
  decl.setConstructor(true);

  createTypeParameters(imports, context, ast, binding, decl);

  List<SingleVariableDeclaration> parameters =
      createParameters(unit.getJavaProject(), imports, context, ast, binding, null, decl);

  createThrownExceptions(decl, binding, imports, context, ast);

  Block body = ast.newBlock();
  decl.setBody(body);

  String delimiter = StubUtility.getLineDelimiterUsed(unit);
  String bodyStatement = ""; // $NON-NLS-1$
  if (!omitSuperForDefConst || !parameters.isEmpty()) {
    SuperConstructorInvocation invocation = ast.newSuperConstructorInvocation();
    SingleVariableDeclaration varDecl = null;
    for (Iterator<SingleVariableDeclaration> iterator = parameters.iterator();
        iterator.hasNext(); ) {
      varDecl = iterator.next();
      invocation.arguments().add(ast.newSimpleName(varDecl.getName().getIdentifier()));
    }
    bodyStatement =
        ASTNodes.asFormattedString(
            invocation, 0, delimiter, unit.getJavaProject().getOptions(true));
  }

  if (todo) {
    String placeHolder =
        CodeGeneration.getMethodBodyContent(
            unit, type, binding.getName(), true, bodyStatement, delimiter);
    if (placeHolder != null) {
      ReturnStatement todoNode =
          (ReturnStatement)
              rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT);
      body.statements().add(todoNode);
    }
  } else {
    ReturnStatement statementNode =
        (ReturnStatement)
            rewrite.createStringPlaceholder(bodyStatement, ASTNode.RETURN_STATEMENT);
    body.statements().add(statementNode);
  }

  if (settings != null && settings.createComments) {
    String string = CodeGeneration.getMethodComment(unit, type, decl, binding, delimiter);
    if (string != null) {
      Javadoc javadoc = (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
      decl.setJavadoc(javadoc);
    }
  }
  return decl;
}
 
开发者ID:eclipse,项目名称:che,代码行数:72,代码来源:StubUtility2.java

示例11: getStub

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration getStub(ASTRewrite rewrite, ASTNode targetTypeDecl)
    throws CoreException {
  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<String>();
  addNewTypeParameters(rewrite, takenNames, decl.typeParameters());

  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$
  if (!isConstructor()) {
    Type returnType = getNewMethodType(rewrite);
    decl.setReturnType2(returnType);

    boolean isVoid =
        returnType instanceof PrimitiveType
            && PrimitiveType.VOID.equals(((PrimitiveType) returnType).getPrimitiveTypeCode());
    if (!fSenderBinding.isInterface() && !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());
  addNewExceptions(rewrite, decl.thrownExceptionTypes());

  Block body = null;
  if (!fSenderBinding.isInterface()) {
    body = ast.newBlock();
    String placeHolder =
        CodeGeneration.getMethodBodyContent(
            getCompilationUnit(),
            fSenderBinding.getName(),
            newNameNode.getIdentifier(),
            isConstructor(),
            bodyStatement,
            String.valueOf('\n'));
    if (placeHolder != null) {
      ReturnStatement todoNode =
          (ReturnStatement)
              rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT);
      body.statements().add(todoNode);
    }
  }
  decl.setBody(body);

  CodeGenerationSettings settings =
      JavaPreferencesSettings.getCodeGenerationSettings(getCompilationUnit().getJavaProject());
  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,项目名称:che,代码行数:80,代码来源:AbstractMethodCorrectionProposal.java

示例12: createConstructorStub

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
public static MethodDeclaration createConstructorStub(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, IMethodBinding binding, String type, int modifiers, boolean omitSuperForDefConst, boolean todo, CodeGenerationSettings settings) throws CoreException {
	AST ast= rewrite.getAST();
	MethodDeclaration decl= ast.newMethodDeclaration();
	decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers & ~Modifier.ABSTRACT & ~Modifier.NATIVE));
	decl.setName(ast.newSimpleName(type));
	decl.setConstructor(true);

	ITypeBinding[] typeParams= binding.getTypeParameters();
	List<TypeParameter> typeParameters= decl.typeParameters();
	for (int i= 0; i < typeParams.length; i++) {
		ITypeBinding curr= typeParams[i];
		TypeParameter newTypeParam= ast.newTypeParameter();
		newTypeParam.setName(ast.newSimpleName(curr.getName()));
		ITypeBinding[] typeBounds= curr.getTypeBounds();
		if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$
			List<Type> newTypeBounds= newTypeParam.typeBounds();
			for (int k= 0; k < typeBounds.length; k++) {
				newTypeBounds.add(imports.addImport(typeBounds[k], ast, context));
			}
		}
		typeParameters.add(newTypeParam);
	}

	List<SingleVariableDeclaration> parameters= createParameters(unit.getJavaProject(), imports, context, ast, binding, decl);

	List<Name> thrownExceptions= decl.thrownExceptions();
	ITypeBinding[] excTypes= binding.getExceptionTypes();
	for (int i= 0; i < excTypes.length; i++) {
		String excTypeName= imports.addImport(excTypes[i], context);
		thrownExceptions.add(ASTNodeFactory.newName(ast, excTypeName));
	}

	Block body= ast.newBlock();
	decl.setBody(body);

	String delimiter= StubUtility.getLineDelimiterUsed(unit);
	String bodyStatement= ""; //$NON-NLS-1$
	if (!omitSuperForDefConst || !parameters.isEmpty()) {
		SuperConstructorInvocation invocation= ast.newSuperConstructorInvocation();
		SingleVariableDeclaration varDecl= null;
		for (Iterator<SingleVariableDeclaration> iterator= parameters.iterator(); iterator.hasNext();) {
			varDecl= iterator.next();
			invocation.arguments().add(ast.newSimpleName(varDecl.getName().getIdentifier()));
		}
		bodyStatement= ASTNodes.asFormattedString(invocation, 0, delimiter, unit.getJavaProject().getOptions(true));
	}

	if (todo) {
		String placeHolder= CodeGeneration.getMethodBodyContent(unit, type, binding.getName(), true, bodyStatement, delimiter);
		if (placeHolder != null) {
			ReturnStatement todoNode= (ReturnStatement) rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT);
			body.statements().add(todoNode);
		}
	} else {
		ReturnStatement statementNode= (ReturnStatement) rewrite.createStringPlaceholder(bodyStatement, ASTNode.RETURN_STATEMENT);
		body.statements().add(statementNode);
	}

	if (settings != null && settings.createComments) {
		String string= CodeGeneration.getMethodComment(unit, type, decl, binding, delimiter);
		if (string != null) {
			Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
			decl.setJavadoc(javadoc);
		}
	}
	return decl;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:68,代码来源:StubUtility2.java

示例13: createConstructorStub

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
public static MethodDeclaration createConstructorStub(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, IMethodBinding binding, String type, int modifiers, boolean omitSuperForDefConst, boolean todo, CodeGenerationSettings settings) throws CoreException {
	AST ast= rewrite.getAST();
	MethodDeclaration decl= ast.newMethodDeclaration();
	decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers & ~Modifier.ABSTRACT & ~Modifier.NATIVE));
	decl.setName(ast.newSimpleName(type));
	decl.setConstructor(true);

	createTypeParameters(imports, context, ast, binding, decl);

	List<SingleVariableDeclaration> parameters= createParameters(unit.getJavaProject(), imports, context, ast, binding, null, decl);

	createThrownExceptions(decl, binding, imports, context, ast);

	Block body= ast.newBlock();
	decl.setBody(body);

	String delimiter= StubUtility.getLineDelimiterUsed(unit);
	String bodyStatement= ""; //$NON-NLS-1$
	if (!omitSuperForDefConst || !parameters.isEmpty()) {
		SuperConstructorInvocation invocation= ast.newSuperConstructorInvocation();
		SingleVariableDeclaration varDecl= null;
		for (Iterator<SingleVariableDeclaration> iterator= parameters.iterator(); iterator.hasNext();) {
			varDecl= iterator.next();
			invocation.arguments().add(ast.newSimpleName(varDecl.getName().getIdentifier()));
		}
		bodyStatement= ASTNodes.asFormattedString(invocation, 0, delimiter, unit.getJavaProject().getOptions(true));
	}

	if (todo) {
		String placeHolder= CodeGeneration.getMethodBodyContent(unit, type, binding.getName(), true, bodyStatement, delimiter);
		if (placeHolder != null) {
			ReturnStatement todoNode= (ReturnStatement) rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT);
			body.statements().add(todoNode);
		}
	} else {
		ReturnStatement statementNode= (ReturnStatement) rewrite.createStringPlaceholder(bodyStatement, ASTNode.RETURN_STATEMENT);
		body.statements().add(statementNode);
	}

	if (settings != null && settings.createComments) {
		String string= CodeGeneration.getMethodComment(unit, type, decl, binding, delimiter);
		if (string != null) {
			Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
			decl.setJavadoc(javadoc);
		}
	}
	return decl;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:49,代码来源:StubUtility2.java

示例14: createTypeMembers

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
@Override
protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
	boolean doMain= isCreateMain();
	boolean doConstr= isCreateConstructors();
	boolean doInherited= isCreateInherited();
	createInheritedMethods(type, doConstr, doInherited, imports, new SubProgressMonitor(monitor, 1));

	if (doMain) {
		StringBuffer buf= new StringBuffer();
		final String lineDelim= "\n"; // OK, since content is formatted afterwards //$NON-NLS-1$
		String comment= CodeGeneration.getMethodComment(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", new String[] {"args"}, new String[0], Signature.createTypeSignature("void", true), null, lineDelim); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		if (comment != null) {
			buf.append(comment);
			buf.append(lineDelim);
		}
		buf.append("public static void main("); //$NON-NLS-1$
		buf.append(imports.addImport("java.lang.String")); //$NON-NLS-1$
		buf.append("[] args) {"); //$NON-NLS-1$
		buf.append(lineDelim);
		final String content= CodeGeneration.getMethodBodyContent(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", false, "", lineDelim); //$NON-NLS-1$ //$NON-NLS-2$
		if (content != null && content.length() != 0)
			buf.append(content);
		buf.append(lineDelim);
		buf.append("}"); //$NON-NLS-1$
		type.createMethod(buf.toString(), null, false, null);
	}

	IDialogSettings dialogSettings= getDialogSettings();
	if (dialogSettings != null) {
		IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
		if (section == null) {
			section= dialogSettings.addNewSection(PAGE_NAME);
		}
		section.put(SETTINGS_CREATEMAIN, isCreateMain());
		section.put(SETTINGS_CREATECONSTR, isCreateConstructors());
		section.put(SETTINGS_CREATEUNIMPLEMENTED, isCreateInherited());
	}

	if (monitor != null) {
		monitor.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:43,代码来源:NewClassWizardPage.java

示例15: createTypeMembers

import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
@Override
protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
	boolean doMain= isCreateMain();
	boolean doConstr= isCreateConstructors();
	boolean doInherited= isCreateInherited();
	createInheritedMethods(type, doConstr, doInherited, imports, new SubProgressMonitor(monitor, 1));

	if (doMain) {
		StringBuffer buf= new StringBuffer();
		final String lineDelim= "\n"; // OK, since content is formatted afterwards //$NON-NLS-1$
		if (isAddComments()) {
			String comment= CodeGeneration.getMethodComment(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", new String[] { "args" }, new String[0], Signature.createTypeSignature("void", true), null, lineDelim); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
			if (comment != null) {
				buf.append(comment);
				buf.append(lineDelim);
			}
		}
		buf.append("public static void main("); //$NON-NLS-1$
		buf.append(imports.addImport("java.lang.String")); //$NON-NLS-1$
		buf.append("[] args) {"); //$NON-NLS-1$
		buf.append(lineDelim);
		final String content= CodeGeneration.getMethodBodyContent(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", false, "", lineDelim); //$NON-NLS-1$ //$NON-NLS-2$
		if (content != null && content.length() != 0)
			buf.append(content);
		buf.append(lineDelim);
		buf.append("}"); //$NON-NLS-1$
		type.createMethod(buf.toString(), null, false, null);
	}

	IDialogSettings dialogSettings= getDialogSettings();
	if (dialogSettings != null) {
		IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
		if (section == null) {
			section= dialogSettings.addNewSection(PAGE_NAME);
		}
		section.put(SETTINGS_CREATECONSTR, isCreateConstructors());
		section.put(SETTINGS_CREATEUNIMPLEMENTED, isCreateInherited());
	}

	if (monitor != null) {
		monitor.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:44,代码来源:NewClassWizardPage.java


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