/** * Builds a new {@link VariableDeclarationStatement} instance. * * @param type * the type of the variable being declared * @param fragment * the fragment being declared * @return a new variable declaration statement */ public VariableDeclarationStatement declareStmt(Type type, VariableDeclarationFragment fragment) { final VariableDeclarationStatement vds = ast.newVariableDeclarationStatement(fragment); vds.setType(type); return vds; }
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); }
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); }
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); }
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); }
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); }
@Override 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); }
/** * Append a local variable declaration. * * @param type Type * @param vname Variable name */ public void addLocalVariableDeclaration(String type, String vname) { VariableDeclarationFragment vfrag = m_ast.newVariableDeclarationFragment(); vfrag.setName(m_ast.newSimpleName(vname)); VariableDeclarationStatement stmt = m_ast.newVariableDeclarationStatement(vfrag); stmt.setType(m_source.createType(type)); m_block.statements().add(stmt); }
/** * @return a statement in form of <code>final int maxLen = 10;</code> */ protected VariableDeclarationStatement createMaxLenDeclaration() { VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment(); fragment.setName(fAst.newSimpleName(fMaxLenVariableName)); fragment.setInitializer(fAst.newNumberLiteral(String.valueOf(fContext.getLimitItemsValue()))); VariableDeclarationStatement declExpression= fAst.newVariableDeclarationStatement(fragment); declExpression.setType(fAst.newPrimitiveType(PrimitiveType.INT)); declExpression.modifiers().add(fAst.newModifier(ModifierKeyword.FINAL_KEYWORD)); return declExpression; }
/** * @return a statement in form of <code>final int maxLen = 10;</code> */ protected VariableDeclarationStatement createMaxLenDeclaration() { VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment(); fragment.setName(fAst.newSimpleName(fMaxLenVariableName)); fragment.setInitializer(fAst.newNumberLiteral(String.valueOf(fContext.getLimitItemsValue()))); VariableDeclarationStatement declExpression= fAst.newVariableDeclarationStatement(fragment); declExpression.setType(fAst.newPrimitiveType(PrimitiveType.INT)); declExpression.modifiers().add(fAst.newModifier(ModifierKeyword.FINAL_KEYWORD)); return declExpression; }
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) { VariableDeclaration original = ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration()); VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment(); fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName())); fragment.setInitializer(intilizer); VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment); result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original))); result.setType(ASTNodeFactory.newType(fAST, original, fImportRewriter, new ContextSensitiveImportRewriteContext(original, fImportRewriter))); return result; }
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) { VariableDeclaration original= ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration()); VariableDeclarationFragment fragment= fAST.newVariableDeclarationFragment(); fragment.setName((SimpleName)ASTNode.copySubtree(fAST, original.getName())); fragment.setInitializer(intilizer); VariableDeclarationStatement result= fAST.newVariableDeclarationStatement(fragment); result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original))); result.setType(ASTNodeFactory.newType(fAST, original)); return result; }
ASTNode clone0(AST target) { VariableDeclarationStatement result = new VariableDeclarationStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.setModifiers(getModifiers()); } if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); } result.setType((Type) getType().clone(target)); result.fragments().addAll( ASTNode.copySubtrees(target, fragments())); return result; }
ASTNode clone0(AST target) { VariableDeclarationStatement result = new VariableDeclarationStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.setModifiers(getModifiers()); } if (this.ast.apiLevel >= AST.JLS3) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); } result.setType((Type) getType().clone(target)); result.fragments().addAll( ASTNode.copySubtrees(target, fragments())); return result; }
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) { VariableDeclaration original= ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration()); VariableDeclarationFragment fragment= fAST.newVariableDeclarationFragment(); fragment.setName((SimpleName)ASTNode.copySubtree(fAST, original.getName())); fragment.setInitializer(intilizer); VariableDeclarationStatement result= fAST.newVariableDeclarationStatement(fragment); result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original))); result.setType(ASTNodeFactory.newType(fAST, original, fImportRewriter, new ContextSensitiveImportRewriteContext(original, fImportRewriter))); return result; }
ASTNode clone0(AST target) { VariableDeclarationStatement result = new VariableDeclarationStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.setModifiers(getModifiers()); } if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); } result.setType((Type) getType().clone(target)); result.fragments().addAll( ASTNode.copySubtrees(target, fragments())); return result; }
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) { VariableDeclaration original= ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration()); VariableDeclarationFragment fragment= fAST.newVariableDeclarationFragment(); fragment.setName((SimpleName)ASTNode.copySubtree(fAST, original.getName())); fragment.setInitializer(intilizer); VariableDeclarationStatement result= fAST.newVariableDeclarationStatement(fragment); result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original))); result.setType(ASTNodeFactory.newType(fAST, original, fImportRewriter, new ContextSensitiveImportRewriteContext(original, fImportRewriter))); return result; }
ASTNode clone0(AST target) { VariableDeclarationStatement result = new VariableDeclarationStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.setModifiers(getModifiers()); } if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); } result.setType((Type) getType().clone(target)); result.fragments().addAll( ASTNode.copySubtrees(target, fragments())); return result; }
@Override protected void initialize() { super.initialize(); fBuilderVariableName= createNameSuggestion(getContext().is50orHigher() ? "builder" : "buffer", NamingConventions.VK_LOCAL); //$NON-NLS-1$ //$NON-NLS-2$ fBuffer= new StringBuffer(); VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment(); fragment.setName(fAst.newSimpleName(fBuilderVariableName)); ClassInstanceCreation classInstance= fAst.newClassInstanceCreation(); Name typeName= addImport(getContext().is50orHigher() ? "java.lang.StringBuilder" : "java.lang.StringBuffer"); //$NON-NLS-1$ //$NON-NLS-2$ classInstance.setType(fAst.newSimpleType(typeName)); fragment.setInitializer(classInstance); VariableDeclarationStatement vStatement= fAst.newVariableDeclarationStatement(fragment); vStatement.setType(fAst.newSimpleType((Name)ASTNode.copySubtree(fAst, typeName))); toStringMethod.getBody().statements().add(vStatement); }
@Override protected void initialize() { super.initialize(); fBuilderVariableName= createNameSuggestion(getContext().is50orHigher() ? "builder" : "buffer", NamingConventions.VK_LOCAL); //$NON-NLS-1$ //$NON-NLS-2$ fBuffer= new StringBuffer(); VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment(); fragment.setName(fAst.newSimpleName(fBuilderVariableName)); ClassInstanceCreation classInstance= fAst.newClassInstanceCreation(); Name typeName= addImport(getContext().is50orHigher() ? "java.lang.StringBuilder" : "java.lang.StringBuffer"); //$NON-NLS-1$ //$NON-NLS-2$ classInstance.setType(fAst.newSimpleType(typeName)); fragment.setInitializer(classInstance); VariableDeclarationStatement vStatement= fAst.newVariableDeclarationStatement(fragment); vStatement.setType(fAst.newSimpleType((Name)ASTNode.copySubtree(fAst, typeName))); toStringMethod.getBody().statements().add(vStatement); }