Refactoring of language injection

This commit is contained in:
Sergey Evdokimov
2013-01-03 23:40:39 +04:00
parent a0a81e3562
commit e97f74b19a
3 changed files with 28 additions and 22 deletions
@@ -43,7 +43,7 @@ public final class MavenPluginConfigurationLanguageInjector implements LanguageI
public boolean process(MavenPluginParamInfo.ParamInfo info, MavenDomConfiguration configuration) {
Language language = info.getLanguage();
if (language != null) {
injectionPlacesRegistrar.addPlace(language, TextRange.from(0, host.getTextLength()), null, null);
injectionPlacesRegistrar.addPlace(language, TextRange.from(0, host.getTextLength()), info.getLanguageInjectionPrefix(), info.getLanguageInjectionSuffix());
return false;
}
return true;
@@ -71,6 +71,12 @@ public class MavenPluginDescriptor extends AbstractExtensionPointBean {
*/
@Attribute("language")
public String language;
@Attribute("languageInjectionPrefix")
public String languageInjectionPrefix;
@Attribute("languageInjectionSuffix")
public String languageInjectionSuffix;
}
public static Pair<String, String> parsePluginId(String mavenId) {
@@ -168,50 +168,50 @@ public class MavenPluginParamInfo {
public static class ParamInfo {
private final ClassLoader myClassLoader;
private final String myProviderClass;
private final MavenPluginDescriptor.Param myParam;
private volatile String myLanguageId;
private volatile boolean myLanguageInitialized;
private Language myLanguageInstance;
private volatile MavenParamReferenceProvider myProviderInstance;
private ParamInfo(ClassLoader classLoader, MavenPluginDescriptor.Param param) {
myClassLoader = classLoader;
myProviderClass = param.refProvider;
myLanguageId = param.language;
myParam = param;
}
public Language getLanguage() {
if (myLanguageInstance != null) {
return myLanguageInstance;
if (!myLanguageInitialized) {
if (myParam.language != null) {
myLanguageInstance = Language.findLanguageByID(myParam.language);
}
myLanguageInitialized = true;
}
String languageId = myLanguageId;
if (languageId == null) return null;
return myLanguageInstance;
}
Language l = Language.findLanguageByID(languageId);
if (l == null) { // May be plugin with language is disabled.
myLanguageId = null;
}
else {
myLanguageInstance = l;
}
public String getLanguageInjectionPrefix() {
return myParam.languageInjectionPrefix;
}
return l;
public String getLanguageInjectionSuffix() {
return myParam.languageInjectionSuffix;
}
public MavenParamReferenceProvider getProviderInstance() {
if (myProviderClass == null) {
return null;
}
MavenParamReferenceProvider res = myProviderInstance;
if (res == null) {
if (myParam.refProvider == null) {
return null;
}
Object instance;
try {
instance = myClassLoader.loadClass(myProviderClass).newInstance();
instance = myClassLoader.loadClass(myParam.refProvider).newInstance();
}
catch (Exception e) {
throw new RuntimeException("Failed to create reference provider instance", e);