use of com.avaloq.tools.ddk.check.check.CheckCatalog 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.CheckCatalog in project dsl-devkit by dsldevkit.
the class AbstractCheckGenerationTestCase method generateAndCompile.
/**
* Generate and compile a Check.
*
* @param sourceStream
* stream containing the Check, must not be {@code null}
* @return map of class name to compiled class, never {@code null}
*/
public Map<String, Class<?>> generateAndCompile(final InputStream sourceStream) {
Validate.notNull(sourceStream, "Argument sourceStream may not be null");
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
Resource res = resourceSet.createResource(URI.createURI("BugDsl27.check"));
try {
res.load(sourceStream, null);
} catch (IOException e) {
fail("Could not load test resource" + e.getMessage());
}
CheckCatalog root = (CheckCatalog) res.getContents().get(0);
assertNotNull("Resource should contain a CheckCatalog", root);
// We also should have some Jvm model here.
JvmType type = null;
for (EObject obj : res.getContents()) {
if (obj instanceof JvmType) {
type = (JvmType) obj;
break;
}
}
assertNotNull("Should have an inferred Jvm model", type);
// Run the generator using an in-memory file system access
InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
for (OutputConfiguration output : outputConfigurationProvider.getOutputConfigurations()) {
fsa.getOutputConfigurations().put(output.getName(), output);
}
generator.doGenerate(res, fsa);
// We now should have a number of files.
String baseName = root.getPackageName() + '.' + root.getName();
String basePath = baseName.replace('.', '/');
Map<String, String> sources = Maps.newHashMap();
for (String name : GENERATED_FILES) {
sources.put(baseName + name, fsa.readTextFile(basePath + name + ".java", IFileSystemAccess.DEFAULT_OUTPUT).toString());
}
// Compile the generated Java files. Raises an IllegalArgumentException if compilation failed.
try {
// Put together a classpath for the compiler. Since we don't know exactly what pathes would be in the transitive closure
// that eclipse computes from the plugin dependencies, and we also cannot get conveniently at the pathes used by our
// own class loader, let eclipse do the work: create our test project and then get the resolved classpath entries from
// that.
IProject project = getOrCreatePluginProject();
IResourcesSetupUtil.waitForAutoBuild();
// enumerateContents(project);
IJavaProject javaProject = JavaCore.create(project);
javaCompiler.clearClassPath();
for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) {
javaCompiler.addClassPath(entry.getPath().toString());
}
// Set our own class loader, otherwise the compiler fails. It can compile the sources, but then fails to load them,
// as the implementation only can load from its temporary folder. Alternatively, we could create our own URLClassLoader
// with all the classpathes we added above. The javaCompiler evidently is not intended to be used for sources that
// reference external classes, but only for self-contained test sets. However, we don't have that here; our
// generated classes do reference quite a few other classes.
javaCompiler.setParentClassLoader(getClass().getClassLoader());
final Map<String, Class<?>> compiledClasses = javaCompiler.compileToClasses(sources);
assertEquals("All sources should have been compiled", sources.size(), compiledClasses.size());
return compiledClasses;
// CHECKSTYLE:OFF Yes, catch anything
} catch (Exception e) {
// CHECKSTYLE:ON
fail("Java compilation failed: " + e.getMessage());
return Collections.emptyMap();
}
}
use of com.avaloq.tools.ddk.check.check.CheckCatalog in project dsl-devkit by dsldevkit.
the class CheckCatalogImpl method setIncludedCatalogs.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setIncludedCatalogs(CheckCatalog newIncludedCatalogs) {
CheckCatalog oldIncludedCatalogs = includedCatalogs;
includedCatalogs = newIncludedCatalogs;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, CheckPackage.CHECK_CATALOG__INCLUDED_CATALOGS, oldIncludedCatalogs, includedCatalogs));
}
use of com.avaloq.tools.ddk.check.check.CheckCatalog in project dsl-devkit by dsldevkit.
the class CheckMarkerHelpExtensionTest method testRemoveElement.
/**
* Tests if a marker help element is removed if the corresponding check is deleted.
*
* @throws Exception
* the exception
*/
@Test
public void testRemoveElement() throws Exception {
final CheckCatalog catalogWithTwoChecks = parser.parse(CATALOG_WITH_TWO_CHECKS);
IPluginExtension extension = createMarkerHelpExtension(catalogWithTwoChecks);
assertEquals("Original catalog has two marker help extensions", 2, extension.getChildCount());
CheckCatalog catalogWithOneCheck = parser.parse(CATALOG_WITH_SECOND_CHECK_ONDEMAND);
markerUtil.updateExtension(catalogWithOneCheck, extension);
assertEquals("Updated catalog has one marker help extension only", 1, extension.getChildCount());
assertEquals("The element for the removed check has been deleted.", SECONDCHECK_CONTEXTID, ((IPluginElement) extension.getChildren()[0]).getAttribute(CheckMarkerHelpExtensionHelper.CONTEXT_ID_ATTRIBUTE_TAG).getValue());
}
use of com.avaloq.tools.ddk.check.check.CheckCatalog in project dsl-devkit by dsldevkit.
the class CheckJavaValidator method checkCircularDependency.
/**
* Checks catalogs for circular dependencies in included catalogs. A catalog cannot include itself and may not include another catalog which includes the
* current one.
*
* @param catalog
* the catalog to be checked
*/
@Check
public void checkCircularDependency(final CheckCatalog catalog) {
if (catalog.getIncludedCatalogs() == null) {
return;
}
final Set<CheckCatalog> visitedCatalogs = Sets.newHashSet(catalog);
CheckCatalog current = catalog.getIncludedCatalogs();
while (current != null) {
if (visitedCatalogs.add(current)) {
current = current.getIncludedCatalogs();
} else {
error(Messages.CheckJavaValidator_CIRCULAR_DEPENDENCY_IN_INCLUDED_CATALOGS, catalog, CheckPackage.Literals.CHECK_CATALOG__INCLUDED_CATALOGS, IssueCodes.INCLUDED_CATALOGS_WITH_CIRCULAR_DEPENDENCIES);
break;
}
}
}
Aggregations