OK. I finally found a work around. JDT plugin does not offer an extension point for what I was trying to do. So I got the TemplateStore and modified it to suit my needs.
@Override
public void sessionStarted() {
filterTemplates();
}
private void filterTemplates() {
templateStore = getTemplateStore();
file = getFileThatsVisibleInTheEditor();
if (//file name is john.java) {
deleteTemplate(templateStore, "org.eclipse.jdt.ui.templates.sysout");
} else {
deleteTemplate(templateStore, "com.eclipse.jdt.ui.templates.sysout");
}
try {
templateStore.save();
} catch (IOException e) {
}
}
private void deleteTemplate(TemplateStore templateStore, String id) {
TemplatePersistenceData templateData = templateStore.getTemplateData(id);
if (templateData != null) {
templateStore.delete(templateData);
}
}
@Override
public void sessionEnded() {
getTemplateStore().restoreDeleted();
}
private TemplateStore getTemplateStore() {
if (templateStore == null) {
final ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry(JavaUI.ID_CU_EDITOR);
final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
templateStore = new ContributionTemplateStore(registry, store, "org.eclipse.jdt.ui.text.custom_templates");
try {
templateStore.load();
} catch (IOException e) {
}
templateStore.startListeningForPreferenceChanges();
}
return templateStore;
}
This whole this is written inside a class that extends IJavaCompletionProposalComputer. So every time you press Ctrl+Space, this code will be executed and your flavor of template will get executed.
In the above code, I have replaced the normal java sysout with the one that my plugin contributes based on the condition, so that at any point in time only one version of the 'sysout' is shown in the proposal. This is a hack, but I got my things done.