org.eclipse.jdt.core.dom.ArrayType Java Examples
The following examples show how to use
org.eclipse.jdt.core.dom.ArrayType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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; }
Example #2
Source File: DimensionRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * 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; }
Example #3
Source File: DimensionRewrite.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * 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; }
Example #4
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 6 votes |
private NewArray convert(org.eclipse.jdt.core.dom.ArrayCreation expression) { ArrayType arrayType = expression.getType(); List<Expression> dimensionExpressions = convertExpressions(JdtUtils.asTypedList(expression.dimensions())); // If some dimensions are not initialized then make that explicit. while (dimensionExpressions.size() < arrayType.getDimensions()) { dimensionExpressions.add(NullLiteral.get()); } ArrayLiteral arrayLiteral = expression.getInitializer() == null ? null : convert(expression.getInitializer()); ArrayTypeDescriptor typeDescriptor = (ArrayTypeDescriptor) JdtUtils.createTypeDescriptor(expression.resolveTypeBinding()); return NewArray.newBuilder() .setTypeDescriptor(typeDescriptor) .setDimensionExpressions(dimensionExpressions) .setArrayLiteral(arrayLiteral) .build(); }
Example #5
Source File: StubUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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; }
Example #6
Source File: RefactoringUtility.java From JDeodorant with MIT License | 6 votes |
private static boolean isQualifiedType(Type type) { if(type instanceof SimpleType) { SimpleType simpleType = (SimpleType)type; Name name = simpleType.getName(); if(name instanceof QualifiedName) { return true; } } else if(type instanceof QualifiedType) { QualifiedType qualifiedType = (QualifiedType)type; Type qualifier = qualifiedType.getQualifier(); return isQualifiedType(qualifier); } else if(type instanceof ArrayType) { ArrayType arrayType = (ArrayType)type; Type elementType = arrayType.getElementType(); return isQualifiedType(elementType); } else if(type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType)type; Type erasureType = parameterizedType.getType(); return isQualifiedType(erasureType); } return false; }
Example #7
Source File: CodeBlock.java From SimFix with GNU General Public License v2.0 | 5 votes |
private ArrayAcc visit(ArrayAccess node) { int startLine = _cunit.getLineNumber(node.getStartPosition()); int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength()); ArrayAcc arrayAcc = new ArrayAcc(startLine, endLine, node); Expr array = (Expr) process(node.getArray()); array.setParent(arrayAcc); arrayAcc.setArray(array); Expr indexExpr = (Expr) process(node.getIndex()); indexExpr.setParent(arrayAcc); arrayAcc.setIndex(indexExpr); Pair<String, String> classAndMethodName = NodeUtils.getTypeDecAndMethodDec(node); String nodeStr = node.toString(); int index = nodeStr.indexOf("["); if(index >= 0){ nodeStr = nodeStr.substring(0, index); } Type type = ProjectInfo.getVariableType(classAndMethodName.getFirst(), classAndMethodName.getSecond(), nodeStr); if(type != null){ if(type instanceof ArrayType){ ArrayType arrayType = (ArrayType) type; type = arrayType.getElementType(); } else { System.out.println("ArrayAccess type error : not array type ! " + node.toString()); } } arrayAcc.setType(type); return arrayAcc; }
Example #8
Source File: TypeContextChecker.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean isVoidArrayType(Type type){ if (! type.isArrayType()) return false; ArrayType arrayType= (ArrayType)type; if (! arrayType.getElementType().isPrimitiveType()) return false; PrimitiveType primitiveType= (PrimitiveType) arrayType.getElementType(); return (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID); }
Example #9
Source File: ASTNodeFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns an {@link ArrayType} that adds one dimension to the given type node. * If the given node is already an ArrayType, then a new {@link Dimension} * without annotations is inserted at the first position. * * @param type the type to be wrapped * @return the array type * @since 3.10 */ public static ArrayType newArrayType(Type type) { if (type instanceof ArrayType) { Dimension dimension= type.getAST().newDimension(); ArrayType arrayType= (ArrayType) type; arrayType.dimensions().add(0, dimension); // first dimension is outermost return arrayType; } else { return type.getAST().newArrayType(type); } }
Example #10
Source File: ASTNodeFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) { if (typeBinding.isParameterizedType()) { Type baseType= newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext); ParameterizedType parameterizedType= ast.newParameterizedType(baseType); for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) { parameterizedType.typeArguments().add(newCreationType(ast, typeArgument, importRewrite, importContext)); } return parameterizedType; } else if (typeBinding.isParameterizedType()) { Type elementType= newCreationType(ast, typeBinding.getElementType(), importRewrite, importContext); ArrayType arrayType= ast.newArrayType(elementType, 0); while (typeBinding.isArray()) { Dimension dimension= ast.newDimension(); IAnnotationBinding[] typeAnnotations= typeBinding.getTypeAnnotations(); for (IAnnotationBinding typeAnnotation : typeAnnotations) { dimension.annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext)); } arrayType.dimensions().add(dimension); typeBinding= typeBinding.getComponentType(); } return arrayType; } else if (typeBinding.isWildcardType()) { ITypeBinding bound= typeBinding.getBound(); typeBinding= (bound != null) ? bound : typeBinding.getErasure(); return newCreationType(ast, typeBinding, importRewrite, importContext); } else { return importRewrite.addImport(typeBinding, ast, importContext); } }
Example #11
Source File: PromoteTempToFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }
Example #12
Source File: InferTypeArgumentsConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@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? }
Example #13
Source File: SuperTypeConstraintsCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public final void endVisit(final ArrayType node) { Type elementType= node.getElementType(); final ConstraintVariable2 variable= fModel.createTypeVariable(elementType); if (variable != null) { elementType.setProperty(PROPERTY_CONSTRAINT_VARIABLE, variable); node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, variable); } }
Example #14
Source File: BindingSignatureVisitor.java From JDeodorant with MIT License | 5 votes |
private void handleType(Type type) { if (type instanceof PrimitiveType) { visit((PrimitiveType) type); } else if (type instanceof ArrayType) { visit((ArrayType) type); } else if (type instanceof SimpleType) { visit((SimpleType) type); } else if (type instanceof QualifiedType) { visit((QualifiedType) type); } else if (type instanceof ParameterizedType) { visit((ParameterizedType) type); } else if (type instanceof WildcardType) { visit((WildcardType) type); } }
Example #15
Source File: Visitor.java From RefactoringMiner with MIT License | 5 votes |
public boolean visit(ArrayType node) { types.add(node.toString()); if(current.getUserObject() != null) { AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject(); anonymous.getTypes().add(node.toString()); } return false; }
Example #16
Source File: JavaApproximateTypeInferencer.java From api-mining with GNU General Public License v3.0 | 5 votes |
/** * @param type * @return */ protected String getNameOfType(final Type type) { final String nameOfType; if (type.isPrimitiveType()) { nameOfType = type.toString(); } else if (type.isParameterizedType()) { nameOfType = getParametrizedType((ParameterizedType) type); } else if (type.isArrayType()) { final ArrayType array = (ArrayType) type; nameOfType = getNameOfType(array.getElementType()) + "[]"; } else if (type.isUnionType()) { final UnionType uType = (UnionType) type; final StringBuffer sb = new StringBuffer(); for (final Object unionedType : uType.types()) { sb.append(getNameOfType(((Type) unionedType))); sb.append(" | "); } sb.delete(sb.length() - 3, sb.length()); nameOfType = sb.toString(); } else if (type.isWildcardType()) { final WildcardType wType = (WildcardType) type; if (wType.getBound() == null) return "?"; nameOfType = (wType.isUpperBound() ? "? extends " : "? super ") + getNameOfType(wType.getBound()); } else { nameOfType = getFullyQualifiedNameFor(type.toString()); } return nameOfType; }
Example #17
Source File: StyledStringVisitor.java From JDeodorant with MIT License | 5 votes |
public boolean visit(ArrayType type) { /* * ArrayType: Type [ ] */ activateDiffStyle(type); handleType(type.getElementType()); for (int i = 0; i < type.getDimensions(); i++) { appendOpenBracket(); appendClosedBracket(); } deactivateDiffStyle(type); return false; }
Example #18
Source File: StyledStringVisitor.java From JDeodorant with MIT License | 5 votes |
private void handleType(Type type) { if (type instanceof PrimitiveType) { visit((PrimitiveType) type); } else if (type instanceof ArrayType) { visit((ArrayType) type); } else if (type instanceof SimpleType) { visit((SimpleType) type); } else if (type instanceof QualifiedType) { visit((QualifiedType) type); } else if (type instanceof ParameterizedType) { visit((ParameterizedType) type); } else if (type instanceof WildcardType) { visit((WildcardType) type); } }
Example #19
Source File: TypeResolver.java From KodeBeagle with Apache License 2.0 | 5 votes |
/** * @param type * @return */ protected String getNameOfType(final Type type) { String nameOfType = ""; if (type != null) { if (type.isPrimitiveType()) { nameOfType = type.toString(); } else if (type.isParameterizedType()) { nameOfType = getParametrizedType((ParameterizedType) type); } else if (type.isArrayType()) { final ArrayType array = (ArrayType) type; nameOfType = getNameOfType(array.getElementType()) /*+ "[]"*/; } else if (type.isUnionType()) { // TODO: this is used for exceptions till now // So we will just capture the first type that we encounter final UnionType uType = (UnionType) type; final StringBuilder sb = new StringBuilder(); for (final Object unionedType : uType.types()) { sb.append(getNameOfType((Type) unionedType)); break; } nameOfType = sb.toString(); } else if (type.isWildcardType()) { final WildcardType wType = (WildcardType) type; nameOfType = (wType.isUpperBound() ? "? extends " : "? super ") + getNameOfType(wType.getBound()); } else { nameOfType = getFullyQualifiedNameFor(type.toString()); } } return nameOfType; }
Example #20
Source File: JavaASTFlattener.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public boolean visit(final ArrayType node) { boolean _java8orHigher = this.java8orHigher(); boolean _not = (!_java8orHigher); if (_not) { node.getComponentType().accept(this); this.appendToBuffer("[]"); } else { ASTNode _genericChildProperty = this._aSTFlattenerUtils.genericChildProperty(node, "elementType"); if (_genericChildProperty!=null) { _genericChildProperty.accept(this); } List<ASTNode> dimensions = this._aSTFlattenerUtils.genericChildListProperty(node, "dimensions"); boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(dimensions); boolean _not_1 = (!_isNullOrEmpty); if (_not_1) { final Consumer<ASTNode> _function = (ASTNode dim) -> { List<ASTNode> _genericChildListProperty = this._aSTFlattenerUtils.genericChildListProperty(dim, "annotations"); if (_genericChildListProperty!=null) { this.visitAll(_genericChildListProperty); } this.appendToBuffer("[]"); }; dimensions.forEach(_function); } } return false; }
Example #21
Source File: ArrayCreationWriter.java From juniversal with MIT License | 5 votes |
@Override public void write(ArrayCreation arrayCreation) { matchAndWrite("new"); List<?> dimensions = arrayCreation.dimensions(); // TODO: Support multidimensional arrays if (dimensions.size() > 1) throw new JUniversalException("Multidimensional arrays not currently supported"); // TODO: Support array initializers if (arrayCreation.getInitializer() != null) throw new JUniversalException("Array initializers not currently supported"); Expression dimensionSizeExpression = (Expression) dimensions.get(0); setPosition(dimensionSizeExpression.getStartPosition()); write("("); writeNode(dimensionSizeExpression); copySpaceAndComments(); write(") "); ArrayType arrayType = arrayCreation.getType(); setPosition(arrayType.getStartPosition()); write("Array<"); writeNode(arrayType.getElementType()); skipSpaceAndComments(); write(">"); setPosition(ASTUtil.getEndPosition(dimensionSizeExpression)); skipSpaceAndComments(); match("]"); }
Example #22
Source File: ASTUtil.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private static String getPrettyTypeName(Type type) { if (type.isArrayType()) { return getPrettyTypeName((ArrayType) type); } else if (type.isParameterizedType()) { return getPrettyTypeName((ParameterizedType) type); } else if (type.isPrimitiveType()) { return getPrettyTypeName((PrimitiveType) type); } else if (type.isQualifiedType()) { return getPrettyTypeName((QualifiedType) type); } else if (type.isSimpleType()) { return getPrettyTypeName((SimpleType) type); } else { return ""; } }
Example #23
Source File: FlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void endVisit(ArrayType node) { if (skipNode(node)) { return; } processSequential(node, node.getElementType()); }
Example #24
Source File: Resolver.java From DesigniteJava with Apache License 2.0 | 5 votes |
private void specifyTypes(Type type) { if (type.isParameterizedType()) { ParameterizedType parameterizedType = (ParameterizedType) type; List<Type> typeArgs = parameterizedType.typeArguments(); for (int i = 0; i < typeArgs.size(); i++) setTypeList(typeArgs.get(i)); } else if (type.isArrayType()) { Type arrayType = ((ArrayType) type).getElementType(); setArrayType(arrayType); } }
Example #25
Source File: ArrayCreate.java From SimFix with GNU General Public License v2.0 | 5 votes |
@Override public StringBuffer toSrcString() { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("new "); if(_dimension != null && _dimension.size() > 0){ // new a[4][]; if(_type instanceof ArrayType){ ArrayType arrayType = (ArrayType) _type; stringBuffer.append(arrayType.getElementType()); for(int i = 0; i < arrayType.getDimensions(); i++){ stringBuffer.append("["); if(_dimension.size() > i){ stringBuffer.append(_dimension.get(i).toSrcString()); } stringBuffer.append("]"); } if(_initializer != null){ stringBuffer.append(_initializer.toSrcString()); } } else { stringBuffer = new StringBuffer(); stringBuffer.append(_originalNode.toString()); } } else { // new a[][]{1,2;3,4}; stringBuffer.append(_type); if(_initializer != null){ stringBuffer.append(_initializer.toSrcString()); } } return stringBuffer; }
Example #26
Source File: BindingSignatureVisitor.java From JDeodorant with MIT License | 4 votes |
public boolean visit(ArrayType type) { handleType(type.getElementType()); return false; }
Example #27
Source File: Util.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static void getFullyQualifiedName(Type type, StringBuffer buffer) { switch (type.getNodeType()) { case ASTNode.ARRAY_TYPE: ArrayType arrayType = (ArrayType) type; getFullyQualifiedName(arrayType.getElementType(), buffer); for (int i = 0, length = arrayType.getDimensions(); i < length; i++) { buffer.append('['); buffer.append(']'); } break; case ASTNode.PARAMETERIZED_TYPE: ParameterizedType parameterizedType = (ParameterizedType) type; getFullyQualifiedName(parameterizedType.getType(), buffer); buffer.append('<'); Iterator iterator = parameterizedType.typeArguments().iterator(); boolean isFirst = true; while (iterator.hasNext()) { if (!isFirst) buffer.append(','); else isFirst = false; Type typeArgument = (Type) iterator.next(); getFullyQualifiedName(typeArgument, buffer); } buffer.append('>'); break; case ASTNode.PRIMITIVE_TYPE: buffer.append(((PrimitiveType) type).getPrimitiveTypeCode().toString()); break; case ASTNode.QUALIFIED_TYPE: buffer.append(((QualifiedType) type).getName().getFullyQualifiedName()); break; case ASTNode.SIMPLE_TYPE: buffer.append(((SimpleType) type).getName().getFullyQualifiedName()); break; case ASTNode.WILDCARD_TYPE: buffer.append('?'); WildcardType wildcardType = (WildcardType) type; Type bound = wildcardType.getBound(); if (bound == null) return; if (wildcardType.isUpperBound()) { buffer.append(" extends "); //$NON-NLS-1$ } else { buffer.append(" super "); //$NON-NLS-1$ } getFullyQualifiedName(bound, buffer); break; } }
Example #28
Source File: IdentifierPerType.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean visit(final ArrayType node) { addToMap(identifiers, node, node.toString()); return super.visit(node); }
Example #29
Source File: GenericVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean visit(ArrayType node) { return visitNode(node); }
Example #30
Source File: GenericVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public void endVisit(ArrayType node) { endVisitNode(node); }