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


Java ArrayCreation.setType方法代码示例

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


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

示例1: createArrayInitStmt

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
@Override
public void createArrayInitStmt(final CaptureLog log, final int logRecNo) {
	final int  oid  = log.objectIds.get(logRecNo);
	
	final Object[] params      = log.params.get(logRecNo);
	final String   arrTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
	final Class<?> arrType     = getClassForName(arrTypeName);
	
	// --- create array instance creation e.g. int[] var = new int[10];
	
	final ArrayType     arrAstType      = (ArrayType) createAstArrayType(arrTypeName, ast);
	final ArrayCreation arrCreationExpr = ast.newArrayCreation();
	arrCreationExpr.setType(arrAstType);
	arrCreationExpr.dimensions().add(ast.newNumberLiteral(String.valueOf(params.length)));
		
	final String 					  arrVarName = this.createNewVarName(oid, arrTypeName);
	final VariableDeclarationFragment vd         = ast.newVariableDeclarationFragment();
	final SimpleName arrVarNameExpr = ast.newSimpleName(arrVarName); 
	vd.setName(arrVarNameExpr);	
	vd.setInitializer(arrCreationExpr);
	
	final VariableDeclarationStatement varDeclStmt = ast.newVariableDeclarationStatement(vd);
	varDeclStmt.setType(this.createAstType(arrTypeName, ast));
	
	methodBlock.statements().add(varDeclStmt);	
	
	// create array access statements var[0] = var1;
	Integer paramOID;
	Assignment assign;
	ArrayAccess arrAccessExpr;
	
	for(int i = 0; i < params.length; i++)
	{
		assign       = ast.newAssignment();
		arrAccessExpr = ast.newArrayAccess();
		arrAccessExpr.setIndex(ast.newNumberLiteral(String.valueOf(i)));
		arrAccessExpr.setArray(arrVarNameExpr);
		
		assign.setLeftHandSide(arrAccessExpr);
		
		paramOID = (Integer) params[i];
		if(paramOID == null)
		{
		   assign.setRightHandSide(ast.newNullLiteral());
		}
		else
		{
			assign.setRightHandSide(ast.newSimpleName(this.oidToVarMapping.get(paramOID)));
		}
		
		methodBlock.statements().add(assign);	
	}
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:54,代码来源:JUnitCodeGenerator.java

示例2: complete

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
@Override
protected void complete() throws CoreException {
	super.complete();
	ReturnStatement rStatement= fAst.newReturnStatement();
	String formatClass;
	if (getContext().is50orHigher())
		formatClass= "java.lang.String"; //$NON-NLS-1$
	else
		formatClass= "java.text.MessageFormat"; //$NON-NLS-1$
	MethodInvocation formatInvocation= createMethodInvocation(addImport(formatClass), "format", null); //$NON-NLS-1$ 
	StringLiteral literal= fAst.newStringLiteral();
	literal.setLiteralValue(buffer.toString());
	formatInvocation.arguments().add(literal);
	if (getContext().is50orHigher()) {
		formatInvocation.arguments().addAll(arguments);
	} else {
		ArrayCreation arrayCreation= fAst.newArrayCreation();
		arrayCreation.setType(fAst.newArrayType(fAst.newSimpleType(addImport("java.lang.Object")))); //$NON-NLS-1$
		ArrayInitializer initializer= fAst.newArrayInitializer();
		arrayCreation.setInitializer(initializer);
		initializer.expressions().addAll(arguments);
		formatInvocation.arguments().add(arrayCreation);
	}
	rStatement.setExpression(formatInvocation);
	toStringMethod.getBody().statements().add(rStatement);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:StringFormatGenerator.java

示例3: getTempInitializerCopy

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
private Expression getTempInitializerCopy(ASTRewrite rewrite) {
  final Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer());
  if (initializer instanceof ArrayInitializer
      && ASTNodes.getDimensions(fTempDeclarationNode) > 0) {
    ArrayCreation arrayCreation = rewrite.getAST().newArrayCreation();
    arrayCreation.setType(
        (ArrayType) ASTNodeFactory.newType(rewrite.getAST(), fTempDeclarationNode));
    arrayCreation.setInitializer((ArrayInitializer) initializer);
    return arrayCreation;
  }
  return initializer;
}
 
开发者ID:eclipse,项目名称:che,代码行数:13,代码来源:PromoteTempToFieldRefactoring.java

示例4: getTempInitializerCopy

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
private Expression getTempInitializerCopy(ASTRewrite rewrite) {
	final Expression initializer= (Expression) rewrite.createCopyTarget(getTempInitializer());
	if (initializer instanceof ArrayInitializer && ASTNodes.getDimensions(fTempDeclarationNode) > 0) {
		ArrayCreation arrayCreation= rewrite.getAST().newArrayCreation();
		arrayCreation.setType((ArrayType) ASTNodeFactory.newType(rewrite.getAST(), fTempDeclarationNode));
		arrayCreation.setInitializer((ArrayInitializer) initializer);
		return arrayCreation;
	}
	return initializer;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:PromoteTempToFieldRefactoring.java

示例5: writeKeyList

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void writeKeyList(QKeyListTerm keyList) {

	VariableDeclarationFragment variable = getAST().newVariableDeclarationFragment();
	variable.setName(getAST().newSimpleName(getCompilationUnit().normalizeTermName(keyList.getName())));
	FieldDeclaration field = getAST().newFieldDeclaration(variable);
	field.modifiers().add(getAST().newModifier(ModifierKeyword.PUBLIC_KEYWORD));

	Type bufferedType = getAST().newSimpleType(getAST().newSimpleName(QBufferedData.class.getSimpleName()));
	field.setType(getAST().newArrayType(bufferedType));

	// array of bufferedData
	ArrayCreation arrayCreation = getAST().newArrayCreation();
	arrayCreation.setType(getAST().newArrayType(getAST().newSimpleType(getAST().newSimpleName(QBufferedData.class.getSimpleName()))));

	ArrayInitializer arrayInitializer = getAST().newArrayInitializer();
	for (String keyField : keyList.getKeyFields()) {

		QExpression expression = expressionParser.parseExpression(keyField);
		Expression jdtExpression = buildExpression(getAST(), expression, null);
		arrayInitializer.expressions().add(jdtExpression);
	}
	arrayCreation.setInitializer(arrayInitializer);

	variable.setInitializer(arrayCreation);

	getTarget().bodyDeclarations().add(field);
}
 
开发者ID:asupdev,项目名称:asup,代码行数:29,代码来源:JDTCallableUnitWriter.java

示例6: visit

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean visit(QCall statement) {

	Block block = blocks.peek();

	MethodInvocation methodInvocation = ast.newMethodInvocation();
	methodInvocation.setExpression(ast.newSimpleName("qRPJ"));
	methodInvocation.setName(ast.newSimpleName("qCall"));

	// program name
	QTermExpression expression = expressionParser.parseTerm(statement.getProgram());
	Expression jdtExpression = buildExpression(ast, expression, String.class);
	methodInvocation.arguments().add(jdtExpression);

	// array of parameter
	ArrayCreation arrayCreation = ast.newArrayCreation();
	arrayCreation.setType(ast.newArrayType(ast.newSimpleType(ast.newSimpleName(QData.class.getSimpleName()))));
	ArrayInitializer arrayInitializer = ast.newArrayInitializer();
	for (String parameter : statement.getParameters()) {
		expression = expressionParser.parseTerm(parameter);
		jdtExpression = buildExpression(ast, expression, null);
		arrayInitializer.expressions().add(jdtExpression);

	}
	arrayCreation.setInitializer(arrayInitializer);
	methodInvocation.arguments().add(arrayCreation);

	ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
	block.statements().add(expressionStatement);

	return super.visit(statement);
}
 
开发者ID:asupdev,项目名称:asup,代码行数:34,代码来源:JDTStatementWriter.java

示例7: createParameterObjectField

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
private FieldDeclaration createParameterObjectField(ParameterObjectFactory pof, TypeDeclaration typeNode, int modifier) {
	AST ast= fBaseCURewrite.getAST();
	ClassInstanceCreation creation= ast.newClassInstanceCreation();
	creation.setType(pof.createType(fDescriptor.isCreateTopLevel(), fBaseCURewrite, typeNode.getStartPosition()));
	ListRewrite listRewrite= fBaseCURewrite.getASTRewrite().getListRewrite(creation, ClassInstanceCreation.ARGUMENTS_PROPERTY);
	for (Iterator<FieldInfo> iter= fVariables.values().iterator(); iter.hasNext();) {
		FieldInfo fi= iter.next();
		if (isCreateField(fi)) {
			Expression expression= fi.initializer;
			if (expression != null && !fi.hasFieldReference()) {
				importNodeTypes(expression, fBaseCURewrite);
				ASTNode createMoveTarget= fBaseCURewrite.getASTRewrite().createMoveTarget(expression);
				if (expression instanceof ArrayInitializer) {
					ArrayInitializer ai= (ArrayInitializer) expression;
					ITypeBinding type= ai.resolveTypeBinding();
					Type addImport= fBaseCURewrite.getImportRewrite().addImport(type, ast);
					fBaseCURewrite.getImportRemover().registerAddedImports(addImport);
					ArrayCreation arrayCreation= ast.newArrayCreation();
					arrayCreation.setType((ArrayType) addImport);
					arrayCreation.setInitializer((ArrayInitializer) createMoveTarget);
					listRewrite.insertLast(arrayCreation, null);
				} else {
					listRewrite.insertLast(createMoveTarget, null);
				}
			}
		}
	}

	VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
	fragment.setName(ast.newSimpleName(fDescriptor.getFieldName()));
	fragment.setInitializer(creation);

	ModifierKeyword acc= null;
	if (Modifier.isPublic(modifier)) {
		acc= ModifierKeyword.PUBLIC_KEYWORD;
	} else if (Modifier.isProtected(modifier)) {
		acc= ModifierKeyword.PROTECTED_KEYWORD;
	} else if (Modifier.isPrivate(modifier)) {
		acc= ModifierKeyword.PRIVATE_KEYWORD;
	}

	FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(fragment);
	fieldDeclaration.setType(pof.createType(fDescriptor.isCreateTopLevel(), fBaseCURewrite, typeNode.getStartPosition()));
	if (acc != null)
		fieldDeclaration.modifiers().add(ast.newModifier(acc));
	return fieldDeclaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:48,代码来源:ExtractClassRefactoring.java

示例8: createParameterObjectField

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
private FieldDeclaration createParameterObjectField(ParameterObjectFactory pof, TypeDeclaration typeNode, int modifier) {
	AST ast= fBaseCURewrite.getAST();
	ClassInstanceCreation creation= ast.newClassInstanceCreation();
	creation.setType(pof.createType(fDescriptor.isCreateTopLevel(), fBaseCURewrite, typeNode.getStartPosition()));
	ListRewrite listRewrite= fBaseCURewrite.getASTRewrite().getListRewrite(creation, ClassInstanceCreation.ARGUMENTS_PROPERTY);
	for (Iterator<FieldInfo> iter= fVariables.values().iterator(); iter.hasNext();) {
		FieldInfo fi= iter.next();
		if (isCreateField(fi)) {
			Expression expression= fi.initializer;
			if (expression != null && !fi.hasFieldReference()) {
				importNodeTypes(expression, fBaseCURewrite);
				ASTNode createMoveTarget= fBaseCURewrite.getASTRewrite().createMoveTarget(expression);
				if (expression instanceof ArrayInitializer) {
					ArrayInitializer ai= (ArrayInitializer) expression;
					ITypeBinding componentType= ai.resolveTypeBinding().getComponentType();
					ArrayCreation arrayCreation= ast.newArrayCreation();
					Type addImport= fBaseCURewrite.getImportRewrite().addImport(componentType, ast);
					fBaseCURewrite.getImportRemover().registerAddedImports(addImport);
					arrayCreation.setType(ast.newArrayType(addImport));
					arrayCreation.setInitializer((ArrayInitializer) createMoveTarget);
					listRewrite.insertLast(arrayCreation, null);
				} else {
					listRewrite.insertLast(createMoveTarget, null);
				}
			}
		}
	}

	VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
	fragment.setName(ast.newSimpleName(fDescriptor.getFieldName()));
	fragment.setInitializer(creation);

	ModifierKeyword acc= null;
	if (Modifier.isPublic(modifier)) {
		acc= ModifierKeyword.PUBLIC_KEYWORD;
	} else if (Modifier.isProtected(modifier)) {
		acc= ModifierKeyword.PROTECTED_KEYWORD;
	} else if (Modifier.isPrivate(modifier)) {
		acc= ModifierKeyword.PRIVATE_KEYWORD;
	}

	FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(fragment);
	fieldDeclaration.setType(pof.createType(fDescriptor.isCreateTopLevel(), fBaseCURewrite, typeNode.getStartPosition()));
	if (acc != null)
		fieldDeclaration.modifiers().add(ast.newModifier(acc));
	return fieldDeclaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:48,代码来源:ExtractClassRefactoring.java

示例9: getModifiedInitializerSource

import org.eclipse.jdt.core.dom.ArrayCreation; //导入方法依赖的package包/类
private Expression getModifiedInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException {
	VariableDeclaration varDecl= getVariableDeclaration();
	Expression initializer= varDecl.getInitializer();

	ASTNode referenceContext= reference.getParent();
	if (Invocations.isResolvedTypeInferredFromExpectedType(initializer)) {
		if (! (referenceContext instanceof VariableDeclarationFragment
				|| referenceContext instanceof SingleVariableDeclaration
				|| referenceContext instanceof Assignment)) {
			ITypeBinding[] typeArguments= Invocations.getInferredTypeArguments(initializer);
			if (typeArguments != null) {
				String newSource= createParameterizedInvocation(initializer, typeArguments, rewrite);
				return (Expression) rewrite.getASTRewrite().createStringPlaceholder(newSource, initializer.getNodeType());
			}
		}
	}
	
	Expression copy= (Expression) rewrite.getASTRewrite().createCopyTarget(initializer);
	
	AST ast= rewrite.getAST();
	ITypeBinding explicitCast= ASTNodes.getExplicitCast(initializer, reference);
	if (explicitCast != null) {
		CastExpression cast= ast.newCastExpression();
		if (NecessaryParenthesesChecker.needsParentheses(initializer, cast, CastExpression.EXPRESSION_PROPERTY)) {
			ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
			parenthesized.setExpression(copy);
			copy= parenthesized;
		}
		cast.setExpression(copy);
		cast.setType(rewrite.getImportRewrite().addImport(explicitCast, ast));
		copy= cast;
		
	} else if (initializer instanceof ArrayInitializer && ASTNodes.getDimensions(varDecl) > 0) {
		ArrayType newType= (ArrayType) ASTNodeFactory.newType(ast, varDecl);

		ArrayCreation newArrayCreation= ast.newArrayCreation();
		newArrayCreation.setType(newType);
		newArrayCreation.setInitializer((ArrayInitializer) copy);
		return newArrayCreation;
	}
	return copy;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:43,代码来源:InlineTempRefactoring.java


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