Skip to content

Commit

Permalink
Add shortmonth variable to type comment templates
Browse files Browse the repository at this point in the history
- References redhat-developer/vscode-java#2052

Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Aug 20, 2021
1 parent 63713d5 commit c3f4999
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jdt.ls.core.internal.preferences;

import java.util.Calendar;
import java.util.Locale;

import org.eclipse.jface.text.templates.SimpleTemplateVariableResolver;
import org.eclipse.jface.text.templates.TemplateContext;
Expand Down Expand Up @@ -207,6 +208,17 @@ protected String resolve(TemplateContext context) {
}
}

public static class ShortMonth extends SimpleTemplateVariableResolver {
public ShortMonth() {
super("shortmonth", "Short form representation of current month"); //$NON-NLS-1$ //$NON-NLS-2$
}

@Override
protected String resolve(TemplateContext context) {
return Calendar.getInstance().getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
}
}

public static class Day extends SimpleTemplateVariableResolver {
public Day() {
super("day", "Current day of month"); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static void initialize() {
// These should be upstreamed into CodeTemplateContextType & GlobalVariables
TemplateContextType tmp = registry.getContextType(CodeTemplateContextType.TYPECOMMENT_CONTEXTTYPE);
tmp.addResolver(new CodeTemplatePreferences.Month());
tmp.addResolver(new CodeTemplatePreferences.ShortMonth());
tmp.addResolver(new CodeTemplatePreferences.Day());
tmp.addResolver(new CodeTemplatePreferences.Hour());
tmp.addResolver(new CodeTemplatePreferences.Minute());
Expand Down

0 comments on commit c3f4999

Please sign in to comment.