org.eclipse.jdt.core.dom.SingleVariableDeclaration#setVarargs ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.SingleVariableDeclaration#setVarargs ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void copyArguments(MethodDeclaration intermediary, CompilationUnitRewrite rew) throws JavaModelException {
	String[] names= fTargetMethod.getParameterNames();
	ITypeBinding[] types= fTargetMethodBinding.getParameterTypes();
	for (int i= 0; i < names.length; i++) {
		ITypeBinding typeBinding= types[i];
		SingleVariableDeclaration newElement= rew.getAST().newSingleVariableDeclaration();
		newElement.setName(rew.getAST().newSimpleName(names[i]));

		if (i == (names.length - 1) && fTargetMethodBinding.isVarargs()) {
			newElement.setVarargs(true);
			if (typeBinding.isArray())
				typeBinding= typeBinding.getComponentType();
		}

		newElement.setType(rew.getImportRewrite().addImport(typeBinding, rew.getAST()));
		intermediary.parameters().add(newElement);
	}
}
 
protected SingleVariableDeclaration createNewSingleVariableDeclaration(ParameterInfo info) {
	SingleVariableDeclaration newP= getASTRewrite().getAST().newSingleVariableDeclaration();
	newP.setName(getASTRewrite().getAST().newSimpleName(info.getNewName()));
	newP.setType(createNewTypeNode(ParameterInfo.stripEllipsis(info.getNewTypeName()), info.getNewTypeBinding()));
	newP.setVarargs(info.isNewVarargs());
	return newP;
}
 
/**
 * Creates and adds the necessary argument declarations to the given factory method.<br>
 * An argument is needed for each original constructor argument for which the
 * evaluation of the actual arguments across all calls was not able to be
 * pushed inside the factory method (e.g. arguments with side-effects, references
 * to fields if the factory method is to be static or reside in a factory class,
 * or arguments that varied across the set of constructor calls).<br>
 * <code>fArgTypes</code> identifies such arguments by a <code>null</code> value.
 * @param ast utility object used to create AST nodes
 * @param newMethod the <code>MethodDeclaration</code> for the factory method
 */
private void createFactoryMethodSignature(AST ast, MethodDeclaration newMethod) {
	List<SingleVariableDeclaration> argDecls= newMethod.parameters();

	for(int i=0; i < fArgTypes.length; i++) {
		SingleVariableDeclaration argDecl= ast.newSingleVariableDeclaration();
		Type argType;

		if (i == (fArgTypes.length - 1) && fCtorIsVarArgs) {
			// The trailing varargs arg has an extra array dimension, compared to
			// what we need to pass to setType()...
			argType= typeNodeForTypeBinding(fArgTypes[i].getElementType(),
					fArgTypes[i].getDimensions()-1, ast);
			argDecl.setVarargs(true);
		} else
			argType= typeNodeForTypeBinding(fArgTypes[i], 0, ast);

		argDecl.setName(ast.newSimpleName(fFormalArgNames[i]));
		argDecl.setType(argType);
		argDecls.add(argDecl);
	}

	ITypeBinding[] ctorExcepts= fCtorBinding.getExceptionTypes();
	List<Type> exceptions= newMethod.thrownExceptionTypes();

	for(int i=0; i < ctorExcepts.length; i++) {
		exceptions.add(fImportRewriter.addImport(ctorExcepts[i], ast));
	}

       copyTypeParameters(ast, newMethod);
}