if (streamAppDefinition.getName().startsWith(appName) && !applicationType.equals(ApplicationType.sink)) { collector.add(proposals.withSuffix(streamAppDefinition.getName())); for (StreamDefinition stream : streamDefinitionRepository.findAll()) { if (stream.getName().startsWith(streamName)) { collector.add(proposals.withSuffix(stream.getName()));
void addPropertiesProposals(String text, String startsWith, AppRegistration appRegistration, Set<String> alreadyPresentOptions, List<CompletionProposal> collector, int detailLevel){ Resource metadataResource = appRegistry.getAppMetadataResource(appRegistration); // For whitelisted properties, use their simple name if (metadataResource != null) { CompletionProposal.Factory proposals = CompletionProposal.expanding(text); for (ConfigurationMetadataProperty property : metadataResolver.listProperties(metadataResource)) { String name = property.getName(); if (!alreadyPresentOptions.contains(name) && name.startsWith(startsWith)) { collector.add(proposals .withSeparateTokens("--" + property.getName() + "=", property.getShortDescription())); } } // For other properties (including WL'ed in full form), use their id if (detailLevel > 1) { for (ConfigurationMetadataProperty property : metadataResolver.listProperties(metadataResource, true)) { String id = property.getId(); if (!alreadyPresentOptions.contains(id) && id.startsWith(startsWith)) { collector.add(proposals .withSeparateTokens("--" + property.getId() + "=", property.getShortDescription())); } } } } }
String candidate = String.valueOf(valueHint.getValue()); if (!candidate.equals(alreadyTyped) && candidate.startsWith(alreadyTyped)) { collector.add(proposals.withSuffix(candidate.substring(alreadyTyped.length()), valueHint.getShortDescription()));
if (streamAppDefinition.getName().startsWith(appName) && !applicationType.equals(ApplicationType.sink)) { collector.add(proposals.withSuffix(streamAppDefinition.getName())); for (StreamDefinition stream : streamDefinitionRepository.findAll()) { if (stream.getName().startsWith(streamName)) { collector.add(proposals.withSuffix(stream.getName()));
for (ModuleDefinition moduleDefinition : streamDefinition.getModuleDefinitions()) { if (moduleDefinition.getLabel().startsWith(moduleName)) { collector.add(proposals.withSuffix(moduleDefinition.getLabel())); for (StreamDefinition stream : streamDefinitionRepository.findAll()) { if (stream.getName().startsWith(streamName)) { collector.add(proposals.withSuffix(stream.getName()));
String expansion = CompletionUtils.maybeQualifyWithLabel(appRegistration.getName(), streamDefinition); collector.add(proposals.withSuffix(expansion.substring(alreadyTyped.length())));
@Override public boolean addProposals(String text, StreamDefinition parseResult, int detailLevel, List<CompletionProposal> collector) { if (text.isEmpty() || !text.endsWith(" ")) { return false; } StreamAppDefinition lastApp = parseResult.getDeploymentOrderIterator().next(); // Consider "bar | foo". If there is indeed a sink named foo in the registry, // "foo" may also be a processor, in which case we can continue boolean couldBeASink = appRegistry.find(lastApp.getName(), ApplicationType.sink) != null; if (couldBeASink) { boolean couldBeAProcessor = appRegistry.find(lastApp.getName(), ApplicationType.processor) != null; if (!couldBeAProcessor) { return false; } } CompletionProposal.Factory proposals = CompletionProposal.expanding(text); for (AppRegistration appRegistration : appRegistry.findAll()) { if (appRegistration.getType() == ApplicationType.processor || appRegistration.getType() == ApplicationType.sink) { String expansion = CompletionUtils.maybeQualifyWithLabel(appRegistration.getName(), parseResult); collector.add(proposals.withSeparateTokens("| " + expansion, "Continue stream definition with a " + appRegistration.getType())); } } return false; } }
void addValueHintsProposals(final String dsl, AppRegistration appRegistration, final List<CompletionProposal> collector, final String propertyName, final ValueHintProvider[] valueHintProviders){ final Resource metadataResource = this.appRegistry.getAppMetadataResource(appRegistration); if (metadataResource != null) { final URLClassLoader classLoader = metadataResolver.createAppClassLoader(metadataResource); this.doWithClassLoader(classLoader, () -> { CompletionProposal.Factory proposals = CompletionProposal.expanding(dsl); List<ConfigurationMetadataProperty> whiteList = metadataResolver.listProperties(metadataResource); for (ConfigurationMetadataProperty property : metadataResolver.listProperties(metadataResource, true)) { if (CompletionUtils.isMatchingProperty(propertyName, property, whiteList)) { for (ValueHintProvider valueHintProvider : valueHintProviders) { for (ValueHint valueHint : valueHintProvider.generateValueHints(property, classLoader)) { collector.add(proposals.withSuffix(String.valueOf(valueHint.getValue()), valueHint.getShortDescription())); } } } } return null; }); } }
@Override public boolean addProposals(String text, TaskDefinition taskDefinition, int detailLevel, List<CompletionProposal> collector) { Set<String> parameterNames = new HashSet<>(taskDefinition.getProperties().keySet()); parameterNames.removeAll(CompletionUtils.IMPLICIT_TASK_PARAMETER_NAMES); if (!parameterNames.isEmpty() || !text.endsWith(taskDefinition.getRegisteredAppName())) { return false; } // Actually add completions String alreadyTyped = taskDefinition.getRegisteredAppName(); CompletionProposal.Factory proposals = CompletionProposal.expanding(text); List<ApplicationType> validTypesAtThisPosition = Arrays.asList(ApplicationType.task); for (AppRegistration appRegistration : appRegistry.findAll()) { String candidateName = appRegistration.getName(); if (validTypesAtThisPosition.contains(appRegistration.getType()) && !alreadyTyped.equals(candidateName) && candidateName.startsWith(alreadyTyped)) { String expansion = appRegistration.getName(); collector.add(proposals.withSuffix(expansion.substring(alreadyTyped.length()))); } } return false; } }
@Override public void addProposals(String dsl, CheckPointedParseException exception, int detailLevel, List<CompletionProposal> collector) { StreamDefinition streamDefinition = new StreamDefinition("__dummy", exception.getExpressionStringUntilCheckpoint()); CompletionProposal.Factory proposals = CompletionProposal.expanding(dsl); // We only support full streams at the moment, so completions can only be // processor or sink for (AppRegistration appRegistration : appRegistry.findAll()) { if (appRegistration.getType() == ApplicationType.processor || appRegistration.getType() == ApplicationType.sink) { String expansion = CompletionUtils.maybeQualifyWithLabel(appRegistration.getName(), streamDefinition); collector.add(proposals.withSeparateTokens(expansion, "Continue stream definition with a " + appRegistration.getType())); } } } }
@Override public void addProposals(String dsl, CheckPointedParseException exception, int detailLevel, List<CompletionProposal> collector) { StreamDefinition streamDefinition = new StreamDefinition("__dummy", exception.getExpressionStringUntilCheckpoint()); CompletionProposal.Factory proposals = CompletionProposal.expanding(dsl); for (AppRegistration appRegistration : appRegistryService.findAll()) { if (appRegistration.getType() == ApplicationType.app) { String expansion = CompletionUtils.maybeQualifyWithLabel(appRegistration.getName(), streamDefinition); collector.add(proposals.withSeparateTokens(expansion, "Continue stream definition with a " + appRegistration.getType())); } } } }
public CompletionProposal withSuffix(String suffix) { return withSuffix(suffix, null); }
public static Factory expanding(String start) { return new Factory(start); }
@Override public void addProposals(String dsl, CheckPointedParseException exception, int detailLevel, List<CompletionProposal> proposals) { CompletionProposal.Factory completionFactory = CompletionProposal.expanding(dsl); for (AppRegistration app : this.registry.findAll()) { if (app.getType() == ApplicationType.task) { proposals.add(completionFactory.withSeparateTokens(app.getName(), "Choose a task app")); } } }
@Override public void addProposals(String dsl, IllegalArgumentException exception, int detailLevel, List<CompletionProposal> proposals) { CompletionProposal.Factory completionFactory = CompletionProposal.expanding(dsl); for (AppRegistration app : this.registry.findAll()) { if (app.getType() == ApplicationType.source || app.getType() == ApplicationType.app) { proposals.add(completionFactory.withSeparateTokens(app.getName(), "Start with a source app or an unbounded streaming app")); } } }
@Override public void addProposals(String dsl, CheckPointedParseException exception, int detailLevel, List<CompletionProposal> proposals) { CompletionProposal.Factory completionFactory = CompletionProposal.expanding(dsl); for (AppRegistration appRegistration : appRegistry.findAll()) { if (appRegistration.getType() == ApplicationType.processor || appRegistration.getType() == ApplicationType.sink) { proposals.add(completionFactory.withSeparateTokens(appRegistration.getName(), "Wire destination into a " + appRegistration.getType() + " app")); } } }
/** * Add a suffix as a new token, that is, make sure there is a space before it. * <p> * A space is not appended if this is the very first token. * * @param suffix the suffix to add * @return a new completion proposal */ public CompletionProposal withSeparateTokens(String suffix) { return withSeparateTokens(suffix, null); } }