Skip to content

Commit

Permalink
Make grammar reference in check language optional
Browse files Browse the repository at this point in the history
-make language attribute of validator extension point optional
-change check generator to handle absence of reference to grammar
  • Loading branch information
Mariya Abrahamyan authored and Mariya Abrahamyan committed May 14, 2018
1 parent b396e77 commit cf3014a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,21 @@ class CheckGenerator extends JvmModelGenerator {
public class «catalog.standaloneSetupClassName» implements ICheckValidatorStandaloneSetup {
private static final Logger LOG = Logger.getLogger(«catalog.standaloneSetupClassName».class);
«IF catalog.grammar !== null»
private static final String GRAMMAR_NAME = "«catalog.grammar.name»";
«ENDIF»
private static final String CATALOG_FILE_PATH = "«catalog.checkFilePath»";
/** {@inheritDoc} */
public void doSetup() {
ICheckValidatorRegistry.INSTANCE.registerValidator(GRAMMAR_NAME, new «catalog.validatorClassName»());
ICheckCatalogRegistry.INSTANCE.registerCatalog(GRAMMAR_NAME, new ModelLocation(
ICheckValidatorRegistry.INSTANCE.registerValidator(«IF catalog.grammar !== null»GRAMMAR_NAME«ELSE»null«ENDIF», new «catalog.validatorClassName»());
ICheckCatalogRegistry.INSTANCE.registerCatalog(«IF catalog.grammar !== null»GRAMMAR_NAME«ELSE»null«ENDIF», new ModelLocation(
«catalog.standaloneSetupClassName».class.getClassLoader().getResource(CATALOG_FILE_PATH), CATALOG_FILE_PATH));
LOG.info("Standalone setup done for «catalog.checkFilePath»");
}
@Override
public String toString() {
return "CheckValidatorSetupcatalog.eResource.URI.path»)";
Expand Down
8 changes: 4 additions & 4 deletions com.avaloq.tools.ddk.check.runtime.core/schema/check.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute kind="identifier"/>
Expand All @@ -40,7 +40,7 @@
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
Expand All @@ -54,7 +54,7 @@
</documentation>
</annotation>
<complexType>
<attribute name="language" type="string" use="required">
<attribute name="language" type="string">
<annotation>
<documentation>
This is the target language for which validations are defined. Corresponds to a grammar ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ private void mergeManifest(final CheckCatalog catalog, final IProgressMonitor mo
final IProject project = RuntimeProjectUtil.getProject(catalog.eResource().getURI(), mapper);
final IFile file = PDEProject.getManifest(project);

if (file.exists() && catalog != null) {
if (file.exists() && catalog != null && catalog.getGrammar() != null) {
InputStream fileContents = null;
try {
fileContents = file.getContents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.pde.core.plugin.IPluginExtension;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
Expand Down Expand Up @@ -262,18 +261,6 @@ public ExtensionType apply(final IPluginExtension from) {
}), Predicates.notNull());
}

/**
* Checks if a check catalog instance has an associated grammar.
*
* @param catalog
* the catalog
* @return {@code true} if a resolvable grammar was found
*/
private boolean hasGrammar(final CheckCatalog catalog) {
Grammar grammar = catalog.getGrammar();
return grammar != null && !grammar.eIsProxy();
}

/**
* Update check catalog extensions if necessary.
*
Expand All @@ -292,13 +279,8 @@ public void updateExtensions(final CheckCatalog catalog, final IPluginModelBase

// Update extensions as appropriate
for (IPluginExtension extension : catalogExtensions) {
if (!hasGrammar(catalog)) {
pluginModel.getPluginBase().remove(extension); // no extensions for Catalogs without valid grammar
continue; // nothing more to do if no grammar is available
} else {
for (ICheckExtensionHelper helper : getExtensionHelpers()) { // TODO getExtensionHelper using extension.getPoint() would make this more efficient
helper.updateExtension(catalog, extension);
}
for (ICheckExtensionHelper helper : getExtensionHelpers()) { // TODO getExtensionHelper using extension.getPoint() would make this more efficient
helper.updateExtension(catalog, extension);
}
}
}
Expand All @@ -320,15 +302,13 @@ public void addExtensions(final CheckCatalog catalog, final IPluginModelBase plu
Collection<IPluginExtension> catalogExtensions = findExtensions(pluginModel, catalogName, ExtensionType.ALL);
Iterable<ExtensionType> registeredExtensionTypes = findExtensionTypes(catalogExtensions);

if (hasGrammar(catalog)) {
for (ExtensionType type : ExtensionType.values()) {
ICheckExtensionHelper helper = getExtensionHelper(type);
if (helper == null) {
continue;
}
if (!Iterables.contains(registeredExtensionTypes, type)) {
helper.addExtensionToPluginBase(pluginModel, catalog, type, getExtensionId(nameProvider.apply(catalog), type));
}
for (ExtensionType type : ExtensionType.values()) {
ICheckExtensionHelper helper = getExtensionHelper(type);
if (helper == null) {
continue;
}
if (!Iterables.contains(registeredExtensionTypes, type)) {
helper.addExtensionToPluginBase(pluginModel, catalog, type, getExtensionId(nameProvider.apply(catalog), type));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ protected boolean isExtensionEnabled(final IPluginModelBase base, final CheckCat
private IPluginElement updateOnlyPluginElement(final CheckCatalog catalog, final IPluginElement element) throws CoreException {
element.setName(PROVIDER_ELEMENT_TAG);
element.setAttribute(TARGET_CLASS_ELEMENT_TAG, getTargetClassName(catalog));
element.setAttribute(LANGUAGE_ELEMENT_TAG, catalog.getGrammar().getName());
if (catalog.getGrammar() != null) {
element.setAttribute(LANGUAGE_ELEMENT_TAG, catalog.getGrammar().getName());
} else if (element.getAttribute(LANGUAGE_ELEMENT_TAG) != null) {
element.setAttribute(LANGUAGE_ELEMENT_TAG, null);
}
return element;
}

Expand Down Expand Up @@ -127,7 +131,8 @@ public boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPlug
&& (!extensionNameMatches(extension, catalog)
|| Iterables.size(elements) != 1
|| !targetClassMatches(Iterables.get(elements, 0), getTargetClassName(catalog))
|| !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName()));
|| catalog.getGrammar() == null && Iterables.get(elements, 0).getAttribute(LANGUAGE_ELEMENT_TAG) != null
|| catalog.getGrammar() != null && !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName()));
return result;
// @Format-On
// CHECKSTYLE:ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public Iterable<IPluginElement> getElements(final CheckCatalog catalog, final IP
private IPluginElement updateOnlyPluginElement(final CheckCatalog catalog, final IPluginElement element) throws CoreException {
element.setName(VALIDATOR_ELEMENT_TAG);
element.setAttribute(TARGET_CLASS_ELEMENT_TAG, getTargetClassName(catalog));
element.setAttribute(LANGUAGE_ELEMENT_TAG, catalog.getGrammar().getName());
if (catalog.getGrammar() != null) {
element.setAttribute(LANGUAGE_ELEMENT_TAG, catalog.getGrammar().getName());
} else if (element.getAttribute(LANGUAGE_ELEMENT_TAG) != null) {
element.setAttribute(LANGUAGE_ELEMENT_TAG, null);
}
element.setAttribute(CATALOG_ELEMENT_TAG, getCatalogResourceName(catalog));
return element;
}
Expand Down Expand Up @@ -119,7 +123,8 @@ public boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPlug
&& (!extensionNameMatches(extension, catalog)
|| Iterables.size(elements) != 1
|| !targetClassMatches(Iterables.get(elements, 0), getTargetClassName(catalog))
|| !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName())
|| catalog.getGrammar() == null && Iterables.get(elements, 0).getAttribute(LANGUAGE_ELEMENT_TAG) != null
|| catalog.getGrammar() != null && !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName())
);
return result;
// @Format-On
Expand Down

0 comments on commit cf3014a

Please sign in to comment.