1 12 package org.eclipse.jdt.ui; 13 14 import org.eclipse.core.runtime.CoreException; 15 16 import org.eclipse.jdt.core.ICompilationUnit; 17 import org.eclipse.jdt.core.IMethod; 18 import org.eclipse.jdt.core.dom.IMethodBinding; 19 import org.eclipse.jdt.core.dom.MethodDeclaration; 20 21 import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility; 22 import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType; 23 24 29 public class CodeGeneration { 30 31 32 37 public static final String CLASS_BODY_TEMPLATE_ID= CodeTemplateContextType.CLASSBODY_ID; 38 39 44 public static final String INTERFACE_BODY_TEMPLATE_ID= CodeTemplateContextType.INTERFACEBODY_ID; 45 46 51 public static final String ENUM_BODY_TEMPLATE_ID= CodeTemplateContextType.ENUMBODY_ID; 52 53 58 public static final String ANNOTATION_BODY_TEMPLATE_ID= CodeTemplateContextType.ANNOTATIONBODY_ID; 59 60 private static final String [] EMPTY= new String [0]; 61 62 private CodeGeneration() { 63 } 64 65 75 public static String getCompilationUnitContent(ICompilationUnit cu, String typeComment, String typeContent, String lineDelimiter) throws CoreException { 76 return getCompilationUnitContent(cu, getFileComment(cu, lineDelimiter), typeComment, typeContent, lineDelimiter); 77 } 78 79 92 public static String getCompilationUnitContent(ICompilationUnit cu, String fileComment, String typeComment, String typeContent, String lineDelimiter) throws CoreException { 93 return StubUtility.getCompilationUnitContent(cu, fileComment, typeComment, typeContent, lineDelimiter); 94 } 95 96 104 public static String getFileComment(ICompilationUnit cu, String lineDelimiter) throws CoreException { 105 return StubUtility.getFileComment(cu, lineDelimiter); 106 } 107 108 117 public static String getTypeComment(ICompilationUnit cu, String typeQualifiedName, String lineDelimiter) throws CoreException { 118 return StubUtility.getTypeComment(cu, typeQualifiedName, EMPTY, lineDelimiter); 119 } 120 121 132 public static String getTypeComment(ICompilationUnit cu, String typeQualifiedName, String [] typeParameterNames, String lineDelimiter) throws CoreException { 133 return StubUtility.getTypeComment(cu, typeQualifiedName, typeParameterNames, lineDelimiter); 134 } 135 136 147 public static String getTypeBody(String typeKind, ICompilationUnit cu, String typeName, String lineDelim) throws CoreException { 148 return StubUtility.getTypeBody(typeKind, cu, typeName, lineDelim); 149 } 150 151 161 public static String getFieldComment(ICompilationUnit cu, String typeName, String fieldName, String lineDelimiter) throws CoreException { 162 return StubUtility.getFieldComment(cu, typeName, fieldName, lineDelimiter); 163 } 164 165 181 public static String getMethodComment(ICompilationUnit cu, String declaringTypeName, MethodDeclaration decl, IMethodBinding overridden, String lineDelimiter) throws CoreException { 182 if (overridden != null) { 183 overridden= overridden.getMethodDeclaration(); 184 String declaringClassQualifiedName= overridden.getDeclaringClass().getQualifiedName(); 185 String linkToMethodName= overridden.getName(); 186 String [] parameterTypesQualifiedNames= StubUtility.getParameterTypeNamesForSeeTag(overridden); 187 return StubUtility.getMethodComment(cu, declaringTypeName, decl, overridden.isDeprecated(), linkToMethodName, declaringClassQualifiedName, parameterTypesQualifiedNames, false, lineDelimiter); 188 } else { 189 return StubUtility.getMethodComment(cu, declaringTypeName, decl, false, null, null, null, false, lineDelimiter); 190 } 191 } 192 193 215 public static String getMethodComment(ICompilationUnit cu, String declaringTypeName, String methodName, String [] paramNames, String [] excTypeSig, String retTypeSig, IMethod overridden, String lineDelimiter) throws CoreException { 216 return StubUtility.getMethodComment(cu, declaringTypeName, methodName, paramNames, excTypeSig, retTypeSig, EMPTY, overridden, false, lineDelimiter); 217 } 218 219 243 public static String getMethodComment(ICompilationUnit cu, String declaringTypeName, String methodName, String [] paramNames, String [] excTypeSig, String retTypeSig, String [] typeParameterNames, IMethod overridden, String lineDelimiter) throws CoreException { 244 return StubUtility.getMethodComment(cu, declaringTypeName, methodName, paramNames, excTypeSig, retTypeSig, typeParameterNames, overridden, false, lineDelimiter); 245 } 246 247 260 public static String getMethodComment(IMethod method, IMethod overridden, String lineDelimiter) throws CoreException { 261 String retType= method.isConstructor() ? null : method.getReturnType(); 262 String [] paramNames= method.getParameterNames(); 263 String [] typeParameterNames= StubUtility.getTypeParameterNames(method.getTypeParameters()); 264 265 return StubUtility.getMethodComment(method.getCompilationUnit(), method.getDeclaringType().getElementName(), 266 method.getElementName(), paramNames, method.getExceptionTypes(), retType, typeParameterNames, overridden, false, lineDelimiter); 267 } 268 269 293 294 public static String getMethodComment(ICompilationUnit cu, String declaringTypeName, MethodDeclaration decl, boolean isDeprecated, String overriddenMethodName, String overriddenMethodDeclaringTypeName, String [] overriddenMethodParameterTypeNames, String lineDelimiter) throws CoreException { 295 return StubUtility.getMethodComment(cu, declaringTypeName, decl, isDeprecated, overriddenMethodName, overriddenMethodDeclaringTypeName, overriddenMethodParameterTypeNames, false, lineDelimiter); 296 } 297 298 314 public static String getMethodBodyContent(ICompilationUnit cu, String declaringTypeName, String methodName, boolean isConstructor, String bodyStatement, String lineDelimiter) throws CoreException { 315 return StubUtility.getMethodBodyContent(isConstructor, cu.getJavaProject(), declaringTypeName, methodName, bodyStatement, lineDelimiter); 316 } 317 318 334 public static String getGetterMethodBodyContent(ICompilationUnit cu, String declaringTypeName, String methodName, String fieldName, String lineDelimiter) throws CoreException { 335 return StubUtility.getGetterMethodBodyContent(cu.getJavaProject(), declaringTypeName, methodName, fieldName, lineDelimiter); 336 } 337 338 355 public static String getSetterMethodBodyContent(ICompilationUnit cu, String declaringTypeName, String methodName, String fieldName, String paramName, String lineDelimiter) throws CoreException { 356 return StubUtility.getSetterMethodBodyContent(cu.getJavaProject(), declaringTypeName, methodName, fieldName, paramName, lineDelimiter); 357 } 358 359 377 public static String getGetterComment(ICompilationUnit cu, String declaringTypeName, String methodName, String fieldName, String fieldType, String bareFieldName, String lineDelimiter) throws CoreException { 378 return StubUtility.getGetterComment(cu, declaringTypeName, methodName, fieldName, fieldType, bareFieldName, lineDelimiter); 379 } 380 381 400 public static String getSetterComment(ICompilationUnit cu, String declaringTypeName, String methodName, String fieldName, String fieldType, String paramName, String bareFieldName, String lineDelimiter) throws CoreException { 401 return StubUtility.getSetterComment(cu, declaringTypeName, methodName, fieldName, fieldType, paramName, bareFieldName, lineDelimiter); 402 } 403 } 404 | Popular Tags |