final String lineDelim= StubUtility.getLineDelimiterUsed(project); if (StubUtility.doAddComments(project)) { typeComment= CodeGeneration.getTypeComment(newCu, fAccessorClassName, lineDelim); fileComment= CodeGeneration.getFileComment(newCu, lineDelim); String cuContent= CodeGeneration.getCompilationUnitContent(newCu, fileComment, typeComment, classContent, lineDelim); if (cuContent == null) { StringBuffer buf= new StringBuffer();
protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException { boolean doMain= isCreateMain(); boolean doConstr= isCreateConstructors(); boolean doInherited= isCreateInherited(); createInheritedMethods(type, doConstr, doInherited, imports, new SubProgressMonitor(monitor, 1)); if (doMain) { StringBuffer buf= new StringBuffer(); final String lineDelim= "\n"; // OK, since content is formatted afterwards //$NON-NLS-1$ String comment= CodeGeneration.getMethodComment(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", new String[] {"args"}, new String[0], Signature.createTypeSignature("void", true), null, lineDelim); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (comment != null) { buf.append(comment); buf.append(lineDelim); } buf.append("public static void main("); //$NON-NLS-1$ buf.append(imports.addImport("java.lang.String")); //$NON-NLS-1$ buf.append("[] args) {"); //$NON-NLS-1$ buf.append(lineDelim); final String content= CodeGeneration.getMethodBodyContent(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", false, "", lineDelim); //$NON-NLS-1$ //$NON-NLS-2$ if (content != null && content.length() != 0) buf.append(content); buf.append(lineDelim); buf.append("}"); //$NON-NLS-1$ type.createMethod(buf.toString(), null, false, null); } if (monitor != null) { monitor.done(); } }
String typeBody= CodeGeneration.getTypeBody(templateID, parentCU, getTypeName(), lineDelimiter); if (typeBody != null) { buf.append(typeBody);
/** * Returns the content for a new compilation unit using the 'new Java file' code template. * @param cu The compilation unit to create the source for. The compilation unit does not need to exist. * @param typeComment The comment for the type to be created. Used when the code template contains a <i>${typecomment}</i> variable. Can be <code>null</code> if * no comment should be added. * @param typeContent The code of the type, including type declaration and body. * @param lineDelimiter The line delimiter to be used. * @return Returns the new content or <code>null</code> if the template is undefined or empty. * @throws CoreException Thrown when the evaluation of the code template fails. */ public static String getCompilationUnitContent(ICompilationUnit cu, String typeComment, String typeContent, String lineDelimiter) throws CoreException { return getCompilationUnitContent(cu, getFileComment(cu, lineDelimiter), typeComment, typeContent, lineDelimiter); }
private Javadoc getNewConstructorComment(ASTRewrite rewrite) throws CoreException { if (StubUtility.doAddComments(fCu.getJavaProject())){ String comment= CodeGeneration.getMethodComment(fCu, getEnclosingTypeName(), getEnclosingTypeName(), new String[0], new String[0], null, null, StubUtility.getLineDelimiterUsed(fCu)); if (comment != null && comment.length() > 0) { return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC); } } return null; }
for (int index= 0; index < parameters.length; index++) names[index]= parameters[index].getElementName(); typeComment= CodeGeneration.getTypeComment(copy, superName, names, delimiter); fileComment= CodeGeneration.getFileComment(copy, delimiter);
typeDecl.getName().setIdentifier(typeName); if (StubUtility.doAddComments(cu.getJavaProject())) { String typeComment= CodeGeneration.getTypeComment(cu, typeName, delim); if (typeComment != null) typeDecl.setJavadoc((Javadoc) rewrite.createStringPlaceholder(typeComment, ASTNode.JAVADOC)); String typeBody= CodeGeneration.getTypeBody(CodeGeneration.CLASS_BODY_TEMPLATE_ID, cu, typeName, delim); if (typeBody != null) { BodyDeclaration typeBodyNode= (BodyDeclaration) rewrite.createStringPlaceholder(typeBody, ASTNode.METHOD_DECLARATION); String qualifiedtypeName= fDestinationType != null ? fDestinationType.getFullyQualifiedName('.') : cu.getParent().getElementName() + '.' + typeName; if (StubUtility.doAddComments(cu.getJavaProject())) { String methodComment= CodeGeneration.getMethodComment(cu, qualifiedtypeName, methodDecl, null, delim); if (methodComment != null) methodDecl.setJavadoc((Javadoc) rewrite.createStringPlaceholder(methodComment, ASTNode.JAVADOC));
String string= CodeGeneration.getMethodComment(cu, binding.getName(), methodDecl, overridden, String.valueOf('\n')); if (string != null) { String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_method_description; typeParamNames= new String[0]; String string= CodeGeneration.getTypeComment(cu, typeQualifiedName, typeParamNames, String.valueOf('\n')); if (string != null) { String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_type_description; String fieldName= decl.getName().getIdentifier(); String typeName= binding.getName(); comment= CodeGeneration.getFieldComment(cu, typeName, fieldName, String.valueOf('\n')); EnumConstantDeclaration enumDecl= (EnumConstantDeclaration) declaration; String id= enumDecl.getName().getIdentifier(); String comment= CodeGeneration.getFieldComment(cu, binding.getName(), id, String.valueOf('\n')); String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_enumconst_description; proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_ENUM, declaration.getStartPosition(), comment));
private String createSourceForNewCu(final ICompilationUnit unit, final IProgressMonitor monitor) throws CoreException { Assert.isNotNull(unit); Assert.isNotNull(monitor); try { monitor.beginTask("", 2); //$NON-NLS-1$ final String separator= StubUtility.getLineDelimiterUsed(fType.getJavaProject()); final String block= getAlignedSourceBlock(unit, fNewSourceOfInputType); String content= CodeGeneration.getCompilationUnitContent(unit, null, block, separator); if (content == null || block.startsWith("/*") || block.startsWith("//")) { //$NON-NLS-1$//$NON-NLS-2$ final StringBuffer buffer= new StringBuffer(); if (!fType.getPackageFragment().isDefaultPackage()) { buffer.append("package ").append(fType.getPackageFragment().getElementName()).append(';'); //$NON-NLS-1$ } buffer.append(separator).append(separator); buffer.append(block); content= buffer.toString(); } unit.getBuffer().setContents(content); addImportsToTargetUnit(unit, new SubProgressMonitor(monitor, 1)); } finally { monitor.done(); } return unit.getSource(); }
private String getTypeComment(String lineDelimiterUsed) throws CoreException { ICompilationUnit cu= fCreatedPackageFragment.getCompilationUnit(PACKAGE_INFO_JAVA_FILENAME); String typeName= PACKAGE_INFO_JAVA_FILENAME.substring(0, PACKAGE_INFO_JAVA_FILENAME.length() - JavaModelUtil.DEFAULT_CU_SUFFIX.length()); return CodeGeneration.getTypeComment(cu, typeName, lineDelimiterUsed); }
StringBuffer buf= new StringBuffer(); if (addComments) { String comment= CodeGeneration.getGetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, field.getElementName(), typeName, accessorName, lineDelim); if (comment != null) { buf.append(comment); String body= CodeGeneration.getGetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, fieldName, lineDelim); if (body != null) { buf.append(body);
StringBuffer buf= new StringBuffer(); if (addComments) { String comment= CodeGeneration.getSetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, field.getElementName(), typeName, argname, accessorName, lineDelim); if (comment != null) { buf.append(comment); fieldName= "this." + fieldName; //$NON-NLS-1$ String body= CodeGeneration.getSetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, fieldName, argname, lineDelim); if (body != null) { buf.append(body);
protected String getFileComment(ICompilationUnit parentCU, String lineDelimiter) throws CoreException { if (fParameterObjectFactory.isCreateComments()) { return CodeGeneration.getFileComment(parentCU, lineDelimiter); } return null; }
private String createFieldComment(IField field, String lineDelimiter) throws JavaModelException, CoreException { String typeName= Signature.toString(field.getTypeSignature()); String fieldName= field.getElementName(); return CodeGeneration.getFieldComment(field.getCompilationUnit(), typeName, fieldName, lineDelimiter); }
@SuppressWarnings("unchecked") private void setReturnStatement(final MethodDeclaration stub, final IMethodBinding methodToOverride, final ITypeBinding declaringType, final AST ast, final ASTRewrite rewrite) throws JavaModelException, CoreException { Expression expression= ASTNodeFactory.newDefaultExpression(ast, stub.getReturnType2(), stub.getExtraDimensions()); if (expression != null) { ReturnStatement returnStatement= ast.newReturnStatement(); returnStatement.setExpression(expression); String delimiter= cunit.findRecommendedLineSeparator(); Map<String, String> options= fJavaProject.getOptions(true); String bodyStatement= ASTNodes.asFormattedString(returnStatement, 0, delimiter, options); String placeHolder= CodeGeneration.getMethodBodyContent(cunit, declaringType.getName(), methodToOverride.getName(), false, bodyStatement, delimiter); if (placeHolder != null) { ASTNode todoNode = rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT); stub.getBody().statements().clear(); stub.getBody().statements().add(todoNode); } } }
private MethodDeclaration createGetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException { FieldDeclaration field= (FieldDeclaration)ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class); Type type= field.getType(); MethodDeclaration result= ast.newMethodDeclaration(); result.setName(ast.newSimpleName(fGetterName)); result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers())); result.setReturnType2((Type)rewriter.createCopyTarget(type)); Block block= ast.newBlock(); result.setBody(block); ReturnStatement rs= ast.newReturnStatement(); rs.setExpression(ast.newSimpleName(fField.getElementName())); block.statements().add(rs); if (fGenerateJavadoc) { String string= CodeGeneration.getGetterComment( fField.getCompilationUnit() , getTypeName(field.getParent()), fGetterName, fField.getElementName(), ASTNodes.asString(type), NamingConventions.removePrefixAndSuffixForFieldName(fField.getJavaProject(), fField.getElementName(), fField.getFlags()), lineDelimiter); if (string != null) { Javadoc javadoc= (Javadoc)fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC); result.setJavadoc(javadoc); } } return result; }
String string= CodeGeneration.getSetterComment( fField.getCompilationUnit() , getTypeName(field.getParent()), fSetterName, fField.getElementName(), ASTNodes.asString(type), fArgName,
/** * Returns the content for a new compilation unit using the 'new Java file' code template. * @param cu The compilation unit to create the source for. The compilation unit does not need to exist. * @param typeComment The comment for the type to be created. Used when the code template contains a <i>${typecomment}</i> variable. Can be <code>null</code> if * no comment should be added. * @param typeContent The code of the type, including type declaration and body. * @param lineDelimiter The line delimiter to be used. * @return Returns the new content or <code>null</code> if the template is undefined or empty. * @throws CoreException Thrown when the evaluation of the code template fails. */ public static String getCompilationUnitContent(ICompilationUnit cu, String typeComment, String typeContent, String lineDelimiter) throws CoreException { return getCompilationUnitContent(cu, getFileComment(cu, lineDelimiter), typeComment, typeContent, lineDelimiter); }
private Javadoc getNewConstructorComment(ASTRewrite rewrite) throws CoreException { if (StubUtility.doAddComments(fCu.getJavaProject())){ String comment= CodeGeneration.getMethodComment(fCu, getEnclosingTypeName(), getEnclosingTypeName(), new String[0], new String[0], null, null, StubUtility.getLineDelimiterUsed(fCu)); if (comment != null && comment.length() > 0) { return (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC); } } return null; }
for (int index= 0; index < parameters.length; index++) names[index]= parameters[index].getElementName(); typeComment= CodeGeneration.getTypeComment(copy, superName, names, delimiter); fileComment= CodeGeneration.getFileComment(copy, delimiter);