public boolean visit(ParameterizedType node) { node.getType().accept(this); this.buffer.append("<");//$NON-NLS-1$ for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { this.buffer.append(",");//$NON-NLS-1$ } } this.buffer.append(">");//$NON-NLS-1$ return false; }
ASTNode clone0(AST target) { ParameterizedType result = new ParameterizedType(target); result.setSourceRange(getStartPosition(), getLength()); result.setType((Type) ((ASTNode) getType()).clone(target)); result.typeArguments().addAll( ASTNode.copySubtrees(target, typeArguments())); return result; }
@Override void accept0(ASTVisitor visitor) { boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order acceptChild(visitor, getType()); acceptChildren(visitor, this.typeArguments); } visitor.endVisit(this); }
/** * Creates and returns a new unparented parameterized type node with the * given type and an empty list of type arguments. * * @param type the type that is parameterized * @return a new unparented parameterized type node * @exception IllegalArgumentException if: * <ul> * <li>the node belongs to a different AST</li> * <li>the node already has a parent</li> * </ul> * @exception UnsupportedOperationException if this operation is used in * a JLS2 AST * @since 3.1 */ public ParameterizedType newParameterizedType(Type type) { ParameterizedType result = new ParameterizedType(this); result.setType(type); return result; }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == TYPE_PROPERTY) { if (get) { return getType(); } else { setType((Type) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
/** * Generecized version of the equivalent JDT method. * * @param node the node on which to call the equivalent JDT method * @return a List of expressions * @see ParameterizedType#typeArguments() */ @SuppressWarnings("unchecked") public static List<Type> typeArguments(ParameterizedType node) { return node.typeArguments(); }
@Override public boolean visit(ParameterizedType node) { node.getType().accept(this); return false; } @Override
private boolean updateParameterizedTypeReference(ITypeBinding[] parameters, ParameterizedType type, CompilationUnitRewrite targetRewrite, TextEditGroup group) { if (!(type.getParent() instanceof ClassInstanceCreation)) { final ListRewrite rewrite= targetRewrite.getASTRewrite().getListRewrite(type, ParameterizedType.TYPE_ARGUMENTS_PROPERTY); final AST ast= targetRewrite.getRoot().getAST(); Type simpleType= null; for (int index= type.typeArguments().size(); index < parameters.length; index++) { simpleType= ast.newSimpleType(ast.newSimpleName(parameters[index].getName())); rewrite.insertLast(simpleType, group); } } return true; }
/** * The selection corresponds to a ParameterizedType (return type of method) */ private String parameterizedTypeSelected(ParameterizedType pt) { ASTNode parent= pt.getParent(); if (parent.getNodeType() == ASTNode.METHOD_DECLARATION){ fMethodBinding= ((MethodDeclaration)parent).resolveBinding(); fParamIndex= -1; fEffectiveSelectionStart= pt.getStartPosition(); fEffectiveSelectionLength= pt.getLength(); setOriginalType(pt.resolveBinding()); } else if (parent.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION){ return singleVariableDeclarationSelected((SingleVariableDeclaration)parent); } else if (parent.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT){ return variableDeclarationStatementSelected((VariableDeclarationStatement)parent); } else if (parent.getNodeType() == ASTNode.FIELD_DECLARATION){ return fieldDeclarationSelected((FieldDeclaration)parent); } else { return nodeTypeNotSupported(); } return null; }
@Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModelCore model) throws CoreException { TextEditGroup group= createTextEditGroup(FixMessages.TypeParametersFix_insert_inferred_type_arguments_description, cuRewrite); ASTRewrite rewrite= cuRewrite.getASTRewrite(); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); AST ast= cuRewrite.getRoot().getAST(); for (int i= 0; i < fCreatedTypes.length; i++) { ParameterizedType createdType= fCreatedTypes[i]; ITypeBinding[] typeArguments= createdType.resolveBinding().getTypeArguments(); ContextSensitiveImportRewriteContext importContext= new ContextSensitiveImportRewriteContext(cuRewrite.getRoot(), createdType.getStartPosition(), importRewrite); ListRewrite argumentsRewrite= rewrite.getListRewrite(createdType, ParameterizedType.TYPE_ARGUMENTS_PROPERTY); for (int j= 0; j < typeArguments.length; j++) { ITypeBinding typeArgument= typeArguments[j]; Type argumentNode= importRewrite.addImport(typeArgument, ast, importContext, TypeLocation.TYPE_ARGUMENT); argumentsRewrite.insertLast(argumentNode, group); } } } }
final List internalGetChildListProperty(ChildListPropertyDescriptor property) { if (property == TYPE_ARGUMENTS_PROPERTY) { return typeArguments(); } // allow default implementation to flag the error return super.internalGetChildListProperty(property); }
@Override public boolean visit(ParameterizedType node) { node.getType().accept(this); return false; } @Override
private boolean updateParameterizedTypeReference(ITypeBinding[] parameters, ParameterizedType type, CompilationUnitRewrite targetRewrite, TextEditGroup group) { if (!(type.getParent() instanceof ClassInstanceCreation)) { final ListRewrite rewrite= targetRewrite.getASTRewrite().getListRewrite(type, ParameterizedType.TYPE_ARGUMENTS_PROPERTY); final AST ast= targetRewrite.getRoot().getAST(); Type simpleType= null; for (int index= type.typeArguments().size(); index < parameters.length; index++) { simpleType= ast.newSimpleType(ast.newSimpleName(parameters[index].getName())); rewrite.insertLast(simpleType, group); } } return true; }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == TYPE_PROPERTY) { if (get) { return getType(); } else { setType((Type) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
/** * The selection corresponds to a ParameterizedType (return type of method) * @param pt the type * @return the message */ private String parameterizedTypeSelected(ParameterizedType pt) { ASTNode parent= pt.getParent(); if (parent.getNodeType() == ASTNode.METHOD_DECLARATION){ fMethodBinding= ((MethodDeclaration)parent).resolveBinding(); fParamIndex= -1; fEffectiveSelectionStart= pt.getStartPosition(); fEffectiveSelectionLength= pt.getLength(); setOriginalType(pt.resolveBinding()); } else if (parent.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION){ return singleVariableDeclarationSelected((SingleVariableDeclaration)parent); } else if (parent.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT){ return variableDeclarationStatementSelected((VariableDeclarationStatement)parent); } else if (parent.getNodeType() == ASTNode.FIELD_DECLARATION){ return fieldDeclarationSelected((FieldDeclaration)parent); } else { return nodeTypeNotSupported(); } return null; }
/** * Creates and returns a new unparented parameterized type node with the * given type and an empty list of type arguments. * * @param type the type that is parameterized * @return a new unparented parameterized type node * @exception IllegalArgumentException if: * <ul> * <li>the node belongs to a different AST</li> * <li>the node already has a parent</li> * </ul> * @exception UnsupportedOperationException if this operation is used in * a JLS2 AST * @since 3.1 */ public ParameterizedType newParameterizedType(Type type) { ParameterizedType result = new ParameterizedType(this); result.setType(type); return result; }
@Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException { TextEditGroup group= createTextEditGroup(FixMessages.TypeParametersFix_insert_inferred_type_arguments_description, cuRewrite); ASTRewrite rewrite= cuRewrite.getASTRewrite(); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); AST ast= cuRewrite.getRoot().getAST(); for (int i= 0; i < fCreatedTypes.length; i++) { ParameterizedType createdType= fCreatedTypes[i]; ITypeBinding[] typeArguments= createdType.resolveBinding().getTypeArguments(); ContextSensitiveImportRewriteContext importContext= new ContextSensitiveImportRewriteContext(cuRewrite.getRoot(), createdType.getStartPosition(), importRewrite); ListRewrite argumentsRewrite= rewrite.getListRewrite(createdType, ParameterizedType.TYPE_ARGUMENTS_PROPERTY); for (int j= 0; j < typeArguments.length; j++) { ITypeBinding typeArgument= typeArguments[j]; Type argumentNode= importRewrite.addImport(typeArgument, ast, importContext); argumentsRewrite.insertLast(argumentNode, group); } } } }
public boolean visit(ParameterizedType node) { node.getType().accept(this); this.buffer.append("<");//$NON-NLS-1$ for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { this.buffer.append(",");//$NON-NLS-1$ } } this.buffer.append(">");//$NON-NLS-1$ return false; }