public PostfixLiveTemplate() { for (PostfixTemplate template : PostfixTemplate.EP_NAME.getExtensions()) { register(template.getKey(), template); Aliases aliases = template.getClass().getAnnotation(Aliases.class); if (aliases != null) { for (String key : aliases.value()) { register(key, template); } } } }
@NotNull @Override public Collection<? extends CustomLiveTemplateLookupElement> getLookupElements( @NotNull PsiFile file, @NotNull Editor editor, int offset) { String key = computeTemplateKeyWithoutContextChecking(editor.getDocument().getCharsSequence(), offset); if (key != null) { Map<String, CustomLiveTemplateLookupElement> result = ContainerUtil.newHashMap(); Condition<PostfixTemplate> isApplicationTemplateFunction = createIsApplicationTemplateFunction(key, file, editor); for (Map.Entry<String, PostfixTemplate> entry : myTemplates.entrySet()) { PostfixTemplate postfixTemplate = entry.getValue(); if (entry.getKey().startsWith(key) && isApplicationTemplateFunction.value(postfixTemplate)) { result.put( postfixTemplate.getKey(), new PostfixTemplateLookupElement( this, postfixTemplate, postfixTemplate.getKey(), false)); } } return result.values(); } return super.getLookupElements(file, editor, offset); }
private void register(@NotNull String key, @NotNull PostfixTemplate template) { PostfixTemplate registered = myTemplates.put(key, template); if (registered != null) { LOG.error("Can't register postfix template. Duplicated key: " + template.getKey()); } }