List of usage examples for org.eclipse.jdt.core.dom ArrayType dimensions
ASTNode.NodeList dimensions
To view the source code for org.eclipse.jdt.core.dom ArrayType dimensions.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(ArrayType node) { if (node.getAST().apiLevel() < AST.JLS8) { getComponentType(node).accept(this); this.fBuffer.append("[]");//$NON-NLS-1$ } else {//from w ww . j a v a 2 s . co m node.getElementType().accept(this); List<Dimension> dimensions = node.dimensions(); for (int i = 0; i < dimensions.size(); i++) { Dimension dimension = dimensions.get(i); dimension.accept(this); } } return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(ArrayType node) { ASTNode parent = node.getParent();//from w w w. j a va 2 s . c o m boolean spaceBeofreOpening, spaceBetween; if (parent instanceof ArrayCreation) { spaceBeofreOpening = this.options.insert_space_before_opening_bracket_in_array_allocation_expression; spaceBetween = this.options.insert_space_between_empty_brackets_in_array_allocation_expression; } else { spaceBeofreOpening = this.options.insert_space_before_opening_bracket_in_array_type_reference; spaceBetween = this.options.insert_space_between_brackets_in_array_type_reference; } List<Dimension> dimensions = node.dimensions(); for (Dimension dimension : dimensions) { handleToken(dimension, TokenNameLBRACKET, spaceBeofreOpening, false); handleEmptyBrackets(dimension, spaceBetween); } return true; }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Helper method for {@link ArrayCreation}s and {@link ArrayType}s. */ private void visitArrayType(ArrayType node, DimensionsOrNot includeDimensions) { if (includeDimensions.isYes() && !node.dimensions().isEmpty()) { builder.open(plusFour);/*from w w w. j a v a 2 s . c o m*/ } node.getElementType().accept(this); if (includeDimensions.isYes()) { for (Dimension dimension : (List<Dimension>) node.dimensions()) { builder.breakToFill(dimension.annotations().isEmpty() ? "" : " "); visit(dimension); } } if (includeDimensions.isYes() && !node.dimensions().isEmpty()) { builder.close(); } }
From source file:org.codemucker.jmutate.ast.JAstFlattener.java
License:Open Source License
public boolean visit(ArrayType node) { if (node.getAST().apiLevel() < AST.JLS8) { visitComponentType(node);/*from w ww . j av a 2 s .c o m*/ this.buffer.append("[]");//$NON-NLS-1$ } else { node.getElementType().accept(this); List dimensions = node.dimensions(); int size = dimensions.size(); for (int i = 0; i < size; i++) { Dimension aDimension = (Dimension) dimensions.get(i); aDimension.accept(this); } } return false; }
From source file:org.decojer.cavaj.utils.Expressions.java
License:Open Source License
/** * New type.//from w ww.j a va 2 s . co m * * @param t * type * @param context * context * @return AST type */ @SuppressWarnings("deprecation") public static Type newType(@Nonnull final T t, @Nonnull final Element context) { final AST ast = context.getCu().getAst(); // handle array first because annot(array()) is special if (t.isArray()) { if (ast.apiLevel() <= AST.JLS4) { final T componentT = t.getComponentT(); assert componentT != null; return ast.newArrayType(newType(componentT, context)); } final T elementT = t.getElementT(); assert elementT != null; for (T checkT = t; checkT != null && checkT.isArray(); checkT = checkT.getComponentT()) { if (checkT.isAnnotated()) { final ArrayType arrayType = ast.newArrayType(newType(elementT, context)); final List<Dimension> dimensions = arrayType.dimensions(); dimensions.clear(); for (T componentT = t; componentT != null && componentT.isArray(); componentT = componentT.getComponentT()) { final Dimension dimension = ast.newDimension(); final List<IExtendedModifier> annotations = dimension.annotations(); assert annotations != null; if (componentT.isAnnotated()) { Annotations.decompileAnnotations(componentT, annotations, context); } dimensions.add(dimension); } return arrayType; } } return ast.newArrayType(newType(elementT, context), t.getDimensions()); } if (t.isAnnotated()) { Type type = newType(t.getRawT(), context); if (ast.apiLevel() <= AST.JLS4) { log.warn("Cannot decompile type annotations for type '" + t + "' in Eclipse AST JLS4!"); return type; } // parameterized type is not directly annotateable in Eclipse; but DecoJer thinks the // whole type is meant, not just the generic type, hence translate here AnnotatableType annotatableType = (AnnotatableType) (type instanceof ParameterizedType ? ((ParameterizedType) type).getType() : type); qualified: if (annotatableType instanceof SimpleType) { // direct annotation of qualified types adds the annotations as first element, // strange Java spec doesn't allow "@A package.Name" but wants "package.@A Name" final Name typeName = ((SimpleType) annotatableType).getName(); if (!(typeName instanceof QualifiedName)) { break qualified; } final Name qualifier = ((QualifiedName) typeName).getQualifier(); final SimpleName name = ((QualifiedName) typeName).getName(); // cannot delete mandory childs, copy them annotatableType = ast.newNameQualifiedType((Name) ASTNode.copySubtree(ast, qualifier), (SimpleName) ASTNode.copySubtree(ast, name)); if (type instanceof ParameterizedType) { ((ParameterizedType) type).setType(annotatableType); } else { type = annotatableType; } } final List<IExtendedModifier> annotations = annotatableType.annotations(); assert annotations != null; Annotations.decompileAnnotations(t, annotations, context); return type; } // doesn't work, now with Dimension (see above): if (t.isArray()) { return // ast.newArrayType(newType(t.getComponentT(), contextT)); } if (t.isParameterized()) { final T genericT = t.getGenericT(); assert genericT != null; final ParameterizedType parameterizedType = ast.newParameterizedType(newType(genericT, context)); for (final T typeArg : t.getTypeArgs()) { assert typeArg != null; parameterizedType.typeArguments().add(newType(typeArg, context)); } return parameterizedType; } if (t.isWildcard()) { final T boundT = t.getBoundT(); if (boundT == null) { return ast.newWildcardType(); } if (t.isSubclassOf()) { final WildcardType wildcardType = ast.newWildcardType(); // default...newWildcardType.setUpperBound(true); wildcardType.setBound(newType(boundT, context)); return wildcardType; } final WildcardType wildcardType = ast.newWildcardType(); wildcardType.setUpperBound(false); wildcardType.setBound(newType(boundT, context)); return wildcardType; } if (t.isMulti()) { log.warn("Convert type for multi-type '" + t + "'!"); // prefer boolean for multi-type with 0 or 1, synchronous to newLiteral()! // prefer byte before char if no explicit char type given } if (t.is(T.BOOLEAN)) { return ast.newPrimitiveType(PrimitiveType.BOOLEAN); } if (t.is(T.BYTE)) { return ast.newPrimitiveType(PrimitiveType.BYTE); } if (t.is(T.CHAR)) { return ast.newPrimitiveType(PrimitiveType.CHAR); } if (t.is(T.SHORT)) { return ast.newPrimitiveType(PrimitiveType.SHORT); } if (t.is(T.INT)) { return ast.newPrimitiveType(PrimitiveType.INT); } if (t.is(T.FLOAT)) { return ast.newPrimitiveType(PrimitiveType.FLOAT); } if (t.is(T.LONG)) { return ast.newPrimitiveType(PrimitiveType.LONG); } if (t.is(T.DOUBLE)) { return ast.newPrimitiveType(PrimitiveType.DOUBLE); } if (t.is(T.VOID)) { return ast.newPrimitiveType(PrimitiveType.VOID); } if (t.isQualified()) { final T qualifierT = t.getQualifierT(); assert qualifierT != null : "cannot be null for qualified"; // could be ParamT etc., not decompileable with name as target; // restrict qualifications to really necessary enclosings: // t = Outer.Inner.InnerInner, t = Outer.Inner ==> Inner final T contextT = context.getT(); assert contextT != null; if (contextT.getFullName().startsWith(qualifierT.getFullName())) { // TODO full name has too much info yet (like annotations) return ast.newSimpleType(newSimpleName(t.getSimpleIdentifier(), ast)); } return ast.newQualifiedType(newType(qualifierT, context), newSimpleName(t.getSimpleIdentifier(), ast)); } // else fall through... return ast.newSimpleType(newTypeName(t, context)); }
From source file:org.juniversal.translator.csharp.CSharpSourceFileWriter.java
License:Open Source License
/** * Add visitors for class, method, field, and type declarations. */// w w w.j a v a 2 s . c om private void addDeclarationWriters() { // TODO: Implement this // Compilation unit addWriter(CompilationUnit.class, new CompilationUnitWriter(this)); // TODO: Implement this // Javadoc comment addWriter(Javadoc.class, new JavadocCommentWriter(this)); // TODO: Implement this // Type (class/interface) declaration addWriter(TypeDeclaration.class, new TypeDeclarationWriter(this)); // TODO: Implement this // Type (class/interface) declaration addWriter(EnumDeclaration.class, new EnumDeclarationWriter(this)); // TODO: Implement this // Method declaration (which includes implementation) addWriter(MethodDeclaration.class, new MethodDeclarationWriter(this)); // Field declaration addWriter(FieldDeclaration.class, new FieldDeclarationWriter(this)); // Simple type addWriter(SimpleType.class, new SimpleTypeWriter(this)); // TODO: Implement this // Variable declaration fragment addWriter(VariableDeclarationFragment.class, new CSharpASTNodeWriter<VariableDeclarationFragment>(this) { @Override public void write(VariableDeclarationFragment variableDeclarationFragment) { String name = variableDeclarationFragment.getName().getIdentifier(); if (getContext().getTypeMethodNames().contains(name)) throw sourceNotSupported("Class also contains a method with name '" + name + "'; in C#, unlike Java, a class can't have a method and a variable with the same name, so rename one of them"); // TODO: Handle syntax with extra dimensions on array if (variableDeclarationFragment.getExtraDimensions() > 0) throw sourceNotSupported( "\"int foo[]\" array type syntax not currently supported; use \"int[] foo\" instead"); writeNode(variableDeclarationFragment.getName()); Expression initializer = variableDeclarationFragment.getInitializer(); if (initializer != null) { copySpaceAndComments(); matchAndWrite("="); copySpaceAndComments(); writeNode(initializer); } } }); // TODO: Implement this // Single variable declaration (used in parameter list, catch clauses, and enhanced for statements) addWriter(SingleVariableDeclaration.class, new CSharpASTNodeWriter<SingleVariableDeclaration>(this) { @Override public void write(SingleVariableDeclaration singleVariableDeclaration) { // TODO: Handle syntax with extra dimensions on array if (singleVariableDeclaration.getExtraDimensions() > 0) throw sourceNotSupported( "\"int foo[]\" array type syntax not currently supported; use \"int[] foo\" instead"); List<?> modifiers = singleVariableDeclaration.modifiers(); ensureModifiersJustFinalOrAnnotations(modifiers); skipModifiers(modifiers); Type type = singleVariableDeclaration.getType(); if (singleVariableDeclaration.isVarargs()) { write("params "); writeNode(type); copySpaceAndComments(); // TODO: Think through & handle all cases where a regular type is converted to an array here matchAndWrite("...", "[]"); } else writeNode(type); copySpaceAndComments(); writeNode(singleVariableDeclaration.getName()); // TODO: Handle initializer if (singleVariableDeclaration.getInitializer() != null) throw new JUniversalException("Unexpected initializer present for SingleVariableDeclaration"); } }); // TODO: Implement this // Parameterized type addWriter(ParameterizedType.class, new CSharpASTNodeWriter<ParameterizedType>(this) { @Override public void write(ParameterizedType parameterizedType) { writeNode(parameterizedType.getType()); copySpaceAndComments(); matchAndWrite("<"); writeCommaDelimitedNodes(parameterizedType.typeArguments()); copySpaceAndComments(); matchAndWrite(">"); } }); addWriter(WildcardType.class, new CSharpASTNodeWriter<WildcardType>(this) { @Override public void write(WildcardType wildcardType) { ArrayList<WildcardType> wildcardTypes = getContext().getMethodWildcardTypes(); if (wildcardTypes == null) throw sourceNotSupported( "Wildcard types (that is, ?) only supported in method parameters and return types. You may want to change the Java source to use an explicitly named generic type instead of a wildcard here."); writeWildcardTypeSyntheticName(wildcardTypes, wildcardType); setPositionToEndOfNode(wildcardType); } }); // Array type addWriter(ArrayType.class, new CSharpASTNodeWriter<ArrayType>(this) { @Override public void write(ArrayType arrayType) { writeNode(arrayType.getElementType()); forEach(arrayType.dimensions(), (Dimension dimension) -> { copySpaceAndComments(); matchAndWrite("["); copySpaceAndComments(); matchAndWrite("]"); }); } }); // TODO: Implement this // Primitive type addWriter(PrimitiveType.class, new CSharpASTNodeWriter<PrimitiveType>(this) { @Override public void write(PrimitiveType primitiveType) { PrimitiveType.Code code = primitiveType.getPrimitiveTypeCode(); if (code == PrimitiveType.BYTE) matchAndWrite("byte", "sbyte"); else if (code == PrimitiveType.SHORT) matchAndWrite("short"); else if (code == PrimitiveType.CHAR) matchAndWrite("char"); else if (code == PrimitiveType.INT) matchAndWrite("int"); else if (code == PrimitiveType.LONG) matchAndWrite("long"); else if (code == PrimitiveType.FLOAT) matchAndWrite("float"); else if (code == PrimitiveType.DOUBLE) matchAndWrite("double"); else if (code == PrimitiveType.BOOLEAN) matchAndWrite("boolean", "bool"); else if (code == PrimitiveType.VOID) matchAndWrite("void", "void"); else throw invalidAST("Unknown primitive type: " + code); } }); // Array initializer addWriter(ArrayInitializer.class, new CSharpASTNodeWriter<ArrayInitializer>(this) { @Override public void write(ArrayInitializer arrayInitializer) { // TODO: Test more cases here if (arrayInitializer.getParent() instanceof ArrayInitializer) { write("new[] "); /* throw sourceNotSupported( "Nested array initializers, without a 'new' specified, aren't supported in C#. Change the " + "Java source to include a new, a syntax supported by both Java and C#. For instance, " + "change { {1, 2, 3}, {10, 11, 12} ) => { new int[] {1, 2, 3}, new int[] {10, 11, 12} }"); */ } matchAndWrite("{"); // TODO: Check that number of expressions matches array size (I think, as I think C# requires exact number and Java allows less) writeCommaDelimitedNodes(arrayInitializer.expressions()); // TODO: Skip extra trailing commas here copySpaceAndComments(); matchAndWrite("}"); } }); }
From source file:org.mybatis.generator.eclipse.core.merge.visitors.TypeStringifier.java
License:Apache License
@Override @SuppressWarnings("unchecked") public boolean visit(ArrayType node) { node.getElementType().accept(this); List<Dimension> dimensions = node.dimensions(); for (Dimension dimension : dimensions) { dimension.accept(this); }//ww w.j a v a 2s . c om return false; }
From source file:parser.AnnotationType.java
License:Open Source License
public boolean visit(ArrayType node) { this.buffer.append(strSplitCharacter); if (node.getAST().apiLevel() < AST.JLS8) { visitComponentType(node);//from w w w. j ava2 s . co m this.buffer.append("[]");//$NON-NLS-1$ } else { node.getElementType().accept(this); List dimensions = node.dimensions(); int size = dimensions.size(); for (int i = 0; i < size; i++) { Dimension aDimension = (Dimension) dimensions.get(i); aDimension.accept(this); } } this.buffer.append(strSplitCharacter); return false; }