use of com.intellij.conversion.ConversionProcessor in project android by JetBrains.
the class AndroidJUnitConfigurationConverter method createRunConfigurationsConverter.
@NotNull
@Override
public ConversionProcessor<RunManagerSettings> createRunConfigurationsConverter() {
return new ConversionProcessor<RunManagerSettings>() {
@Override
public boolean isConversionNeeded(RunManagerSettings settings) {
return IdeInfo.getInstance().isAndroidStudio() && !getConfigurationsToConvert(settings).isEmpty();
}
@Override
public void process(RunManagerSettings settings) throws CannotConvertException {
// Converts the factory identifications from JUnitConfigurationType to AndroidJUnitConfigurationType
for (Element element : getConfigurationsToConvert(settings)) {
element.setAttribute(CONFIGURATION_TYPE_ATTRIBUTE, ANDROID_JUNIT_CONFIGURATION_TYPE);
element.setAttribute(FACTORY_NAME_ATTRIBUTE, ANDROID_JUNIT_CONFIGURATION_FACTORY_NAME);
}
}
@NotNull
private Collection<Element> getConfigurationsToConvert(RunManagerSettings settings) {
Collection<? extends Element> configurationElements = settings.getRunConfigurations();
Collection<Element> toConvert = new HashSet<>();
// Searches for RunConfiguration persistent elements of type JUnit and adds them to the ones to be converted
for (Element element : configurationElements) {
String typeName = element.getAttributeValue(CONFIGURATION_TYPE_ATTRIBUTE);
String factoryName = element.getAttributeValue(FACTORY_NAME_ATTRIBUTE);
Boolean isTemplate = Boolean.valueOf(element.getAttributeValue(TEMPLATE_FLAG_ATTRIBUTE)).booleanValue();
if (!isTemplate && typeName.equals(JUNIT_CONFIGURATION_TYPE) && factoryName.equals(JUNIT_CONFIGURATION_FACTORY_NAME)) {
toConvert.add(element);
}
}
return toConvert;
}
};
}
Aggregations