本文整理汇总了Java中org.eclipse.jdt.core.dom.ArrayCreation类的典型用法代码示例。如果您正苦于以下问题:Java ArrayCreation类的具体用法?Java ArrayCreation怎么用?Java ArrayCreation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArrayCreation类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ArrayCreation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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);
}
示例3: visit
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
@Override
public boolean visit(ArrayCreation node) {
this.fBuffer.append("new ");//$NON-NLS-1$
ArrayType at= node.getType();
int dims= at.getDimensions();
Type elementType= at.getElementType();
elementType.accept(this);
for (Iterator<Expression> it= node.dimensions().iterator(); it.hasNext();) {
this.fBuffer.append("[");//$NON-NLS-1$
Expression e= it.next();
e.accept(this);
this.fBuffer.append("]");//$NON-NLS-1$
dims--;
}
// add empty "[]" for each extra array dimension
for (int i= 0; i < dims; i++) {
this.fBuffer.append("[]");//$NON-NLS-1$
}
if (node.getInitializer() != null) {
node.getInitializer().accept(this);
}
return false;
}
示例4: visit
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
public boolean visit(ArrayCreation node) {
this.buffer.append("new ");//$NON-NLS-1$
ArrayType at = node.getType();
int dims = at.getDimensions();
Type elementType = at.getElementType();
elementType.accept(this);
for (Iterator it = node.dimensions().iterator(); it.hasNext(); ) {
this.buffer.append("[");//$NON-NLS-1$
Expression e = (Expression) it.next();
e.accept(this);
this.buffer.append("]");//$NON-NLS-1$
dims--;
}
// add empty "[]" for each extra array dimension
for (int i= 0; i < dims; i++) {
this.buffer.append("[]");//$NON-NLS-1$
}
if (node.getInitializer() != null) {
node.getInitializer().accept(this);
}
return false;
}
示例5: visit
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
@Override
public boolean visit(ArrayCreation node) {
//System.out.println("Found: " + node.getClass());
if (node.getInitializer() != null) {
node.getInitializer().accept(this);
return false;
}
print("new ");
Type base = node.getType().getComponentType();
while (base instanceof ArrayType) {
base = ((ArrayType)base).getComponentType();
}
base.accept(this);
print("[");
int printed = 0;
for (Object o : node.dimensions()) {
Expression e = (Expression)o;
if (printed > 0) {
print("][");
}
e.accept(this);
printed++;
}
print("]");
return false;
}
示例6: getTargetTypeForArrayInitializer
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
private static ITypeBinding getTargetTypeForArrayInitializer(ArrayInitializer arrayInitializer) {
ASTNode initializerParent= arrayInitializer.getParent();
while (initializerParent instanceof ArrayInitializer) {
initializerParent= initializerParent.getParent();
}
if (initializerParent instanceof ArrayCreation) {
return ((ArrayCreation) initializerParent).getType().getElementType().resolveBinding();
} else if (initializerParent instanceof VariableDeclaration) {
ITypeBinding typeBinding= ((VariableDeclaration) initializerParent).getName().resolveTypeBinding();
if (typeBinding != null) {
return typeBinding.getElementType();
}
}
return null;
}
示例7: endVisit
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
@Override
public void endVisit(ArrayCreation node) {
if (skipNode(node)) {
return;
}
GenericSequentialFlowInfo info = processSequential(node, node.getType());
process(info, node.dimensions());
process(info, node.getInitializer());
}
示例8: endVisit
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
@Override
public void endVisit(ArrayCreation node) {
ArrayType arrayType = node.getType();
TypeVariable2 arrayTypeCv = (TypeVariable2) getConstraintVariable(arrayType);
if (arrayTypeCv == null) return;
setConstraintVariable(node, arrayTypeCv);
// TODO: constraints for array initializer?
}
示例9: 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;
}
示例10: retrieveVariableReference
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
private VariableReference retrieveVariableReference(ArrayCreation arrayCreation) {
Class<?> arrayType = retrieveTypeClass(arrayCreation.getType());
List<?> dimensions = ((AbstractList<?>) arrayCreation.getStructuralProperty(ArrayCreation.DIMENSIONS_PROPERTY));
if (dimensions.size() > 1) {
throw new RuntimeException("Multidimensional arrays not implemented!");
}
Integer length = (Integer) ((NumberLiteral) dimensions.get(0)).resolveConstantExpressionValue();
// ArrayReference arrayReference = new
// ValidArrayReference(testCase.getReference(), arrayType, length);
ArrayStatement arrayAssignment = new ArrayStatement(testCase.getReference(),
arrayType, length);
testCase.addStatement(arrayAssignment);
return arrayAssignment.getReturnValue();
}
示例11: endVisit
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
@Override
public final void endVisit(final ArrayCreation node) {
final ConstraintVariable2 ancestor= (ConstraintVariable2) node.getType().getProperty(PROPERTY_CONSTRAINT_VARIABLE);
node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor);
final ArrayInitializer initializer= node.getInitializer();
if (initializer != null) {
final ConstraintVariable2 descendant= (ConstraintVariable2) initializer.getProperty(PROPERTY_CONSTRAINT_VARIABLE);
if (descendant != null)
fModel.createSubtypeConstraint(descendant, ancestor);
}
}
示例12: endVisit
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
@Override
public void endVisit(ArrayCreation node) {
ArrayType arrayType= node.getType();
TypeVariable2 arrayTypeCv= (TypeVariable2) getConstraintVariable(arrayType);
if (arrayTypeCv == null)
return;
setConstraintVariable(node, arrayTypeCv);
//TODO: constraints for array initializer?
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:InferTypeArgumentsConstraintCreator.java
示例13: 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
示例14: endVisit
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
@Override
public void endVisit(ArrayCreation node) {
if (skipNode(node))
return;
GenericSequentialFlowInfo info= processSequential(node, node.getType());
process(info, node.dimensions());
process(info, node.getInitializer());
}
示例15: write
import org.eclipse.jdt.core.dom.ArrayCreation; //导入依赖的package包/类
@Override
public void write(ArrayCreation arrayCreation) {
// TODO: C# doesn't support an exact equivalent to Integer[], with boxed integers (or other primitive types).
// Consider disallowing arrays of that type to be created, instead forcing the dev to either create an
// Object[] if they want boxed types or an int[] if they want primitive types
List<?> dimensions = arrayCreation.dimensions();
// TODO: Support multidimensional arrays
if (dimensions.size() > 1)
throw new JUniversalException("Multidimensional arrays not currently supported");
matchAndWrite("new");
copySpaceAndComments();
writeNode(arrayCreation.getType().getElementType());
copySpaceAndComments();
matchAndWrite("[");
writeNodes(arrayCreation.dimensions());
copySpaceAndComments();
matchAndWrite("]");
// TODO: Check all syntax combinations here
@Nullable ArrayInitializer arrayInitializer = arrayCreation.getInitializer();
if (arrayInitializer != null) {
copySpaceAndComments();
writeNode(arrayInitializer);
}
}