use of org.eclipse.jdt.ls.core.internal.corext.template.java.CodeTemplateContext in project eclipse.jdt.ls by eclipse.
the class StubUtility method getCatchBodyContent.
public static String getCatchBodyContent(ICompilationUnit cu, String exceptionType, String variableName, String enclosingType, String enclosingMethod, String lineDelimiter) throws CoreException {
// Template template = getCodeTemplate(CodeTemplateContextType.CATCHBLOCK_ID, cu.getJavaProject());
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.CATCHBODY;
Template template = templateSetting.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, enclosingType);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, enclosingMethod);
context.setVariable(CodeTemplateContextType.EXCEPTION_TYPE, exceptionType);
context.setVariable(CodeTemplateContextType.EXCEPTION_VAR, variableName);
return evaluateTemplate(context, template);
}
use of org.eclipse.jdt.ls.core.internal.corext.template.java.CodeTemplateContext in project eclipse.jdt.ls by eclipse.
the class StubUtility method getSetterMethodBodyContent.
/*
* Don't use this method directly, use CodeGeneration.
*/
public static String getSetterMethodBodyContent(IJavaProject project, String destTypeName, String methodName, String fieldName, String paramName, String lineDelimiter) throws CoreException {
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.SETTERBOY;
Template template = templateSetting.createTemplate(project);
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldName);
context.setVariable(CodeTemplateContextType.PARAM, paramName);
return evaluateTemplate(context, template);
}
use of org.eclipse.jdt.ls.core.internal.corext.template.java.CodeTemplateContext in project eclipse.jdt.ls by eclipse.
the class StubUtility method getFieldComment.
//
// // remove lines for empty variables
// private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables) throws MalformedTreeException, BadLocationException {
// IDocument doc= new Document(buffer.getString());
// int nLines= doc.getNumberOfLines();
// MultiTextEdit edit= new MultiTextEdit();
// HashSet<Integer> removedLines= new HashSet<>();
// for (int i= 0; i < variables.length; i++) {
// TemplateVariable position= findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
// if (position == null || position.getLength() > 0) {
// continue;
// }
// int[] offsets= position.getOffsets();
// for (int k= 0; k < offsets.length; k++) {
// int line= doc.getLineOfOffset(offsets[k]);
// IRegion lineInfo= doc.getLineInformation(line);
// int offset= lineInfo.getOffset();
// String str= doc.get(offset, lineInfo.getLength());
// if (Strings.containsOnlyWhitespaces(str) && nLines > line + 1 && removedLines.add(new Integer(line))) {
// int nextStart= doc.getLineOffset(line + 1);
// edit.addChild(new DeleteEdit(offset, nextStart - offset));
// }
// }
// }
// edit.apply(doc, 0);
// return doc.get();
// }
//
/*
* Don't use this method directly, use CodeGeneration.
*/
public static String getFieldComment(ICompilationUnit cu, String typeName, String fieldName, String lineDelimiter) throws CoreException {
Template template = CodeGenerationTemplate.FIELDCOMMENT.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, typeName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
return evaluateTemplate(context, template);
}
use of org.eclipse.jdt.ls.core.internal.corext.template.java.CodeTemplateContext in project eclipse.jdt.ls by eclipse.
the class StubUtility method getSetterComment.
/*
* Don't use this method directly, use CodeGeneration.
* @see org.eclipse.jdt.ui.CodeGeneration#getSetterComment(ICompilationUnit, String, String, String, String, String, String, String)
*/
public static String getSetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String paramName, String bareFieldName, String lineDelimiter) throws CoreException {
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.SETTERCOMMENT;
Template template = templateSetting.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, typeName);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldType);
context.setVariable(CodeTemplateContextType.BARE_FIELD_NAME, bareFieldName);
context.setVariable(CodeTemplateContextType.PARAM, paramName);
return evaluateTemplate(context, template);
}
use of org.eclipse.jdt.ls.core.internal.corext.template.java.CodeTemplateContext in project eclipse.jdt.ls by eclipse.
the class StubUtility method getGetterMethodBodyContent.
//
// private static final Set<String> VALID_TYPE_BODY_TEMPLATES;
// static {
// VALID_TYPE_BODY_TEMPLATES= new HashSet<>();
// VALID_TYPE_BODY_TEMPLATES.add(CodeTemplateContextType.CLASSBODY_ID);
// VALID_TYPE_BODY_TEMPLATES.add(CodeTemplateContextType.INTERFACEBODY_ID);
// VALID_TYPE_BODY_TEMPLATES.add(CodeTemplateContextType.ENUMBODY_ID);
// VALID_TYPE_BODY_TEMPLATES.add(CodeTemplateContextType.ANNOTATIONBODY_ID);
// }
//
// /*
// * Don't use this method directly, use CodeGeneration.
// */
// public static String getMethodBodyContent(boolean isConstructor, IJavaProject project, String destTypeName, String methodName, String bodyStatement, String lineDelimiter) throws CoreException {
// String templateName= isConstructor ? CodeTemplateContextType.CONSTRUCTORSTUB_ID : CodeTemplateContextType.METHODSTUB_ID;
// Template template= getCodeTemplate(templateName, project);
// if (template == null) {
// return bodyStatement;
// }
// CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
// context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
// context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
// context.setVariable(CodeTemplateContextType.BODY_STATEMENT, bodyStatement);
// String str= evaluateTemplate(context, template, new String[] { CodeTemplateContextType.BODY_STATEMENT });
// if (str == null && !Strings.containsOnlyWhitespaces(bodyStatement)) {
// return bodyStatement;
// }
// return str;
// }
/*
* Don't use this method directly, use CodeGeneration.
*/
public static String getGetterMethodBodyContent(IJavaProject project, String destTypeName, String methodName, String fieldName, String lineDelimiter) throws CoreException {
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.GETTERBODY;
Template template = templateSetting.createTemplate(project);
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
return evaluateTemplate(context, template);
}
Aggregations