本文整理汇总了Java中org.eclipse.jdt.core.dom.ArrayType类的典型用法代码示例。如果您正苦于以下问题:Java ArrayType类的具体用法?Java ArrayType怎么用?Java ArrayType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArrayType类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ArrayType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDimensions
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
public static int getDimensions(VariableDeclaration declaration) {
int dim= declaration.getExtraDimensions();
if (declaration instanceof VariableDeclarationFragment && declaration.getParent() instanceof LambdaExpression) {
LambdaExpression lambda= (LambdaExpression) declaration.getParent();
IMethodBinding methodBinding= lambda.resolveMethodBinding();
if (methodBinding != null) {
ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
int index= lambda.parameters().indexOf(declaration);
ITypeBinding typeBinding= parameterTypes[index];
return typeBinding.getDimensions();
}
} else {
Type type= getType(declaration);
if (type instanceof ArrayType) {
dim+= ((ArrayType) type).getDimensions();
}
}
return dim;
}
示例2: copyTypeAndAddDimensions
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
/**
* Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code>
* and adds <code>extraDimensions</code> to it.
*
* @param type the type to copy
* @param extraDimensions the dimensions to add
* @param rewrite the ASTRewrite with which to create new nodes
* @return the copy target with added dimensions
*/
public static Type copyTypeAndAddDimensions(Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
AST ast= rewrite.getAST();
if (extraDimensions.isEmpty()) {
return (Type) rewrite.createCopyTarget(type);
}
ArrayType result;
if (type instanceof ArrayType) {
ArrayType arrayType= (ArrayType) type;
Type varElementType= (Type) rewrite.createCopyTarget(arrayType.getElementType());
result= ast.newArrayType(varElementType, 0);
result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
} else {
Type elementType= (Type) rewrite.createCopyTarget(type);
result= ast.newArrayType(elementType, 0);
result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
}
return result;
}
示例3: getVariableNameSuggestions
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
private static String[] getVariableNameSuggestions(int variableKind, IJavaProject project, Type expectedType, Collection<String> excluded, boolean evaluateDefault) {
int dim= 0;
if (expectedType.isArrayType()) {
ArrayType arrayType= (ArrayType)expectedType;
dim= arrayType.getDimensions();
expectedType= arrayType.getElementType();
}
if (expectedType.isParameterizedType()) {
expectedType= ((ParameterizedType)expectedType).getType();
}
String typeName= ASTNodes.getTypeName(expectedType);
if (typeName.length() > 0) {
return getVariableNameSuggestions(variableKind, project, typeName, dim, excluded, evaluateDefault);
}
return EMPTY;
}
示例4: copyTypeAndAddDimensions
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
/**
* Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code> and adds
* <code>extraDimensions</code> to it.
*
* @param type the type to copy
* @param extraDimensions the dimensions to add
* @param rewrite the ASTRewrite with which to create new nodes
* @return the copy target with added dimensions
*/
public static Type copyTypeAndAddDimensions(
Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
AST ast = rewrite.getAST();
if (extraDimensions.isEmpty()) {
return (Type) rewrite.createCopyTarget(type);
}
ArrayType result;
if (type instanceof ArrayType) {
ArrayType arrayType = (ArrayType) type;
Type varElementType = (Type) rewrite.createCopyTarget(arrayType.getElementType());
result = ast.newArrayType(varElementType, 0);
result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
} else {
Type elementType = (Type) rewrite.createCopyTarget(type);
result = ast.newArrayType(elementType, 0);
result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
}
return result;
}
示例5: getVariableNameSuggestions
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
private static String[] getVariableNameSuggestions(
int variableKind,
IJavaProject project,
Type expectedType,
Collection<String> excluded,
boolean evaluateDefault) {
int dim = 0;
if (expectedType.isArrayType()) {
ArrayType arrayType = (ArrayType) expectedType;
dim = arrayType.getDimensions();
expectedType = arrayType.getElementType();
}
if (expectedType.isParameterizedType()) {
expectedType = ((ParameterizedType) expectedType).getType();
}
String typeName = ASTNodes.getTypeName(expectedType);
if (typeName.length() > 0) {
return getVariableNameSuggestions(
variableKind, project, typeName, dim, excluded, evaluateDefault);
}
return EMPTY;
}
示例6: createArrayInitStmt
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的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);
}
}
示例7: copyTypeAndAddDimensions
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
/**
* Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code>
* and adds <code>extraDimensions</code> to it.
*
* @param type the type to copy
* @param extraDimensions the dimensions to add
* @param rewrite the ASTRewrite with which to create new nodes
* @return the copy target with added dimensions
*/
public static Type copyTypeAndAddDimensions(Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
AST ast= rewrite.getAST();
if (extraDimensions.isEmpty()) {
return (Type) rewrite.createCopyTarget(type);
}
ArrayType result;
if (type instanceof ArrayType) {
ArrayType arrayType= (ArrayType) type;
Type varElementType= (Type) rewrite.createCopyTarget(arrayType.getElementType());
result= ast.newArrayType(varElementType, 0);
result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
} else {
Type elementType= (Type) rewrite.createCopyTarget(type);
result= ast.newArrayType(elementType, 0);
result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
}
return result;
}
示例8: visit
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的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;
}
示例9: visit
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的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;
}
示例10: repairBug
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
@Override
protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
MethodDeclaration thisMethod = TraversalUtil.findEnclosingMethod(workingUnit, bug.getPrimarySourceLineAnnotation());
@SuppressWarnings("unchecked")
List<SingleVariableDeclaration> params = thisMethod.parameters();
SingleVariableDeclaration lastParam = params.get(params.size() - 1);
removeArrayDimensions(rewrite, lastParam);
rewrite.set(lastParam, SingleVariableDeclaration.VARARGS_PROPERTY, Boolean.TRUE, null);
Type lastType = lastParam.getType();
if (lastType.isArrayType()) { // can be false for the int a[] declaration
Type bareType = ((ArrayType) lastType).getElementType();
rewrite.replace(lastType, rewrite.createCopyTarget(bareType), null);
}
}
示例11: getBindingForArrayType
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
public Binding getBindingForArrayType(final ArrayType type) {
Binding result = null;
ITypeBinding binding = type.resolveBinding();
if (binding == null) {
if (this.logJDTBindingsIssues) {
MoDiscoLogger.logWarning("*** WARNING : binding '" //$NON-NLS-1$
+ type.toString() + "' unresolved.", JavaActivator //$NON-NLS-1$
.getDefault());
}
result = new UnresolvedBinding(type.toString());
} else {
result = new ClassBinding();
result.setName(binding.getQualifiedName());
}
return result;
}
示例12: visit
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的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;
}
示例13: tryToResolve
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
protected boolean tryToResolve(Type type) {
boolean result = false;
if (underResolution.getResolverMap().containsKey(type)) {
result = true;
} else {
if (type.isPrimitiveType()) {
result = tryToResolve((PrimitiveType)type);
} else if (type.isQualifiedType()) {
result = tryToResolve((QualifiedType)type);
} else if (type.isArrayType()) {
result = tryToResolve(((ArrayType)type).getElementType());
} else if (type.isSimpleType()) {
result = tryToResolve((SimpleType)type);
} else if (type.isParameterizedType()) {
result = tryToResolve((ParameterizedType)type);
} else if (type.isWildcardType()) {
result = tryToResolve((WildcardType)type);
} else {
CoreActivator.log(IStatus.INFO, "Type not handled " + type.toString());
}
}
return result;
}
示例14: getName
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
/**
* Return a name instance from a Type instance
*/
public static Name getName(Type t) {
if (t.isArrayType()) {
ArrayType arrayType = (ArrayType) t;
return getName(ASTArrayTypeHelper.getComponentType(arrayType));
} else if (t.isParameterizedType()) {
return getName(((ParameterizedType) t).getType());
} else if (t.isPrimitiveType()) {
return null;
} else if (t.isQualifiedType()) {
return ((QualifiedType) t).getName();
} else if (t.isSimpleType()) {
return ((SimpleType) t).getName();
}
return null;
}
示例15: getArrayTypeElementPropertyDescriptor
import org.eclipse.jdt.core.dom.ArrayType; //导入依赖的package包/类
public static ChildPropertyDescriptor getArrayTypeElementPropertyDescriptor(ArrayType node) {
List<?> propertyDescriptors = ArrayType.propertyDescriptors(node.getAST().apiLevel());
for (Object propertyDescriptor : propertyDescriptors) {
if (propertyDescriptor instanceof ChildPropertyDescriptor) {
ChildPropertyDescriptor childListPropertyDescriptor = (ChildPropertyDescriptor) propertyDescriptor;
if (DESCRIPTOR_NAME_AST4.equals(childListPropertyDescriptor.getId())) {
if (OptimusLogger.logger.isLoggable(Level.FINE)) {
OptimusLogger.logger.fine(String.format(RETURNED_DESCRIPTOR_MESSAGE, DESCRIPTOR_NAME_AST4));
}
return childListPropertyDescriptor;
} else if (DESCRIPTOR_NAME_AST8.equals(childListPropertyDescriptor.getId())) {
if (OptimusLogger.logger.isLoggable(Level.FINE)) {
OptimusLogger.logger.fine(String.format(RETURNED_DESCRIPTOR_MESSAGE, DESCRIPTOR_NAME_AST8));
}
return childListPropertyDescriptor;
}
}
}
return null;
}