use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class I18nConverter method getAllPossibleValues.
public boolean getAllPossibleValues(final List<Completion> completions, final Class<?> requiredType, final String existingData, final String optionContext, final MethodTarget target) {
for (final I18n i18n : i18nSupport.getSupportedLanguages()) {
final Locale locale = i18n.getLocale();
final StringBuilder localeString = new StringBuilder(locale.getLanguage());
if (locale.getCountry() == null || locale.getCountry().length() > 0) {
localeString.append("_").append(locale.getCountry().toUpperCase());
}
completions.add(new Completion(localeString.toString()));
}
return true;
}
use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class JLineCompletorAdapter method complete.
@SuppressWarnings("all")
public int complete(final String buffer, final int cursor, final List candidates) {
int result;
try {
JLineLogHandler.cancelRedrawProhibition();
final List<Completion> completions = new ArrayList<Completion>();
result = parser.completeAdvanced(buffer, cursor, completions);
for (final Completion completion : completions) {
candidates.add(new jline.Completion(completion.getValue(), completion.getFormattedValue(), completion.getHeading()));
}
} finally {
JLineLogHandler.prohibitRedraw();
}
return result;
}
use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class JavaTypeConverter method addCompletionsForTypesInTargetModule.
private void addCompletionsForTypesInTargetModule(final List<Completion> completions, final String optionContext, final Pom targetModule, final String heading, final String prefix, final String formattedPrefix, final String topLevelPackage, final String basePackage) {
final Collection<JavaType> typesInModule = getTypesForModule(optionContext, targetModule);
completions.add(new Completion(prefix + topLevelPackage, formattedPrefix + topLevelPackage, heading, 1));
for (final JavaType javaType : typesInModule) {
String type = javaType.getFullyQualifiedTypeName();
if (type.startsWith(basePackage)) {
type = StringUtils.replace(type, topLevelPackage, TOP_LEVEL_PACKAGE_SYMBOL, 1);
completions.add(new Completion(prefix + type, formattedPrefix + type, heading, 1));
}
}
}
use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class JavaPackageConverterTest method testGetAllPossibleValuesWhenProjectIsAvailable.
@Test
public void testGetAllPossibleValuesWhenProjectIsAvailable() {
// Set up
final Pom mockPom1 = setUpMockPom("/path/to/pom/1", new JavaType("com.example.domain.Choice"), new JavaType("com.example.domain.Vote"));
final Pom mockPom2 = setUpMockPom("/path/to/pom/2", new JavaType("com.example.web.ChoiceController"), new JavaType("com.example.web.VoteController"));
when(mockProjectOperations.getPoms()).thenReturn(Arrays.asList(mockPom1, mockPom2));
// Invoke and check
assertGetAllPossibleValues(true, new Completion("com.example"), new Completion("com.example.domain"), new Completion("com.example.web"));
}
use of org.springframework.roo.shell.Completion in project spring-roo by spring-projects.
the class JavaPackageConverterTest method assertGetAllPossibleValues.
/**
* Asserts that when the converter is asked for possible completions, the
* expected completions are provided.
*
* @param projectAvailable
* @param expectedAllComplete
* @param expectedCompletions
*/
private void assertGetAllPossibleValues(final boolean projectAvailable, final Completion... expectedCompletions) {
// Set up
when(mockProjectOperations.isFocusedProjectAvailable()).thenReturn(projectAvailable);
final List<Completion> completions = new ArrayList<Completion>();
final Pom mockPom1 = setUpMockPom("/path/to/pom/1", new JavaType("com.example.domain.Choice"), new JavaType("com.example.web.ChoiceController"));
when(mockProjectOperations.getFocusedModule()).thenReturn(mockPom1);
when(mockTypeLocationService.getTopLevelPackageForModule(mockPom1)).thenReturn(TOP_LEVEL_PACKAGE);
// Invoke
final boolean allComplete = converter.getAllPossibleValues(completions, JavaPackage.class, null, null, null);
// Check
assertEquals(false, allComplete);
assertEquals(Arrays.asList(expectedCompletions), completions);
}
Aggregations