use of com.avaloq.tools.ddk.check.check.Check in project dsl-devkit by dsldevkit.
the class CheckCfgTemplateProposalProvider method addConfiguredCheckTemplates.
/**
* Adds template proposals for all checks which may be referenced in current catalog configuration. Only proposals for checks
* which have not yet been configured are provided.
*
* @param templateContext
* the template context
* @param context
* the context
* @param acceptor
* the acceptor
*/
private void addConfiguredCheckTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
// NOPMD
ConfiguredCatalog configuredCatalog = EcoreUtil2.getContainerOfType(context.getCurrentModel(), ConfiguredCatalog.class);
Iterable<String> alreadyConfiguredCheckNames = Iterables.filter(Iterables.transform(configuredCatalog.getCheckConfigurations(), new Function<ConfiguredCheck, String>() {
@Override
public String apply(final ConfiguredCheck from) {
if (from.getCheck() != null) {
return from.getCheck().getName();
}
return null;
}
}), Predicates.notNull());
final CheckCatalog catalog = configuredCatalog.getCatalog();
for (final Check check : catalog.getAllChecks()) {
// create a template on the fly
final String checkName = check.getName();
if (!Iterables.contains(alreadyConfiguredCheckNames, checkName)) {
// check if referenced check has configurable parameters
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
final StringJoiner paramsJoiner = new StringJoiner(", ", " (", ")");
// $NON-NLS-1$
paramsJoiner.setEmptyValue("");
for (final FormalParameter param : check.getFormalParameters()) {
final String paramName = param.getName();
final Object defaultValue = interpreter.evaluate(param.getRight()).getResult();
final String valuePlaceholder = helper.createLiteralValuePattern(paramName, defaultValue);
// $NON-NLS-1$
paramsJoiner.add(paramName + " = " + valuePlaceholder);
}
// $NON-NLS-1$ //$NON-NLS-2$
final String severity = (catalog.isFinal() || check.isFinal()) ? "default " : "${default:Enum('SeverityKind')} ";
// $NON-NLS-1$ //$NON-NLS-2$
final String description = "Configures the check \"" + check.getLabel() + "\"";
// $NON-NLS-1$
final String contextTypeId = "com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck." + checkName;
// $NON-NLS-1$
final String pattern = severity + qualifiedNameValueConverter.toString(checkName) + paramsJoiner + "${cursor}";
Template t = new Template(checkName, description, contextTypeId, pattern, true);
TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCheck(check.getDefaultSeverity()), getRelevance(t));
acceptor.accept(tp);
}
}
}
use of com.avaloq.tools.ddk.check.check.Check in project dsl-devkit by dsldevkit.
the class XIssueExpressionImpl method setCheck.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setCheck(Check newCheck) {
Check oldCheck = check;
check = newCheck;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, CheckPackage.XISSUE_EXPRESSION__CHECK, oldCheck, check));
}
use of com.avaloq.tools.ddk.check.check.Check in project dsl-devkit by dsldevkit.
the class CheckContextsGenerator method updateContextsFile.
/**
* Update contexts file.
*
* @param uri
* the uri to the current catalog
* @param buildContext
* the context
* @throws CoreException
* the core exception
*/
public void updateContextsFile(final URI uri, final IBuildContext buildContext) throws CoreException {
IFile file = projectHelper.getHelpFile(uri, CheckContextsExtensionHelper.CONTEXTS_FILE_NAME);
CtxHelpModel model = new CtxHelpModel(CoreUtility.getTextDocument(file.getContents()), false);
model.setUnderlyingResource(file);
model.load();
CtxHelpRoot root = model.getCtxHelpRoot();
CtxHelpDocumentFactory factory = model.getFactory();
Iterable<CtxHelpContext> contexts = Iterables.filter(model.getCtxHelpRoot().getChildren(), CtxHelpContext.class);
// all context ids belonging to the catalog
Set<String> ids = Sets.newHashSet();
String contextIdPrefix = projectHelper.getCatalog(buildContext, uri).getName().toLowerCase() + "_";
for (CtxHelpContext context : contexts) {
if (context.getId().startsWith(contextIdPrefix)) {
ids.add(context.getId());
}
}
Set<String> checkIds = Sets.newHashSet();
// Add context for all checks which have been added
for (Check check : projectHelper.getCatalog(buildContext, uri).getAllChecks()) {
if (!ids.contains(generatorNaming.getContextId(check))) {
root.addChild(createContextForCheck(factory, check));
}
// all contextIds constructed of the checks of the catalog
checkIds.add(generatorNaming.getContextId(check));
}
// Remove context for checks which have been deleted.
for (String id : ids) {
if (!checkIds.contains(id)) {
for (CtxHelpContext context : contexts) {
if (context.getId().equals(id)) {
root.removeChild(context);
}
}
}
}
sortAllContexts(model);
model.save();
model.dispose();
}
use of com.avaloq.tools.ddk.check.check.Check in project dsl-devkit by dsldevkit.
the class CheckHoverProvider method getHoverInfoAsHtml.
@Override
protected String getHoverInfoAsHtml(final EObject object) {
if (!hasHover(object) || object.eIsProxy()) {
// TODO object will be proxy in CA when referencing CheckCatalogs!
return null;
}
if (object instanceof Check) {
Check check = (Check) object;
// a dispatcher would be nice
StringBuffer buffer = new StringBuffer();
buffer.append(getFirstLine(check));
appendSection(buffer, "Description", generatorExtension.formatDescription(check.getDescription()));
appendSection(buffer, "Message", generatorExtension.replacePlaceholder(check.getMessage()));
return buffer.toString();
} else if (object instanceof CheckCatalog) {
CheckCatalog catalog = (CheckCatalog) object;
StringBuffer buffer = new StringBuffer();
buffer.append(getFirstLine(catalog));
appendSection(buffer, "Description", generatorExtension.formatDescription(catalog.getDescription()));
return buffer.toString();
}
return super.getHoverInfoAsHtml(object);
}
Aggregations