Search in sources :

Example 1 with Completion

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;
}
Also used : Locale(java.util.Locale) Completion(org.springframework.roo.shell.Completion)

Example 2 with Completion

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;
}
Also used : Completion(org.springframework.roo.shell.Completion) ArrayList(java.util.ArrayList)

Example 3 with Completion

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));
        }
    }
}
Also used : JavaType(org.springframework.roo.model.JavaType) Completion(org.springframework.roo.shell.Completion)

Example 4 with Completion

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"));
}
Also used : JavaType(org.springframework.roo.model.JavaType) Completion(org.springframework.roo.shell.Completion) Pom(org.springframework.roo.project.maven.Pom) Test(org.junit.Test)

Example 5 with Completion

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);
}
Also used : JavaType(org.springframework.roo.model.JavaType) Completion(org.springframework.roo.shell.Completion) ArrayList(java.util.ArrayList) Pom(org.springframework.roo.project.maven.Pom)

Aggregations

Completion (org.springframework.roo.shell.Completion)16 JavaType (org.springframework.roo.model.JavaType)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Pom (org.springframework.roo.project.maven.Pom)4 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 Repository (org.apache.felix.bundlerepository.Repository)1 Resource (org.apache.felix.bundlerepository.Resource)1